@vercel/fs-detectors 5.8.16 → 5.8.17

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, 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,10 @@ __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
+ getInternalServiceCronPathPrefix: () => import_utils.getInternalServiceCronPathPrefix,
43
44
  getInternalServiceFunctionPath: () => import_utils.getInternalServiceFunctionPath,
45
+ getInternalServiceWorkerPath: () => import_utils.getInternalServiceWorkerPath,
46
+ getInternalServiceWorkerPathPrefix: () => import_utils.getInternalServiceWorkerPathPrefix,
44
47
  getProjectPaths: () => import_get_project_paths.getProjectPaths,
45
48
  getServicesBuilders: () => import_get_services_builders.getServicesBuilders,
46
49
  getWorkspacePackagePaths: () => import_get_workspace_package_paths.getWorkspacePackagePaths,
@@ -96,7 +99,10 @@ var import_detect_instrumentation = require("./detect-instrumentation");
96
99
  detectOutputDirectory,
97
100
  detectServices,
98
101
  generateServicesRoutes,
102
+ getInternalServiceCronPathPrefix,
99
103
  getInternalServiceFunctionPath,
104
+ getInternalServiceWorkerPath,
105
+ getInternalServiceWorkerPathPrefix,
100
106
  getProjectPaths,
101
107
  getServicesBuilders,
102
108
  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,10 @@ 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: TODO - internal routes under `/_svc/`
30
34
  */
31
35
  export declare function generateServicesRoutes(services: ResolvedService[]): ServicesRoutes;
@@ -148,8 +148,25 @@ 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
+ }
151
165
  return { rewrites, defaults, crons, workers };
152
166
  }
167
+ function escapeRegex(str) {
168
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
169
+ }
153
170
  function getWebRoutePrefixes(services) {
154
171
  const unique = /* @__PURE__ */ new Set();
155
172
  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
  };
@@ -28,7 +28,6 @@ export interface ServicesRoutes {
28
28
  /**
29
29
  * Internal routes for worker services.
30
30
  * These route `/_svc/{serviceName}/workers/{entry}/{handler}` to the worker function.
31
- * TODO: Implement
32
31
  */
33
32
  workers: Route[];
34
33
  }
@@ -6,6 +6,9 @@ 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;
9
12
  export declare function getBuilderForRuntime(runtime: ServiceRuntime): string;
10
13
  export declare function isStaticBuild(service: ResolvedService): boolean;
11
14
  /**
@@ -21,7 +21,10 @@ __export(utils_exports, {
21
21
  INTERNAL_SERVICE_PREFIX: () => INTERNAL_SERVICE_PREFIX,
22
22
  filterFrameworksByRuntime: () => filterFrameworksByRuntime,
23
23
  getBuilderForRuntime: () => getBuilderForRuntime,
24
+ getInternalServiceCronPathPrefix: () => getInternalServiceCronPathPrefix,
24
25
  getInternalServiceFunctionPath: () => getInternalServiceFunctionPath,
26
+ getInternalServiceWorkerPath: () => getInternalServiceWorkerPath,
27
+ getInternalServiceWorkerPathPrefix: () => getInternalServiceWorkerPathPrefix,
25
28
  hasFile: () => hasFile,
26
29
  inferRuntimeFromFramework: () => inferRuntimeFromFramework,
27
30
  inferServiceRuntime: () => inferServiceRuntime,
@@ -43,6 +46,20 @@ const INTERNAL_SERVICE_PREFIX = "/_svc";
43
46
  function getInternalServiceFunctionPath(serviceName) {
44
47
  return `${INTERNAL_SERVICE_PREFIX}/${serviceName}/index`;
45
48
  }
49
+ function normalizeInternalServiceEntrypoint(entrypoint) {
50
+ const normalized = entrypoint.replace(/\\/g, "/").replace(/^\/+/, "").replace(/\.[^/.]+$/, "");
51
+ return normalized || "index";
52
+ }
53
+ function getInternalServiceWorkerPathPrefix(serviceName) {
54
+ return `${INTERNAL_SERVICE_PREFIX}/${serviceName}/workers`;
55
+ }
56
+ function getInternalServiceCronPathPrefix(serviceName) {
57
+ return `${INTERNAL_SERVICE_PREFIX}/${serviceName}/crons`;
58
+ }
59
+ function getInternalServiceWorkerPath(serviceName, entrypoint, handler = "worker") {
60
+ const normalizedEntrypoint = normalizeInternalServiceEntrypoint(entrypoint);
61
+ return `${getInternalServiceWorkerPathPrefix(serviceName)}/${normalizedEntrypoint}/${handler}`;
62
+ }
46
63
  function getBuilderForRuntime(runtime) {
47
64
  const builder = import_types.RUNTIME_BUILDERS[runtime];
48
65
  if (!builder) {
@@ -127,7 +144,10 @@ async function readVercelConfig(fs) {
127
144
  INTERNAL_SERVICE_PREFIX,
128
145
  filterFrameworksByRuntime,
129
146
  getBuilderForRuntime,
147
+ getInternalServiceCronPathPrefix,
130
148
  getInternalServiceFunctionPath,
149
+ getInternalServiceWorkerPath,
150
+ getInternalServiceWorkerPathPrefix,
131
151
  hasFile,
132
152
  inferRuntimeFromFramework,
133
153
  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.17",
4
4
  "description": "Vercel filesystem detectors",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -19,9 +19,9 @@
19
19
  "json5": "2.2.2",
20
20
  "minimatch": "3.1.2",
21
21
  "semver": "6.3.1",
22
+ "@vercel/routing-utils": "6.0.2",
22
23
  "@vercel/error-utils": "2.0.3",
23
- "@vercel/frameworks": "3.20.0",
24
- "@vercel/routing-utils": "6.0.2"
24
+ "@vercel/frameworks": "3.20.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/glob": "7.2.0",