@vercel/fs-detectors 5.7.21 → 5.7.22

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/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { detectBuilders, detectOutputDirectory, detectApiDirectory, detectApiExtensions, type Options as DetectBuildersOptions, } from './detect-builders';
2
2
  export { detectServices, generateServicesRoutes, } from './services/detect-services';
3
+ export { isStaticBuild } from './services/utils';
3
4
  export { getServicesBuilders } from './services/get-services-builders';
4
5
  export type { DetectServicesOptions, DetectServicesResult, ResolvedService, ServicesRoutes, ServiceDetectionError, } from './services/types';
5
6
  export { detectFileSystemAPI } from './detect-file-system-api';
package/dist/index.js CHANGED
@@ -43,6 +43,7 @@ __export(src_exports, {
43
43
  getWorkspacePackagePaths: () => import_get_workspace_package_paths.getWorkspacePackagePaths,
44
44
  getWorkspaces: () => import_get_workspaces.getWorkspaces,
45
45
  isOfficialRuntime: () => import_is_official_runtime.isOfficialRuntime,
46
+ isStaticBuild: () => import_utils.isStaticBuild,
46
47
  isStaticRuntime: () => import_is_official_runtime.isStaticRuntime,
47
48
  monorepoManagers: () => import_monorepo_managers.monorepoManagers,
48
49
  packageManagers: () => import_package_managers.packageManagers,
@@ -51,6 +52,7 @@ __export(src_exports, {
51
52
  module.exports = __toCommonJS(src_exports);
52
53
  var import_detect_builders = require("./detect-builders");
53
54
  var import_detect_services = require("./services/detect-services");
55
+ var import_utils = require("./services/utils");
54
56
  var import_get_services_builders = require("./services/get-services-builders");
55
57
  var import_detect_file_system_api = require("./detect-file-system-api");
56
58
  var import_detect_framework = require("./detect-framework");
@@ -92,6 +94,7 @@ var import_detect_instrumentation = require("./detect-instrumentation");
92
94
  getWorkspacePackagePaths,
93
95
  getWorkspaces,
94
96
  isOfficialRuntime,
97
+ isStaticBuild,
95
98
  isStaticRuntime,
96
99
  monorepoManagers,
97
100
  packageManagers,
@@ -9,11 +9,12 @@ export declare function detectServices(options: DetectServicesOptions): Promise<
9
9
  /**
10
10
  * Generate routing rules for services.
11
11
  *
12
- * Web services: Routes are ordered by prefix length (longest first) to ensure
13
- * more specific routes match before broader ones. For example, `/api/users`
14
- * must be checked before `/api`, which must be checked before the catch-all `/`.
12
+ * Routes are ordered by prefix length (longest first) to ensure more specific
13
+ * routes match before broader ones. For example, `/api/users` must be checked
14
+ * before `/api`, which must be checked before the catch-all `/`.
15
15
  *
16
- * Cron/Worker services: TODO
17
- * Use internal routes under `/_svc/crons` and `/_svc/workers`
16
+ * - Static/SPA services: SPA fallback routes to index.html
17
+ * - Serverless services: Rewrite to the function entrypoint
18
+ * - Cron/Worker services: TODO - internal routes under `/_svc/`
18
19
  */
19
20
  export declare function generateServicesRoutes(services: ResolvedService[]): ServicesRoutes;
@@ -65,33 +65,34 @@ function generateServicesRoutes(services) {
65
65
  const defaults = [];
66
66
  const crons = [];
67
67
  const workers = [];
68
- const webServices = services.filter(
68
+ const sortedWebServices = services.filter(
69
69
  (s) => s.type === "web" && typeof s.routePrefix === "string"
70
- );
71
- const sortedWebServices = [...webServices].sort((a, b) => {
72
- if (a.routePrefix === "/")
73
- return 1;
74
- if (b.routePrefix === "/")
75
- return -1;
76
- return b.routePrefix.length - a.routePrefix.length;
77
- });
70
+ ).sort((a, b) => b.routePrefix.length - a.routePrefix.length);
78
71
  for (const service of sortedWebServices) {
79
- const { routePrefix, builder } = service;
80
- const builderSrc = builder.src || routePrefix;
81
- const functionPath = builderSrc.startsWith("/") ? builderSrc : `/${builderSrc}`;
82
- if (routePrefix === "/") {
83
- defaults.push({
84
- src: "^/(.*)$",
85
- dest: functionPath,
86
- check: true
87
- });
72
+ const { routePrefix } = service;
73
+ const normalizedPrefix = routePrefix.slice(1);
74
+ if ((0, import_utils.isStaticBuild)(service)) {
75
+ if (routePrefix === "/") {
76
+ defaults.push({ handle: "filesystem" });
77
+ defaults.push({ src: "/(.*)", dest: "/index.html" });
78
+ } else {
79
+ rewrites.push({
80
+ src: `^/${normalizedPrefix}(?:/.*)?$`,
81
+ dest: `/${normalizedPrefix}/index.html`
82
+ });
83
+ }
88
84
  } else {
89
- const normalizedPrefix = routePrefix.startsWith("/") ? routePrefix.slice(1) : routePrefix;
90
- rewrites.push({
91
- src: `^/${normalizedPrefix}(?:/.*)?$`,
92
- dest: functionPath,
93
- check: true
94
- });
85
+ const builderSrc = service.builder.src || routePrefix;
86
+ const functionPath = builderSrc.startsWith("/") ? builderSrc : `/${builderSrc}`;
87
+ if (routePrefix === "/") {
88
+ defaults.push({ src: "^/(.*)$", dest: functionPath, check: true });
89
+ } else {
90
+ rewrites.push({
91
+ src: `^/${normalizedPrefix}(?:/.*)?$`,
92
+ dest: functionPath,
93
+ check: true
94
+ });
95
+ }
95
96
  }
96
97
  }
97
98
  return { rewrites, defaults, crons, workers };
@@ -131,7 +131,7 @@ function resolveConfiguredService(name, config, group) {
131
131
  builderUse = (0, import_utils.getBuilderForRuntime)(inferredRuntime);
132
132
  builderSrc = config.entrypoint;
133
133
  }
134
- const routePrefix = type === "web" ? config.routePrefix : void 0;
134
+ const routePrefix = type === "web" && config.routePrefix ? config.routePrefix.startsWith("/") ? config.routePrefix : `/${config.routePrefix}` : void 0;
135
135
  const isRoot = workspace === ".";
136
136
  if (!isRoot && !builderSrc.startsWith(workspace + "/")) {
137
137
  builderSrc = import_path.posix.join(workspace, builderSrc);
@@ -147,6 +147,13 @@ function resolveConfiguredService(name, config, group) {
147
147
  builderConfig.excludeFiles = config.excludeFiles;
148
148
  const isStaticBuild = import_types.STATIC_BUILDERS.has(builderUse);
149
149
  const runtime = isStaticBuild ? void 0 : inferredRuntime;
150
+ if (routePrefix) {
151
+ const stripped = routePrefix.startsWith("/") ? routePrefix.slice(1) : routePrefix;
152
+ builderConfig.routePrefix = stripped || ".";
153
+ }
154
+ if (config.framework) {
155
+ builderConfig.framework = config.framework;
156
+ }
150
157
  return {
151
158
  name,
152
159
  type,
@@ -1,6 +1,7 @@
1
1
  import type { DetectorFilesystem } from '../detectors/filesystem';
2
- import type { ServiceRuntime, ExperimentalServices, ServiceDetectionError } from './types';
2
+ import type { ServiceRuntime, ExperimentalServices, ServiceDetectionError, ResolvedService } from './types';
3
3
  export declare function getBuilderForRuntime(runtime: ServiceRuntime): string;
4
+ export declare function isStaticBuild(service: ResolvedService): boolean;
4
5
  /**
5
6
  * Infer runtime from available service configuration.
6
7
  *
@@ -20,6 +20,7 @@ var utils_exports = {};
20
20
  __export(utils_exports, {
21
21
  getBuilderForRuntime: () => getBuilderForRuntime,
22
22
  inferServiceRuntime: () => inferServiceRuntime,
23
+ isStaticBuild: () => isStaticBuild,
23
24
  readVercelConfig: () => readVercelConfig
24
25
  });
25
26
  module.exports = __toCommonJS(utils_exports);
@@ -32,6 +33,9 @@ function getBuilderForRuntime(runtime) {
32
33
  }
33
34
  return builder;
34
35
  }
36
+ function isStaticBuild(service) {
37
+ return import_types.STATIC_BUILDERS.has(service.builder.use);
38
+ }
35
39
  function inferServiceRuntime(config) {
36
40
  if (config.runtime && config.runtime in import_types.RUNTIME_BUILDERS) {
37
41
  return config.runtime;
@@ -81,5 +85,6 @@ async function readVercelConfig(fs) {
81
85
  0 && (module.exports = {
82
86
  getBuilderForRuntime,
83
87
  inferServiceRuntime,
88
+ isStaticBuild,
84
89
  readVercelConfig
85
90
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/fs-detectors",
3
- "version": "5.7.21",
3
+ "version": "5.7.22",
4
4
  "description": "Vercel filesystem detectors",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -20,8 +20,8 @@
20
20
  "minimatch": "3.1.2",
21
21
  "semver": "6.3.1",
22
22
  "@vercel/error-utils": "2.0.3",
23
- "@vercel/frameworks": "3.16.1",
24
- "@vercel/routing-utils": "5.3.2"
23
+ "@vercel/routing-utils": "5.3.2",
24
+ "@vercel/frameworks": "3.16.1"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/glob": "7.2.0",