@shopify/cli-hydrogen 5.1.0 → 5.1.2
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.
- package/dist/commands/hydrogen/build.js +11 -8
- package/dist/commands/hydrogen/check.js +3 -3
- package/dist/commands/hydrogen/codegen-unstable.js +4 -4
- package/dist/commands/hydrogen/dev.js +12 -6
- package/dist/commands/hydrogen/init.test.js +197 -51
- package/dist/commands/hydrogen/preview.js +1 -1
- package/dist/commands/hydrogen/setup/css.js +1 -1
- package/dist/commands/hydrogen/setup/markets.js +1 -1
- package/dist/commands/hydrogen/setup.js +3 -3
- package/dist/commands/hydrogen/setup.test.js +62 -0
- package/dist/generator-templates/starter/app/root.tsx +7 -13
- package/dist/generator-templates/starter/app/styles/app.css +1 -1
- package/dist/generator-templates/starter/package.json +7 -7
- package/dist/lib/file.test.js +4 -5
- package/dist/lib/log.js +32 -1
- package/dist/lib/onboarding/remote.js +8 -3
- package/dist/lib/remix-config.js +135 -0
- package/dist/lib/remix-version-check.js +51 -0
- package/dist/lib/remix-version-check.test.js +38 -0
- package/dist/lib/remix-version-interop.js +2 -2
- package/dist/lib/remix-version-interop.test.js +1 -1
- package/dist/lib/setups/routes/generate.js +1 -1
- package/dist/lib/setups/routes/generate.test.js +12 -13
- package/oclif.manifest.json +1 -1
- package/package.json +10 -11
- package/dist/lib/config.js +0 -141
package/dist/lib/config.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { renderFatalError } from '@shopify/cli-kit/node/ui';
|
|
2
|
-
import { outputWarn } from '@shopify/cli-kit/node/output';
|
|
3
|
-
import { fileExists } from '@shopify/cli-kit/node/fs';
|
|
4
|
-
import { fileURLToPath } from 'url';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
import fs from 'fs/promises';
|
|
7
|
-
|
|
8
|
-
const BUILD_DIR = "dist";
|
|
9
|
-
const CLIENT_SUBDIR = "client";
|
|
10
|
-
const WORKER_SUBDIR = "worker";
|
|
11
|
-
const oxygenServerMainFields = ["browser", "module", "main"];
|
|
12
|
-
function getProjectPaths(appPath, entry) {
|
|
13
|
-
const root = appPath ?? process.cwd();
|
|
14
|
-
const publicPath = path.join(root, "public");
|
|
15
|
-
const buildPath = path.join(root, BUILD_DIR);
|
|
16
|
-
const buildPathClient = path.join(buildPath, CLIENT_SUBDIR);
|
|
17
|
-
const buildPathWorkerFile = path.join(buildPath, WORKER_SUBDIR, "index.js");
|
|
18
|
-
return {
|
|
19
|
-
root,
|
|
20
|
-
buildPath,
|
|
21
|
-
buildPathClient,
|
|
22
|
-
buildPathWorkerFile,
|
|
23
|
-
publicPath
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
async function getRemixConfig(root, skipOxygenChecks = false, mode = process.env.NODE_ENV) {
|
|
27
|
-
const { readConfig } = await import('@remix-run/dev/dist/config.js');
|
|
28
|
-
const config = await readConfig(root, mode);
|
|
29
|
-
if (!skipOxygenChecks) {
|
|
30
|
-
if (!config.serverEntryPoint) {
|
|
31
|
-
throwConfigError(
|
|
32
|
-
"Could not find a server entry point.",
|
|
33
|
-
"Please add a server option to your remix.config.js pointing to an Oxygen worker entry file."
|
|
34
|
-
);
|
|
35
|
-
} else {
|
|
36
|
-
assertEntryFileExists(config.rootDirectory, config.serverEntryPoint);
|
|
37
|
-
}
|
|
38
|
-
if (config.serverPlatform !== "neutral") {
|
|
39
|
-
throwConfigError(
|
|
40
|
-
'The serverPlatform in remix.config.js must be "neutral".'
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
if (config.serverModuleFormat !== "esm") {
|
|
44
|
-
throwConfigError(
|
|
45
|
-
'The serverModuleFormat in remix.config.js must be "esm".'
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
if (config.serverDependenciesToBundle !== "all") {
|
|
49
|
-
throwConfigError(
|
|
50
|
-
'The serverDependenciesToBundle in remix.config.js must be "all".'
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
if (!config.serverConditions?.includes("worker")) {
|
|
54
|
-
throwConfigError(
|
|
55
|
-
'The serverConditions in remix.config.js must include "worker".'
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
if (process.env.NODE_ENV === "development" && !config.serverConditions?.includes("development")) {
|
|
59
|
-
outputWarn(
|
|
60
|
-
"Add `process.env.NODE_ENV` value to serverConditions in remix.config.js to enable debugging features in development."
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
if (!config.serverMainFields || !oxygenServerMainFields.every(
|
|
64
|
-
(v, i) => config.serverMainFields?.[i] === v
|
|
65
|
-
)) {
|
|
66
|
-
throwConfigError(
|
|
67
|
-
`The serverMainFields in remix.config.js must be ${JSON.stringify(
|
|
68
|
-
oxygenServerMainFields
|
|
69
|
-
)}.`
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
const cdnUrl = process.env.HYDROGEN_ASSET_BASE_URL;
|
|
73
|
-
if (cdnUrl && !config.publicPath.startsWith(cdnUrl)) {
|
|
74
|
-
throwConfigError(
|
|
75
|
-
"The publicPath in remix.config.js must be prepended with the value of `process.env.HYDROGEN_ASSET_BASE_URL`."
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
const expectedServerBuildPath = path.join(
|
|
79
|
-
BUILD_DIR,
|
|
80
|
-
WORKER_SUBDIR,
|
|
81
|
-
"index.js"
|
|
82
|
-
);
|
|
83
|
-
if (config.serverBuildPath !== path.resolve(root, expectedServerBuildPath)) {
|
|
84
|
-
throwConfigError(
|
|
85
|
-
`The serverBuildPath in remix.config.js must be "${expectedServerBuildPath}".`
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
const expectedAssetsBuildDirectory = path.join(BUILD_DIR, CLIENT_SUBDIR);
|
|
89
|
-
if (!config.assetsBuildDirectory.startsWith(
|
|
90
|
-
path.resolve(root, expectedAssetsBuildDirectory)
|
|
91
|
-
)) {
|
|
92
|
-
throwConfigError(
|
|
93
|
-
`The assetsBuildDirectory in remix.config.js must be in "${expectedAssetsBuildDirectory}".`
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (process.env.LOCAL_DEV) {
|
|
98
|
-
const packagesPath = fileURLToPath(new URL("../../..", import.meta.url));
|
|
99
|
-
config.watchPaths ??= [];
|
|
100
|
-
config.watchPaths.push(
|
|
101
|
-
...(await fs.readdir(packagesPath)).map(
|
|
102
|
-
(pkg) => pkg === "hydrogen-react" ? path.resolve(packagesPath, pkg, "dist", "browser-dev", "index.mjs") : path.resolve(packagesPath, pkg, "dist", "development", "index.js")
|
|
103
|
-
)
|
|
104
|
-
);
|
|
105
|
-
config.watchPaths.push(
|
|
106
|
-
path.join(packagesPath, "cli", "dist", "virtual-routes", "**", "*")
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
return config;
|
|
110
|
-
}
|
|
111
|
-
function throwConfigError(message, tryMessage = null) {
|
|
112
|
-
renderFatalError({
|
|
113
|
-
name: "ConfigError",
|
|
114
|
-
type: 0,
|
|
115
|
-
message,
|
|
116
|
-
tryMessage
|
|
117
|
-
});
|
|
118
|
-
process.exit(1);
|
|
119
|
-
}
|
|
120
|
-
async function assertEntryFileExists(root, fileRelative) {
|
|
121
|
-
const fileAbsolute = path.resolve(root, fileRelative);
|
|
122
|
-
const exists = await fileExists(fileAbsolute);
|
|
123
|
-
if (!exists) {
|
|
124
|
-
if (!path.extname(fileAbsolute)) {
|
|
125
|
-
const { readdir } = await import('fs/promises');
|
|
126
|
-
const files = await readdir(path.dirname(fileAbsolute));
|
|
127
|
-
const exists2 = files.some((file) => {
|
|
128
|
-
const { name, ext } = path.parse(file);
|
|
129
|
-
return name === path.basename(fileAbsolute) && /^\.[jt]s$/.test(ext);
|
|
130
|
-
});
|
|
131
|
-
if (exists2)
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
throwConfigError(
|
|
135
|
-
`Entry file "${fileRelative}" not found.`,
|
|
136
|
-
"Please ensure the file exists and that the path is correctly added to the `server` property in remix.config.js."
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export { assertEntryFileExists, getProjectPaths, getRemixConfig };
|