@vercel/remix-builder 5.3.0 → 5.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +158 -154
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -2811,21 +2811,38 @@ var reactRouterServerSrcPromise = import_fs2.promises.readFile(
2811
2811
  (0, import_path2.join)(DEFAULTS_PATH, "server-react-router.mjs"),
2812
2812
  "utf-8"
2813
2813
  );
2814
+ var COMMON_NODE_RUNTIME_SETTINGS = {
2815
+ traceFunction: traceNodeFiles,
2816
+ createRuntimeFunction: createNodeFunction
2817
+ };
2818
+ var COMMON_EDGE_RUNTIME_SETTINGS = {
2819
+ traceFunction: traceEdgeFiles,
2820
+ createRuntimeFunction: createEdgeFunction
2821
+ };
2814
2822
  var REMIX_FRAMEWORK_SETTINGS = {
2815
2823
  primaryPackageName: "@remix-run/dev",
2816
2824
  buildCommand: "remix build",
2817
2825
  buildResultFilePath: ".vercel/remix-build-result.json",
2826
+ presetDocumentationLink: "https://vercel.com/docs/frameworks/remix#vercel-vite-preset",
2818
2827
  slug: "remix",
2819
2828
  sourceSearchValue: "@remix-run/dev/server-build",
2820
2829
  edge: {
2830
+ ...COMMON_EDGE_RUNTIME_SETTINGS,
2821
2831
  serverSourcePromise: edgeServerSrcPromise,
2822
2832
  traceWarningTag: "@remix-run/server-runtime"
2823
2833
  },
2824
2834
  node: {
2835
+ ...COMMON_NODE_RUNTIME_SETTINGS,
2825
2836
  serverSourcePromise: nodeServerSrcPromise,
2826
2837
  traceWarningTag: "@remix-run/node",
2827
2838
  options: {}
2828
2839
  },
2840
+ getRuntimeSettings(runtime) {
2841
+ if (runtime === "edge") {
2842
+ return this.edge;
2843
+ }
2844
+ return this.node;
2845
+ },
2829
2846
  createRenderFunction({
2830
2847
  nodeVersion,
2831
2848
  entrypointDir,
@@ -2835,43 +2852,45 @@ var REMIX_FRAMEWORK_SETTINGS = {
2835
2852
  frameworkVersion,
2836
2853
  config
2837
2854
  }) {
2838
- if (config.runtime === "edge") {
2839
- return createRenderEdgeFunction(
2840
- entrypointDir,
2841
- rootDir,
2842
- serverBuildPath,
2843
- serverEntryPoint,
2844
- frameworkVersion,
2845
- config
2846
- );
2847
- }
2848
- return createRenderNodeFunction(
2849
- nodeVersion,
2855
+ return createRenderFunction({
2850
2856
  entrypointDir,
2851
2857
  rootDir,
2852
2858
  serverBuildPath,
2853
2859
  serverEntryPoint,
2854
2860
  frameworkVersion,
2855
- config
2856
- );
2861
+ config,
2862
+ frameworkRuntimeSettings: this.getRuntimeSettings(config),
2863
+ sourceSearchValue: this.sourceSearchValue,
2864
+ frameworkSlug: this.slug,
2865
+ nodeVersion
2866
+ });
2857
2867
  }
2858
2868
  };
2859
2869
  var REACT_ROUTER_FRAMEWORK_SETTINGS = {
2860
2870
  primaryPackageName: "react-router",
2861
2871
  buildCommand: "react-router build",
2862
2872
  buildResultFilePath: ".vercel/react-router-build-result.json",
2873
+ presetDocumentationLink: "https://vercel.com/docs/frameworks/react-router#vercel-react-router-preset",
2863
2874
  slug: "react-router",
2864
2875
  sourceSearchValue: "virtual:react-router/server-build",
2865
2876
  // React Router uses the same server source for both node and edge
2866
2877
  edge: {
2878
+ ...COMMON_EDGE_RUNTIME_SETTINGS,
2867
2879
  serverSourcePromise: reactRouterServerSrcPromise,
2868
2880
  traceWarningTag: "react-router"
2869
2881
  },
2870
2882
  node: {
2883
+ ...COMMON_NODE_RUNTIME_SETTINGS,
2871
2884
  serverSourcePromise: reactRouterServerSrcPromise,
2872
2885
  traceWarningTag: "react-router",
2873
2886
  options: { useWebApi: true }
2874
2887
  },
2888
+ getRuntimeSettings(runtime) {
2889
+ if (runtime === "edge") {
2890
+ return this.edge;
2891
+ }
2892
+ return this.node;
2893
+ },
2875
2894
  createRenderFunction({
2876
2895
  nodeVersion,
2877
2896
  entrypointDir,
@@ -2881,15 +2900,18 @@ var REACT_ROUTER_FRAMEWORK_SETTINGS = {
2881
2900
  frameworkVersion,
2882
2901
  config
2883
2902
  }) {
2884
- return createRenderReactRouterFunction(
2885
- nodeVersion,
2903
+ return createRenderFunction({
2886
2904
  entrypointDir,
2887
2905
  rootDir,
2888
2906
  serverBuildPath,
2889
2907
  serverEntryPoint,
2890
2908
  frameworkVersion,
2891
- config
2892
- );
2909
+ config,
2910
+ frameworkRuntimeSettings: this.getRuntimeSettings(config),
2911
+ sourceSearchValue: this.sourceSearchValue,
2912
+ frameworkSlug: this.slug,
2913
+ nodeVersion
2914
+ });
2893
2915
  }
2894
2916
  };
2895
2917
  function determineFrameworkSettings(workPath) {
@@ -3040,6 +3062,9 @@ var build = async ({
3040
3062
  const buildDirectory2 = (0, import_path2.join)(entrypointFsDirname, "build");
3041
3063
  if ((0, import_fs2.statSync)(buildDirectory2).isDirectory()) {
3042
3064
  console.warn("WARN: The `vercelPreset()` Preset was not detected.");
3065
+ console.warn(
3066
+ `See ${frameworkSettings.presetDocumentationLink} for more information`
3067
+ );
3043
3068
  buildResult = {
3044
3069
  buildManifest: {
3045
3070
  routes: {
@@ -3143,171 +3168,150 @@ var build = async ({
3143
3168
  });
3144
3169
  return { routes, output, framework: { version: frameworkVersion } };
3145
3170
  };
3146
- async function edgeReadFile(fsPath) {
3147
- let source;
3148
- try {
3149
- source = await import_fs2.promises.readFile(fsPath);
3150
- } catch (err) {
3151
- if (err.code === "ENOENT" || err.code === "EISDIR") {
3152
- return null;
3171
+ async function traceEdgeFiles({
3172
+ handlerPath,
3173
+ rootDir,
3174
+ entrypointDir
3175
+ }) {
3176
+ const EDGE_TRACE_CONDITIONS = [
3177
+ "edge-light",
3178
+ "browser",
3179
+ "module",
3180
+ "import",
3181
+ "require"
3182
+ ];
3183
+ async function edgeReadFile(fsPath) {
3184
+ let source;
3185
+ try {
3186
+ source = await import_fs2.promises.readFile(fsPath);
3187
+ } catch (err) {
3188
+ if (err.code === "ENOENT" || err.code === "EISDIR") {
3189
+ return null;
3190
+ }
3191
+ throw err;
3153
3192
  }
3154
- throw err;
3155
- }
3156
- if ((0, import_path2.basename)(fsPath) === "package.json") {
3157
- const pkgJson = JSON.parse(source.toString());
3158
- for (const prop of ["browser", "module"]) {
3159
- const val = pkgJson[prop];
3160
- if (typeof val === "string") {
3161
- pkgJson.main = val;
3162
- source = JSON.stringify(pkgJson);
3163
- break;
3193
+ if ((0, import_path2.basename)(fsPath) === "package.json") {
3194
+ const pkgJson = JSON.parse(source.toString());
3195
+ for (const prop of ["browser", "module"]) {
3196
+ const val = pkgJson[prop];
3197
+ if (typeof val === "string") {
3198
+ pkgJson.main = val;
3199
+ source = JSON.stringify(pkgJson);
3200
+ break;
3201
+ }
3164
3202
  }
3165
3203
  }
3204
+ return source;
3166
3205
  }
3167
- return source;
3168
- }
3169
- var EDGE_TRACE_CONDITIONS = [
3170
- "edge-light",
3171
- "browser",
3172
- "module",
3173
- "import",
3174
- "require"
3175
- ];
3176
- var COMMON_NODE_FUNCTION_OPTIONS = {
3177
- shouldAddHelpers: false,
3178
- shouldAddSourcemapSupport: false,
3179
- operationType: "SSR",
3180
- supportsResponseStreaming: true
3181
- };
3182
- var COMMON_EDGE_FUNCTION_OPTIONS = { deploymentTarget: "v8-worker" };
3183
- async function createRenderReactRouterFunction(nodeVersion, entrypointDir, rootDir, serverBuildPath, serverEntryPoint, frameworkVersion, config) {
3184
- const isEdgeFunction = config.runtime === "edge";
3185
- const { handler, handlerPath } = await determineHandler({
3186
- rootDir,
3187
- serverBuildPath,
3188
- serverEntryPoint,
3189
- serverSourcePromise: (
3190
- // React Router has the same promise for both edge and node
3191
- // so this chooses edge out of convenience
3192
- REACT_ROUTER_FRAMEWORK_SETTINGS.edge.serverSourcePromise
3193
- ),
3194
- sourceSearchValue: REACT_ROUTER_FRAMEWORK_SETTINGS.sourceSearchValue
3195
- });
3196
- let conditions;
3197
- let readFile;
3198
- if (isEdgeFunction) {
3199
- conditions = EDGE_TRACE_CONDITIONS;
3200
- readFile = edgeReadFile;
3201
- }
3202
- const trace = await (0, import_nft.nodeFileTrace)([handlerPath], {
3206
+ return await (0, import_nft.nodeFileTrace)([handlerPath], {
3203
3207
  base: rootDir,
3204
3208
  processCwd: entrypointDir,
3205
- conditions,
3206
- readFile
3209
+ conditions: EDGE_TRACE_CONDITIONS,
3210
+ readFile: edgeReadFile
3207
3211
  });
3208
- logNftWarnings(
3209
- trace.warnings,
3210
- REACT_ROUTER_FRAMEWORK_SETTINGS.edge.traceWarningTag
3211
- );
3212
- const files = await getFilesFromTrace({ fileList: trace.fileList, rootDir });
3213
- let fn;
3214
- if (isEdgeFunction) {
3215
- fn = new import_build_utils3.EdgeFunction({
3216
- ...COMMON_EDGE_FUNCTION_OPTIONS,
3217
- files,
3218
- entrypoint: handler,
3219
- regions: config.regions,
3220
- framework: {
3221
- slug: REACT_ROUTER_FRAMEWORK_SETTINGS.slug,
3222
- version: frameworkVersion
3223
- }
3224
- });
3225
- } else {
3226
- fn = new import_build_utils3.NodejsLambda({
3227
- ...COMMON_NODE_FUNCTION_OPTIONS,
3228
- files,
3229
- handler,
3230
- runtime: nodeVersion.runtime,
3231
- useWebApi: REACT_ROUTER_FRAMEWORK_SETTINGS.node.options.useWebApi,
3232
- regions: config.regions,
3233
- memory: config.memory,
3234
- maxDuration: config.maxDuration,
3235
- framework: {
3236
- slug: REACT_ROUTER_FRAMEWORK_SETTINGS.slug,
3237
- version: frameworkVersion
3238
- }
3239
- });
3240
- }
3241
- return fn;
3242
3212
  }
3243
- async function createRenderNodeFunction(nodeVersion, entrypointDir, rootDir, serverBuildPath, serverEntryPoint, frameworkVersion, config) {
3244
- const { handler, handlerPath } = await determineHandler({
3245
- rootDir,
3246
- serverBuildPath,
3247
- serverEntryPoint,
3248
- serverSourcePromise: REMIX_FRAMEWORK_SETTINGS.node.serverSourcePromise,
3249
- sourceSearchValue: REMIX_FRAMEWORK_SETTINGS.sourceSearchValue
3250
- });
3251
- const trace = await (0, import_nft.nodeFileTrace)([handlerPath], {
3213
+ async function traceNodeFiles({
3214
+ handlerPath,
3215
+ rootDir,
3216
+ entrypointDir
3217
+ }) {
3218
+ return await (0, import_nft.nodeFileTrace)([handlerPath], {
3252
3219
  base: rootDir,
3253
3220
  processCwd: entrypointDir
3254
3221
  });
3255
- logNftWarnings(trace.warnings, REMIX_FRAMEWORK_SETTINGS.node.traceWarningTag);
3256
- const files = await getFilesFromTrace({ fileList: trace.fileList, rootDir });
3257
- const fn = new import_build_utils3.NodejsLambda({
3258
- ...COMMON_NODE_FUNCTION_OPTIONS,
3222
+ }
3223
+ async function getFilesFromTrace({
3224
+ fileList,
3225
+ rootDir
3226
+ }) {
3227
+ const files = {};
3228
+ for (const file of fileList) {
3229
+ files[file] = await import_build_utils3.FileFsRef.fromFsPath({ fsPath: (0, import_path2.join)(rootDir, file) });
3230
+ }
3231
+ return files;
3232
+ }
3233
+ function createEdgeFunction({
3234
+ files,
3235
+ handler,
3236
+ config,
3237
+ frameworkSlug,
3238
+ frameworkVersion
3239
+ }) {
3240
+ return new import_build_utils3.EdgeFunction({
3241
+ deploymentTarget: "v8-worker",
3242
+ files,
3243
+ entrypoint: handler,
3244
+ regions: config.regions,
3245
+ framework: {
3246
+ slug: frameworkSlug,
3247
+ version: frameworkVersion
3248
+ }
3249
+ });
3250
+ }
3251
+ function createNodeFunction({
3252
+ files,
3253
+ handler,
3254
+ config,
3255
+ frameworkSlug,
3256
+ frameworkVersion,
3257
+ nodeVersion,
3258
+ useWebApi
3259
+ }) {
3260
+ return new import_build_utils3.NodejsLambda({
3261
+ shouldAddHelpers: false,
3262
+ shouldAddSourcemapSupport: false,
3263
+ operationType: "SSR",
3264
+ supportsResponseStreaming: true,
3259
3265
  files,
3260
3266
  handler,
3261
3267
  runtime: nodeVersion.runtime,
3262
3268
  regions: config.regions,
3263
3269
  memory: config.memory,
3264
3270
  maxDuration: config.maxDuration,
3265
- useWebApi: REMIX_FRAMEWORK_SETTINGS.node.options.useWebApi,
3271
+ useWebApi,
3266
3272
  framework: {
3267
- slug: REMIX_FRAMEWORK_SETTINGS.slug,
3273
+ slug: frameworkSlug,
3268
3274
  version: frameworkVersion
3269
3275
  }
3270
3276
  });
3271
- return fn;
3272
3277
  }
3273
- async function createRenderEdgeFunction(entrypointDir, rootDir, serverBuildPath, serverEntryPoint, frameworkVersion, config) {
3278
+ async function createRenderFunction({
3279
+ rootDir,
3280
+ serverBuildPath,
3281
+ serverEntryPoint,
3282
+ entrypointDir,
3283
+ config,
3284
+ frameworkVersion,
3285
+ frameworkRuntimeSettings,
3286
+ sourceSearchValue,
3287
+ frameworkSlug,
3288
+ nodeVersion
3289
+ }) {
3274
3290
  const { handler, handlerPath } = await determineHandler({
3275
3291
  rootDir,
3276
3292
  serverBuildPath,
3277
3293
  serverEntryPoint,
3278
- serverSourcePromise: REMIX_FRAMEWORK_SETTINGS.edge.serverSourcePromise,
3279
- sourceSearchValue: REMIX_FRAMEWORK_SETTINGS.sourceSearchValue
3294
+ serverSourcePromise: frameworkRuntimeSettings.serverSourcePromise,
3295
+ sourceSearchValue
3280
3296
  });
3281
- const trace = await (0, import_nft.nodeFileTrace)([handlerPath], {
3282
- base: rootDir,
3283
- processCwd: entrypointDir,
3284
- conditions: EDGE_TRACE_CONDITIONS,
3285
- readFile: edgeReadFile
3297
+ const trace = await frameworkRuntimeSettings.traceFunction({
3298
+ handlerPath,
3299
+ rootDir,
3300
+ entrypointDir
3286
3301
  });
3287
- logNftWarnings(trace.warnings, REMIX_FRAMEWORK_SETTINGS.edge.traceWarningTag);
3302
+ logNftWarnings(trace.warnings, frameworkRuntimeSettings.traceWarningTag);
3288
3303
  const files = await getFilesFromTrace({ fileList: trace.fileList, rootDir });
3289
- const fn = new import_build_utils3.EdgeFunction({
3290
- ...COMMON_EDGE_FUNCTION_OPTIONS,
3304
+ const fn = frameworkRuntimeSettings.createRuntimeFunction({
3291
3305
  files,
3292
- entrypoint: handler,
3293
- regions: config.regions,
3294
- framework: {
3295
- slug: REMIX_FRAMEWORK_SETTINGS.slug,
3296
- version: frameworkVersion
3297
- }
3306
+ handler,
3307
+ config,
3308
+ frameworkSlug,
3309
+ frameworkVersion,
3310
+ nodeVersion,
3311
+ useWebApi: frameworkRuntimeSettings.options?.useWebApi
3298
3312
  });
3299
3313
  return fn;
3300
3314
  }
3301
- async function getFilesFromTrace({
3302
- fileList,
3303
- rootDir
3304
- }) {
3305
- const files = {};
3306
- for (const file of fileList) {
3307
- files[file] = await import_build_utils3.FileFsRef.fromFsPath({ fsPath: (0, import_path2.join)(rootDir, file) });
3308
- }
3309
- return files;
3310
- }
3311
3315
 
3312
3316
  // src/build-legacy.ts
3313
3317
  var import_ts_morph2 = require("ts-morph");
@@ -3733,7 +3737,7 @@ module.exports = config;`;
3733
3737
  };
3734
3738
  const serverBuildPath = (0, import_path4.join)(entrypointFsDirname, bundle.serverBuildPath);
3735
3739
  if (config2.runtime === "edge") {
3736
- return createRenderEdgeFunction2(
3740
+ return createRenderEdgeFunction(
3737
3741
  entrypointFsDirname,
3738
3742
  repoRootPath,
3739
3743
  serverBuildPath,
@@ -3742,7 +3746,7 @@ module.exports = config;`;
3742
3746
  config2
3743
3747
  );
3744
3748
  }
3745
- return createRenderNodeFunction2(
3749
+ return createRenderNodeFunction(
3746
3750
  nodeVersion,
3747
3751
  entrypointFsDirname,
3748
3752
  repoRootPath,
@@ -3813,7 +3817,7 @@ function hasScript2(scriptName, pkg) {
3813
3817
  const scripts = pkg && pkg.scripts || {};
3814
3818
  return typeof scripts[scriptName] === "string";
3815
3819
  }
3816
- async function createRenderNodeFunction2(nodeVersion, entrypointDir, rootDir, serverBuildPath, serverEntryPoint, remixVersion, config) {
3820
+ async function createRenderNodeFunction(nodeVersion, entrypointDir, rootDir, serverBuildPath, serverEntryPoint, remixVersion, config) {
3817
3821
  const files = {};
3818
3822
  let handler = (0, import_path4.relative)(rootDir, serverBuildPath);
3819
3823
  let handlerPath = (0, import_path4.join)(rootDir, handler);
@@ -3859,7 +3863,7 @@ async function createRenderNodeFunction2(nodeVersion, entrypointDir, rootDir, se
3859
3863
  });
3860
3864
  return fn;
3861
3865
  }
3862
- async function createRenderEdgeFunction2(entrypointDir, rootDir, serverBuildPath, serverEntryPoint, remixVersion, config) {
3866
+ async function createRenderEdgeFunction(entrypointDir, rootDir, serverBuildPath, serverEntryPoint, remixVersion, config) {
3863
3867
  const files = {};
3864
3868
  let handler = (0, import_path4.relative)(rootDir, serverBuildPath);
3865
3869
  let handlerPath = (0, import_path4.join)(rootDir, handler);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/remix-builder",
3
- "version": "5.3.0",
3
+ "version": "5.3.1",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index.js",
6
6
  "homepage": "https://vercel.com/docs",
@@ -26,7 +26,7 @@
26
26
  "@types/jest": "27.5.1",
27
27
  "@types/node": "14.18.33",
28
28
  "@types/semver": "7.3.13",
29
- "@vercel/build-utils": "9.3.0",
29
+ "@vercel/build-utils": "9.3.1",
30
30
  "glob": "10.3.16",
31
31
  "jest-junit": "16.0.0",
32
32
  "semver": "7.5.2",