@shopify/cli-hydrogen 10.0.2 → 11.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/dist/assets/hydrogen/starter/.cursor/rules/hydrogen-react-router.mdc +50 -0
  2. package/dist/assets/hydrogen/starter/CHANGELOG.md +10 -14
  3. package/dist/assets/hydrogen/starter/app/components/AddToCartButton.tsx +1 -1
  4. package/dist/assets/hydrogen/starter/app/components/CartLineItem.tsx +1 -1
  5. package/dist/assets/hydrogen/starter/app/components/CartMain.tsx +1 -1
  6. package/dist/assets/hydrogen/starter/app/components/CartSummary.tsx +1 -1
  7. package/dist/assets/hydrogen/starter/app/components/Footer.tsx +1 -1
  8. package/dist/assets/hydrogen/starter/app/components/Header.tsx +1 -1
  9. package/dist/assets/hydrogen/starter/app/components/PageLayout.tsx +1 -1
  10. package/dist/assets/hydrogen/starter/app/components/ProductForm.tsx +1 -1
  11. package/dist/assets/hydrogen/starter/app/components/ProductItem.tsx +1 -1
  12. package/dist/assets/hydrogen/starter/app/components/SearchForm.tsx +1 -1
  13. package/dist/assets/hydrogen/starter/app/components/SearchFormPredictive.tsx +1 -6
  14. package/dist/assets/hydrogen/starter/app/components/SearchResults.tsx +1 -1
  15. package/dist/assets/hydrogen/starter/app/components/SearchResultsPredictive.tsx +1 -1
  16. package/dist/assets/hydrogen/starter/app/entry.client.tsx +2 -2
  17. package/dist/assets/hydrogen/starter/app/entry.server.tsx +9 -4
  18. package/dist/assets/hydrogen/starter/app/lib/variants.ts +1 -1
  19. package/dist/assets/hydrogen/starter/app/root.tsx +1 -1
  20. package/dist/assets/hydrogen/starter/app/routes/_index.tsx +1 -1
  21. package/dist/assets/hydrogen/starter/app/routes/account.addresses.tsx +1 -1
  22. package/dist/assets/hydrogen/starter/app/routes/account.orders.$id.tsx +4 -4
  23. package/dist/assets/hydrogen/starter/app/routes/account.orders._index.tsx +1 -1
  24. package/dist/assets/hydrogen/starter/app/routes/account.profile.tsx +1 -7
  25. package/dist/assets/hydrogen/starter/app/routes/account.tsx +1 -1
  26. package/dist/assets/hydrogen/starter/app/routes/api.$version.[graphql.json].tsx +14 -0
  27. package/dist/assets/hydrogen/starter/app/routes/blogs.$blogHandle.$articleHandle.tsx +1 -1
  28. package/dist/assets/hydrogen/starter/app/routes/blogs.$blogHandle._index.tsx +1 -1
  29. package/dist/assets/hydrogen/starter/app/routes/blogs._index.tsx +1 -1
  30. package/dist/assets/hydrogen/starter/app/routes/cart.tsx +7 -2
  31. package/dist/assets/hydrogen/starter/app/routes/collections.$handle.tsx +1 -1
  32. package/dist/assets/hydrogen/starter/app/routes/collections._index.tsx +1 -1
  33. package/dist/assets/hydrogen/starter/app/routes/collections.all.tsx +2 -2
  34. package/dist/assets/hydrogen/starter/app/routes/pages.$handle.tsx +1 -1
  35. package/dist/assets/hydrogen/starter/app/routes/policies.$handle.tsx +1 -1
  36. package/dist/assets/hydrogen/starter/app/routes/policies._index.tsx +1 -1
  37. package/dist/assets/hydrogen/starter/app/routes/products.$handle.tsx +1 -1
  38. package/dist/assets/hydrogen/starter/app/routes/search.tsx +1 -1
  39. package/dist/assets/hydrogen/starter/app/routes.ts +2 -2
  40. package/dist/assets/hydrogen/starter/env.d.ts +12 -2
  41. package/dist/assets/hydrogen/starter/eslint.config.js +2 -0
  42. package/dist/assets/hydrogen/starter/package.json +10 -11
  43. package/dist/assets/hydrogen/starter/react-router.config.ts +7 -0
  44. package/dist/assets/hydrogen/starter/server.ts +2 -5
  45. package/dist/assets/hydrogen/starter/tsconfig.json +18 -6
  46. package/dist/assets/hydrogen/starter/vite.config.ts +2 -23
  47. package/dist/assets/hydrogen/virtual-routes/components/RequestDetails.jsx +1 -1
  48. package/dist/assets/hydrogen/virtual-routes/layout.jsx +1 -7
  49. package/dist/assets/hydrogen/virtual-routes/routes/index.jsx +1 -1
  50. package/dist/assets/hydrogen/virtual-routes/routes/subrequest-profiler.jsx +1 -1
  51. package/dist/assets/hydrogen/virtual-routes/virtual-root-with-layout.jsx +1 -1
  52. package/dist/assets/hydrogen/virtual-routes/virtual-root.jsx +1 -1
  53. package/dist/assets/hydrogen/vite/vite.config.js +1 -1
  54. package/dist/commands/hydrogen/build.js +7 -3
  55. package/dist/commands/hydrogen/debug/cpu.js +5 -9
  56. package/dist/commands/hydrogen/deploy.js +5 -4
  57. package/dist/commands/hydrogen/dev.js +10 -17
  58. package/dist/commands/hydrogen/preview.js +16 -27
  59. package/dist/commands/hydrogen/upgrade.js +42 -0
  60. package/dist/hooks/init.js +1 -1
  61. package/dist/index.d.ts +0 -3
  62. package/dist/lib/codegen.js +17 -3
  63. package/dist/lib/flags.js +0 -6
  64. package/dist/lib/mini-oxygen/index.js +1 -6
  65. package/dist/lib/onboarding/common.js +1 -0
  66. package/dist/lib/remix-config.js +7 -132
  67. package/dist/lib/setups/routes/generate.js +2 -1
  68. package/dist/lib/vite-config.js +13 -9
  69. package/oclif.manifest.json +3 -23
  70. package/package.json +4 -4
  71. package/dist/lib/classic-compiler/build.js +0 -139
  72. package/dist/lib/classic-compiler/debug-cpu.js +0 -52
  73. package/dist/lib/classic-compiler/dev.js +0 -280
  74. package/dist/lib/virtual-routes.js +0 -49
@@ -1,280 +0,0 @@
1
- import fs from 'node:fs/promises';
2
- import { outputInfo, outputDebug } from '@shopify/cli-kit/node/output';
3
- import { fileExists } from '@shopify/cli-kit/node/fs';
4
- import { renderFatalError } from '@shopify/cli-kit/node/ui';
5
- import { relativePath, resolvePath } from '@shopify/cli-kit/node/path';
6
- import { copyPublicFiles } from './build.js';
7
- import { getProjectPaths, assertOxygenChecks, handleRemixImportFail, getRemixConfig } from '../remix-config.js';
8
- import { setH2OVerbose, isH2Verbose, muteDevLogs, createRemixLogger, enhanceH2Logs } from '../log.js';
9
- import { DEFAULT_APP_PORT } from '../flags.js';
10
- import { buildAssetsUrl, startMiniOxygen } from '../mini-oxygen/index.js';
11
- import { addVirtualRoutes } from '../virtual-routes.js';
12
- import { spawnCodegenProcess } from '../codegen.js';
13
- import { getAllEnvironmentVariables } from '../environment-variables.js';
14
- import { setupLiveReload } from '../live-reload.js';
15
- import { checkRemixVersions } from '../remix-version-check.js';
16
- import { displayDevUpgradeNotice } from '../../commands/hydrogen/upgrade.js';
17
- import { findPort } from '../find-port.js';
18
- import { getDevConfigInBackground, startTunnelAndPushConfig, isMockShop, notifyIssueWithTunnelAndMockShop } from '../dev-shared.js';
19
- import { getCliCommand } from '../shell.js';
20
- import { importLocal } from '../import-utils.js';
21
-
22
- const LOG_REBUILDING = "\u{1F9F1} Rebuilding...";
23
- const LOG_REBUILT = "\u{1F680} Rebuilt";
24
- function filterOutVirtualRoutes(config) {
25
- let routes = {};
26
- Object.entries(config.routes).forEach(([key, value]) => {
27
- if (!key.includes("virtual-routes")) {
28
- routes[key] = value;
29
- }
30
- });
31
- return {
32
- ...config,
33
- routes
34
- };
35
- }
36
- async function runClassicCompilerDev({
37
- port: appPort,
38
- path: appPath,
39
- codegen: useCodegen = false,
40
- legacyRuntime = false,
41
- codegenConfigPath,
42
- disableVirtualRoutes,
43
- env: envHandle,
44
- envBranch,
45
- debug = false,
46
- sourcemap = true,
47
- disableVersionCheck = false,
48
- inspectorPort,
49
- customerAccountPush: customerAccountPushFlag = false,
50
- shouldLiveReload = true,
51
- envFile,
52
- cliConfig,
53
- verbose
54
- }) {
55
- if (!process.env.NODE_ENV) process.env.NODE_ENV = "development";
56
- if (verbose) setH2OVerbose();
57
- if (!isH2Verbose()) muteDevLogs();
58
- const { root, publicPath, buildPathClient, buildPathWorkerFile } = getProjectPaths(appPath);
59
- const copyFilesPromise = copyPublicFiles(publicPath, buildPathClient);
60
- const cliCommandPromise = getCliCommand(root);
61
- const reloadConfig = async () => {
62
- const config = await getRemixConfig(root);
63
- return disableVirtualRoutes ? filterOutVirtualRoutes(config) : addVirtualRoutes(config).catch((error) => {
64
- outputDebug(
65
- "Could not add virtual routes: " + (error?.stack ?? error?.message ?? error)
66
- );
67
- return config;
68
- });
69
- };
70
- const getFilePaths = (file) => {
71
- const fileRelative = relativePath(root, file);
72
- return [fileRelative, resolvePath(root, fileRelative)];
73
- };
74
- const serverBundleExists = () => fileExists(buildPathWorkerFile);
75
- if (!appPort) {
76
- appPort = await findPort(DEFAULT_APP_PORT);
77
- }
78
- const assetsPort = legacyRuntime ? 0 : await findPort(appPort + 100);
79
- if (assetsPort) {
80
- process.env.HYDROGEN_ASSET_BASE_URL = await buildAssetsUrl(
81
- assetsPort,
82
- root
83
- );
84
- }
85
- const backgroundPromise = getDevConfigInBackground(
86
- root,
87
- customerAccountPushFlag,
88
- envFile
89
- );
90
- const tunnelPromise = cliConfig && backgroundPromise.then(({ customerAccountPush, storefrontId }) => {
91
- if (customerAccountPush) {
92
- return startTunnelAndPushConfig(
93
- root,
94
- cliConfig,
95
- appPort,
96
- storefrontId
97
- );
98
- }
99
- });
100
- const remixConfig = await reloadConfig();
101
- assertOxygenChecks(remixConfig);
102
- const envPromise = backgroundPromise.then(
103
- ({ fetchRemote, localVariables }) => getAllEnvironmentVariables({
104
- root,
105
- fetchRemote,
106
- envBranch,
107
- envHandle,
108
- localVariables,
109
- envFile
110
- })
111
- );
112
- const [{ watch }, { createFileWatchCache }] = await Promise.all([
113
- importLocal("@remix-run/dev/dist/compiler/watch.js", root),
114
- importLocal(
115
- "@remix-run/dev/dist/compiler/fileWatchCache.js",
116
- root
117
- )
118
- ]).catch(handleRemixImportFail);
119
- let isInitialBuild = true;
120
- let initialBuildDurationMs = 0;
121
- let initialBuildStartTimeMs = Date.now();
122
- const liveReload = shouldLiveReload ? await setupLiveReload(remixConfig.dev?.port ?? 8002, root) : void 0;
123
- let miniOxygen;
124
- let codegenProcess;
125
- async function safeStartMiniOxygen() {
126
- if (miniOxygen) return;
127
- const { allVariables, logInjectedVariables } = await envPromise;
128
- miniOxygen = await startMiniOxygen(
129
- {
130
- root,
131
- debug,
132
- appPort,
133
- assetsPort,
134
- inspectorPort,
135
- watch: !liveReload,
136
- buildPathWorkerFile,
137
- buildPathClient,
138
- env: allVariables
139
- },
140
- legacyRuntime
141
- );
142
- logInjectedVariables();
143
- const host = (await tunnelPromise)?.host ?? miniOxygen.listeningAt;
144
- const cliCommand = await cliCommandPromise;
145
- enhanceH2Logs({ host, cliCommand, ...remixConfig });
146
- const { storefrontTitle } = await backgroundPromise;
147
- miniOxygen.showBanner({
148
- appName: storefrontTitle,
149
- headlinePrefix: initialBuildDurationMs > 0 ? `Initial build: ${initialBuildDurationMs}ms
150
- ` : "",
151
- host
152
- });
153
- if (useCodegen) {
154
- codegenProcess = spawnCodegenProcess({
155
- ...remixConfig,
156
- configFilePath: codegenConfigPath
157
- });
158
- }
159
- checkRemixVersions(root);
160
- if (!disableVersionCheck) {
161
- displayDevUpgradeNotice({ targetPath: appPath });
162
- }
163
- if (customerAccountPushFlag && isMockShop(allVariables)) {
164
- notifyIssueWithTunnelAndMockShop(cliCommand);
165
- }
166
- }
167
- const fileWatchCache = createFileWatchCache();
168
- let skipRebuildLogs = false;
169
- const closeWatcher = await watch(
170
- {
171
- config: remixConfig,
172
- options: {
173
- mode: process.env.NODE_ENV,
174
- sourcemap
175
- },
176
- fileWatchCache,
177
- logger: createRemixLogger()
178
- },
179
- {
180
- reloadConfig,
181
- onBuildStart(ctx) {
182
- if (!isInitialBuild && !skipRebuildLogs) {
183
- outputInfo(LOG_REBUILDING);
184
- console.time(LOG_REBUILT);
185
- }
186
- liveReload?.onBuildStart(ctx);
187
- },
188
- onBuildManifest: liveReload?.onBuildManifest,
189
- async onBuildFinish(context, duration, succeeded) {
190
- if (isInitialBuild) {
191
- await copyFilesPromise;
192
- initialBuildDurationMs = Date.now() - initialBuildStartTimeMs;
193
- isInitialBuild = false;
194
- } else if (!skipRebuildLogs) {
195
- skipRebuildLogs = false;
196
- console.timeEnd(LOG_REBUILT);
197
- if (!miniOxygen) console.log("");
198
- }
199
- if (!miniOxygen && !await serverBundleExists()) {
200
- return renderFatalError({
201
- name: "BuildError",
202
- type: 0,
203
- message: "MiniOxygen cannot start because the server bundle has not been generated.",
204
- skipOclifErrorHandling: true,
205
- tryMessage: "This is likely due to an error in your app and Remix is unable to compile. Try fixing the app and MiniOxygen will start."
206
- });
207
- }
208
- if (succeeded) {
209
- if (!miniOxygen) {
210
- await safeStartMiniOxygen();
211
- } else if (liveReload) {
212
- await miniOxygen.reload();
213
- }
214
- liveReload?.onAppReady(context);
215
- }
216
- },
217
- async onFileCreated(file) {
218
- const [relative, absolute] = getFilePaths(file);
219
- outputInfo(`
220
- \u{1F4C4} File created: ${relative}`);
221
- if (absolute.startsWith(publicPath)) {
222
- await copyPublicFiles(
223
- absolute,
224
- absolute.replace(publicPath, buildPathClient)
225
- );
226
- }
227
- },
228
- async onFileChanged(file) {
229
- fileWatchCache.invalidateFile(file);
230
- const [relative, absolute] = getFilePaths(file);
231
- outputInfo(`
232
- \u{1F4C4} File changed: ${relative}`);
233
- if (relative.endsWith(envFile)) {
234
- skipRebuildLogs = true;
235
- const { fetchRemote } = await backgroundPromise;
236
- const { allVariables, logInjectedVariables } = await getAllEnvironmentVariables({
237
- root,
238
- fetchRemote,
239
- envBranch,
240
- envHandle,
241
- envFile
242
- });
243
- logInjectedVariables();
244
- await miniOxygen.reload({
245
- env: allVariables
246
- });
247
- }
248
- if (absolute.startsWith(publicPath)) {
249
- await copyPublicFiles(
250
- absolute,
251
- absolute.replace(publicPath, buildPathClient)
252
- );
253
- }
254
- },
255
- async onFileDeleted(file) {
256
- fileWatchCache.invalidateFile(file);
257
- const [relative, absolute] = getFilePaths(file);
258
- outputInfo(`
259
- \u{1F4C4} File deleted: ${relative}`);
260
- if (absolute.startsWith(publicPath)) {
261
- await fs.unlink(absolute.replace(publicPath, buildPathClient));
262
- }
263
- }
264
- }
265
- );
266
- return {
267
- getUrl: () => miniOxygen.listeningAt,
268
- async close() {
269
- codegenProcess?.removeAllListeners("close");
270
- codegenProcess?.kill("SIGINT");
271
- await Promise.allSettled([
272
- closeWatcher(),
273
- miniOxygen?.close(),
274
- Promise.resolve(tunnelPromise).then((tunnel) => tunnel?.cleanup?.())
275
- ]);
276
- }
277
- };
278
- }
279
-
280
- export { runClassicCompilerDev };
@@ -1,49 +0,0 @@
1
- import { glob } from '@shopify/cli-kit/node/fs';
2
- import { joinPath, relativePath } from '@shopify/cli-kit/node/path';
3
- import { hydrogenPackagesPath, getAssetsDir } from './build.js';
4
-
5
- const VIRTUAL_ROUTES_DIR = "virtual-routes/routes";
6
- const VIRTUAL_ROOT = "virtual-routes/virtual-root";
7
- async function addVirtualRoutes(config) {
8
- const distPath = process.env.SHOPIFY_UNIT_TEST && hydrogenPackagesPath ? joinPath(hydrogenPackagesPath, "hydrogen", "src", "vite") : await getAssetsDir();
9
- const userRouteList = Object.values(config.routes);
10
- const virtualRoutesPath = joinPath(distPath, VIRTUAL_ROUTES_DIR);
11
- for (const absoluteFilePath of await glob(
12
- joinPath(virtualRoutesPath, "**", "*")
13
- )) {
14
- const relativeFilePath = relativePath(virtualRoutesPath, absoluteFilePath);
15
- const routePath = relativeFilePath.replace(/\.[jt]sx?$/, "").replaceAll("\\", "/");
16
- const isIndex = /(^|\/)index$/.test(routePath);
17
- const normalizedVirtualRoutePath = isIndex ? routePath.slice(0, -"index".length).replace(/\/$/, "") || void 0 : (
18
- // TODO: support v2 flat routes?
19
- routePath.replace(/\$/g, ":").replace(/[\[\]]/g, "")
20
- );
21
- const hasUserRoute = userRouteList.some(
22
- (r) => r.parentId === "root" && r.path === normalizedVirtualRoutePath
23
- );
24
- if (!hasUserRoute) {
25
- const id = VIRTUAL_ROUTES_DIR + "/" + routePath;
26
- config.routes[id] = {
27
- id,
28
- parentId: VIRTUAL_ROOT,
29
- path: normalizedVirtualRoutePath,
30
- index: isIndex || void 0,
31
- caseSensitive: void 0,
32
- file: relativePath(config.appDirectory, absoluteFilePath)
33
- };
34
- if (!config.routes[VIRTUAL_ROOT]) {
35
- config.routes[VIRTUAL_ROOT] = {
36
- id: VIRTUAL_ROOT,
37
- path: "",
38
- file: relativePath(
39
- config.appDirectory,
40
- joinPath(distPath, VIRTUAL_ROOT + ".jsx")
41
- )
42
- };
43
- }
44
- }
45
- }
46
- return config;
47
- }
48
-
49
- export { VIRTUAL_ROOT, VIRTUAL_ROUTES_DIR, addVirtualRoutes };