@shopify/cli-hydrogen 5.3.0 → 5.3.1

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.
@@ -1,6 +1,6 @@
1
1
  import { Flags } from '@oclif/core';
2
2
  import Command from '@shopify/cli-kit/node/base-command';
3
- import { outputInfo, outputContent, outputToken, outputWarn } from '@shopify/cli-kit/node/output';
3
+ import { outputInfo, outputWarn, outputContent, outputToken } from '@shopify/cli-kit/node/output';
4
4
  import { rmdir, fileSize, fileExists, copyFile } from '@shopify/cli-kit/node/fs';
5
5
  import { resolvePath, relativePath } from '@shopify/cli-kit/node/path';
6
6
  import { getPackageManager } from '@shopify/cli-kit/node/node-package-manager';
@@ -11,7 +11,7 @@ import { checkLockfileStatus } from '../../lib/check-lockfile.js';
11
11
  import { findMissingRoutes } from '../../lib/missing-routes.js';
12
12
  import { muteRemixLogs, createRemixLogger } from '../../lib/log.js';
13
13
  import { codegen } from '../../lib/codegen.js';
14
- import { buildBundleAnalysis, getBundleAnalysisSummary } from '../../lib/bundle/analyzer.js';
14
+ import { hasMetafile, buildBundleAnalysis, getBundleAnalysisSummary } from '../../lib/bundle/analyzer.js';
15
15
  import { AbortError } from '@shopify/cli-kit/node/error';
16
16
 
17
17
  const LOG_WORKER_BUILT = "\u{1F4E6} Worker built";
@@ -104,35 +104,21 @@ async function runBuild({
104
104
  if (process.env.NODE_ENV !== "development") {
105
105
  console.timeEnd(LOG_WORKER_BUILT);
106
106
  const sizeMB = await fileSize(buildPathWorkerFile) / (1024 * 1024);
107
- const bundleAnalysisPath = await buildBundleAnalysis(buildPath);
108
- outputInfo(
109
- outputContent` ${colors.dim(
110
- relativePath(root, buildPathWorkerFile)
111
- )} ${outputToken.link(
112
- colors.yellow(sizeMB.toFixed(2) + " MB"),
113
- bundleAnalysisPath
114
- )}\n`
115
- );
116
- if (bundleStats && sizeMB < MAX_WORKER_BUNDLE_SIZE) {
117
- outputInfo(
118
- outputContent`${await getBundleAnalysisSummary(buildPathWorkerFile) || "\n"}\n │\n └─── ${outputToken.link(
119
- "Complete analysis: " + bundleAnalysisPath,
120
- bundleAnalysisPath
121
- )}\n\n`
107
+ if (await hasMetafile(buildPath)) {
108
+ await writeBundleAnalysis(
109
+ buildPath,
110
+ root,
111
+ buildPathWorkerFile,
112
+ sizeMB,
113
+ bundleStats,
114
+ remixConfig
122
115
  );
123
- }
124
- if (sizeMB >= MAX_WORKER_BUNDLE_SIZE) {
125
- throw new AbortError(
126
- "\u{1F6A8} Worker bundle exceeds 10 MB! Oxygen has a maximum worker bundle size of 10 MB.",
127
- outputContent`See the bundle analysis for a breakdown of what is contributing to the bundle size:\n${outputToken.link(
128
- bundleAnalysisPath,
129
- bundleAnalysisPath
130
- )}`
131
- );
132
- } else if (sizeMB >= 5) {
133
- outputWarn(
134
- `\u{1F6A8} Worker bundle exceeds 5 MB! This can delay your worker response.${remixConfig.serverMinify ? "" : " Minify your bundle by adding `serverMinify: true` to remix.config.js."}
135
- `
116
+ } else {
117
+ await writeSimpleBuildStatus(
118
+ root,
119
+ buildPathWorkerFile,
120
+ sizeMB,
121
+ remixConfig
136
122
  );
137
123
  }
138
124
  }
@@ -153,6 +139,56 @@ This build is missing ${missingRoutes.length} route${missingRoutes.length > 1 ?
153
139
  process.exit(0);
154
140
  }
155
141
  }
142
+ async function writeBundleAnalysis(buildPath, root, buildPathWorkerFile, sizeMB, bundleStats, remixConfig) {
143
+ const bundleAnalysisPath = await buildBundleAnalysis(buildPath);
144
+ outputInfo(
145
+ outputContent` ${colors.dim(
146
+ relativePath(root, buildPathWorkerFile)
147
+ )} ${outputToken.link(
148
+ colors.yellow(sizeMB.toFixed(2) + " MB"),
149
+ bundleAnalysisPath
150
+ )}\n`
151
+ );
152
+ if (bundleStats && sizeMB < MAX_WORKER_BUNDLE_SIZE) {
153
+ outputInfo(
154
+ outputContent`${await getBundleAnalysisSummary(buildPathWorkerFile) || "\n"}\n │\n └─── ${outputToken.link(
155
+ "Complete analysis: " + bundleAnalysisPath,
156
+ bundleAnalysisPath
157
+ )}\n\n`
158
+ );
159
+ }
160
+ if (sizeMB >= MAX_WORKER_BUNDLE_SIZE) {
161
+ throw new AbortError(
162
+ "\u{1F6A8} Worker bundle exceeds 10 MB! Oxygen has a maximum worker bundle size of 10 MB.",
163
+ outputContent`See the bundle analysis for a breakdown of what is contributing to the bundle size:\n${outputToken.link(
164
+ bundleAnalysisPath,
165
+ bundleAnalysisPath
166
+ )}`
167
+ );
168
+ } else if (sizeMB >= 5) {
169
+ outputWarn(
170
+ `\u{1F6A8} Worker bundle exceeds 5 MB! This can delay your worker response.${remixConfig.serverMinify ? "" : " Minify your bundle by adding `serverMinify: true` to remix.config.js."}
171
+ `
172
+ );
173
+ }
174
+ }
175
+ async function writeSimpleBuildStatus(root, buildPathWorkerFile, sizeMB, remixConfig) {
176
+ outputInfo(
177
+ outputContent` ${colors.dim(
178
+ relativePath(root, buildPathWorkerFile)
179
+ )} ${colors.yellow(sizeMB.toFixed(2) + " MB")}\n`
180
+ );
181
+ if (sizeMB >= MAX_WORKER_BUNDLE_SIZE) {
182
+ throw new AbortError(
183
+ "\u{1F6A8} Worker bundle exceeds 10 MB! Oxygen has a maximum worker bundle size of 10 MB."
184
+ );
185
+ } else if (sizeMB >= 5) {
186
+ outputWarn(
187
+ `\u{1F6A8} Worker bundle exceeds 5 MB! This can delay your worker response.${remixConfig.serverMinify ? "" : " Minify your bundle by adding `serverMinify: true` to remix.config.js."}
188
+ `
189
+ );
190
+ }
191
+ }
156
192
  async function copyPublicFiles(publicPath, buildPathClient) {
157
193
  if (!await fileExists(publicPath)) {
158
194
  return;
@@ -15,7 +15,7 @@
15
15
  "dependencies": {
16
16
  "@remix-run/react": "1.19.1",
17
17
  "@shopify/cli": "3.49.2",
18
- "@shopify/cli-hydrogen": "^5.3.0",
18
+ "@shopify/cli-hydrogen": "^5.3.1",
19
19
  "@shopify/hydrogen": "^2023.7.8",
20
20
  "@shopify/remix-oxygen": "^1.1.4",
21
21
  "graphql": "^16.6.0",
@@ -1,8 +1,14 @@
1
1
  import { joinPath, dirname } from '@shopify/cli-kit/node/path';
2
2
  import { fileURLToPath } from 'node:url';
3
- import { readFile, writeFile } from '@shopify/cli-kit/node/fs';
3
+ import { fileExists, readFile, writeFile } from '@shopify/cli-kit/node/fs';
4
4
  import colors from '@shopify/cli-kit/node/colors';
5
5
 
6
+ async function hasMetafile(buildPath) {
7
+ return (await Promise.all([
8
+ fileExists(joinPath(buildPath, "worker", "metafile.server.json")),
9
+ fileExists(joinPath(buildPath, "worker", "metafile.js.json"))
10
+ ])).every(Boolean);
11
+ }
6
12
  async function buildBundleAnalysis(buildPath) {
7
13
  await Promise.all([
8
14
  writeBundleAnalyzerFile(
@@ -46,11 +52,11 @@ async function getBundleAnalysisSummary(bundlePath) {
46
52
  color: true
47
53
  })).split("\n").filter((line) => {
48
54
  const match = line.match(
49
- /(.*)\/node_modules\/(react-dom|@remix-run|@shopify\/hydrogen|react-router|react-router-dom)\/(.*)/g
55
+ /(.*)(node_modules\/|server-assets-manifest:|server-entry-module:)(react-dom|@remix-run|@shopify\/hydrogen|react-router|react-router-dom)\/(.*)/g
50
56
  );
51
57
  return !match;
52
58
  }).slice(2, 12).join("\n").replace(/dist\/worker\/_assets\/.*$/ms, "\n").replace(/\n/g, "\n ").replace(/(\.\.\/)+node_modules\//g, (match) => colors.dim(match));
53
59
  }
54
60
  }
55
61
 
56
- export { buildBundleAnalysis, getBundleAnalysisSummary };
62
+ export { buildBundleAnalysis, getBundleAnalysisSummary, hasMetafile };
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.3.0",
2
+ "version": "5.3.1",
3
3
  "commands": {
4
4
  "hydrogen:build": {
5
5
  "id": "hydrogen:build",
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public",
5
5
  "@shopify:registry": "https://registry.npmjs.org"
6
6
  },
7
- "version": "5.3.0",
7
+ "version": "5.3.1",
8
8
  "license": "MIT",
9
9
  "type": "module",
10
10
  "scripts": {