@vercel/remix-builder 5.3.0 → 5.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +159 -167
  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,29 +2900,20 @@ 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
- function determineFrameworkSettings(workPath) {
2896
- const isReactRouter = findConfig(workPath, "react-router.config", [
2897
- ".js",
2898
- ".ts",
2899
- ".mjs",
2900
- ".mts"
2901
- ]);
2902
- if (isReactRouter) {
2903
- return REACT_ROUTER_FRAMEWORK_SETTINGS;
2904
- }
2905
- return REMIX_FRAMEWORK_SETTINGS;
2906
- }
2907
2917
  async function determineHandler({
2908
2918
  rootDir,
2909
2919
  serverBuildPath,
@@ -2935,7 +2945,7 @@ var build = async ({
2935
2945
  const { installCommand, buildCommand } = config;
2936
2946
  const mountpoint = (0, import_path2.dirname)(entrypoint);
2937
2947
  const entrypointFsDirname = (0, import_path2.join)(workPath, mountpoint);
2938
- const frameworkSettings = determineFrameworkSettings(workPath);
2948
+ const frameworkSettings = config.framework === "react-router" ? REACT_ROUTER_FRAMEWORK_SETTINGS : REMIX_FRAMEWORK_SETTINGS;
2939
2949
  const nodeVersion = await (0, import_build_utils3.getNodeVersion)(
2940
2950
  entrypointFsDirname,
2941
2951
  void 0,
@@ -3040,6 +3050,9 @@ var build = async ({
3040
3050
  const buildDirectory2 = (0, import_path2.join)(entrypointFsDirname, "build");
3041
3051
  if ((0, import_fs2.statSync)(buildDirectory2).isDirectory()) {
3042
3052
  console.warn("WARN: The `vercelPreset()` Preset was not detected.");
3053
+ console.warn(
3054
+ `See ${frameworkSettings.presetDocumentationLink} for more information`
3055
+ );
3043
3056
  buildResult = {
3044
3057
  buildManifest: {
3045
3058
  routes: {
@@ -3143,171 +3156,150 @@ var build = async ({
3143
3156
  });
3144
3157
  return { routes, output, framework: { version: frameworkVersion } };
3145
3158
  };
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;
3159
+ async function traceEdgeFiles({
3160
+ handlerPath,
3161
+ rootDir,
3162
+ entrypointDir
3163
+ }) {
3164
+ const EDGE_TRACE_CONDITIONS = [
3165
+ "edge-light",
3166
+ "browser",
3167
+ "module",
3168
+ "import",
3169
+ "require"
3170
+ ];
3171
+ async function edgeReadFile(fsPath) {
3172
+ let source;
3173
+ try {
3174
+ source = await import_fs2.promises.readFile(fsPath);
3175
+ } catch (err) {
3176
+ if (err.code === "ENOENT" || err.code === "EISDIR") {
3177
+ return null;
3178
+ }
3179
+ throw err;
3153
3180
  }
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;
3181
+ if ((0, import_path2.basename)(fsPath) === "package.json") {
3182
+ const pkgJson = JSON.parse(source.toString());
3183
+ for (const prop of ["browser", "module"]) {
3184
+ const val = pkgJson[prop];
3185
+ if (typeof val === "string") {
3186
+ pkgJson.main = val;
3187
+ source = JSON.stringify(pkgJson);
3188
+ break;
3189
+ }
3164
3190
  }
3165
3191
  }
3192
+ return source;
3166
3193
  }
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], {
3194
+ return await (0, import_nft.nodeFileTrace)([handlerPath], {
3203
3195
  base: rootDir,
3204
3196
  processCwd: entrypointDir,
3205
- conditions,
3206
- readFile
3197
+ conditions: EDGE_TRACE_CONDITIONS,
3198
+ readFile: edgeReadFile
3207
3199
  });
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
3200
  }
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], {
3201
+ async function traceNodeFiles({
3202
+ handlerPath,
3203
+ rootDir,
3204
+ entrypointDir
3205
+ }) {
3206
+ return await (0, import_nft.nodeFileTrace)([handlerPath], {
3252
3207
  base: rootDir,
3253
3208
  processCwd: entrypointDir
3254
3209
  });
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,
3210
+ }
3211
+ async function getFilesFromTrace({
3212
+ fileList,
3213
+ rootDir
3214
+ }) {
3215
+ const files = {};
3216
+ for (const file of fileList) {
3217
+ files[file] = await import_build_utils3.FileFsRef.fromFsPath({ fsPath: (0, import_path2.join)(rootDir, file) });
3218
+ }
3219
+ return files;
3220
+ }
3221
+ function createEdgeFunction({
3222
+ files,
3223
+ handler,
3224
+ config,
3225
+ frameworkSlug,
3226
+ frameworkVersion
3227
+ }) {
3228
+ return new import_build_utils3.EdgeFunction({
3229
+ deploymentTarget: "v8-worker",
3230
+ files,
3231
+ entrypoint: handler,
3232
+ regions: config.regions,
3233
+ framework: {
3234
+ slug: frameworkSlug,
3235
+ version: frameworkVersion
3236
+ }
3237
+ });
3238
+ }
3239
+ function createNodeFunction({
3240
+ files,
3241
+ handler,
3242
+ config,
3243
+ frameworkSlug,
3244
+ frameworkVersion,
3245
+ nodeVersion,
3246
+ useWebApi
3247
+ }) {
3248
+ return new import_build_utils3.NodejsLambda({
3249
+ shouldAddHelpers: false,
3250
+ shouldAddSourcemapSupport: false,
3251
+ operationType: "SSR",
3252
+ supportsResponseStreaming: true,
3259
3253
  files,
3260
3254
  handler,
3261
3255
  runtime: nodeVersion.runtime,
3262
3256
  regions: config.regions,
3263
3257
  memory: config.memory,
3264
3258
  maxDuration: config.maxDuration,
3265
- useWebApi: REMIX_FRAMEWORK_SETTINGS.node.options.useWebApi,
3259
+ useWebApi,
3266
3260
  framework: {
3267
- slug: REMIX_FRAMEWORK_SETTINGS.slug,
3261
+ slug: frameworkSlug,
3268
3262
  version: frameworkVersion
3269
3263
  }
3270
3264
  });
3271
- return fn;
3272
3265
  }
3273
- async function createRenderEdgeFunction(entrypointDir, rootDir, serverBuildPath, serverEntryPoint, frameworkVersion, config) {
3266
+ async function createRenderFunction({
3267
+ rootDir,
3268
+ serverBuildPath,
3269
+ serverEntryPoint,
3270
+ entrypointDir,
3271
+ config,
3272
+ frameworkVersion,
3273
+ frameworkRuntimeSettings,
3274
+ sourceSearchValue,
3275
+ frameworkSlug,
3276
+ nodeVersion
3277
+ }) {
3274
3278
  const { handler, handlerPath } = await determineHandler({
3275
3279
  rootDir,
3276
3280
  serverBuildPath,
3277
3281
  serverEntryPoint,
3278
- serverSourcePromise: REMIX_FRAMEWORK_SETTINGS.edge.serverSourcePromise,
3279
- sourceSearchValue: REMIX_FRAMEWORK_SETTINGS.sourceSearchValue
3282
+ serverSourcePromise: frameworkRuntimeSettings.serverSourcePromise,
3283
+ sourceSearchValue
3280
3284
  });
3281
- const trace = await (0, import_nft.nodeFileTrace)([handlerPath], {
3282
- base: rootDir,
3283
- processCwd: entrypointDir,
3284
- conditions: EDGE_TRACE_CONDITIONS,
3285
- readFile: edgeReadFile
3285
+ const trace = await frameworkRuntimeSettings.traceFunction({
3286
+ handlerPath,
3287
+ rootDir,
3288
+ entrypointDir
3286
3289
  });
3287
- logNftWarnings(trace.warnings, REMIX_FRAMEWORK_SETTINGS.edge.traceWarningTag);
3290
+ logNftWarnings(trace.warnings, frameworkRuntimeSettings.traceWarningTag);
3288
3291
  const files = await getFilesFromTrace({ fileList: trace.fileList, rootDir });
3289
- const fn = new import_build_utils3.EdgeFunction({
3290
- ...COMMON_EDGE_FUNCTION_OPTIONS,
3292
+ const fn = frameworkRuntimeSettings.createRuntimeFunction({
3291
3293
  files,
3292
- entrypoint: handler,
3293
- regions: config.regions,
3294
- framework: {
3295
- slug: REMIX_FRAMEWORK_SETTINGS.slug,
3296
- version: frameworkVersion
3297
- }
3294
+ handler,
3295
+ config,
3296
+ frameworkSlug,
3297
+ frameworkVersion,
3298
+ nodeVersion,
3299
+ useWebApi: frameworkRuntimeSettings.options?.useWebApi
3298
3300
  });
3299
3301
  return fn;
3300
3302
  }
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
3303
 
3312
3304
  // src/build-legacy.ts
3313
3305
  var import_ts_morph2 = require("ts-morph");
@@ -3733,7 +3725,7 @@ module.exports = config;`;
3733
3725
  };
3734
3726
  const serverBuildPath = (0, import_path4.join)(entrypointFsDirname, bundle.serverBuildPath);
3735
3727
  if (config2.runtime === "edge") {
3736
- return createRenderEdgeFunction2(
3728
+ return createRenderEdgeFunction(
3737
3729
  entrypointFsDirname,
3738
3730
  repoRootPath,
3739
3731
  serverBuildPath,
@@ -3742,7 +3734,7 @@ module.exports = config;`;
3742
3734
  config2
3743
3735
  );
3744
3736
  }
3745
- return createRenderNodeFunction2(
3737
+ return createRenderNodeFunction(
3746
3738
  nodeVersion,
3747
3739
  entrypointFsDirname,
3748
3740
  repoRootPath,
@@ -3813,7 +3805,7 @@ function hasScript2(scriptName, pkg) {
3813
3805
  const scripts = pkg && pkg.scripts || {};
3814
3806
  return typeof scripts[scriptName] === "string";
3815
3807
  }
3816
- async function createRenderNodeFunction2(nodeVersion, entrypointDir, rootDir, serverBuildPath, serverEntryPoint, remixVersion, config) {
3808
+ async function createRenderNodeFunction(nodeVersion, entrypointDir, rootDir, serverBuildPath, serverEntryPoint, remixVersion, config) {
3817
3809
  const files = {};
3818
3810
  let handler = (0, import_path4.relative)(rootDir, serverBuildPath);
3819
3811
  let handlerPath = (0, import_path4.join)(rootDir, handler);
@@ -3859,7 +3851,7 @@ async function createRenderNodeFunction2(nodeVersion, entrypointDir, rootDir, se
3859
3851
  });
3860
3852
  return fn;
3861
3853
  }
3862
- async function createRenderEdgeFunction2(entrypointDir, rootDir, serverBuildPath, serverEntryPoint, remixVersion, config) {
3854
+ async function createRenderEdgeFunction(entrypointDir, rootDir, serverBuildPath, serverEntryPoint, remixVersion, config) {
3863
3855
  const files = {};
3864
3856
  let handler = (0, import_path4.relative)(rootDir, serverBuildPath);
3865
3857
  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.2",
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": "10.0.1",
30
30
  "glob": "10.3.16",
31
31
  "jest-junit": "16.0.0",
32
32
  "semver": "7.5.2",