@vercel/fs-detectors 5.8.16 → 5.8.18

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
@@ -2,7 +2,7 @@ export { detectBuilders, detectOutputDirectory, detectApiDirectory, detectApiExt
2
2
  export { detectServices, generateServicesRoutes, } from './services/detect-services';
3
3
  export { autoDetectServices } from './services/auto-detect';
4
4
  export type { AutoDetectOptions, AutoDetectResult, } from './services/auto-detect';
5
- export { isStaticBuild, isRouteOwningBuilder, INTERNAL_SERVICE_PREFIX, getInternalServiceFunctionPath, } from './services/utils';
5
+ export { isStaticBuild, isRouteOwningBuilder, INTERNAL_SERVICE_PREFIX, getInternalServiceFunctionPath, getInternalServiceCronPath, getInternalServiceCronPathPrefix, getInternalServiceWorkerPath, getInternalServiceWorkerPathPrefix, } from './services/utils';
6
6
  export { getServicesBuilders } from './services/get-services-builders';
7
7
  export type { DetectServicesOptions, DetectServicesResult, DetectServicesSource, ResolvedService, Service, ServicesRoutes, ServiceDetectionError, } from './services/types';
8
8
  export { detectFileSystemAPI } from './detect-file-system-api';
package/dist/index.js CHANGED
@@ -40,7 +40,11 @@ __export(src_exports, {
40
40
  detectOutputDirectory: () => import_detect_builders.detectOutputDirectory,
41
41
  detectServices: () => import_detect_services.detectServices,
42
42
  generateServicesRoutes: () => import_detect_services.generateServicesRoutes,
43
+ getInternalServiceCronPath: () => import_utils.getInternalServiceCronPath,
44
+ getInternalServiceCronPathPrefix: () => import_utils.getInternalServiceCronPathPrefix,
43
45
  getInternalServiceFunctionPath: () => import_utils.getInternalServiceFunctionPath,
46
+ getInternalServiceWorkerPath: () => import_utils.getInternalServiceWorkerPath,
47
+ getInternalServiceWorkerPathPrefix: () => import_utils.getInternalServiceWorkerPathPrefix,
44
48
  getProjectPaths: () => import_get_project_paths.getProjectPaths,
45
49
  getServicesBuilders: () => import_get_services_builders.getServicesBuilders,
46
50
  getWorkspacePackagePaths: () => import_get_workspace_package_paths.getWorkspacePackagePaths,
@@ -96,7 +100,11 @@ var import_detect_instrumentation = require("./detect-instrumentation");
96
100
  detectOutputDirectory,
97
101
  detectServices,
98
102
  generateServicesRoutes,
103
+ getInternalServiceCronPath,
104
+ getInternalServiceCronPathPrefix,
99
105
  getInternalServiceFunctionPath,
106
+ getInternalServiceWorkerPath,
107
+ getInternalServiceWorkerPathPrefix,
100
108
  getProjectPaths,
101
109
  getServicesBuilders,
102
110
  getWorkspacePackagePaths,
@@ -112,6 +112,9 @@ async function detectServicesAtRoot(fs, rootFramework) {
112
112
  if (backendResult.error) {
113
113
  return { services: null, errors: [backendResult.error] };
114
114
  }
115
+ if (Object.keys(backendResult.services).length === 0) {
116
+ return { services: null, errors: [] };
117
+ }
115
118
  Object.assign(services, backendResult.services);
116
119
  return { services, errors: [] };
117
120
  }
@@ -26,6 +26,12 @@ export declare function detectServices(options: DetectServicesOptions): Promise<
26
26
  * Builders that provide their own routing (`@vercel/next`, `@vercel/backends`,
27
27
  * Build Output API builders, etc.) are not given synthetic routes here.
28
28
  *
29
- * - Cron/Worker services: TODO - internal routes under `/_svc/`
29
+ * - Worker services:
30
+ * Internal queue callback routes under `/_svc/{serviceName}/workers/{entry}/{handler}`
31
+ * that rewrite to `/_svc/{serviceName}/index`.
32
+ *
33
+ * - Cron services:
34
+ * Internal cron callback routes under `/_svc/{serviceName}/crons/{entry}/{handler}`
35
+ * that rewrite to `/_svc/{serviceName}/index`.
30
36
  */
31
37
  export declare function generateServicesRoutes(services: ResolvedService[]): ServicesRoutes;
@@ -148,8 +148,36 @@ function generateServicesRoutes(services) {
148
148
  continue;
149
149
  }
150
150
  }
151
+ const workerServices = services.filter((s) => s.type === "worker");
152
+ for (const service of workerServices) {
153
+ const workerEntrypoint = service.entrypoint || service.builder.src || "index";
154
+ const workerPath = (0, import_utils.getInternalServiceWorkerPath)(
155
+ service.name,
156
+ workerEntrypoint
157
+ );
158
+ const functionPath = (0, import_utils.getInternalServiceFunctionPath)(service.name);
159
+ workers.push({
160
+ src: `^${escapeRegex(workerPath)}$`,
161
+ dest: functionPath,
162
+ check: true
163
+ });
164
+ }
165
+ const cronServices = services.filter((s) => s.type === "cron");
166
+ for (const service of cronServices) {
167
+ const cronEntrypoint = service.entrypoint || service.builder.src || "index";
168
+ const cronPath = (0, import_utils.getInternalServiceCronPath)(service.name, cronEntrypoint);
169
+ const functionPath = (0, import_utils.getInternalServiceFunctionPath)(service.name);
170
+ crons.push({
171
+ src: `^${escapeRegex(cronPath)}$`,
172
+ dest: functionPath,
173
+ check: true
174
+ });
175
+ }
151
176
  return { rewrites, defaults, crons, workers };
152
177
  }
178
+ function escapeRegex(str) {
179
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
180
+ }
153
181
  function getWebRoutePrefixes(services) {
154
182
  const unique = /* @__PURE__ */ new Set();
155
183
  for (const service of services) {
@@ -84,7 +84,11 @@ async function getServicesBuilders(options) {
84
84
  warnings: warningResponses,
85
85
  defaultRoutes: result.routes.defaults.length > 0 ? result.routes.defaults : null,
86
86
  redirectRoutes: [],
87
- rewriteRoutes: result.routes.rewrites.length > 0 ? result.routes.rewrites : null,
87
+ rewriteRoutes: result.routes.rewrites.length > 0 || result.routes.workers.length > 0 || result.routes.crons.length > 0 ? [
88
+ ...result.routes.rewrites,
89
+ ...result.routes.workers,
90
+ ...result.routes.crons
91
+ ] : null,
88
92
  errorRoutes: [],
89
93
  services: result.services
90
94
  };
@@ -22,13 +22,11 @@ export interface ServicesRoutes {
22
22
  /**
23
23
  * Internal routes for cron services.
24
24
  * These route `/_svc/{serviceName}/crons/{entry}/{handler}` to the cron function.
25
- * TODO: Implement
26
25
  */
27
26
  crons: Route[];
28
27
  /**
29
28
  * Internal routes for worker services.
30
29
  * These route `/_svc/{serviceName}/workers/{entry}/{handler}` to the worker function.
31
- * TODO: Implement
32
30
  */
33
31
  workers: Route[];
34
32
  }
@@ -6,6 +6,10 @@ export declare function hasFile(fs: DetectorFilesystem, filePath: string): Promi
6
6
  */
7
7
  export declare const INTERNAL_SERVICE_PREFIX = "/_svc";
8
8
  export declare function getInternalServiceFunctionPath(serviceName: string): string;
9
+ export declare function getInternalServiceWorkerPathPrefix(serviceName: string): string;
10
+ export declare function getInternalServiceCronPathPrefix(serviceName: string): string;
11
+ export declare function getInternalServiceWorkerPath(serviceName: string, entrypoint: string, handler?: string): string;
12
+ export declare function getInternalServiceCronPath(serviceName: string, entrypoint: string, handler?: string): string;
9
13
  export declare function getBuilderForRuntime(runtime: ServiceRuntime): string;
10
14
  export declare function isStaticBuild(service: ResolvedService): boolean;
11
15
  /**
@@ -21,7 +21,11 @@ __export(utils_exports, {
21
21
  INTERNAL_SERVICE_PREFIX: () => INTERNAL_SERVICE_PREFIX,
22
22
  filterFrameworksByRuntime: () => filterFrameworksByRuntime,
23
23
  getBuilderForRuntime: () => getBuilderForRuntime,
24
+ getInternalServiceCronPath: () => getInternalServiceCronPath,
25
+ getInternalServiceCronPathPrefix: () => getInternalServiceCronPathPrefix,
24
26
  getInternalServiceFunctionPath: () => getInternalServiceFunctionPath,
27
+ getInternalServiceWorkerPath: () => getInternalServiceWorkerPath,
28
+ getInternalServiceWorkerPathPrefix: () => getInternalServiceWorkerPathPrefix,
25
29
  hasFile: () => hasFile,
26
30
  inferRuntimeFromFramework: () => inferRuntimeFromFramework,
27
31
  inferServiceRuntime: () => inferServiceRuntime,
@@ -43,6 +47,24 @@ const INTERNAL_SERVICE_PREFIX = "/_svc";
43
47
  function getInternalServiceFunctionPath(serviceName) {
44
48
  return `${INTERNAL_SERVICE_PREFIX}/${serviceName}/index`;
45
49
  }
50
+ function normalizeInternalServiceEntrypoint(entrypoint) {
51
+ const normalized = entrypoint.replace(/\\/g, "/").replace(/^\/+/, "").replace(/\.[^/.]+$/, "");
52
+ return normalized || "index";
53
+ }
54
+ function getInternalServiceWorkerPathPrefix(serviceName) {
55
+ return `${INTERNAL_SERVICE_PREFIX}/${serviceName}/workers`;
56
+ }
57
+ function getInternalServiceCronPathPrefix(serviceName) {
58
+ return `${INTERNAL_SERVICE_PREFIX}/${serviceName}/crons`;
59
+ }
60
+ function getInternalServiceWorkerPath(serviceName, entrypoint, handler = "worker") {
61
+ const normalizedEntrypoint = normalizeInternalServiceEntrypoint(entrypoint);
62
+ return `${getInternalServiceWorkerPathPrefix(serviceName)}/${normalizedEntrypoint}/${handler}`;
63
+ }
64
+ function getInternalServiceCronPath(serviceName, entrypoint, handler = "cron") {
65
+ const normalizedEntrypoint = normalizeInternalServiceEntrypoint(entrypoint);
66
+ return `${getInternalServiceCronPathPrefix(serviceName)}/${normalizedEntrypoint}/${handler}`;
67
+ }
46
68
  function getBuilderForRuntime(runtime) {
47
69
  const builder = import_types.RUNTIME_BUILDERS[runtime];
48
70
  if (!builder) {
@@ -127,7 +149,11 @@ async function readVercelConfig(fs) {
127
149
  INTERNAL_SERVICE_PREFIX,
128
150
  filterFrameworksByRuntime,
129
151
  getBuilderForRuntime,
152
+ getInternalServiceCronPath,
153
+ getInternalServiceCronPathPrefix,
130
154
  getInternalServiceFunctionPath,
155
+ getInternalServiceWorkerPath,
156
+ getInternalServiceWorkerPathPrefix,
131
157
  hasFile,
132
158
  inferRuntimeFromFramework,
133
159
  inferServiceRuntime,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/fs-detectors",
3
- "version": "5.8.16",
3
+ "version": "5.8.18",
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.20.0",
24
- "@vercel/routing-utils": "6.0.2"
23
+ "@vercel/routing-utils": "6.0.2",
24
+ "@vercel/frameworks": "3.20.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/glob": "7.2.0",
@@ -32,7 +32,7 @@
32
32
  "@types/semver": "7.3.10",
33
33
  "jest-junit": "16.0.0",
34
34
  "typescript": "4.9.5",
35
- "@vercel/build-utils": "13.6.2"
35
+ "@vercel/build-utils": "13.6.3"
36
36
  },
37
37
  "scripts": {
38
38
  "build": "node ../../utils/build.mjs",