@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 CHANGED
@@ -1,480 +1,567 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.build = void 0;
4
- const ts_morph_1 = require("ts-morph");
5
- const fs_1 = require("fs");
6
- const path_1 = require("path");
7
- const build_utils_1 = require("@vercel/build-utils");
8
- const static_config_1 = require("@vercel/static-config");
9
- const nft_1 = require("@vercel/nft");
10
- const utils_1 = require("./utils");
11
- const hydrogen_1 = require("./hydrogen");
12
- const remixBuilderPkg = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../package.json'), 'utf8'));
13
- const remixRunDevForkVersion = remixBuilderPkg.devDependencies['@remix-run/dev'];
14
- const DEFAULTS_PATH = (0, path_1.join)(__dirname, '../defaults');
15
- const edgeServerSrcPromise = fs_1.promises.readFile((0, path_1.join)(DEFAULTS_PATH, 'server-edge.mjs'), 'utf-8');
16
- const nodeServerSrcPromise = fs_1.promises.readFile((0, path_1.join)(DEFAULTS_PATH, 'server-node.mjs'), 'utf-8');
17
- // Minimum supported version of the `@vercel/remix` package
18
- const VERCEL_REMIX_MIN_VERSION = '1.10.0';
19
- // Minimum supported version of the `@vercel/remix-run-dev` forked compiler
20
- const REMIX_RUN_DEV_MIN_VERSION = '1.15.0';
21
- // Maximum version of `@vercel/remix-run-dev` fork
22
- // (and also `@vercel/remix` since they get published at the same time)
23
- const REMIX_RUN_DEV_MAX_VERSION = remixRunDevForkVersion.slice(remixRunDevForkVersion.lastIndexOf('@') + 1);
24
- const build = async ({ entrypoint, files, workPath, repoRootPath, config, meta = {}, }) => {
25
- const { installCommand, buildCommand } = config;
26
- await (0, build_utils_1.download)(files, workPath, meta);
27
- const mountpoint = (0, path_1.dirname)(entrypoint);
28
- const entrypointFsDirname = (0, path_1.join)(workPath, mountpoint);
29
- // Run "Install Command"
30
- const nodeVersion = await (0, build_utils_1.getNodeVersion)(entrypointFsDirname, undefined, config, meta);
31
- const { cliType, packageJsonPath, lockfileVersion } = await (0, build_utils_1.scanParentDirs)(entrypointFsDirname);
32
- if (!packageJsonPath) {
33
- throw new Error('Failed to locate `package.json` file in your project');
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
- const pkgRaw = await fs_1.promises.readFile(packageJsonPath, 'utf8');
36
- const pkg = JSON.parse(pkgRaw);
37
- const spawnOpts = (0, build_utils_1.getSpawnOptions)(meta, nodeVersion);
38
- if (!spawnOpts.env) {
39
- spawnOpts.env = {};
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
- spawnOpts.env = (0, build_utils_1.getEnvForPackageManager)({
42
- cliType,
43
- lockfileVersion,
44
- nodeVersion,
45
- env: spawnOpts.env,
141
+ }
142
+ if (depsToAdd.length) {
143
+ await (0, import_utils.addDependencies)(cliType, depsToAdd, {
144
+ ...spawnOpts,
145
+ cwd: entrypointFsDirname
46
146
  });
47
- if (typeof installCommand === 'string') {
48
- if (installCommand.trim()) {
49
- console.log(`Running "install" command: \`${installCommand}\`...`);
50
- await (0, build_utils_1.execCommand)(installCommand, {
51
- ...spawnOpts,
52
- cwd: entrypointFsDirname,
53
- });
54
- }
55
- else {
56
- console.log(`Skipping "install" command...`);
57
- }
58
- }
59
- else {
60
- await (0, build_utils_1.runNpmInstall)(entrypointFsDirname, [], spawnOpts, meta, nodeVersion);
61
- }
62
- const isHydrogen2 = pkg.dependencies?.['@shopify/remix-oxygen'] ||
63
- pkg.devDependencies?.['@shopify/remix-oxygen'];
64
- // Determine the version of Remix based on the `@remix-run/dev`
65
- // package version.
66
- const remixRunDevPath = await (0, utils_1.ensureResolvable)(entrypointFsDirname, repoRootPath, '@remix-run/dev');
67
- const remixRunDevPkg = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(remixRunDevPath, 'package.json'), 'utf8'));
68
- const remixVersion = remixRunDevPkg.version;
69
- const remixConfig = await (0, utils_1.chdirAndReadConfig)(remixRunDevPath, entrypointFsDirname, packageJsonPath);
70
- const { serverEntryPoint, appDirectory } = remixConfig;
71
- const remixRoutes = Object.values(remixConfig.routes);
72
- const depsToAdd = [];
73
- // Override the official `@remix-run/dev` package with the
74
- // Vercel fork, which supports the `serverBundles` config
75
- if (!isHydrogen2 && remixRunDevPkg.name !== '@vercel/remix-run-dev') {
76
- const remixDevForkVersion = (0, utils_1.resolveSemverMinMax)(REMIX_RUN_DEV_MIN_VERSION, REMIX_RUN_DEV_MAX_VERSION, remixVersion);
77
- depsToAdd.push(`@remix-run/dev@npm:@vercel/remix-run-dev@${remixDevForkVersion}`);
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
- if (depsToAdd.length) {
96
- await (0, utils_1.addDependencies)(cliType, depsToAdd, {
97
- ...spawnOpts,
98
- cwd: entrypointFsDirname,
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 userEntryClientFile = (0, utils_1.findEntry)(remixConfig.appDirectory, 'entry.client');
102
- if (!userEntryClientFile) {
103
- await fs_1.promises.copyFile((0, path_1.join)(DEFAULTS_PATH, 'entry.client.react.jsx'), (0, path_1.join)(appDirectory, 'entry.client.jsx'));
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
- let remixConfigWrapped = false;
106
- let serverEntryPointAbs;
107
- let originalServerEntryPoint;
108
- const remixConfigPath = (0, utils_1.findConfig)(entrypointFsDirname, 'remix.config');
109
- const renamedRemixConfigPath = remixConfigPath
110
- ? `${remixConfigPath}.original${(0, path_1.extname)(remixConfigPath)}`
111
- : undefined;
112
- // These get populated inside the try/catch below
113
- let serverBundles;
114
- const serverBundlesMap = new Map();
115
- const resolvedConfigsMap = new Map();
116
- try {
117
- // Read the `export const config` (if any) for each route
118
- const project = new ts_morph_1.Project();
119
- const staticConfigsMap = new Map();
120
- for (const route of remixRoutes) {
121
- const routePath = (0, path_1.join)(remixConfig.appDirectory, route.file);
122
- let staticConfig = (0, static_config_1.getConfig)(project, routePath);
123
- if (staticConfig && isHydrogen2) {
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
- else {
175
- patchedConfig = `const config = require('./${(0, path_1.basename)(renamedRemixConfigPath)}');
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
- await fs_1.promises.writeFile(remixConfigPath, patchedConfig);
184
- remixConfigWrapped = true;
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
- finally {
229
- const cleanupOps = [];
230
- // Clean up our patched `remix.config.js` to be polite
231
- if (remixConfigWrapped && remixConfigPath && renamedRemixConfigPath) {
232
- cleanupOps.push(fs_1.promises
233
- .rename(renamedRemixConfigPath, remixConfigPath)
234
- .then(() => (0, build_utils_1.debug)(`Restored original "${(0, path_1.basename)(remixConfigPath)}" file`)));
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
- // Restore original server entrypoint if it was modified (for Hydrogen v2)
237
- if (serverEntryPointAbs && originalServerEntryPoint) {
238
- cleanupOps.push(fs_1.promises
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
- // This needs to happen before we run NFT to create the Node/Edge functions
245
- await Promise.all([
246
- (0, utils_1.ensureResolvable)(entrypointFsDirname, repoRootPath, '@remix-run/server-runtime'),
247
- !isHydrogen2
248
- ? (0, utils_1.ensureResolvable)(entrypointFsDirname, repoRootPath, '@remix-run/node')
249
- : null,
250
- ]);
251
- const staticDir = (0, path_1.join)(remixConfig.assetsBuildDirectory, ...remixConfig.publicPath
252
- .replace(/^\/|\/$/g, '')
253
- .split('/')
254
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
255
- .map(_ => '..'));
256
- const [staticFiles, ...functions] = await Promise.all([
257
- (0, build_utils_1.glob)('**', staticDir),
258
- ...serverBundles.map(bundle => {
259
- const firstRoute = remixConfig.routes[bundle.routes[0]];
260
- const config = resolvedConfigsMap.get(firstRoute) ?? {
261
- runtime: 'nodejs',
262
- };
263
- if (config.runtime === 'edge') {
264
- return createRenderEdgeFunction(entrypointFsDirname, repoRootPath, (0, path_1.join)(entrypointFsDirname, bundle.serverBuildPath), serverEntryPoint, remixVersion, config);
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
- const func = functions[funcIndex];
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
- // Add a 404 path for not found pages to be server-side rendered by Remix.
318
- // Use an edge function bundle if one was generated, otherwise use Node.js.
319
- if (!output['404']) {
320
- const edgeFunctionIndex = Array.from(serverBundlesMap.values()).findIndex(routes => {
321
- const runtime = resolvedConfigsMap.get(routes[0])?.runtime;
322
- return runtime === 'edge';
323
- });
324
- const func = edgeFunctionIndex !== -1 ? functions[edgeFunctionIndex] : functions[0];
325
- output['404'] =
326
- func instanceof build_utils_1.EdgeFunction
327
- ? new build_utils_1.EdgeFunction({ ...func, name: '404' })
328
- : func;
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
- routes.push({
331
- src: '/(.*)',
332
- dest: '/404',
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
- return { routes, output, framework: { version: remixVersion } };
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
- const scripts = (pkg && pkg.scripts) || {};
339
- return typeof scripts[scriptName] === 'string';
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
- const files = {};
343
- let handler = (0, path_1.relative)(rootDir, serverBuildPath);
344
- let handlerPath = (0, path_1.join)(rootDir, handler);
345
- if (!serverEntryPoint) {
346
- const baseServerBuildPath = (0, path_1.basename)(serverBuildPath, '.js');
347
- handler = (0, path_1.join)((0, path_1.dirname)(handler), `server-${baseServerBuildPath}.mjs`);
348
- handlerPath = (0, path_1.join)(rootDir, handler);
349
- // Copy the `server-node.mjs` file into the "build" directory
350
- const nodeServerSrc = await nodeServerSrcPromise;
351
- await writeEntrypointFile(handlerPath, nodeServerSrc.replace('@remix-run/dev/server-build', `./${baseServerBuildPath}.js`), rootDir);
352
- }
353
- // Trace the handler with `@vercel/nft`
354
- const trace = await (0, nft_1.nodeFileTrace)([handlerPath], {
355
- base: rootDir,
356
- processCwd: entrypointDir,
357
- });
358
- for (const warning of trace.warnings) {
359
- (0, build_utils_1.debug)(`Warning from trace: ${warning.message}`);
360
- }
361
- for (const file of trace.fileList) {
362
- files[file] = await build_utils_1.FileFsRef.fromFsPath({ fsPath: (0, path_1.join)(rootDir, file) });
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
- const fn = new build_utils_1.NodejsLambda({
365
- files,
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
- const files = {};
384
- let handler = (0, path_1.relative)(rootDir, serverBuildPath);
385
- let handlerPath = (0, path_1.join)(rootDir, handler);
386
- if (!serverEntryPoint) {
387
- const baseServerBuildPath = (0, path_1.basename)(serverBuildPath, '.js');
388
- handler = (0, path_1.join)((0, path_1.dirname)(handler), `server-${baseServerBuildPath}.mjs`);
389
- handlerPath = (0, path_1.join)(rootDir, handler);
390
- // Copy the `server-edge.mjs` file into the "build" directory
391
- const edgeServerSrc = await edgeServerSrcPromise;
392
- await writeEntrypointFile(handlerPath, edgeServerSrc.replace('@remix-run/dev/server-build', `./${baseServerBuildPath}.js`), rootDir);
393
- }
394
- let remixRunVercelPkgJson;
395
- // Trace the handler with `@vercel/nft`
396
- const trace = await (0, nft_1.nodeFileTrace)([handlerPath], {
397
- base: rootDir,
398
- processCwd: entrypointDir,
399
- conditions: ['edge-light', 'browser', 'module', 'import', 'require'],
400
- async readFile(fsPath) {
401
- let source;
402
- try {
403
- source = await fs_1.promises.readFile(fsPath);
404
- }
405
- catch (err) {
406
- if (err.code === 'ENOENT' || err.code === 'EISDIR') {
407
- return null;
408
- }
409
- throw err;
410
- }
411
- if ((0, path_1.basename)(fsPath) === 'package.json') {
412
- // For Edge Functions, patch "main" field to prefer "browser" or "module"
413
- const pkgJson = JSON.parse(source.toString());
414
- // When `@remix-run/vercel` is detected, we need to modify the `package.json`
415
- // to include the "browser" field so that the proper Edge entrypoint file
416
- // is used. This is a temporary stop gap until this PR is merged:
417
- // https://github.com/remix-run/remix/pull/5537
418
- if (pkgJson.name === '@remix-run/vercel') {
419
- pkgJson.browser = 'dist/edge.js';
420
- pkgJson.dependencies['@remix-run/server-runtime'] =
421
- pkgJson.dependencies['@remix-run/node'];
422
- if (!remixRunVercelPkgJson) {
423
- remixRunVercelPkgJson = JSON.stringify(pkgJson, null, 2) + '\n';
424
- // Copy in the edge entrypoint so that NFT can properly resolve it
425
- const vercelEdgeEntrypointPath = (0, path_1.join)(DEFAULTS_PATH, 'vercel-edge-entrypoint.js');
426
- const vercelEdgeEntrypointDest = (0, path_1.join)((0, path_1.dirname)(fsPath), 'dist/edge.js');
427
- await fs_1.promises.copyFile(vercelEdgeEntrypointPath, vercelEdgeEntrypointDest);
428
- }
429
- }
430
- for (const prop of ['browser', 'module']) {
431
- const val = pkgJson[prop];
432
- if (typeof val === 'string') {
433
- pkgJson.main = val;
434
- // Return the modified `package.json` to nft
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
- else {
453
- files[file] = await build_utils_1.FileFsRef.fromFsPath({ fsPath: (0, path_1.join)(rootDir, file) });
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
- const fn = new build_utils_1.EdgeFunction({
457
- files,
458
- deploymentTarget: 'v8-worker',
459
- name: 'render',
460
- entrypoint: handler,
461
- regions: config.regions,
462
- framework: {
463
- slug: 'remix',
464
- version: remixVersion,
465
- },
466
- });
467
- return fn;
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
- try {
471
- await fs_1.promises.writeFile(path, data);
472
- }
473
- catch (err) {
474
- if (err.code === 'ENOENT') {
475
- throw new Error(`The "${(0, path_1.relative)(rootDir, (0, path_1.dirname)(path))}" directory does not exist. Please contact support at https://vercel.com/help.`);
476
- }
477
- throw err;
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
- //# sourceMappingURL=build.js.map
563
+ // Annotate the CommonJS export names for ESM import in node:
564
+ 0 && (module.exports = {
565
+ build
566
+ });
567
+ //# sourceMappingURL=build.js.map