@vercel/remix-builder 2.0.1 → 2.0.3
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/build.js +527 -440
- package/dist/build.js.map +7 -1
- package/dist/hydrogen.js +92 -81
- package/dist/hydrogen.js.map +7 -1
- package/dist/index.js +32 -19
- package/dist/index.js.map +7 -1
- package/dist/prepare-cache.js +56 -23
- package/dist/prepare-cache.js.map +7 -1
- package/dist/utils.js +285 -301
- package/dist/utils.js.map +7 -1
- package/package.json +4 -4
package/dist/build.js
CHANGED
|
@@ -1,480 +1,567 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var build_exports = {};
|
|
20
|
+
__export(build_exports, {
|
|
21
|
+
build: () => build
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(build_exports);
|
|
24
|
+
var import_ts_morph = require("ts-morph");
|
|
25
|
+
var import_fs = require("fs");
|
|
26
|
+
var import_path = require("path");
|
|
27
|
+
var import_build_utils = require("@vercel/build-utils");
|
|
28
|
+
var import_static_config = require("@vercel/static-config");
|
|
29
|
+
var import_nft = require("@vercel/nft");
|
|
30
|
+
var import_utils = require("./utils");
|
|
31
|
+
var import_hydrogen = require("./hydrogen");
|
|
32
|
+
const remixBuilderPkg = JSON.parse(
|
|
33
|
+
(0, import_fs.readFileSync)((0, import_path.join)(__dirname, "../package.json"), "utf8")
|
|
34
|
+
);
|
|
35
|
+
const remixRunDevForkVersion = remixBuilderPkg.devDependencies["@remix-run/dev"];
|
|
36
|
+
const DEFAULTS_PATH = (0, import_path.join)(__dirname, "../defaults");
|
|
37
|
+
const edgeServerSrcPromise = import_fs.promises.readFile(
|
|
38
|
+
(0, import_path.join)(DEFAULTS_PATH, "server-edge.mjs"),
|
|
39
|
+
"utf-8"
|
|
40
|
+
);
|
|
41
|
+
const nodeServerSrcPromise = import_fs.promises.readFile(
|
|
42
|
+
(0, import_path.join)(DEFAULTS_PATH, "server-node.mjs"),
|
|
43
|
+
"utf-8"
|
|
44
|
+
);
|
|
45
|
+
const VERCEL_REMIX_MIN_VERSION = "1.10.0";
|
|
46
|
+
const REMIX_RUN_DEV_MIN_VERSION = "1.15.0";
|
|
47
|
+
const REMIX_RUN_DEV_MAX_VERSION = remixRunDevForkVersion.slice(
|
|
48
|
+
remixRunDevForkVersion.lastIndexOf("@") + 1
|
|
49
|
+
);
|
|
50
|
+
const build = async ({
|
|
51
|
+
entrypoint,
|
|
52
|
+
files,
|
|
53
|
+
workPath,
|
|
54
|
+
repoRootPath,
|
|
55
|
+
config,
|
|
56
|
+
meta = {}
|
|
57
|
+
}) => {
|
|
58
|
+
const { installCommand, buildCommand } = config;
|
|
59
|
+
await (0, import_build_utils.download)(files, workPath, meta);
|
|
60
|
+
const mountpoint = (0, import_path.dirname)(entrypoint);
|
|
61
|
+
const entrypointFsDirname = (0, import_path.join)(workPath, mountpoint);
|
|
62
|
+
const nodeVersion = await (0, import_build_utils.getNodeVersion)(
|
|
63
|
+
entrypointFsDirname,
|
|
64
|
+
void 0,
|
|
65
|
+
config,
|
|
66
|
+
meta
|
|
67
|
+
);
|
|
68
|
+
const { cliType, packageJsonPath, lockfileVersion } = await (0, import_build_utils.scanParentDirs)(
|
|
69
|
+
entrypointFsDirname
|
|
70
|
+
);
|
|
71
|
+
if (!packageJsonPath) {
|
|
72
|
+
throw new Error("Failed to locate `package.json` file in your project");
|
|
73
|
+
}
|
|
74
|
+
const pkgRaw = await import_fs.promises.readFile(packageJsonPath, "utf8");
|
|
75
|
+
const pkg = JSON.parse(pkgRaw);
|
|
76
|
+
const spawnOpts = (0, import_build_utils.getSpawnOptions)(meta, nodeVersion);
|
|
77
|
+
if (!spawnOpts.env) {
|
|
78
|
+
spawnOpts.env = {};
|
|
79
|
+
}
|
|
80
|
+
spawnOpts.env = (0, import_build_utils.getEnvForPackageManager)({
|
|
81
|
+
cliType,
|
|
82
|
+
lockfileVersion,
|
|
83
|
+
nodeVersion,
|
|
84
|
+
env: spawnOpts.env
|
|
85
|
+
});
|
|
86
|
+
if (typeof installCommand === "string") {
|
|
87
|
+
if (installCommand.trim()) {
|
|
88
|
+
console.log(`Running "install" command: \`${installCommand}\`...`);
|
|
89
|
+
await (0, import_build_utils.execCommand)(installCommand, {
|
|
90
|
+
...spawnOpts,
|
|
91
|
+
cwd: entrypointFsDirname
|
|
92
|
+
});
|
|
93
|
+
} else {
|
|
94
|
+
console.log(`Skipping "install" command...`);
|
|
34
95
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
96
|
+
} else {
|
|
97
|
+
await (0, import_build_utils.runNpmInstall)(entrypointFsDirname, [], spawnOpts, meta, nodeVersion);
|
|
98
|
+
}
|
|
99
|
+
const isHydrogen2 = pkg.dependencies?.["@shopify/remix-oxygen"] || pkg.devDependencies?.["@shopify/remix-oxygen"];
|
|
100
|
+
const remixRunDevPath = await (0, import_utils.ensureResolvable)(
|
|
101
|
+
entrypointFsDirname,
|
|
102
|
+
repoRootPath,
|
|
103
|
+
"@remix-run/dev"
|
|
104
|
+
);
|
|
105
|
+
const remixRunDevPkg = JSON.parse(
|
|
106
|
+
(0, import_fs.readFileSync)((0, import_path.join)(remixRunDevPath, "package.json"), "utf8")
|
|
107
|
+
);
|
|
108
|
+
const remixVersion = remixRunDevPkg.version;
|
|
109
|
+
const remixConfig = await (0, import_utils.chdirAndReadConfig)(
|
|
110
|
+
remixRunDevPath,
|
|
111
|
+
entrypointFsDirname,
|
|
112
|
+
packageJsonPath
|
|
113
|
+
);
|
|
114
|
+
const { serverEntryPoint, appDirectory } = remixConfig;
|
|
115
|
+
const remixRoutes = Object.values(remixConfig.routes);
|
|
116
|
+
const depsToAdd = [];
|
|
117
|
+
if (!isHydrogen2 && remixRunDevPkg.name !== "@vercel/remix-run-dev") {
|
|
118
|
+
const remixDevForkVersion = (0, import_utils.resolveSemverMinMax)(
|
|
119
|
+
REMIX_RUN_DEV_MIN_VERSION,
|
|
120
|
+
REMIX_RUN_DEV_MAX_VERSION,
|
|
121
|
+
remixVersion
|
|
122
|
+
);
|
|
123
|
+
depsToAdd.push(
|
|
124
|
+
`@remix-run/dev@npm:@vercel/remix-run-dev@${remixDevForkVersion}`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
const userEntryServerFile = (0, import_utils.findEntry)(appDirectory, "entry.server");
|
|
128
|
+
if (!userEntryServerFile) {
|
|
129
|
+
await import_fs.promises.copyFile(
|
|
130
|
+
(0, import_path.join)(DEFAULTS_PATH, "entry.server.jsx"),
|
|
131
|
+
(0, import_path.join)(appDirectory, "entry.server.jsx")
|
|
132
|
+
);
|
|
133
|
+
if (!pkg.dependencies["@vercel/remix"]) {
|
|
134
|
+
const vercelRemixVersion = (0, import_utils.resolveSemverMinMax)(
|
|
135
|
+
VERCEL_REMIX_MIN_VERSION,
|
|
136
|
+
REMIX_RUN_DEV_MAX_VERSION,
|
|
137
|
+
remixVersion
|
|
138
|
+
);
|
|
139
|
+
depsToAdd.push(`@vercel/remix@${vercelRemixVersion}`);
|
|
40
140
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
141
|
+
}
|
|
142
|
+
if (depsToAdd.length) {
|
|
143
|
+
await (0, import_utils.addDependencies)(cliType, depsToAdd, {
|
|
144
|
+
...spawnOpts,
|
|
145
|
+
cwd: entrypointFsDirname
|
|
46
146
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
// `app/entry.server.tsx` and `app/entry.client.tsx` are optional in Remix,
|
|
80
|
-
// so if either of those files are missing then add our own versions.
|
|
81
|
-
const userEntryServerFile = (0, utils_1.findEntry)(appDirectory, 'entry.server');
|
|
82
|
-
if (!userEntryServerFile) {
|
|
83
|
-
await fs_1.promises.copyFile((0, path_1.join)(DEFAULTS_PATH, 'entry.server.jsx'), (0, path_1.join)(appDirectory, 'entry.server.jsx'));
|
|
84
|
-
if (!pkg.dependencies['@vercel/remix']) {
|
|
85
|
-
// Dependency version resolution logic
|
|
86
|
-
// 1. Users app is on 1.9.0 -> we install the 1.10.0 (minimum) version of `@vercel/remix`.
|
|
87
|
-
// 2. Users app is on 1.11.0 (a version greater than 1.10.0 and less than the known max
|
|
88
|
-
// published version) -> we install the (matching) 1.11.0 version of `@vercel/remix`.
|
|
89
|
-
// 3. Users app is on something greater than our latest version of the fork -> we install
|
|
90
|
-
// the latest known published version of `@vercel/remix`.
|
|
91
|
-
const vercelRemixVersion = (0, utils_1.resolveSemverMinMax)(VERCEL_REMIX_MIN_VERSION, REMIX_RUN_DEV_MAX_VERSION, remixVersion);
|
|
92
|
-
depsToAdd.push(`@vercel/remix@${vercelRemixVersion}`);
|
|
93
|
-
}
|
|
147
|
+
}
|
|
148
|
+
const userEntryClientFile = (0, import_utils.findEntry)(
|
|
149
|
+
remixConfig.appDirectory,
|
|
150
|
+
"entry.client"
|
|
151
|
+
);
|
|
152
|
+
if (!userEntryClientFile) {
|
|
153
|
+
await import_fs.promises.copyFile(
|
|
154
|
+
(0, import_path.join)(DEFAULTS_PATH, "entry.client.react.jsx"),
|
|
155
|
+
(0, import_path.join)(appDirectory, "entry.client.jsx")
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
let remixConfigWrapped = false;
|
|
159
|
+
let serverEntryPointAbs;
|
|
160
|
+
let originalServerEntryPoint;
|
|
161
|
+
const remixConfigPath = (0, import_utils.findConfig)(entrypointFsDirname, "remix.config");
|
|
162
|
+
const renamedRemixConfigPath = remixConfigPath ? `${remixConfigPath}.original${(0, import_path.extname)(remixConfigPath)}` : void 0;
|
|
163
|
+
let serverBundles;
|
|
164
|
+
const serverBundlesMap = /* @__PURE__ */ new Map();
|
|
165
|
+
const resolvedConfigsMap = /* @__PURE__ */ new Map();
|
|
166
|
+
try {
|
|
167
|
+
const project = new import_ts_morph.Project();
|
|
168
|
+
const staticConfigsMap = /* @__PURE__ */ new Map();
|
|
169
|
+
for (const route of remixRoutes) {
|
|
170
|
+
const routePath = (0, import_path.join)(remixConfig.appDirectory, route.file);
|
|
171
|
+
let staticConfig = (0, import_static_config.getConfig)(project, routePath);
|
|
172
|
+
if (staticConfig && isHydrogen2) {
|
|
173
|
+
console.log(
|
|
174
|
+
"WARN: `export const config` is currently not supported for Hydrogen v2 apps"
|
|
175
|
+
);
|
|
176
|
+
staticConfig = null;
|
|
177
|
+
}
|
|
178
|
+
staticConfigsMap.set(route, staticConfig);
|
|
94
179
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
180
|
+
for (const route of remixRoutes) {
|
|
181
|
+
const config2 = (0, import_utils.getResolvedRouteConfig)(
|
|
182
|
+
route,
|
|
183
|
+
remixConfig.routes,
|
|
184
|
+
staticConfigsMap,
|
|
185
|
+
isHydrogen2
|
|
186
|
+
);
|
|
187
|
+
resolvedConfigsMap.set(route, config2);
|
|
100
188
|
}
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
189
|
+
for (const route of remixRoutes) {
|
|
190
|
+
if ((0, import_utils.isLayoutRoute)(route.id, remixRoutes))
|
|
191
|
+
continue;
|
|
192
|
+
const config2 = resolvedConfigsMap.get(route);
|
|
193
|
+
if (!config2) {
|
|
194
|
+
throw new Error(`Expected resolved config for "${route.id}"`);
|
|
195
|
+
}
|
|
196
|
+
const hash = (0, import_utils.calculateRouteConfigHash)(config2);
|
|
197
|
+
let routesForHash = serverBundlesMap.get(hash);
|
|
198
|
+
if (!Array.isArray(routesForHash)) {
|
|
199
|
+
routesForHash = [];
|
|
200
|
+
serverBundlesMap.set(hash, routesForHash);
|
|
201
|
+
}
|
|
202
|
+
routesForHash.push(route);
|
|
104
203
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
console.log('WARN: `export const config` is currently not supported for Hydrogen v2 apps');
|
|
125
|
-
staticConfig = null;
|
|
126
|
-
}
|
|
127
|
-
staticConfigsMap.set(route, staticConfig);
|
|
128
|
-
}
|
|
129
|
-
for (const route of remixRoutes) {
|
|
130
|
-
const config = (0, utils_1.getResolvedRouteConfig)(route, remixConfig.routes, staticConfigsMap, isHydrogen2);
|
|
131
|
-
resolvedConfigsMap.set(route, config);
|
|
132
|
-
}
|
|
133
|
-
// Figure out which routes belong to which server bundles
|
|
134
|
-
// based on having common static config properties
|
|
135
|
-
for (const route of remixRoutes) {
|
|
136
|
-
if ((0, utils_1.isLayoutRoute)(route.id, remixRoutes))
|
|
137
|
-
continue;
|
|
138
|
-
const config = resolvedConfigsMap.get(route);
|
|
139
|
-
if (!config) {
|
|
140
|
-
throw new Error(`Expected resolved config for "${route.id}"`);
|
|
141
|
-
}
|
|
142
|
-
const hash = (0, utils_1.calculateRouteConfigHash)(config);
|
|
143
|
-
let routesForHash = serverBundlesMap.get(hash);
|
|
144
|
-
if (!Array.isArray(routesForHash)) {
|
|
145
|
-
routesForHash = [];
|
|
146
|
-
serverBundlesMap.set(hash, routesForHash);
|
|
147
|
-
}
|
|
148
|
-
routesForHash.push(route);
|
|
149
|
-
}
|
|
150
|
-
serverBundles = Array.from(serverBundlesMap.entries()).map(([hash, routes]) => {
|
|
151
|
-
const runtime = resolvedConfigsMap.get(routes[0])?.runtime ?? 'nodejs';
|
|
152
|
-
return {
|
|
153
|
-
serverBuildPath: isHydrogen2
|
|
154
|
-
? (0, path_1.relative)(entrypointFsDirname, remixConfig.serverBuildPath)
|
|
155
|
-
: `${(0, path_1.relative)(entrypointFsDirname, (0, path_1.dirname)(remixConfig.serverBuildPath))}/build-${runtime}-${hash}.js`,
|
|
156
|
-
routes: routes.map(r => r.id),
|
|
157
|
-
};
|
|
158
|
-
});
|
|
159
|
-
// We need to patch the `remix.config.js` file to force some values necessary
|
|
160
|
-
// for a build that works on either Node.js or the Edge runtime
|
|
161
|
-
if (!isHydrogen2 && remixConfigPath && renamedRemixConfigPath) {
|
|
162
|
-
await fs_1.promises.rename(remixConfigPath, renamedRemixConfigPath);
|
|
163
|
-
let patchedConfig;
|
|
164
|
-
// Figure out if the `remix.config` file is using ESM syntax
|
|
165
|
-
if ((0, utils_1.isESM)(renamedRemixConfigPath)) {
|
|
166
|
-
patchedConfig = `import config from './${(0, path_1.basename)(renamedRemixConfigPath)}';
|
|
204
|
+
serverBundles = Array.from(serverBundlesMap.entries()).map(
|
|
205
|
+
([hash, routes2]) => {
|
|
206
|
+
const runtime = resolvedConfigsMap.get(routes2[0])?.runtime ?? "nodejs";
|
|
207
|
+
return {
|
|
208
|
+
serverBuildPath: isHydrogen2 ? (0, import_path.relative)(entrypointFsDirname, remixConfig.serverBuildPath) : `${(0, import_path.relative)(
|
|
209
|
+
entrypointFsDirname,
|
|
210
|
+
(0, import_path.dirname)(remixConfig.serverBuildPath)
|
|
211
|
+
)}/build-${runtime}-${hash}.js`,
|
|
212
|
+
routes: routes2.map((r) => r.id)
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
);
|
|
216
|
+
if (!isHydrogen2 && remixConfigPath && renamedRemixConfigPath) {
|
|
217
|
+
await import_fs.promises.rename(remixConfigPath, renamedRemixConfigPath);
|
|
218
|
+
let patchedConfig;
|
|
219
|
+
if ((0, import_utils.isESM)(renamedRemixConfigPath)) {
|
|
220
|
+
patchedConfig = `import config from './${(0, import_path.basename)(
|
|
221
|
+
renamedRemixConfigPath
|
|
222
|
+
)}';
|
|
167
223
|
config.serverBuildTarget = undefined;
|
|
168
224
|
config.serverModuleFormat = 'cjs';
|
|
169
225
|
config.serverPlatform = 'node';
|
|
170
226
|
config.serverBuildPath = undefined;
|
|
171
227
|
config.serverBundles = ${JSON.stringify(serverBundles)};
|
|
172
228
|
export default config;`;
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
229
|
+
} else {
|
|
230
|
+
patchedConfig = `const config = require('./${(0, import_path.basename)(
|
|
231
|
+
renamedRemixConfigPath
|
|
232
|
+
)}');
|
|
176
233
|
config.serverBuildTarget = undefined;
|
|
177
234
|
config.serverModuleFormat = 'cjs';
|
|
178
235
|
config.serverPlatform = 'node';
|
|
179
236
|
config.serverBuildPath = undefined;
|
|
180
237
|
config.serverBundles = ${JSON.stringify(serverBundles)};
|
|
181
238
|
module.exports = config;`;
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
// For Hydrogen v2, patch the `server.ts` file to be Vercel-compatible
|
|
187
|
-
if (isHydrogen2) {
|
|
188
|
-
if (remixConfig.serverEntryPoint) {
|
|
189
|
-
serverEntryPointAbs = (0, path_1.join)(entrypointFsDirname, remixConfig.serverEntryPoint);
|
|
190
|
-
originalServerEntryPoint = await fs_1.promises.readFile(serverEntryPointAbs, 'utf8');
|
|
191
|
-
const patchedServerEntryPoint = (0, hydrogen_1.patchHydrogenServer)(project, serverEntryPointAbs);
|
|
192
|
-
if (patchedServerEntryPoint) {
|
|
193
|
-
(0, build_utils_1.debug)(`Patched Hydrogen server file: ${remixConfig.serverEntryPoint}`);
|
|
194
|
-
await fs_1.promises.writeFile(serverEntryPointAbs, patchedServerEntryPoint);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
console.log('WARN: No "server" field found in Remix config');
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
// Make `remix build` output production mode
|
|
202
|
-
spawnOpts.env.NODE_ENV = 'production';
|
|
203
|
-
// Run "Build Command"
|
|
204
|
-
if (buildCommand) {
|
|
205
|
-
(0, build_utils_1.debug)(`Executing build command "${buildCommand}"`);
|
|
206
|
-
await (0, build_utils_1.execCommand)(buildCommand, {
|
|
207
|
-
...spawnOpts,
|
|
208
|
-
cwd: entrypointFsDirname,
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
if (hasScript('vercel-build', pkg)) {
|
|
213
|
-
(0, build_utils_1.debug)(`Executing "yarn vercel-build"`);
|
|
214
|
-
await (0, build_utils_1.runPackageJsonScript)(entrypointFsDirname, 'vercel-build', spawnOpts);
|
|
215
|
-
}
|
|
216
|
-
else if (hasScript('build', pkg)) {
|
|
217
|
-
(0, build_utils_1.debug)(`Executing "yarn build"`);
|
|
218
|
-
await (0, build_utils_1.runPackageJsonScript)(entrypointFsDirname, 'build', spawnOpts);
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
await (0, build_utils_1.execCommand)('remix build', {
|
|
222
|
-
...spawnOpts,
|
|
223
|
-
cwd: entrypointFsDirname,
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
}
|
|
239
|
+
}
|
|
240
|
+
await import_fs.promises.writeFile(remixConfigPath, patchedConfig);
|
|
241
|
+
remixConfigWrapped = true;
|
|
227
242
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
243
|
+
if (isHydrogen2) {
|
|
244
|
+
if (remixConfig.serverEntryPoint) {
|
|
245
|
+
serverEntryPointAbs = (0, import_path.join)(
|
|
246
|
+
entrypointFsDirname,
|
|
247
|
+
remixConfig.serverEntryPoint
|
|
248
|
+
);
|
|
249
|
+
originalServerEntryPoint = await import_fs.promises.readFile(
|
|
250
|
+
serverEntryPointAbs,
|
|
251
|
+
"utf8"
|
|
252
|
+
);
|
|
253
|
+
const patchedServerEntryPoint = (0, import_hydrogen.patchHydrogenServer)(
|
|
254
|
+
project,
|
|
255
|
+
serverEntryPointAbs
|
|
256
|
+
);
|
|
257
|
+
if (patchedServerEntryPoint) {
|
|
258
|
+
(0, import_build_utils.debug)(
|
|
259
|
+
`Patched Hydrogen server file: ${remixConfig.serverEntryPoint}`
|
|
260
|
+
);
|
|
261
|
+
await import_fs.promises.writeFile(serverEntryPointAbs, patchedServerEntryPoint);
|
|
235
262
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
.writeFile(serverEntryPointAbs, originalServerEntryPoint)
|
|
240
|
-
.then(() => (0, build_utils_1.debug)(`Restored original "${(0, path_1.basename)(serverEntryPointAbs)}" file`)));
|
|
241
|
-
}
|
|
242
|
-
await Promise.all(cleanupOps);
|
|
263
|
+
} else {
|
|
264
|
+
console.log('WARN: No "server" field found in Remix config');
|
|
265
|
+
}
|
|
243
266
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
.
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
return createRenderNodeFunction(nodeVersion, entrypointFsDirname, repoRootPath, (0, path_1.join)(entrypointFsDirname, bundle.serverBuildPath), serverEntryPoint, remixVersion, config);
|
|
267
|
-
}),
|
|
268
|
-
]);
|
|
269
|
-
const output = staticFiles;
|
|
270
|
-
const routes = [
|
|
271
|
-
{
|
|
272
|
-
src: '^/build/(.*)$',
|
|
273
|
-
headers: { 'cache-control': 'public, max-age=31536000, immutable' },
|
|
274
|
-
continue: true,
|
|
275
|
-
},
|
|
276
|
-
{
|
|
277
|
-
handle: 'filesystem',
|
|
278
|
-
},
|
|
279
|
-
];
|
|
280
|
-
for (const route of remixRoutes) {
|
|
281
|
-
// Layout routes don't get a function / route added
|
|
282
|
-
if ((0, utils_1.isLayoutRoute)(route.id, remixRoutes))
|
|
283
|
-
continue;
|
|
284
|
-
const { path, rePath } = (0, utils_1.getPathFromRoute)(route, remixConfig.routes);
|
|
285
|
-
// If the route is a pathless layout route (at the root level)
|
|
286
|
-
// and doesn't have any sub-routes, then a function should not be created.
|
|
287
|
-
if (!path) {
|
|
288
|
-
continue;
|
|
289
|
-
}
|
|
290
|
-
const funcIndex = serverBundles.findIndex(bundle => {
|
|
291
|
-
return bundle.routes.includes(route.id);
|
|
267
|
+
spawnOpts.env.NODE_ENV = "production";
|
|
268
|
+
if (buildCommand) {
|
|
269
|
+
(0, import_build_utils.debug)(`Executing build command "${buildCommand}"`);
|
|
270
|
+
await (0, import_build_utils.execCommand)(buildCommand, {
|
|
271
|
+
...spawnOpts,
|
|
272
|
+
cwd: entrypointFsDirname
|
|
273
|
+
});
|
|
274
|
+
} else {
|
|
275
|
+
if (hasScript("vercel-build", pkg)) {
|
|
276
|
+
(0, import_build_utils.debug)(`Executing "yarn vercel-build"`);
|
|
277
|
+
await (0, import_build_utils.runPackageJsonScript)(
|
|
278
|
+
entrypointFsDirname,
|
|
279
|
+
"vercel-build",
|
|
280
|
+
spawnOpts
|
|
281
|
+
);
|
|
282
|
+
} else if (hasScript("build", pkg)) {
|
|
283
|
+
(0, import_build_utils.debug)(`Executing "yarn build"`);
|
|
284
|
+
await (0, import_build_utils.runPackageJsonScript)(entrypointFsDirname, "build", spawnOpts);
|
|
285
|
+
} else {
|
|
286
|
+
await (0, import_build_utils.execCommand)("remix build", {
|
|
287
|
+
...spawnOpts,
|
|
288
|
+
cwd: entrypointFsDirname
|
|
292
289
|
});
|
|
293
|
-
|
|
294
|
-
if (!func) {
|
|
295
|
-
throw new Error(`Could not determine server bundle for "${route.id}"`);
|
|
296
|
-
}
|
|
297
|
-
output[path] =
|
|
298
|
-
func instanceof build_utils_1.EdgeFunction
|
|
299
|
-
? // `EdgeFunction` currently requires the "name" property to be set.
|
|
300
|
-
// Ideally this property will be removed, at which point we can
|
|
301
|
-
// return the same `edgeFunction` instance instead of creating a
|
|
302
|
-
// new one for each page.
|
|
303
|
-
new build_utils_1.EdgeFunction({
|
|
304
|
-
...func,
|
|
305
|
-
name: path,
|
|
306
|
-
})
|
|
307
|
-
: func;
|
|
308
|
-
// If this is a dynamic route then add a Vercel route
|
|
309
|
-
const re = (0, utils_1.getRegExpFromPath)(rePath);
|
|
310
|
-
if (re) {
|
|
311
|
-
routes.push({
|
|
312
|
-
src: re.source,
|
|
313
|
-
dest: path,
|
|
314
|
-
});
|
|
315
|
-
}
|
|
290
|
+
}
|
|
316
291
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
if (
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
292
|
+
} finally {
|
|
293
|
+
const cleanupOps = [];
|
|
294
|
+
if (remixConfigWrapped && remixConfigPath && renamedRemixConfigPath) {
|
|
295
|
+
cleanupOps.push(
|
|
296
|
+
import_fs.promises.rename(renamedRemixConfigPath, remixConfigPath).then(
|
|
297
|
+
() => (0, import_build_utils.debug)(`Restored original "${(0, import_path.basename)(remixConfigPath)}" file`)
|
|
298
|
+
)
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
if (serverEntryPointAbs && originalServerEntryPoint) {
|
|
302
|
+
cleanupOps.push(
|
|
303
|
+
import_fs.promises.writeFile(serverEntryPointAbs, originalServerEntryPoint).then(
|
|
304
|
+
() => (0, import_build_utils.debug)(`Restored original "${(0, import_path.basename)(serverEntryPointAbs)}" file`)
|
|
305
|
+
)
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
await Promise.all(cleanupOps);
|
|
309
|
+
}
|
|
310
|
+
await Promise.all([
|
|
311
|
+
(0, import_utils.ensureResolvable)(
|
|
312
|
+
entrypointFsDirname,
|
|
313
|
+
repoRootPath,
|
|
314
|
+
"@remix-run/server-runtime"
|
|
315
|
+
),
|
|
316
|
+
!isHydrogen2 ? (0, import_utils.ensureResolvable)(entrypointFsDirname, repoRootPath, "@remix-run/node") : null
|
|
317
|
+
]);
|
|
318
|
+
const staticDir = (0, import_path.join)(
|
|
319
|
+
remixConfig.assetsBuildDirectory,
|
|
320
|
+
...remixConfig.publicPath.replace(/^\/|\/$/g, "").split("/").map((_) => "..")
|
|
321
|
+
);
|
|
322
|
+
const [staticFiles, ...functions] = await Promise.all([
|
|
323
|
+
(0, import_build_utils.glob)("**", staticDir),
|
|
324
|
+
...serverBundles.map((bundle) => {
|
|
325
|
+
const firstRoute = remixConfig.routes[bundle.routes[0]];
|
|
326
|
+
const config2 = resolvedConfigsMap.get(firstRoute) ?? {
|
|
327
|
+
runtime: "nodejs"
|
|
328
|
+
};
|
|
329
|
+
if (config2.runtime === "edge") {
|
|
330
|
+
return createRenderEdgeFunction(
|
|
331
|
+
entrypointFsDirname,
|
|
332
|
+
repoRootPath,
|
|
333
|
+
(0, import_path.join)(entrypointFsDirname, bundle.serverBuildPath),
|
|
334
|
+
serverEntryPoint,
|
|
335
|
+
remixVersion,
|
|
336
|
+
config2
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
return createRenderNodeFunction(
|
|
340
|
+
nodeVersion,
|
|
341
|
+
entrypointFsDirname,
|
|
342
|
+
repoRootPath,
|
|
343
|
+
(0, import_path.join)(entrypointFsDirname, bundle.serverBuildPath),
|
|
344
|
+
serverEntryPoint,
|
|
345
|
+
remixVersion,
|
|
346
|
+
config2
|
|
347
|
+
);
|
|
348
|
+
})
|
|
349
|
+
]);
|
|
350
|
+
const output = staticFiles;
|
|
351
|
+
const routes = [
|
|
352
|
+
{
|
|
353
|
+
src: "^/build/(.*)$",
|
|
354
|
+
headers: { "cache-control": "public, max-age=31536000, immutable" },
|
|
355
|
+
continue: true
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
handle: "filesystem"
|
|
329
359
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
360
|
+
];
|
|
361
|
+
for (const route of remixRoutes) {
|
|
362
|
+
if ((0, import_utils.isLayoutRoute)(route.id, remixRoutes))
|
|
363
|
+
continue;
|
|
364
|
+
const { path, rePath } = (0, import_utils.getPathFromRoute)(route, remixConfig.routes);
|
|
365
|
+
if (!path) {
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
const funcIndex = serverBundles.findIndex((bundle) => {
|
|
369
|
+
return bundle.routes.includes(route.id);
|
|
333
370
|
});
|
|
334
|
-
|
|
371
|
+
const func = functions[funcIndex];
|
|
372
|
+
if (!func) {
|
|
373
|
+
throw new Error(`Could not determine server bundle for "${route.id}"`);
|
|
374
|
+
}
|
|
375
|
+
output[path] = func instanceof import_build_utils.EdgeFunction ? (
|
|
376
|
+
// `EdgeFunction` currently requires the "name" property to be set.
|
|
377
|
+
// Ideally this property will be removed, at which point we can
|
|
378
|
+
// return the same `edgeFunction` instance instead of creating a
|
|
379
|
+
// new one for each page.
|
|
380
|
+
new import_build_utils.EdgeFunction({
|
|
381
|
+
...func,
|
|
382
|
+
name: path
|
|
383
|
+
})
|
|
384
|
+
) : func;
|
|
385
|
+
const re = (0, import_utils.getRegExpFromPath)(rePath);
|
|
386
|
+
if (re) {
|
|
387
|
+
routes.push({
|
|
388
|
+
src: re.source,
|
|
389
|
+
dest: path
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
if (!output["404"]) {
|
|
394
|
+
const edgeFunctionIndex = Array.from(serverBundlesMap.values()).findIndex(
|
|
395
|
+
(routes2) => {
|
|
396
|
+
const runtime = resolvedConfigsMap.get(routes2[0])?.runtime;
|
|
397
|
+
return runtime === "edge";
|
|
398
|
+
}
|
|
399
|
+
);
|
|
400
|
+
const func = edgeFunctionIndex !== -1 ? functions[edgeFunctionIndex] : functions[0];
|
|
401
|
+
output["404"] = func instanceof import_build_utils.EdgeFunction ? new import_build_utils.EdgeFunction({ ...func, name: "404" }) : func;
|
|
402
|
+
}
|
|
403
|
+
routes.push({
|
|
404
|
+
src: "/(.*)",
|
|
405
|
+
dest: "/404"
|
|
406
|
+
});
|
|
407
|
+
return { routes, output, framework: { version: remixVersion } };
|
|
335
408
|
};
|
|
336
|
-
exports.build = build;
|
|
337
409
|
function hasScript(scriptName, pkg) {
|
|
338
|
-
|
|
339
|
-
|
|
410
|
+
const scripts = pkg && pkg.scripts || {};
|
|
411
|
+
return typeof scripts[scriptName] === "string";
|
|
340
412
|
}
|
|
341
413
|
async function createRenderNodeFunction(nodeVersion, entrypointDir, rootDir, serverBuildPath, serverEntryPoint, remixVersion, config) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
414
|
+
const files = {};
|
|
415
|
+
let handler = (0, import_path.relative)(rootDir, serverBuildPath);
|
|
416
|
+
let handlerPath = (0, import_path.join)(rootDir, handler);
|
|
417
|
+
if (!serverEntryPoint) {
|
|
418
|
+
const baseServerBuildPath = (0, import_path.basename)(serverBuildPath, ".js");
|
|
419
|
+
handler = (0, import_path.join)((0, import_path.dirname)(handler), `server-${baseServerBuildPath}.mjs`);
|
|
420
|
+
handlerPath = (0, import_path.join)(rootDir, handler);
|
|
421
|
+
const nodeServerSrc = await nodeServerSrcPromise;
|
|
422
|
+
await writeEntrypointFile(
|
|
423
|
+
handlerPath,
|
|
424
|
+
nodeServerSrc.replace(
|
|
425
|
+
"@remix-run/dev/server-build",
|
|
426
|
+
`./${baseServerBuildPath}.js`
|
|
427
|
+
),
|
|
428
|
+
rootDir
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
const trace = await (0, import_nft.nodeFileTrace)([handlerPath], {
|
|
432
|
+
base: rootDir,
|
|
433
|
+
processCwd: entrypointDir
|
|
434
|
+
});
|
|
435
|
+
for (const warning of trace.warnings) {
|
|
436
|
+
(0, import_build_utils.debug)(`Warning from trace: ${warning.message}`);
|
|
437
|
+
}
|
|
438
|
+
for (const file of trace.fileList) {
|
|
439
|
+
files[file] = await import_build_utils.FileFsRef.fromFsPath({ fsPath: (0, import_path.join)(rootDir, file) });
|
|
440
|
+
}
|
|
441
|
+
const fn = new import_build_utils.NodejsLambda({
|
|
442
|
+
files,
|
|
443
|
+
handler,
|
|
444
|
+
runtime: nodeVersion.runtime,
|
|
445
|
+
shouldAddHelpers: false,
|
|
446
|
+
shouldAddSourcemapSupport: false,
|
|
447
|
+
operationType: "SSR",
|
|
448
|
+
supportsResponseStreaming: true,
|
|
449
|
+
regions: config.regions,
|
|
450
|
+
memory: config.memory,
|
|
451
|
+
maxDuration: config.maxDuration,
|
|
452
|
+
framework: {
|
|
453
|
+
slug: "remix",
|
|
454
|
+
version: remixVersion
|
|
363
455
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
handler,
|
|
367
|
-
runtime: nodeVersion.runtime,
|
|
368
|
-
shouldAddHelpers: false,
|
|
369
|
-
shouldAddSourcemapSupport: false,
|
|
370
|
-
operationType: 'SSR',
|
|
371
|
-
supportsResponseStreaming: true,
|
|
372
|
-
regions: config.regions,
|
|
373
|
-
memory: config.memory,
|
|
374
|
-
maxDuration: config.maxDuration,
|
|
375
|
-
framework: {
|
|
376
|
-
slug: 'remix',
|
|
377
|
-
version: remixVersion,
|
|
378
|
-
},
|
|
379
|
-
});
|
|
380
|
-
return fn;
|
|
456
|
+
});
|
|
457
|
+
return fn;
|
|
381
458
|
}
|
|
382
459
|
async function createRenderEdgeFunction(entrypointDir, rootDir, serverBuildPath, serverEntryPoint, remixVersion, config) {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
source = JSON.stringify(pkgJson);
|
|
436
|
-
break;
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
return source;
|
|
441
|
-
},
|
|
442
|
-
});
|
|
443
|
-
for (const warning of trace.warnings) {
|
|
444
|
-
(0, build_utils_1.debug)(`Warning from trace: ${warning.message}`);
|
|
445
|
-
}
|
|
446
|
-
for (const file of trace.fileList) {
|
|
447
|
-
if (remixRunVercelPkgJson &&
|
|
448
|
-
file.endsWith(`@remix-run${path_1.sep}vercel${path_1.sep}package.json`)) {
|
|
449
|
-
// Use the modified `@remix-run/vercel` package.json which contains "browser" field
|
|
450
|
-
files[file] = new build_utils_1.FileBlob({ data: remixRunVercelPkgJson });
|
|
460
|
+
const files = {};
|
|
461
|
+
let handler = (0, import_path.relative)(rootDir, serverBuildPath);
|
|
462
|
+
let handlerPath = (0, import_path.join)(rootDir, handler);
|
|
463
|
+
if (!serverEntryPoint) {
|
|
464
|
+
const baseServerBuildPath = (0, import_path.basename)(serverBuildPath, ".js");
|
|
465
|
+
handler = (0, import_path.join)((0, import_path.dirname)(handler), `server-${baseServerBuildPath}.mjs`);
|
|
466
|
+
handlerPath = (0, import_path.join)(rootDir, handler);
|
|
467
|
+
const edgeServerSrc = await edgeServerSrcPromise;
|
|
468
|
+
await writeEntrypointFile(
|
|
469
|
+
handlerPath,
|
|
470
|
+
edgeServerSrc.replace(
|
|
471
|
+
"@remix-run/dev/server-build",
|
|
472
|
+
`./${baseServerBuildPath}.js`
|
|
473
|
+
),
|
|
474
|
+
rootDir
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
let remixRunVercelPkgJson;
|
|
478
|
+
const trace = await (0, import_nft.nodeFileTrace)([handlerPath], {
|
|
479
|
+
base: rootDir,
|
|
480
|
+
processCwd: entrypointDir,
|
|
481
|
+
conditions: ["edge-light", "browser", "module", "import", "require"],
|
|
482
|
+
async readFile(fsPath) {
|
|
483
|
+
let source;
|
|
484
|
+
try {
|
|
485
|
+
source = await import_fs.promises.readFile(fsPath);
|
|
486
|
+
} catch (err) {
|
|
487
|
+
if (err.code === "ENOENT" || err.code === "EISDIR") {
|
|
488
|
+
return null;
|
|
489
|
+
}
|
|
490
|
+
throw err;
|
|
491
|
+
}
|
|
492
|
+
if ((0, import_path.basename)(fsPath) === "package.json") {
|
|
493
|
+
const pkgJson = JSON.parse(source.toString());
|
|
494
|
+
if (pkgJson.name === "@remix-run/vercel") {
|
|
495
|
+
pkgJson.browser = "dist/edge.js";
|
|
496
|
+
pkgJson.dependencies["@remix-run/server-runtime"] = pkgJson.dependencies["@remix-run/node"];
|
|
497
|
+
if (!remixRunVercelPkgJson) {
|
|
498
|
+
remixRunVercelPkgJson = JSON.stringify(pkgJson, null, 2) + "\n";
|
|
499
|
+
const vercelEdgeEntrypointPath = (0, import_path.join)(
|
|
500
|
+
DEFAULTS_PATH,
|
|
501
|
+
"vercel-edge-entrypoint.js"
|
|
502
|
+
);
|
|
503
|
+
const vercelEdgeEntrypointDest = (0, import_path.join)(
|
|
504
|
+
(0, import_path.dirname)(fsPath),
|
|
505
|
+
"dist/edge.js"
|
|
506
|
+
);
|
|
507
|
+
await import_fs.promises.copyFile(
|
|
508
|
+
vercelEdgeEntrypointPath,
|
|
509
|
+
vercelEdgeEntrypointDest
|
|
510
|
+
);
|
|
511
|
+
}
|
|
451
512
|
}
|
|
452
|
-
|
|
453
|
-
|
|
513
|
+
for (const prop of ["browser", "module"]) {
|
|
514
|
+
const val = pkgJson[prop];
|
|
515
|
+
if (typeof val === "string") {
|
|
516
|
+
pkgJson.main = val;
|
|
517
|
+
source = JSON.stringify(pkgJson);
|
|
518
|
+
break;
|
|
519
|
+
}
|
|
454
520
|
}
|
|
521
|
+
}
|
|
522
|
+
return source;
|
|
455
523
|
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
524
|
+
});
|
|
525
|
+
for (const warning of trace.warnings) {
|
|
526
|
+
(0, import_build_utils.debug)(`Warning from trace: ${warning.message}`);
|
|
527
|
+
}
|
|
528
|
+
for (const file of trace.fileList) {
|
|
529
|
+
if (remixRunVercelPkgJson && file.endsWith(`@remix-run${import_path.sep}vercel${import_path.sep}package.json`)) {
|
|
530
|
+
files[file] = new import_build_utils.FileBlob({ data: remixRunVercelPkgJson });
|
|
531
|
+
} else {
|
|
532
|
+
files[file] = await import_build_utils.FileFsRef.fromFsPath({ fsPath: (0, import_path.join)(rootDir, file) });
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
const fn = new import_build_utils.EdgeFunction({
|
|
536
|
+
files,
|
|
537
|
+
deploymentTarget: "v8-worker",
|
|
538
|
+
name: "render",
|
|
539
|
+
entrypoint: handler,
|
|
540
|
+
regions: config.regions,
|
|
541
|
+
framework: {
|
|
542
|
+
slug: "remix",
|
|
543
|
+
version: remixVersion
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
return fn;
|
|
468
547
|
}
|
|
469
548
|
async function writeEntrypointFile(path, data, rootDir) {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
549
|
+
try {
|
|
550
|
+
await import_fs.promises.writeFile(path, data);
|
|
551
|
+
} catch (err) {
|
|
552
|
+
if (err.code === "ENOENT") {
|
|
553
|
+
throw new Error(
|
|
554
|
+
`The "${(0, import_path.relative)(
|
|
555
|
+
rootDir,
|
|
556
|
+
(0, import_path.dirname)(path)
|
|
557
|
+
)}" directory does not exist. Please contact support at https://vercel.com/help.`
|
|
558
|
+
);
|
|
478
559
|
}
|
|
560
|
+
throw err;
|
|
561
|
+
}
|
|
479
562
|
}
|
|
480
|
-
|
|
563
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
564
|
+
0 && (module.exports = {
|
|
565
|
+
build
|
|
566
|
+
});
|
|
567
|
+
//# sourceMappingURL=build.js.map
|