@vercel/fs-detectors 6.1.0 → 6.2.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.
@@ -41,6 +41,7 @@ export declare function detectBuilders(files: string[], pkg?: PackageJson | unde
41
41
  warnings: ErrorResponse[];
42
42
  hostRewriteRoutes?: Route[] | null;
43
43
  defaultRoutes: Route[] | null;
44
+ fallbackRoutes?: Route[] | null;
44
45
  redirectRoutes: Route[] | null;
45
46
  rewriteRoutes: Route[] | null;
46
47
  errorRoutes: Route[] | null;
@@ -97,7 +97,9 @@ async function detectBuilders(files, pkg, options = {}) {
97
97
  const hasServicesConfig = services != null && typeof services === "object";
98
98
  if (hasServicesConfig || framework === "services") {
99
99
  return (0, import_get_services_builders.getServicesBuilders)({
100
- workPath: options.workPath
100
+ workPath: options.workPath,
101
+ configuredServices: services,
102
+ projectFramework: framework
101
103
  });
102
104
  }
103
105
  const errors = [];
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var get_project_paths_exports = {};
30
20
  __export(get_project_paths_exports, {
@@ -32,7 +22,7 @@ __export(get_project_paths_exports, {
32
22
  });
33
23
  module.exports = __toCommonJS(get_project_paths_exports);
34
24
  var import_detect_framework = require("./detect-framework");
35
- var import_frameworks = __toESM(require("@vercel/frameworks"));
25
+ var import_frameworks = require("@vercel/frameworks");
36
26
  const MAX_DEPTH_TRAVERSE = 3;
37
27
  const getProjectPaths = async ({
38
28
  fs,
@@ -49,7 +39,7 @@ const getProjectPaths = async ({
49
39
  }
50
40
  const framework = await (0, import_detect_framework.detectFramework)({
51
41
  fs: fs.chdir(topPath),
52
- frameworkList: import_frameworks.default
42
+ frameworkList: import_frameworks.frameworkList
53
43
  });
54
44
  if (framework !== null)
55
45
  allPaths.push(topPath);
@@ -37,6 +37,7 @@ function emptyRoutes() {
37
37
  hostRewrites: [],
38
38
  rewrites: [],
39
39
  defaults: [],
40
+ fallbacks: [],
40
41
  crons: [],
41
42
  workers: []
42
43
  };
@@ -186,6 +187,7 @@ function generateServicesRoutes(services) {
186
187
  const hostRewrites = [];
187
188
  const rewrites = [];
188
189
  const defaults = [];
190
+ const fallbacks = [];
189
191
  const crons = [];
190
192
  const workers = [];
191
193
  const sortedWebServices = services.filter(
@@ -222,13 +224,12 @@ function generateServicesRoutes(services) {
222
224
  }
223
225
  if ((0, import_utils.isStaticBuild)(service)) {
224
226
  if (routePrefix === "/") {
225
- defaults.push({ handle: "filesystem" });
226
- defaults.push({
227
+ fallbacks.push({
227
228
  src: (0, import_routing_utils.scopeRouteSourceToOwnership)("/(.*)", ownershipGuard),
228
229
  dest: "/index.html"
229
230
  });
230
231
  } else {
231
- rewrites.push({
232
+ fallbacks.push({
232
233
  src: (0, import_routing_utils.scopeRouteSourceToOwnership)(
233
234
  `^/${normalizedPrefix}(?:/.*)?$`,
234
235
  ownershipGuard
@@ -266,7 +267,7 @@ function generateServicesRoutes(services) {
266
267
  check: true
267
268
  });
268
269
  }
269
- return { hostRewrites, rewrites, defaults, crons, workers };
270
+ return { hostRewrites, rewrites, defaults, fallbacks, crons, workers };
270
271
  }
271
272
  function escapeRegex(str) {
272
273
  return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
@@ -1,5 +1,5 @@
1
1
  import type { Route } from '@vercel/routing-utils';
2
- import type { Builder } from '@vercel/build-utils';
2
+ import type { Builder, ExperimentalServices } from '@vercel/build-utils';
3
3
  import type { ResolvedService } from './types';
4
4
  export interface ErrorResponse {
5
5
  code: string;
@@ -9,6 +9,8 @@ export interface ErrorResponse {
9
9
  }
10
10
  export interface GetServicesBuildersOptions {
11
11
  workPath?: string;
12
+ configuredServices?: ExperimentalServices;
13
+ projectFramework?: string | null;
12
14
  }
13
15
  export interface ServicesBuildersResult {
14
16
  builders: Builder[] | null;
@@ -16,6 +18,7 @@ export interface ServicesBuildersResult {
16
18
  warnings: ErrorResponse[];
17
19
  hostRewriteRoutes: Route[] | null;
18
20
  defaultRoutes: Route[] | null;
21
+ fallbackRoutes: Route[] | null;
19
22
  redirectRoutes: Route[] | null;
20
23
  rewriteRoutes: Route[] | null;
21
24
  errorRoutes: Route[] | null;
@@ -23,8 +23,31 @@ __export(get_services_builders_exports, {
23
23
  module.exports = __toCommonJS(get_services_builders_exports);
24
24
  var import_detect_services = require("./detect-services");
25
25
  var import_local_file_system_detector = require("../detectors/local-file-system-detector");
26
+ function isExperimentalServicesAutoDetectionEnabled() {
27
+ const env = process.env.VERCEL_USE_EXPERIMENTAL_SERVICES;
28
+ return env === "1" || env?.toLowerCase() === "true";
29
+ }
26
30
  async function getServicesBuilders(options) {
27
- const { workPath } = options;
31
+ const { workPath, configuredServices, projectFramework } = options;
32
+ const hasServiceDefinitions = configuredServices != null && Object.keys(configuredServices).length > 0;
33
+ if (projectFramework === "services" && !hasServiceDefinitions && !isExperimentalServicesAutoDetectionEnabled()) {
34
+ return {
35
+ builders: null,
36
+ errors: [
37
+ {
38
+ code: "MISSING_EXPERIMENTAL_SERVICES",
39
+ message: 'Project framework is set to "services", but no services are declared. Add `experimentalServices` to vercel.json with at least one service, or change the project framework setting.'
40
+ }
41
+ ],
42
+ warnings: [],
43
+ hostRewriteRoutes: null,
44
+ defaultRoutes: null,
45
+ fallbackRoutes: null,
46
+ redirectRoutes: null,
47
+ rewriteRoutes: null,
48
+ errorRoutes: null
49
+ };
50
+ }
28
51
  if (!workPath) {
29
52
  return {
30
53
  builders: null,
@@ -37,6 +60,7 @@ async function getServicesBuilders(options) {
37
60
  warnings: [],
38
61
  hostRewriteRoutes: null,
39
62
  defaultRoutes: null,
63
+ fallbackRoutes: null,
40
64
  redirectRoutes: null,
41
65
  rewriteRoutes: null,
42
66
  errorRoutes: null
@@ -58,6 +82,7 @@ async function getServicesBuilders(options) {
58
82
  warnings: warningResponses,
59
83
  hostRewriteRoutes: null,
60
84
  defaultRoutes: null,
85
+ fallbackRoutes: null,
61
86
  redirectRoutes: null,
62
87
  rewriteRoutes: null,
63
88
  errorRoutes: null
@@ -75,6 +100,7 @@ async function getServicesBuilders(options) {
75
100
  warnings: warningResponses,
76
101
  hostRewriteRoutes: null,
77
102
  defaultRoutes: null,
103
+ fallbackRoutes: null,
78
104
  redirectRoutes: null,
79
105
  rewriteRoutes: null,
80
106
  errorRoutes: null
@@ -87,6 +113,7 @@ async function getServicesBuilders(options) {
87
113
  warnings: warningResponses,
88
114
  hostRewriteRoutes: result.routes.hostRewrites.length > 0 ? result.routes.hostRewrites : null,
89
115
  defaultRoutes: result.routes.defaults.length > 0 ? result.routes.defaults : null,
116
+ fallbackRoutes: result.routes.fallbacks.length > 0 ? result.routes.fallbacks : null,
90
117
  redirectRoutes: [],
91
118
  rewriteRoutes: result.routes.rewrites.length > 0 || result.routes.workers.length > 0 || result.routes.crons.length > 0 ? [
92
119
  ...result.routes.rewrites,
@@ -282,7 +282,10 @@ function validateServiceConfig(name, config) {
282
282
  }
283
283
  const serviceType = config.type || "web";
284
284
  const isJobService = serviceType === "job" || serviceType === "cron";
285
- const isScheduleJobService = serviceType === "cron" || serviceType === "job" && config.trigger === "schedule";
285
+ const isScheduleJobService = (0, import_build_utils.isScheduleTriggeredService)({
286
+ type: serviceType,
287
+ trigger: config.trigger
288
+ });
286
289
  const isQueueJobService = serviceType === "job" && config.trigger === "queue";
287
290
  const isWorkflowService = serviceType === "job" && config.trigger === "workflow";
288
291
  const isNonWebService = serviceType === "worker" || isJobService;
@@ -527,7 +530,8 @@ async function resolveConfiguredService(options) {
527
530
  builderUse = config.builder;
528
531
  builderSrc = resolvedEntrypointFile || frameworkDefinition?.useRuntime?.src || "package.json";
529
532
  } else if (config.framework) {
530
- if (type === "web" && (0, import_build_utils2.isNodeBackendFramework)(config.framework)) {
533
+ const isCronService = (0, import_build_utils.isScheduleTriggeredService)({ type, trigger });
534
+ if ((0, import_build_utils2.isNodeBackendFramework)(config.framework) && (type === "web" || isCronService)) {
531
535
  builderUse = "@vercel/backends";
532
536
  } else {
533
537
  builderUse = frameworkDefinition?.useRuntime?.use || "@vercel/static-build";
@@ -540,7 +544,8 @@ async function resolveConfiguredService(options) {
540
544
  );
541
545
  }
542
546
  if (inferredRuntime === "node") {
543
- builderUse = type === "web" ? "@vercel/backends" : "@vercel/node";
547
+ const isCronService = (0, import_build_utils.isScheduleTriggeredService)({ type, trigger });
548
+ builderUse = type === "web" || isCronService ? "@vercel/backends" : "@vercel/node";
544
549
  } else {
545
550
  builderUse = (0, import_utils.getBuilderForRuntime)(inferredRuntime);
546
551
  }
@@ -21,6 +21,8 @@ export interface ServicesRoutes {
21
21
  rewrites: Route[];
22
22
  /** Default routes (catch-all for root web service) */
23
23
  defaults: Route[];
24
+ /** SPA fallback routes for static web services */
25
+ fallbacks: Route[];
24
26
  /**
25
27
  * Internal routes for schedule-triggered job services.
26
28
  * These route `/_svc/{serviceName}/crons/{entry}/{handler}` to the scheduled job function.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/fs-detectors",
3
- "version": "6.1.0",
3
+ "version": "6.2.0",
4
4
  "description": "Vercel filesystem detectors",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -20,25 +20,27 @@
20
20
  "minimatch": "3.1.2",
21
21
  "semver": "6.3.1",
22
22
  "smol-toml": "1.5.2",
23
- "@vercel/build-utils": "13.21.0",
24
23
  "@vercel/error-utils": "2.1.0",
25
- "@vercel/frameworks": "3.25.0",
24
+ "@vercel/build-utils": "13.22.0",
25
+ "@vercel/frameworks": "3.25.1",
26
26
  "@vercel/routing-utils": "6.2.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/glob": "7.2.0",
30
- "@types/jest": "27.5.1",
31
30
  "@types/js-yaml": "4.0.5",
32
31
  "@types/minimatch": "3.0.5",
33
32
  "@types/node": "20.11.0",
34
33
  "@types/semver": "7.3.10",
35
- "jest-junit": "16.0.0"
34
+ "vitest": "2.0.3"
36
35
  },
37
36
  "scripts": {
38
37
  "build": "node ../../utils/build.mjs",
39
- "test": "jest --reporters=default --reporters=jest-junit --env node --verbose --runInBand --bail",
38
+ "test": "vitest run --config ../../vitest.config.mts",
40
39
  "test-unit": "pnpm test test/unit.*test.*",
41
40
  "test-e2e": "pnpm test test/integration.test.ts",
42
- "type-check": "tsc --noEmit"
41
+ "type-check": "tsc --noEmit",
42
+ "vitest-run": "vitest -c ../../vitest.config.mts",
43
+ "vitest-unit": "glob --absolute 'test/unit.*test.*'",
44
+ "vitest-e2e": "glob --absolute 'test/integration.test.ts'"
43
45
  }
44
46
  }