@vercel/fs-detectors 7.12.4 → 7.13.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.
- package/dist/detect-builders.d.ts +28 -1
- package/dist/detect-builders.js +18 -8
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -0
- package/dist/services/resolve-v2.js +94 -6
- package/package.json +6 -6
|
@@ -5,6 +5,11 @@ import type { PackageJson, Builder, BuilderFunctions, ProjectSettings } from '@v
|
|
|
5
5
|
* Pattern for finding all supported middleware files.
|
|
6
6
|
*/
|
|
7
7
|
export declare const REGEX_MIDDLEWARE_FILES = "middleware.[jt]s";
|
|
8
|
+
/**
|
|
9
|
+
* Pattern for files that the Vercel platform cares about separately from frameworks.
|
|
10
|
+
* These files are excluded from static file serving.
|
|
11
|
+
*/
|
|
12
|
+
export declare const VERCEL_PLATFORM_FILES: string[];
|
|
8
13
|
export declare const REGEX_VERCEL_PLATFORM_FILES: string;
|
|
9
14
|
/**
|
|
10
15
|
* Pattern for non-Vercel platform files.
|
|
@@ -63,6 +68,21 @@ export declare function detectBuilders(files: string[], pkg?: PackageJson | unde
|
|
|
63
68
|
rewriteRoutes: Route[] | null;
|
|
64
69
|
errorRoutes: Route[] | null;
|
|
65
70
|
}>;
|
|
71
|
+
export interface ResolvedProxy {
|
|
72
|
+
/**
|
|
73
|
+
* `vercel-config`: the `proxy` property in the Vercel config (`vercel.json`, etc.).
|
|
74
|
+
* `file-convention`: a root-level `middleware.js` / `middleware.ts`.
|
|
75
|
+
*/
|
|
76
|
+
source: 'vercel-config' | 'file-convention';
|
|
77
|
+
entrypoint: string | null;
|
|
78
|
+
file: string;
|
|
79
|
+
builder: Builder;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Resolves the project's proxy: the `proxy` entrypoint if configured,
|
|
83
|
+
* otherwise a root-level `middleware.js` / `middleware.ts`.
|
|
84
|
+
*/
|
|
85
|
+
export declare function resolveProxy(files: string[], options: Options): ResolvedProxy | null;
|
|
66
86
|
export declare function getProxyBuilder(proxy: ProxyConfig, tag?: string, functions?: BuilderFunctions): Builder;
|
|
67
87
|
/**
|
|
68
88
|
* Validates a `proxy` config value in isolation, without knowledge of the
|
|
@@ -70,4 +90,11 @@ export declare function getProxyBuilder(proxy: ProxyConfig, tag?: string, functi
|
|
|
70
90
|
* `vercel.json` before builders are detected.
|
|
71
91
|
*/
|
|
72
92
|
export declare function validateProxyConfig(proxy: ProxyConfig): ErrorResponse | null;
|
|
73
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Validates the `proxy` config on its own.
|
|
95
|
+
*/
|
|
96
|
+
export declare function validateProxy(options: Pick<Options, 'proxy'>, files: string[], _framework: string | null | undefined): ErrorResponse | null;
|
|
97
|
+
/**
|
|
98
|
+
* Validates a resolved proxy against the rest of the project.
|
|
99
|
+
*/
|
|
100
|
+
export declare function validateResolvedProxy(proxy: ResolvedProxy, framework: string | null | undefined): ErrorResponse | null;
|
package/dist/detect-builders.js
CHANGED
|
@@ -321,15 +321,18 @@ __export(detect_builders_exports, {
|
|
|
321
321
|
REGEX_MIDDLEWARE_FILES: () => REGEX_MIDDLEWARE_FILES,
|
|
322
322
|
REGEX_NON_VERCEL_PLATFORM_FILES: () => REGEX_NON_VERCEL_PLATFORM_FILES,
|
|
323
323
|
REGEX_VERCEL_PLATFORM_FILES: () => REGEX_VERCEL_PLATFORM_FILES,
|
|
324
|
+
VERCEL_PLATFORM_FILES: () => VERCEL_PLATFORM_FILES,
|
|
324
325
|
builderToFrameworks: () => builderToFrameworks,
|
|
325
326
|
detectApiDirectory: () => detectApiDirectory,
|
|
326
327
|
detectApiExtensions: () => detectApiExtensions,
|
|
327
328
|
detectBuilders: () => detectBuilders,
|
|
328
329
|
detectOutputDirectory: () => detectOutputDirectory,
|
|
329
330
|
getProxyBuilder: () => getProxyBuilder,
|
|
331
|
+
resolveProxy: () => resolveProxy,
|
|
330
332
|
sortFiles: () => sortFiles,
|
|
331
333
|
validateProxy: () => validateProxy,
|
|
332
|
-
validateProxyConfig: () => validateProxyConfig
|
|
334
|
+
validateProxyConfig: () => validateProxyConfig,
|
|
335
|
+
validateResolvedProxy: () => validateResolvedProxy
|
|
333
336
|
});
|
|
334
337
|
module.exports = __toCommonJS(detect_builders_exports);
|
|
335
338
|
var import_minimatch = __toESM(require("minimatch"));
|
|
@@ -455,7 +458,9 @@ function detectOutputDirectory(builders) {
|
|
|
455
458
|
async function detectBuilders(files, pkg, options = {}) {
|
|
456
459
|
const { projectSettings = {} } = options;
|
|
457
460
|
const { framework } = projectSettings;
|
|
458
|
-
const
|
|
461
|
+
const proxyConfigError = validateProxy(options, files, framework);
|
|
462
|
+
const proxy = proxyConfigError ? null : resolveProxy(files, options);
|
|
463
|
+
const proxyError = proxyConfigError ?? (proxy && validateResolvedProxy(proxy, framework));
|
|
459
464
|
if (proxyError) {
|
|
460
465
|
return {
|
|
461
466
|
builders: null,
|
|
@@ -492,7 +497,6 @@ async function detectBuilders(files, pkg, options = {}) {
|
|
|
492
497
|
usedFunctions.add(key);
|
|
493
498
|
};
|
|
494
499
|
const absolutePathCache = /* @__PURE__ */ new Map();
|
|
495
|
-
const proxy = resolveProxy(files, options);
|
|
496
500
|
const reservedFiles = getReservedFiles(options);
|
|
497
501
|
const claimedFiles = /* @__PURE__ */ new Set([
|
|
498
502
|
...proxy?.source === "vercel-config" ? [proxy.file] : [],
|
|
@@ -906,7 +910,7 @@ function validateProxyConfig(proxy) {
|
|
|
906
910
|
}
|
|
907
911
|
return null;
|
|
908
912
|
}
|
|
909
|
-
function validateProxy(options, files,
|
|
913
|
+
function validateProxy(options, files, _framework) {
|
|
910
914
|
const { proxy } = options;
|
|
911
915
|
if (!proxy) {
|
|
912
916
|
return null;
|
|
@@ -922,15 +926,18 @@ function validateProxy(options, files, framework) {
|
|
|
922
926
|
message: `The proxy entrypoint \`${proxy.entrypoint}\` does not exist.`
|
|
923
927
|
};
|
|
924
928
|
}
|
|
929
|
+
return null;
|
|
930
|
+
}
|
|
931
|
+
function validateResolvedProxy(proxy, framework) {
|
|
925
932
|
const appRuntime = (0, import_framework.inferBuilderRuntimeFromFramework)(framework);
|
|
926
|
-
const proxyRuntime = import_constants.ENTRYPOINT_EXTENSIONS[(0, import_path.extname)(file)];
|
|
933
|
+
const proxyRuntime = import_constants.ENTRYPOINT_EXTENSIONS[(0, import_path.extname)(proxy.file)];
|
|
927
934
|
if (appRuntime !== void 0 && proxyRuntime !== void 0 && appRuntime !== proxyRuntime) {
|
|
928
935
|
return {
|
|
929
936
|
code: "proxy_runtime_mismatch",
|
|
930
|
-
message: `The proxy entrypoint \`${proxy.entrypoint}\` uses the ${proxyRuntime} runtime, but the app uses the ${appRuntime} runtime. The proxy and app must use the same runtime.`
|
|
937
|
+
message: proxy.source === "vercel-config" ? `The proxy entrypoint \`${proxy.entrypoint}\` uses the ${proxyRuntime} runtime, but the app uses the ${appRuntime} runtime. The proxy and app must use the same runtime.` : `The middleware \`${proxy.file}\` uses the ${proxyRuntime} runtime, but the app uses the ${appRuntime} runtime. The middleware and app must use the same runtime.`
|
|
931
938
|
};
|
|
932
939
|
}
|
|
933
|
-
if (framework === "nextjs" || framework === "astro") {
|
|
940
|
+
if (proxy.source === "vercel-config" && (framework === "nextjs" || framework === "astro")) {
|
|
934
941
|
return {
|
|
935
942
|
code: "proxy_framework_conflict",
|
|
936
943
|
message: `The \`proxy\` property cannot be used with ${framework === "nextjs" ? "Next.js" : "Astro"} because the framework builds its own routing middleware.`
|
|
@@ -1427,13 +1434,16 @@ function sortFilesBySegmentCount(fileA, fileB) {
|
|
|
1427
1434
|
REGEX_MIDDLEWARE_FILES,
|
|
1428
1435
|
REGEX_NON_VERCEL_PLATFORM_FILES,
|
|
1429
1436
|
REGEX_VERCEL_PLATFORM_FILES,
|
|
1437
|
+
VERCEL_PLATFORM_FILES,
|
|
1430
1438
|
builderToFrameworks,
|
|
1431
1439
|
detectApiDirectory,
|
|
1432
1440
|
detectApiExtensions,
|
|
1433
1441
|
detectBuilders,
|
|
1434
1442
|
detectOutputDirectory,
|
|
1435
1443
|
getProxyBuilder,
|
|
1444
|
+
resolveProxy,
|
|
1436
1445
|
sortFiles,
|
|
1437
1446
|
validateProxy,
|
|
1438
|
-
validateProxyConfig
|
|
1447
|
+
validateProxyConfig,
|
|
1448
|
+
validateResolvedProxy
|
|
1439
1449
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { builderToFrameworks, detectBuilders, detectOutputDirectory, detectApiDirectory, detectApiExtensions, getProxyBuilder, validateProxyConfig, validateProxy, type Options as DetectBuildersOptions, type ProxyConfig, } from './detect-builders';
|
|
1
|
+
export { builderToFrameworks, detectBuilders, detectOutputDirectory, detectApiDirectory, detectApiExtensions, getProxyBuilder, validateProxyConfig, validateProxy, resolveProxy, validateResolvedProxy, type Options as DetectBuildersOptions, type ProxyConfig, type ResolvedProxy, } from './detect-builders';
|
|
2
2
|
export { detectServices, generateServiceRewrites, generateServicesRoutes, } from './services/detect-services';
|
|
3
3
|
export { detectDaemons } from './services/detect-daemons';
|
|
4
4
|
export { resolveAllConfiguredServicesV2, resolveConfiguredServiceV2, validateServiceConfigV2, } from './services/resolve-v2';
|
package/dist/index.js
CHANGED
|
@@ -66,9 +66,11 @@ __export(src_exports, {
|
|
|
66
66
|
resolveAllConfiguredServices: () => import_resolve.resolveAllConfiguredServices,
|
|
67
67
|
resolveAllConfiguredServicesV2: () => import_resolve_v2.resolveAllConfiguredServicesV2,
|
|
68
68
|
resolveConfiguredServiceV2: () => import_resolve_v2.resolveConfiguredServiceV2,
|
|
69
|
+
resolveProxy: () => import_detect_builders.resolveProxy,
|
|
69
70
|
resolveWorkspacePackageTargets: () => import_resolve_workspace_package_targets.resolveWorkspacePackageTargets,
|
|
70
71
|
validateProxy: () => import_detect_builders.validateProxy,
|
|
71
72
|
validateProxyConfig: () => import_detect_builders.validateProxyConfig,
|
|
73
|
+
validateResolvedProxy: () => import_detect_builders.validateResolvedProxy,
|
|
72
74
|
validateServiceConfigV2: () => import_resolve_v2.validateServiceConfigV2,
|
|
73
75
|
workspaceManagers: () => import_workspace_managers.workspaceManagers
|
|
74
76
|
});
|
|
@@ -146,9 +148,11 @@ var import_detect_instrumentation = require("./detect-instrumentation");
|
|
|
146
148
|
resolveAllConfiguredServices,
|
|
147
149
|
resolveAllConfiguredServicesV2,
|
|
148
150
|
resolveConfiguredServiceV2,
|
|
151
|
+
resolveProxy,
|
|
149
152
|
resolveWorkspacePackageTargets,
|
|
150
153
|
validateProxy,
|
|
151
154
|
validateProxyConfig,
|
|
155
|
+
validateResolvedProxy,
|
|
152
156
|
validateServiceConfigV2,
|
|
153
157
|
workspaceManagers,
|
|
154
158
|
...require("./monorepos/get-monorepo-default-settings")
|
|
@@ -33,6 +33,7 @@ var import_entrypoint = require("./runtimes/entrypoint");
|
|
|
33
33
|
var import_buildpack_runtimes = require("../buildpack-runtimes");
|
|
34
34
|
var import_resolve = require("./resolve");
|
|
35
35
|
var import_utils = require("./utils");
|
|
36
|
+
var import_detect_builders = require("../detect-builders");
|
|
36
37
|
const frameworksBySlug = new Map(import_frameworks.frameworkList.map((f) => [f.slug, f]));
|
|
37
38
|
const MAX_SERVICE_NAME_LENGTH = 64;
|
|
38
39
|
const SERVICE_NAME_REGEX = /^[a-z]([a-z_-]*[a-z])?$/;
|
|
@@ -156,25 +157,30 @@ function validateServiceConfigV2(name, config) {
|
|
|
156
157
|
serviceName: name
|
|
157
158
|
};
|
|
158
159
|
}
|
|
159
|
-
if (
|
|
160
|
+
if (config.image !== void 0) {
|
|
161
|
+
const imageError = validateImageServiceConfigV2(name, config);
|
|
162
|
+
if (imageError)
|
|
163
|
+
return imageError;
|
|
164
|
+
} else if (typeof config.root !== "string" || config.root.length === 0) {
|
|
160
165
|
return {
|
|
161
166
|
code: "MISSING_ROOT",
|
|
162
|
-
message: `Service "${name}" must specify a "root".`,
|
|
167
|
+
message: `Service "${name}" must specify a "root" or an "image".`,
|
|
163
168
|
serviceName: name
|
|
164
169
|
};
|
|
165
170
|
}
|
|
166
|
-
const
|
|
171
|
+
const root = config.root ?? ".";
|
|
172
|
+
const normalizedRoot = import_path.posix.normalize(root);
|
|
167
173
|
if (normalizedRoot.startsWith("/")) {
|
|
168
174
|
return {
|
|
169
175
|
code: "INVALID_ROOT",
|
|
170
|
-
message: `Service "${name}" has invalid "root" "${
|
|
176
|
+
message: `Service "${name}" has invalid "root" "${root}". Must be a relative path.`,
|
|
171
177
|
serviceName: name
|
|
172
178
|
};
|
|
173
179
|
}
|
|
174
180
|
if (normalizedRoot === ".." || normalizedRoot.startsWith("../")) {
|
|
175
181
|
return {
|
|
176
182
|
code: "INVALID_ROOT",
|
|
177
|
-
message: `Service "${name}" has invalid "root" "${
|
|
183
|
+
message: `Service "${name}" has invalid "root" "${root}". Must not escape the project root.`,
|
|
178
184
|
serviceName: name
|
|
179
185
|
};
|
|
180
186
|
}
|
|
@@ -204,8 +210,87 @@ function validateServiceConfigV2(name, config) {
|
|
|
204
210
|
}
|
|
205
211
|
return null;
|
|
206
212
|
}
|
|
213
|
+
function validateImageServiceConfigV2(name, config) {
|
|
214
|
+
const invalid = (message) => ({
|
|
215
|
+
code: "INVALID_SERVICE_CONFIG",
|
|
216
|
+
message,
|
|
217
|
+
serviceName: name
|
|
218
|
+
});
|
|
219
|
+
const imageProblem = (0, import_build_utils.getVcrImageProblem)(config.image);
|
|
220
|
+
if (imageProblem) {
|
|
221
|
+
return invalid(`Service "${name}" has invalid "image": it ${imageProblem}`);
|
|
222
|
+
}
|
|
223
|
+
const conflicts = import_build_utils.SERVICE_IMAGE_BUILD_SETTINGS.filter(
|
|
224
|
+
(field) => config[field] !== void 0
|
|
225
|
+
);
|
|
226
|
+
if (conflicts.length > 0) {
|
|
227
|
+
const fields = conflicts.map((field) => `"${field}"`).join(", ");
|
|
228
|
+
return invalid(
|
|
229
|
+
`Service "${name}" sets "image", so it isn't built and can't set ${fields}.`
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
if (config.runtime !== void 0 && config.runtime !== "container") {
|
|
233
|
+
return invalid(
|
|
234
|
+
`Service "${name}" sets "image", so its "runtime" can only be "container".`
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
if (config.functions !== void 0) {
|
|
238
|
+
return invalid(
|
|
239
|
+
`Service "${name}" sets "image", so it can't set "functions". The functions configuration isn't supported for image services.`
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
function resolveImageServiceV2(name, config, normalizedRoot) {
|
|
245
|
+
const isRoot = normalizedRoot === ".";
|
|
246
|
+
const command = normalizeContainerCommand(config.command);
|
|
247
|
+
const image = (0, import_build_utils.normalizeVcrImageRef)(config.image);
|
|
248
|
+
const builderConfig = {
|
|
249
|
+
zeroConfig: true,
|
|
250
|
+
handler: image
|
|
251
|
+
};
|
|
252
|
+
if (!isRoot) {
|
|
253
|
+
builderConfig.workspace = normalizedRoot;
|
|
254
|
+
}
|
|
255
|
+
if (command) {
|
|
256
|
+
builderConfig.command = command;
|
|
257
|
+
}
|
|
258
|
+
return {
|
|
259
|
+
service: {
|
|
260
|
+
schema: "experimentalServicesV2",
|
|
261
|
+
name,
|
|
262
|
+
root: normalizedRoot,
|
|
263
|
+
runtime: "container",
|
|
264
|
+
image,
|
|
265
|
+
command,
|
|
266
|
+
builder: {
|
|
267
|
+
// Names no file, but must be unique per build and must not look like a
|
|
268
|
+
// Dockerfile.
|
|
269
|
+
src: import_path.posix.join(normalizedRoot, `.vercel/images/${name}/<image>`),
|
|
270
|
+
use: "@vercel/container",
|
|
271
|
+
config: builderConfig
|
|
272
|
+
},
|
|
273
|
+
bindings: config.bindings,
|
|
274
|
+
headers: config.headers,
|
|
275
|
+
redirects: config.redirects,
|
|
276
|
+
rewrites: config.rewrites,
|
|
277
|
+
routes: config.routes,
|
|
278
|
+
cleanUrls: config.cleanUrls,
|
|
279
|
+
trailingSlash: config.trailingSlash
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
}
|
|
207
283
|
async function resolveConfiguredServiceV2(name, config, fs) {
|
|
208
|
-
const normalizedRoot = (0, import_entrypoint.stripTrailingSlash)(
|
|
284
|
+
const normalizedRoot = (0, import_entrypoint.stripTrailingSlash)(
|
|
285
|
+
import_path.posix.normalize(config.root ?? ".")
|
|
286
|
+
);
|
|
287
|
+
if (config.image !== void 0) {
|
|
288
|
+
return resolveImageServiceV2(
|
|
289
|
+
name,
|
|
290
|
+
{ ...config, image: config.image },
|
|
291
|
+
normalizedRoot
|
|
292
|
+
);
|
|
293
|
+
}
|
|
209
294
|
const serviceFsResult = normalizedRoot === "." ? { fs } : await (0, import_resolve.getServiceFs)(fs, name, normalizedRoot);
|
|
210
295
|
if (serviceFsResult.error) {
|
|
211
296
|
return { error: serviceFsResult.error };
|
|
@@ -337,6 +422,9 @@ async function resolveConfiguredServiceV2(name, config, fs) {
|
|
|
337
422
|
if (builderUse === "@vercel/backends") {
|
|
338
423
|
builderConfig.serviceName = name;
|
|
339
424
|
}
|
|
425
|
+
if (builderUse === "@vercel/static") {
|
|
426
|
+
builderConfig.excludeFiles = [...import_detect_builders.VERCEL_PLATFORM_FILES];
|
|
427
|
+
}
|
|
340
428
|
if (framework) {
|
|
341
429
|
builderConfig.framework = framework;
|
|
342
430
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/fs-detectors",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.13.0",
|
|
4
4
|
"description": "Vercel filesystem detectors",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"minimatch": "3.1.2",
|
|
21
21
|
"semver": "6.3.1",
|
|
22
22
|
"smol-toml": "1.5.2",
|
|
23
|
-
"@vercel/build-utils": "15.
|
|
23
|
+
"@vercel/build-utils": "15.6.0",
|
|
24
|
+
"@vercel/frameworks": "3.35.1",
|
|
24
25
|
"@vercel/error-utils": "2.2.1",
|
|
25
|
-
"@vercel/
|
|
26
|
-
"@vercel/routing-utils": "6.6.1"
|
|
27
|
-
"@vercel/python-analysis": "0.15.3"
|
|
26
|
+
"@vercel/python-analysis": "0.15.4",
|
|
27
|
+
"@vercel/routing-utils": "6.6.1"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/glob": "7.2.0",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@types/node": "20.11.0",
|
|
34
34
|
"@types/semver": "7.3.10",
|
|
35
35
|
"vitest": "4.1.10",
|
|
36
|
-
"@vercel-internals/runtimes": "1.2.
|
|
36
|
+
"@vercel-internals/runtimes": "1.2.13"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "node build.mjs",
|