@vercel/remix-builder 5.0.2 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/defaults/server-node.mjs +5 -1
- package/defaults/server-react-router.mjs +3 -0
- package/dist/index.js +201 -44
- package/package.json +2 -2
package/defaults/server-node.mjs
CHANGED
|
@@ -8,9 +8,13 @@ import * as build from '@remix-run/dev/server-build';
|
|
|
8
8
|
|
|
9
9
|
installGlobals({
|
|
10
10
|
nativeFetch:
|
|
11
|
+
// Explicit opt-in to native fetch via runtime env var
|
|
11
12
|
(parseInt(process.versions.node, 10) >= 20 &&
|
|
12
13
|
process.env.VERCEL_REMIX_NATIVE_FETCH === '1') ||
|
|
13
|
-
|
|
14
|
+
// `unstable_singleFetch` future flag added in Remix v2.9.0
|
|
15
|
+
build.future.unstable_singleFetch ||
|
|
16
|
+
// `v3_singleFetch` future flag stabilized in Remix v2.13.0
|
|
17
|
+
build.future.v3_singleFetch,
|
|
14
18
|
});
|
|
15
19
|
|
|
16
20
|
const handleRequest = createRemixRequestHandler(
|
package/dist/index.js
CHANGED
|
@@ -3066,17 +3066,15 @@ function hasScript(scriptName, pkg) {
|
|
|
3066
3066
|
const scripts = pkg?.scripts || {};
|
|
3067
3067
|
return typeof scripts[scriptName] === "string";
|
|
3068
3068
|
}
|
|
3069
|
-
async function
|
|
3070
|
-
const resolvedPath = require_.resolve(
|
|
3069
|
+
async function getPackageVersion(name, dir, base) {
|
|
3070
|
+
const resolvedPath = require_.resolve(name, { paths: [dir] });
|
|
3071
3071
|
const pkgPath = await (0, import_build_utils2.walkParentDirs)({
|
|
3072
3072
|
base,
|
|
3073
3073
|
start: (0, import_path.dirname)(resolvedPath),
|
|
3074
3074
|
filename: "package.json"
|
|
3075
3075
|
});
|
|
3076
3076
|
if (!pkgPath) {
|
|
3077
|
-
throw new Error(
|
|
3078
|
-
`Failed to find \`package.json\` file for "@remix-run/dev"`
|
|
3079
|
-
);
|
|
3077
|
+
throw new Error(`Failed to find \`package.json\` file for "${name}"`);
|
|
3080
3078
|
}
|
|
3081
3079
|
const { version: version2 } = JSON.parse(
|
|
3082
3080
|
await import_fs.promises.readFile(pkgPath, "utf8")
|
|
@@ -3137,6 +3135,80 @@ var nodeServerSrcPromise = import_fs2.promises.readFile(
|
|
|
3137
3135
|
(0, import_path2.join)(DEFAULTS_PATH, "server-node.mjs"),
|
|
3138
3136
|
"utf-8"
|
|
3139
3137
|
);
|
|
3138
|
+
var reactRouterServerSrcPromise = import_fs2.promises.readFile(
|
|
3139
|
+
(0, import_path2.join)(DEFAULTS_PATH, "server-react-router.mjs"),
|
|
3140
|
+
"utf-8"
|
|
3141
|
+
);
|
|
3142
|
+
var REMIX_FRAMEWORK_SETTINGS = {
|
|
3143
|
+
primaryPackageName: "@remix-run/dev",
|
|
3144
|
+
buildCommand: "remix build",
|
|
3145
|
+
buildResultFilePath: ".vercel/remix-build-result.json",
|
|
3146
|
+
createRenderFunction({
|
|
3147
|
+
nodeVersion,
|
|
3148
|
+
entrypointDir,
|
|
3149
|
+
rootDir,
|
|
3150
|
+
serverBuildPath,
|
|
3151
|
+
serverEntryPoint,
|
|
3152
|
+
frameworkVersion,
|
|
3153
|
+
config
|
|
3154
|
+
}) {
|
|
3155
|
+
if (config.runtime === "edge") {
|
|
3156
|
+
return createRenderEdgeFunction(
|
|
3157
|
+
entrypointDir,
|
|
3158
|
+
rootDir,
|
|
3159
|
+
serverBuildPath,
|
|
3160
|
+
serverEntryPoint,
|
|
3161
|
+
frameworkVersion,
|
|
3162
|
+
config
|
|
3163
|
+
);
|
|
3164
|
+
}
|
|
3165
|
+
return createRenderNodeFunction(
|
|
3166
|
+
nodeVersion,
|
|
3167
|
+
entrypointDir,
|
|
3168
|
+
rootDir,
|
|
3169
|
+
serverBuildPath,
|
|
3170
|
+
serverEntryPoint,
|
|
3171
|
+
frameworkVersion,
|
|
3172
|
+
config
|
|
3173
|
+
);
|
|
3174
|
+
}
|
|
3175
|
+
};
|
|
3176
|
+
var REACT_ROUTER_FRAMEWORK_SETTINGS = {
|
|
3177
|
+
primaryPackageName: "react-router",
|
|
3178
|
+
buildCommand: "react-router build",
|
|
3179
|
+
buildResultFilePath: ".vercel/react-router-build-result.json",
|
|
3180
|
+
createRenderFunction({
|
|
3181
|
+
nodeVersion,
|
|
3182
|
+
entrypointDir,
|
|
3183
|
+
rootDir,
|
|
3184
|
+
serverBuildPath,
|
|
3185
|
+
serverEntryPoint,
|
|
3186
|
+
frameworkVersion,
|
|
3187
|
+
config
|
|
3188
|
+
}) {
|
|
3189
|
+
return createRenderReactRouterFunction(
|
|
3190
|
+
nodeVersion,
|
|
3191
|
+
entrypointDir,
|
|
3192
|
+
rootDir,
|
|
3193
|
+
serverBuildPath,
|
|
3194
|
+
serverEntryPoint,
|
|
3195
|
+
frameworkVersion,
|
|
3196
|
+
config
|
|
3197
|
+
);
|
|
3198
|
+
}
|
|
3199
|
+
};
|
|
3200
|
+
function determineFrameworkSettings(workPath) {
|
|
3201
|
+
const isReactRouter = findConfig(workPath, "react-router.config", [
|
|
3202
|
+
".js",
|
|
3203
|
+
".ts",
|
|
3204
|
+
".mjs",
|
|
3205
|
+
".mts"
|
|
3206
|
+
]);
|
|
3207
|
+
if (isReactRouter) {
|
|
3208
|
+
return REACT_ROUTER_FRAMEWORK_SETTINGS;
|
|
3209
|
+
}
|
|
3210
|
+
return REMIX_FRAMEWORK_SETTINGS;
|
|
3211
|
+
}
|
|
3140
3212
|
var build = async ({
|
|
3141
3213
|
entrypoint,
|
|
3142
3214
|
workPath,
|
|
@@ -3147,6 +3219,7 @@ var build = async ({
|
|
|
3147
3219
|
const { installCommand, buildCommand } = config;
|
|
3148
3220
|
const mountpoint = (0, import_path2.dirname)(entrypoint);
|
|
3149
3221
|
const entrypointFsDirname = (0, import_path2.join)(workPath, mountpoint);
|
|
3222
|
+
const frameworkSettings = determineFrameworkSettings(workPath);
|
|
3150
3223
|
const nodeVersion = await (0, import_build_utils3.getNodeVersion)(
|
|
3151
3224
|
entrypointFsDirname,
|
|
3152
3225
|
void 0,
|
|
@@ -3185,7 +3258,11 @@ var build = async ({
|
|
|
3185
3258
|
} else {
|
|
3186
3259
|
await (0, import_build_utils3.runNpmInstall)(entrypointFsDirname, [], spawnOpts, meta, nodeVersion);
|
|
3187
3260
|
}
|
|
3188
|
-
const
|
|
3261
|
+
const frameworkVersion = await getPackageVersion(
|
|
3262
|
+
frameworkSettings.primaryPackageName,
|
|
3263
|
+
entrypointFsDirname,
|
|
3264
|
+
repoRootPath
|
|
3265
|
+
);
|
|
3189
3266
|
if (buildCommand) {
|
|
3190
3267
|
(0, import_build_utils3.debug)(`Executing build command "${buildCommand}"`);
|
|
3191
3268
|
await (0, import_build_utils3.execCommand)(buildCommand, {
|
|
@@ -3204,28 +3281,28 @@ var build = async ({
|
|
|
3204
3281
|
(0, import_build_utils3.debug)(`Executing "build" script`);
|
|
3205
3282
|
await (0, import_build_utils3.runPackageJsonScript)(entrypointFsDirname, "build", spawnOpts);
|
|
3206
3283
|
} else {
|
|
3207
|
-
await (0, import_build_utils3.execCommand)(
|
|
3284
|
+
await (0, import_build_utils3.execCommand)(frameworkSettings.buildCommand, {
|
|
3208
3285
|
...spawnOpts,
|
|
3209
3286
|
cwd: entrypointFsDirname
|
|
3210
3287
|
});
|
|
3211
3288
|
}
|
|
3212
3289
|
}
|
|
3213
|
-
const
|
|
3290
|
+
const buildResultJsonPath = (0, import_path2.join)(
|
|
3214
3291
|
entrypointFsDirname,
|
|
3215
|
-
|
|
3292
|
+
frameworkSettings.buildResultFilePath
|
|
3216
3293
|
);
|
|
3217
|
-
let
|
|
3294
|
+
let buildResult;
|
|
3218
3295
|
try {
|
|
3219
|
-
const
|
|
3220
|
-
|
|
3296
|
+
const buildResultContents = (0, import_fs2.readFileSync)(buildResultJsonPath, "utf8");
|
|
3297
|
+
buildResult = JSON.parse(buildResultContents);
|
|
3221
3298
|
} catch (err) {
|
|
3222
3299
|
if (!(0, import_error_utils.isErrnoException)(err) || err.code !== "ENOENT") {
|
|
3223
3300
|
throw err;
|
|
3224
3301
|
}
|
|
3225
|
-
const
|
|
3226
|
-
if ((0, import_fs2.statSync)(
|
|
3302
|
+
const buildDirectory2 = (0, import_path2.join)(entrypointFsDirname, "build");
|
|
3303
|
+
if ((0, import_fs2.statSync)(buildDirectory2).isDirectory()) {
|
|
3227
3304
|
console.warn("WARN: The `vercelPreset()` Preset was not detected.");
|
|
3228
|
-
|
|
3305
|
+
buildResult = {
|
|
3229
3306
|
buildManifest: {
|
|
3230
3307
|
routes: {
|
|
3231
3308
|
root: {
|
|
@@ -3244,15 +3321,15 @@ var build = async ({
|
|
|
3244
3321
|
}
|
|
3245
3322
|
},
|
|
3246
3323
|
remixConfig: {
|
|
3247
|
-
buildDirectory
|
|
3324
|
+
buildDirectory: buildDirectory2
|
|
3248
3325
|
}
|
|
3249
3326
|
};
|
|
3250
3327
|
const serverPath = "build/server/index.js";
|
|
3251
3328
|
if ((0, import_fs2.existsSync)((0, import_path2.join)(entrypointFsDirname, serverPath))) {
|
|
3252
|
-
|
|
3329
|
+
buildResult.buildManifest.routeIdToServerBundleId = {
|
|
3253
3330
|
"routes/_index": ""
|
|
3254
3331
|
};
|
|
3255
|
-
|
|
3332
|
+
buildResult.buildManifest.serverBundles = {
|
|
3256
3333
|
"": {
|
|
3257
3334
|
id: "",
|
|
3258
3335
|
file: serverPath,
|
|
@@ -3262,36 +3339,27 @@ var build = async ({
|
|
|
3262
3339
|
}
|
|
3263
3340
|
}
|
|
3264
3341
|
}
|
|
3265
|
-
if (!
|
|
3342
|
+
if (!buildResult) {
|
|
3266
3343
|
throw new Error(
|
|
3267
3344
|
"Could not determine build output directory. Please configure the `vercelPreset()` Preset from the `@vercel/remix` npm package"
|
|
3268
3345
|
);
|
|
3269
3346
|
}
|
|
3270
|
-
const { buildManifest,
|
|
3271
|
-
const
|
|
3347
|
+
const { buildManifest, viteConfig } = buildResult;
|
|
3348
|
+
const buildDirectory = "remixConfig" in buildResult ? buildResult.remixConfig.buildDirectory : buildResult.reactRouterConfig.buildDirectory;
|
|
3349
|
+
const staticDir = (0, import_path2.join)(buildDirectory, "client");
|
|
3272
3350
|
const serverBundles = Object.values(buildManifest.serverBundles ?? {});
|
|
3273
3351
|
const [staticFiles, ...functions] = await Promise.all([
|
|
3274
3352
|
(0, import_build_utils3.glob)("**", staticDir),
|
|
3275
3353
|
...serverBundles.map((bundle) => {
|
|
3276
|
-
|
|
3277
|
-
return createRenderEdgeFunction(
|
|
3278
|
-
entrypointFsDirname,
|
|
3279
|
-
repoRootPath,
|
|
3280
|
-
(0, import_path2.join)(entrypointFsDirname, bundle.file),
|
|
3281
|
-
void 0,
|
|
3282
|
-
remixVersion,
|
|
3283
|
-
bundle.config
|
|
3284
|
-
);
|
|
3285
|
-
}
|
|
3286
|
-
return createRenderNodeFunction(
|
|
3354
|
+
return frameworkSettings.createRenderFunction({
|
|
3287
3355
|
nodeVersion,
|
|
3288
|
-
entrypointFsDirname,
|
|
3289
|
-
repoRootPath,
|
|
3290
|
-
(0, import_path2.join)(entrypointFsDirname, bundle.file),
|
|
3291
|
-
void 0,
|
|
3292
|
-
|
|
3293
|
-
bundle.config
|
|
3294
|
-
);
|
|
3356
|
+
entrypointDir: entrypointFsDirname,
|
|
3357
|
+
rootDir: repoRootPath,
|
|
3358
|
+
serverBuildPath: (0, import_path2.join)(entrypointFsDirname, bundle.file),
|
|
3359
|
+
serverEntryPoint: void 0,
|
|
3360
|
+
frameworkVersion,
|
|
3361
|
+
config: bundle.config
|
|
3362
|
+
});
|
|
3295
3363
|
})
|
|
3296
3364
|
]);
|
|
3297
3365
|
const functionsMap = /* @__PURE__ */ new Map();
|
|
@@ -3335,9 +3403,98 @@ var build = async ({
|
|
|
3335
3403
|
src: "/(.*)",
|
|
3336
3404
|
dest: "/"
|
|
3337
3405
|
});
|
|
3338
|
-
return { routes, output, framework: { version:
|
|
3406
|
+
return { routes, output, framework: { version: frameworkVersion } };
|
|
3339
3407
|
};
|
|
3340
|
-
async function
|
|
3408
|
+
async function createRenderReactRouterFunction(nodeVersion, entrypointDir, rootDir, serverBuildPath, serverEntryPoint, frameworkVersion, config) {
|
|
3409
|
+
const isEdgeFunction = config.runtime === "edge";
|
|
3410
|
+
const files = {};
|
|
3411
|
+
let handler = (0, import_path2.relative)(rootDir, serverBuildPath);
|
|
3412
|
+
let handlerPath = (0, import_path2.join)(rootDir, handler);
|
|
3413
|
+
if (!serverEntryPoint) {
|
|
3414
|
+
const baseServerBuildPath = (0, import_path2.basename)(serverBuildPath, ".js");
|
|
3415
|
+
handler = (0, import_path2.join)((0, import_path2.dirname)(handler), `server-${baseServerBuildPath}.mjs`);
|
|
3416
|
+
handlerPath = (0, import_path2.join)(rootDir, handler);
|
|
3417
|
+
const reactRouterServerSrc = await reactRouterServerSrcPromise;
|
|
3418
|
+
await import_fs2.promises.writeFile(
|
|
3419
|
+
handlerPath,
|
|
3420
|
+
reactRouterServerSrc.replace(
|
|
3421
|
+
"ENTRYPOINT_PLACEHOLDER",
|
|
3422
|
+
`./${baseServerBuildPath}.js`
|
|
3423
|
+
)
|
|
3424
|
+
);
|
|
3425
|
+
}
|
|
3426
|
+
let conditions;
|
|
3427
|
+
let readFile;
|
|
3428
|
+
if (isEdgeFunction) {
|
|
3429
|
+
conditions = ["edge-light", "browser", "module", "import", "require"];
|
|
3430
|
+
readFile = async (fsPath) => {
|
|
3431
|
+
let source;
|
|
3432
|
+
try {
|
|
3433
|
+
source = await import_fs2.promises.readFile(fsPath);
|
|
3434
|
+
} catch (err) {
|
|
3435
|
+
if (err.code === "ENOENT" || err.code === "EISDIR") {
|
|
3436
|
+
return null;
|
|
3437
|
+
}
|
|
3438
|
+
throw err;
|
|
3439
|
+
}
|
|
3440
|
+
if ((0, import_path2.basename)(fsPath) === "package.json") {
|
|
3441
|
+
const pkgJson = JSON.parse(source.toString());
|
|
3442
|
+
for (const prop of ["browser", "module"]) {
|
|
3443
|
+
const val = pkgJson[prop];
|
|
3444
|
+
if (typeof val === "string") {
|
|
3445
|
+
pkgJson.main = val;
|
|
3446
|
+
source = JSON.stringify(pkgJson);
|
|
3447
|
+
break;
|
|
3448
|
+
}
|
|
3449
|
+
}
|
|
3450
|
+
}
|
|
3451
|
+
return source;
|
|
3452
|
+
};
|
|
3453
|
+
}
|
|
3454
|
+
const trace = await (0, import_nft.nodeFileTrace)([handlerPath], {
|
|
3455
|
+
base: rootDir,
|
|
3456
|
+
processCwd: entrypointDir,
|
|
3457
|
+
conditions,
|
|
3458
|
+
readFile
|
|
3459
|
+
});
|
|
3460
|
+
logNftWarnings(trace.warnings, "react-router");
|
|
3461
|
+
for (const file of trace.fileList) {
|
|
3462
|
+
files[file] = await import_build_utils3.FileFsRef.fromFsPath({ fsPath: (0, import_path2.join)(rootDir, file) });
|
|
3463
|
+
}
|
|
3464
|
+
let fn;
|
|
3465
|
+
if (isEdgeFunction) {
|
|
3466
|
+
fn = new import_build_utils3.EdgeFunction({
|
|
3467
|
+
files,
|
|
3468
|
+
deploymentTarget: "v8-worker",
|
|
3469
|
+
entrypoint: handler,
|
|
3470
|
+
regions: config.regions,
|
|
3471
|
+
framework: {
|
|
3472
|
+
slug: "react-router",
|
|
3473
|
+
version: frameworkVersion
|
|
3474
|
+
}
|
|
3475
|
+
});
|
|
3476
|
+
} else {
|
|
3477
|
+
fn = new import_build_utils3.NodejsLambda({
|
|
3478
|
+
files,
|
|
3479
|
+
handler,
|
|
3480
|
+
runtime: nodeVersion.runtime,
|
|
3481
|
+
shouldAddHelpers: false,
|
|
3482
|
+
shouldAddSourcemapSupport: false,
|
|
3483
|
+
operationType: "SSR",
|
|
3484
|
+
supportsResponseStreaming: true,
|
|
3485
|
+
useWebApi: true,
|
|
3486
|
+
regions: config.regions,
|
|
3487
|
+
memory: config.memory,
|
|
3488
|
+
maxDuration: config.maxDuration,
|
|
3489
|
+
framework: {
|
|
3490
|
+
slug: "react-router",
|
|
3491
|
+
version: frameworkVersion
|
|
3492
|
+
}
|
|
3493
|
+
});
|
|
3494
|
+
}
|
|
3495
|
+
return fn;
|
|
3496
|
+
}
|
|
3497
|
+
async function createRenderNodeFunction(nodeVersion, entrypointDir, rootDir, serverBuildPath, serverEntryPoint, frameworkVersion, config) {
|
|
3341
3498
|
const files = {};
|
|
3342
3499
|
let handler = (0, import_path2.relative)(rootDir, serverBuildPath);
|
|
3343
3500
|
let handlerPath = (0, import_path2.join)(rootDir, handler);
|
|
@@ -3375,12 +3532,12 @@ async function createRenderNodeFunction(nodeVersion, entrypointDir, rootDir, ser
|
|
|
3375
3532
|
maxDuration: config.maxDuration,
|
|
3376
3533
|
framework: {
|
|
3377
3534
|
slug: "remix",
|
|
3378
|
-
version:
|
|
3535
|
+
version: frameworkVersion
|
|
3379
3536
|
}
|
|
3380
3537
|
});
|
|
3381
3538
|
return fn;
|
|
3382
3539
|
}
|
|
3383
|
-
async function createRenderEdgeFunction(entrypointDir, rootDir, serverBuildPath, serverEntryPoint,
|
|
3540
|
+
async function createRenderEdgeFunction(entrypointDir, rootDir, serverBuildPath, serverEntryPoint, frameworkVersion, config) {
|
|
3384
3541
|
const files = {};
|
|
3385
3542
|
let handler = (0, import_path2.relative)(rootDir, serverBuildPath);
|
|
3386
3543
|
let handlerPath = (0, import_path2.join)(rootDir, handler);
|
|
@@ -3441,7 +3598,7 @@ async function createRenderEdgeFunction(entrypointDir, rootDir, serverBuildPath,
|
|
|
3441
3598
|
regions: config.regions,
|
|
3442
3599
|
framework: {
|
|
3443
3600
|
slug: "remix",
|
|
3444
|
-
version:
|
|
3601
|
+
version: frameworkVersion
|
|
3445
3602
|
}
|
|
3446
3603
|
});
|
|
3447
3604
|
return fn;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/remix-builder",
|
|
3
|
-
"version": "5.0
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"homepage": "https://vercel.com/docs",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@types/jest": "27.5.1",
|
|
25
25
|
"@types/node": "14.18.33",
|
|
26
26
|
"@types/semver": "7.3.13",
|
|
27
|
-
"@vercel/build-utils": "9.0
|
|
27
|
+
"@vercel/build-utils": "9.1.0",
|
|
28
28
|
"glob": "10.3.16",
|
|
29
29
|
"jest-junit": "16.0.0",
|
|
30
30
|
"path-to-regexp": "6.2.1",
|