@vercel/build-utils 2.12.3-canary.8 → 2.13.1-canary.1

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.
@@ -0,0 +1,32 @@
1
+ $ node build
2
+ ncc: Version 0.24.0
3
+ ncc: Compiling file index.js
4
+ ncc: Using typescript@4.3.4 (local user-provided)
5
+ 0kB dist/main/should-serve.d.ts
6
+ 0kB dist/main/get-ignore-filter.d.ts
7
+ 0kB dist/main/detect-framework.d.ts
8
+ 0kB dist/main/fs/stream-to-buffer.d.ts
9
+ 0kB dist/main/fs/rename.d.ts
10
+ 0kB dist/main/fs/read-config-file.d.ts
11
+ 0kB dist/main/fs/normalize-path.d.ts
12
+ 0kB dist/main/fs/node-version.d.ts
13
+ 0kB dist/main/fs/glob.d.ts
14
+ 0kB dist/main/fs/get-writable-directory.d.ts
15
+ 0kB dist/main/fs/download.d.ts
16
+ 0kB dist/main/debug.d.ts
17
+ 1kB dist/main/schemas.d.ts
18
+ 1kB dist/main/prerender.d.ts
19
+ 1kB dist/main/lambda.d.ts
20
+ 1kB dist/main/file-ref.d.ts
21
+ 1kB dist/main/file-fs-ref.d.ts
22
+ 1kB dist/main/file-blob.d.ts
23
+ 1kB dist/main/errors.d.ts
24
+ 1kB dist/main/detect-file-system-api.d.ts
25
+ 1kB dist/main/detect-builders.d.ts
26
+ 2kB dist/main/detectors/filesystem.d.ts
27
+ 2kB dist/main/convert-runtime-to-plugin.d.ts
28
+ 3kB dist/main/index.d.ts
29
+ 4kB dist/main/fs/run-user-scripts.d.ts
30
+ 9kB dist/main/types.d.ts
31
+ 1245kB dist/main/index.js
32
+ 1274kB [7772ms] - ncc 0.24.0
@@ -0,0 +1,65 @@
1
+ import { Lambda } from './lambda';
2
+ import type { BuildOptions } from './types';
3
+ /**
4
+ * Convert legacy Runtime to a Plugin.
5
+ * @param buildRuntime - a legacy build() function from a Runtime
6
+ * @param packageName - the name of the package, for example `vercel-plugin-python`
7
+ * @param ext - the file extension, for example `.py`
8
+ */
9
+ export declare function _experimental_convertRuntimeToPlugin(buildRuntime: (options: BuildOptions) => Promise<{
10
+ output: Lambda;
11
+ }>, packageName: string, ext: string): ({ workPath }: {
12
+ workPath: string;
13
+ }) => Promise<void>;
14
+ /**
15
+ * If `.output/functions-manifest.json` exists, append to the pages
16
+ * property. Otherwise write a new file.
17
+ */
18
+ export declare function _experimental_updateFunctionsManifest({ workPath, pages, }: {
19
+ workPath: string;
20
+ pages: {
21
+ [key: string]: any;
22
+ };
23
+ }): Promise<void>;
24
+ /**
25
+ * Append routes to the `routes-manifest.json` file.
26
+ * If the file does not exist, it will be created.
27
+ */
28
+ export declare function _experimental_updateRoutesManifest({ workPath, redirects, rewrites, headers, dynamicRoutes, staticRoutes, }: {
29
+ workPath: string;
30
+ redirects?: {
31
+ source: string;
32
+ destination: string;
33
+ statusCode: number;
34
+ regex: string;
35
+ }[];
36
+ rewrites?: {
37
+ source: string;
38
+ destination: string;
39
+ regex: string;
40
+ }[];
41
+ headers?: {
42
+ source: string;
43
+ headers: {
44
+ key: string;
45
+ value: string;
46
+ }[];
47
+ regex: string;
48
+ }[];
49
+ dynamicRoutes?: {
50
+ page: string;
51
+ regex: string;
52
+ namedRegex?: string;
53
+ routeKeys?: {
54
+ [named: string]: string;
55
+ };
56
+ }[];
57
+ staticRoutes?: {
58
+ page: string;
59
+ regex: string;
60
+ namedRegex?: string;
61
+ routeKeys?: {
62
+ [named: string]: string;
63
+ };
64
+ }[];
65
+ }): Promise<void>;
@@ -0,0 +1,296 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports._experimental_updateRoutesManifest = exports._experimental_updateFunctionsManifest = exports._experimental_convertRuntimeToPlugin = void 0;
7
+ const fs_extra_1 = __importDefault(require("fs-extra"));
8
+ const path_1 = require("path");
9
+ const glob_1 = __importDefault(require("./fs/glob"));
10
+ const normalize_path_1 = require("./fs/normalize-path");
11
+ const _1 = require(".");
12
+ // `.output` was already created by the Build Command, so we have
13
+ // to ensure its contents don't get bundled into the Lambda. Similarily,
14
+ // we don't want to bundle anything from `.vercel` either. Lastly,
15
+ // Builders/Runtimes didn't have `vercel.json` or `now.json`.
16
+ const ignoredPaths = ['.output', '.vercel', 'vercel.json', 'now.json'];
17
+ const shouldIgnorePath = (file, ignoreFilter, ignoreFile) => {
18
+ const isNative = ignoredPaths.some(item => {
19
+ return file.startsWith(item);
20
+ });
21
+ if (!ignoreFile) {
22
+ return isNative;
23
+ }
24
+ return isNative || ignoreFilter(file);
25
+ };
26
+ const getSourceFiles = async (workPath, ignoreFilter) => {
27
+ const list = await glob_1.default('**', {
28
+ cwd: workPath,
29
+ });
30
+ // We're not passing this as an `ignore` filter to the `glob` function above,
31
+ // so that we can re-use exactly the same `getIgnoreFilter` method that the
32
+ // Build Step uses (literally the same code). Note that this exclusion only applies
33
+ // when deploying. Locally, another exclusion is needed, which is handled
34
+ // further below in the `convertRuntimeToPlugin` function.
35
+ for (const file in list) {
36
+ if (shouldIgnorePath(file, ignoreFilter, true)) {
37
+ delete list[file];
38
+ }
39
+ }
40
+ return list;
41
+ };
42
+ /**
43
+ * Convert legacy Runtime to a Plugin.
44
+ * @param buildRuntime - a legacy build() function from a Runtime
45
+ * @param packageName - the name of the package, for example `vercel-plugin-python`
46
+ * @param ext - the file extension, for example `.py`
47
+ */
48
+ function _experimental_convertRuntimeToPlugin(buildRuntime, packageName, ext) {
49
+ // This `build()` signature should match `plugin.build()` signature in `vercel build`.
50
+ return async function build({ workPath }) {
51
+ // We also don't want to provide any files to Runtimes that were ignored
52
+ // through `.vercelignore` or `.nowignore`, because the Build Step does the same.
53
+ const ignoreFilter = await _1.getIgnoreFilter(workPath);
54
+ // Retrieve the files that are currently available on the File System,
55
+ // before the Legacy Runtime has even started to build.
56
+ const sourceFilesPreBuild = await getSourceFiles(workPath, ignoreFilter);
57
+ // Instead of doing another `glob` to get all the matching source files,
58
+ // we'll filter the list of existing files down to only the ones
59
+ // that are matching the entrypoint pattern, so we're first creating
60
+ // a clean new list to begin.
61
+ const entrypoints = Object.assign({}, sourceFilesPreBuild);
62
+ const entrypointMatch = new RegExp(`^api/.*${ext}$`);
63
+ // Up next, we'll strip out the files from the list of entrypoints
64
+ // that aren't actually considered entrypoints.
65
+ for (const file in entrypoints) {
66
+ if (!entrypointMatch.test(file)) {
67
+ delete entrypoints[file];
68
+ }
69
+ }
70
+ const pages = {};
71
+ const pluginName = packageName.replace('vercel-plugin-', '');
72
+ const outputPath = path_1.join(workPath, '.output');
73
+ const traceDir = path_1.join(outputPath, `inputs`,
74
+ // Legacy Runtimes can only provide API Routes, so that's
75
+ // why we can use this prefix for all of them. Here, we have to
76
+ // make sure to not use a cryptic hash name, because people
77
+ // need to be able to easily inspect the output.
78
+ `api-routes-${pluginName}`);
79
+ await fs_extra_1.default.ensureDir(traceDir);
80
+ const entryRoot = path_1.join(outputPath, 'server', 'pages');
81
+ for (const entrypoint of Object.keys(entrypoints)) {
82
+ const { output } = await buildRuntime({
83
+ files: sourceFilesPreBuild,
84
+ entrypoint,
85
+ workPath,
86
+ config: {
87
+ zeroConfig: true,
88
+ },
89
+ meta: {
90
+ avoidTopLevelInstall: true,
91
+ skipDownload: true,
92
+ },
93
+ });
94
+ const lambdaFiles = output.files;
95
+ // When deploying, the `files` that are passed to the Legacy Runtimes already
96
+ // have certain files that are ignored stripped, but locally, that list of
97
+ // files isn't used by the Legacy Runtimes, so we need to apply the filters
98
+ // to the outputs that they are returning instead.
99
+ for (const file in lambdaFiles) {
100
+ if (shouldIgnorePath(file, ignoreFilter, false)) {
101
+ delete lambdaFiles[file];
102
+ }
103
+ }
104
+ let handlerFileBase = output.handler;
105
+ let handlerFile = lambdaFiles[handlerFileBase];
106
+ let handlerHasImport = false;
107
+ const { handler } = output;
108
+ const handlerMethod = handler.split('.').pop();
109
+ const handlerFileName = handler.replace(`.${handlerMethod}`, '');
110
+ // For compiled languages, the launcher file for the Lambda generated
111
+ // by the Legacy Runtime matches the `handler` defined for it, but for
112
+ // interpreted languages, the `handler` consists of the launcher file name
113
+ // without an extension, plus the name of the method inside of that file
114
+ // that should be invoked, so we have to construct the file path explicitly.
115
+ if (!handlerFile) {
116
+ handlerFileBase = handlerFileName + ext;
117
+ handlerFile = lambdaFiles[handlerFileBase];
118
+ handlerHasImport = true;
119
+ }
120
+ if (!handlerFile || !handlerFile.fsPath) {
121
+ throw new Error(`Could not find a handler file. Please ensure that \`files\` for the returned \`Lambda\` contains an \`FileFsRef\` named "${handlerFileBase}" with a valid \`fsPath\`.`);
122
+ }
123
+ const handlerExtName = path_1.extname(handlerFile.fsPath);
124
+ const entryBase = path_1.basename(entrypoint).replace(ext, handlerExtName);
125
+ const entryPath = path_1.join(path_1.dirname(entrypoint), entryBase);
126
+ const entry = path_1.join(entryRoot, entryPath);
127
+ // Create the parent directory of the API Route that will be created
128
+ // for the current entrypoint inside of `.output/server/pages/api`.
129
+ await fs_extra_1.default.ensureDir(path_1.dirname(entry));
130
+ // For compiled languages, the launcher file will be binary and therefore
131
+ // won't try to import a user-provided request handler (instead, it will
132
+ // contain it). But for interpreted languages, the launcher might try to
133
+ // load a user-provided request handler from the source file instead of bundling
134
+ // it, so we have to adjust the import statement inside the launcher to point
135
+ // to the respective source file. Previously, Legacy Runtimes simply expected
136
+ // the user-provided request-handler to be copied right next to the launcher,
137
+ // but with the new File System API, files won't be moved around unnecessarily.
138
+ if (handlerHasImport) {
139
+ const { fsPath } = handlerFile;
140
+ const encoding = 'utf-8';
141
+ // This is the true directory of the user-provided request handler in the
142
+ // source files, so that's what we will use as an import path in the launcher.
143
+ const locationPrefix = path_1.relative(entry, outputPath);
144
+ let handlerContent = await fs_extra_1.default.readFile(fsPath, encoding);
145
+ const importPaths = [
146
+ // This is the full entrypoint path, like `./api/test.py`. In our tests
147
+ // Python didn't support importing from a parent directory without using different
148
+ // code in the launcher that registers it as a location for modules and then changing
149
+ // the importing syntax, but continuing to import it like before seems to work. If
150
+ // other languages need this, we should consider excluding Python explicitly.
151
+ // `./${entrypoint}`,
152
+ // This is the entrypoint path without extension, like `api/test`
153
+ entrypoint.slice(0, -ext.length),
154
+ ];
155
+ // Generate a list of regular expressions that we can use for
156
+ // finding matches, but only allow matches if the import path is
157
+ // wrapped inside single (') or double quotes (").
158
+ const patterns = importPaths.map(path => {
159
+ // eslint-disable-next-line no-useless-escape
160
+ return new RegExp(`('|")(${path.replace(/\./g, '\\.')})('|")`, 'g');
161
+ });
162
+ let replacedMatch = null;
163
+ for (const pattern of patterns) {
164
+ const newContent = handlerContent.replace(pattern, (_, p1, p2, p3) => {
165
+ return `${p1}${path_1.join(locationPrefix, p2)}${p3}`;
166
+ });
167
+ if (newContent !== handlerContent) {
168
+ _1.debug(`Replaced "${pattern}" inside "${entry}" to ensure correct import of user-provided request handler`);
169
+ handlerContent = newContent;
170
+ replacedMatch = true;
171
+ }
172
+ }
173
+ if (!replacedMatch) {
174
+ new Error(`No replacable matches for "${importPaths[0]}" or "${importPaths[1]}" found in "${fsPath}"`);
175
+ }
176
+ await fs_extra_1.default.writeFile(entry, handlerContent, encoding);
177
+ }
178
+ else {
179
+ await fs_extra_1.default.copy(handlerFile.fsPath, entry);
180
+ }
181
+ // Legacy Runtimes based on interpreted languages will create a new launcher file
182
+ // for every entrypoint, but they will create each one inside `workPath`, which means that
183
+ // the launcher for one entrypoint will overwrite the launcher provided for the previous
184
+ // entrypoint. That's why, above, we copy the file contents into the new destination (and
185
+ // optionally transform them along the way), instead of linking. We then also want to remove
186
+ // the copy origin right here, so that the `workPath` doesn't contain a useless launcher file
187
+ // once the build has finished running.
188
+ await fs_extra_1.default.remove(handlerFile.fsPath);
189
+ _1.debug(`Removed temporary file "${handlerFile.fsPath}"`);
190
+ const nft = `${entry}.nft.json`;
191
+ const json = JSON.stringify({
192
+ version: 2,
193
+ files: Object.keys(lambdaFiles)
194
+ .map(file => {
195
+ const { fsPath } = lambdaFiles[file];
196
+ if (!fsPath) {
197
+ throw new Error(`File "${file}" is missing valid \`fsPath\` property`);
198
+ }
199
+ // The handler was already moved into position above.
200
+ if (file === handlerFileBase) {
201
+ return;
202
+ }
203
+ return normalize_path_1.normalizePath(path_1.relative(path_1.dirname(nft), fsPath));
204
+ })
205
+ .filter(Boolean),
206
+ });
207
+ await fs_extra_1.default.writeFile(nft, json);
208
+ // Add an entry that will later on be added to the `functions-manifest.json`
209
+ // file that is placed inside of the `.output` directory.
210
+ pages[normalize_path_1.normalizePath(entryPath)] = {
211
+ // Because the underlying file used as a handler was placed
212
+ // inside `.output/server/pages/api`, it no longer has the name it originally
213
+ // had and is now named after the API Route that it's responsible for,
214
+ // so we have to adjust the name of the Lambda handler accordingly.
215
+ handler: handler.replace(handlerFileName, path_1.parse(entry).name),
216
+ runtime: output.runtime,
217
+ memory: output.memory,
218
+ maxDuration: output.maxDuration,
219
+ environment: output.environment,
220
+ allowQuery: output.allowQuery,
221
+ };
222
+ }
223
+ // Add any Serverless Functions that were exposed by the Legacy Runtime
224
+ // to the `functions-manifest.json` file provided in `.output`.
225
+ await _experimental_updateFunctionsManifest({ workPath, pages });
226
+ };
227
+ }
228
+ exports._experimental_convertRuntimeToPlugin = _experimental_convertRuntimeToPlugin;
229
+ async function readJson(filePath) {
230
+ try {
231
+ const str = await fs_extra_1.default.readFile(filePath, 'utf8');
232
+ return JSON.parse(str);
233
+ }
234
+ catch (err) {
235
+ if (err.code === 'ENOENT') {
236
+ return {};
237
+ }
238
+ throw err;
239
+ }
240
+ }
241
+ /**
242
+ * If `.output/functions-manifest.json` exists, append to the pages
243
+ * property. Otherwise write a new file.
244
+ */
245
+ async function _experimental_updateFunctionsManifest({ workPath, pages, }) {
246
+ const functionsManifestPath = path_1.join(workPath, '.output', 'functions-manifest.json');
247
+ const functionsManifest = await readJson(functionsManifestPath);
248
+ if (!functionsManifest.version)
249
+ functionsManifest.version = 2;
250
+ if (!functionsManifest.pages)
251
+ functionsManifest.pages = {};
252
+ for (const [pageKey, pageConfig] of Object.entries(pages)) {
253
+ functionsManifest.pages[pageKey] = { ...pageConfig };
254
+ }
255
+ await fs_extra_1.default.writeFile(functionsManifestPath, JSON.stringify(functionsManifest));
256
+ }
257
+ exports._experimental_updateFunctionsManifest = _experimental_updateFunctionsManifest;
258
+ /**
259
+ * Append routes to the `routes-manifest.json` file.
260
+ * If the file does not exist, it will be created.
261
+ */
262
+ async function _experimental_updateRoutesManifest({ workPath, redirects, rewrites, headers, dynamicRoutes, staticRoutes, }) {
263
+ const routesManifestPath = path_1.join(workPath, '.output', 'routes-manifest.json');
264
+ const routesManifest = await readJson(routesManifestPath);
265
+ if (!routesManifest.version)
266
+ routesManifest.version = 3;
267
+ if (routesManifest.pages404 === undefined)
268
+ routesManifest.pages404 = true;
269
+ if (redirects) {
270
+ if (!routesManifest.redirects)
271
+ routesManifest.redirects = [];
272
+ routesManifest.redirects.push(...redirects);
273
+ }
274
+ if (rewrites) {
275
+ if (!routesManifest.rewrites)
276
+ routesManifest.rewrites = [];
277
+ routesManifest.rewrites.push(...rewrites);
278
+ }
279
+ if (headers) {
280
+ if (!routesManifest.headers)
281
+ routesManifest.headers = [];
282
+ routesManifest.headers.push(...headers);
283
+ }
284
+ if (dynamicRoutes) {
285
+ if (!routesManifest.dynamicRoutes)
286
+ routesManifest.dynamicRoutes = [];
287
+ routesManifest.dynamicRoutes.push(...dynamicRoutes);
288
+ }
289
+ if (staticRoutes) {
290
+ if (!routesManifest.staticRoutes)
291
+ routesManifest.staticRoutes = [];
292
+ routesManifest.staticRoutes.push(...staticRoutes);
293
+ }
294
+ await fs_extra_1.default.writeFile(routesManifestPath, JSON.stringify(routesManifest));
295
+ }
296
+ exports._experimental_updateRoutesManifest = _experimental_updateRoutesManifest;
@@ -1,5 +1,5 @@
1
1
  import { Route } from '@vercel/routing-utils';
2
- import { PackageJson, Builder, BuilderFunctions } from './types';
2
+ import { PackageJson, Builder, BuilderFunctions, ProjectSettings } from './types';
3
3
  interface ErrorResponse {
4
4
  code: string;
5
5
  message: string;
@@ -10,14 +10,7 @@ interface Options {
10
10
  tag?: 'canary' | 'latest' | string;
11
11
  functions?: BuilderFunctions;
12
12
  ignoreBuildScript?: boolean;
13
- projectSettings?: {
14
- framework?: string | null;
15
- devCommand?: string | null;
16
- installCommand?: string | null;
17
- buildCommand?: string | null;
18
- outputDirectory?: string | null;
19
- createdAt?: number;
20
- };
13
+ projectSettings?: ProjectSettings;
21
14
  cleanUrls?: boolean;
22
15
  trailingSlash?: boolean;
23
16
  featHandleMiss?: boolean;
@@ -34,5 +27,11 @@ export declare function detectBuilders(files: string[], pkg?: PackageJson | unde
34
27
  redirectRoutes: Route[] | null;
35
28
  rewriteRoutes: Route[] | null;
36
29
  errorRoutes: Route[] | null;
30
+ limitedRoutes: LimitedRoutes | null;
37
31
  }>;
32
+ interface LimitedRoutes {
33
+ defaultRoutes: Route[];
34
+ redirectRoutes: Route[];
35
+ rewriteRoutes: Route[];
36
+ }
38
37
  export {};
@@ -66,6 +66,7 @@ async function detectBuilders(files, pkg, options = {}) {
66
66
  redirectRoutes: null,
67
67
  rewriteRoutes: null,
68
68
  errorRoutes: null,
69
+ limitedRoutes: null,
69
70
  };
70
71
  }
71
72
  const sortedFiles = files.sort(sortFiles);
@@ -113,6 +114,7 @@ async function detectBuilders(files, pkg, options = {}) {
113
114
  redirectRoutes: null,
114
115
  rewriteRoutes: null,
115
116
  errorRoutes: null,
117
+ limitedRoutes: null,
116
118
  };
117
119
  }
118
120
  if (apiRoute) {
@@ -167,6 +169,7 @@ async function detectBuilders(files, pkg, options = {}) {
167
169
  defaultRoutes: null,
168
170
  rewriteRoutes: null,
169
171
  errorRoutes: null,
172
+ limitedRoutes: null,
170
173
  };
171
174
  }
172
175
  // If `outputDirectory` is an empty string,
@@ -203,6 +206,7 @@ async function detectBuilders(files, pkg, options = {}) {
203
206
  defaultRoutes: null,
204
207
  rewriteRoutes: null,
205
208
  errorRoutes: null,
209
+ limitedRoutes: null,
206
210
  };
207
211
  }
208
212
  const builders = [];
@@ -221,7 +225,7 @@ async function detectBuilders(files, pkg, options = {}) {
221
225
  });
222
226
  }
223
227
  }
224
- const routesResult = getRouteResult(apiRoutes, dynamicRoutes, usedOutputDirectory, apiBuilders, frontendBuilder, options);
228
+ const routesResult = getRouteResult(pkg, apiRoutes, dynamicRoutes, usedOutputDirectory, apiBuilders, frontendBuilder, options);
225
229
  return {
226
230
  warnings,
227
231
  builders: builders.length ? builders : null,
@@ -230,6 +234,7 @@ async function detectBuilders(files, pkg, options = {}) {
230
234
  defaultRoutes: routesResult.defaultRoutes,
231
235
  rewriteRoutes: routesResult.rewriteRoutes,
232
236
  errorRoutes: routesResult.errorRoutes,
237
+ limitedRoutes: routesResult.limitedRoutes,
233
238
  };
234
239
  }
235
240
  exports.detectBuilders = detectBuilders;
@@ -670,23 +675,51 @@ function createRouteFromPath(filePath, featHandleMiss, cleanUrls) {
670
675
  }
671
676
  return { route, isDynamic };
672
677
  }
673
- function getRouteResult(apiRoutes, dynamicRoutes, outputDirectory, apiBuilders, frontendBuilder, options) {
678
+ function getRouteResult(pkg, apiRoutes, dynamicRoutes, outputDirectory, apiBuilders, frontendBuilder, options) {
674
679
  var _a, _b;
680
+ const deps = Object.assign({}, pkg === null || pkg === void 0 ? void 0 : pkg.dependencies, pkg === null || pkg === void 0 ? void 0 : pkg.devDependencies);
675
681
  const defaultRoutes = [];
676
682
  const redirectRoutes = [];
677
683
  const rewriteRoutes = [];
678
684
  const errorRoutes = [];
685
+ const limitedRoutes = {
686
+ defaultRoutes: [],
687
+ redirectRoutes: [],
688
+ rewriteRoutes: [],
689
+ };
679
690
  const framework = ((_a = frontendBuilder === null || frontendBuilder === void 0 ? void 0 : frontendBuilder.config) === null || _a === void 0 ? void 0 : _a.framework) || '';
680
691
  const isNextjs = framework === 'nextjs' || _1.isOfficialRuntime('next', frontendBuilder === null || frontendBuilder === void 0 ? void 0 : frontendBuilder.use);
681
692
  const ignoreRuntimes = (_b = slugToFramework.get(framework)) === null || _b === void 0 ? void 0 : _b.ignoreRuntimes;
682
693
  if (apiRoutes && apiRoutes.length > 0) {
683
694
  if (options.featHandleMiss) {
695
+ // Exclude extension names if the corresponding plugin is not found in package.json
696
+ // detectBuilders({ignoreRoutesForBuilders: ['@vercel/python']})
697
+ // return a copy of routes.
698
+ // We should exclud errorRoutes and
684
699
  const extSet = detectApiExtensions(apiBuilders);
700
+ const withTag = options.tag ? `@${options.tag}` : '';
701
+ const extSetLimited = detectApiExtensions(apiBuilders.filter(b => {
702
+ if (b.use === `@vercel/python${withTag}` &&
703
+ !('vercel-plugin-python' in deps)) {
704
+ return false;
705
+ }
706
+ if (b.use === `@vercel/go${withTag}` &&
707
+ !('vercel-plugin-go' in deps)) {
708
+ return false;
709
+ }
710
+ if (b.use === `@vercel/ruby${withTag}` &&
711
+ !('vercel-plugin-ruby' in deps)) {
712
+ return false;
713
+ }
714
+ return true;
715
+ }));
685
716
  if (extSet.size > 0) {
686
- const exts = Array.from(extSet)
717
+ const extGroup = `(?:\\.(?:${Array.from(extSet)
687
718
  .map(ext => ext.slice(1))
688
- .join('|');
689
- const extGroup = `(?:\\.(?:${exts}))`;
719
+ .join('|')}))`;
720
+ const extGroupLimited = `(?:\\.(?:${Array.from(extSetLimited)
721
+ .map(ext => ext.slice(1))
722
+ .join('|')}))`;
690
723
  if (options.cleanUrls) {
691
724
  redirectRoutes.push({
692
725
  src: `^/(api(?:.+)?)/index${extGroup}?/?$`,
@@ -700,6 +733,18 @@ function getRouteResult(apiRoutes, dynamicRoutes, outputDirectory, apiBuilders,
700
733
  },
701
734
  status: 308,
702
735
  });
736
+ limitedRoutes.redirectRoutes.push({
737
+ src: `^/(api(?:.+)?)/index${extGroupLimited}?/?$`,
738
+ headers: { Location: options.trailingSlash ? '/$1/' : '/$1' },
739
+ status: 308,
740
+ });
741
+ limitedRoutes.redirectRoutes.push({
742
+ src: `^/api/(.+)${extGroupLimited}/?$`,
743
+ headers: {
744
+ Location: options.trailingSlash ? '/api/$1/' : '/api/$1',
745
+ },
746
+ status: 308,
747
+ });
703
748
  }
704
749
  else {
705
750
  defaultRoutes.push({ handle: 'miss' });
@@ -708,9 +753,16 @@ function getRouteResult(apiRoutes, dynamicRoutes, outputDirectory, apiBuilders,
708
753
  dest: '/api/$1',
709
754
  check: true,
710
755
  });
756
+ limitedRoutes.defaultRoutes.push({ handle: 'miss' });
757
+ limitedRoutes.defaultRoutes.push({
758
+ src: `^/api/(.+)${extGroupLimited}$`,
759
+ dest: '/api/$1',
760
+ check: true,
761
+ });
711
762
  }
712
763
  }
713
764
  rewriteRoutes.push(...dynamicRoutes);
765
+ limitedRoutes.rewriteRoutes.push(...dynamicRoutes);
714
766
  if (typeof ignoreRuntimes === 'undefined') {
715
767
  // This route is only necessary to hide the directory listing
716
768
  // to avoid enumerating serverless function names.
@@ -755,6 +807,7 @@ function getRouteResult(apiRoutes, dynamicRoutes, outputDirectory, apiBuilders,
755
807
  redirectRoutes,
756
808
  rewriteRoutes,
757
809
  errorRoutes,
810
+ limitedRoutes,
758
811
  };
759
812
  }
760
813
  function sortFilesBySegmentCount(fileA, fileB) {
@@ -0,0 +1,34 @@
1
+ import type { Builder, BuilderFunctions, PackageJson, ProjectSettings } from './types';
2
+ interface Metadata {
3
+ plugins: string[];
4
+ hasDotOutput: boolean;
5
+ hasMiddleware: boolean;
6
+ }
7
+ /**
8
+ * If the Deployment can be built with the new File System API,
9
+ * return the new Builder. Otherwise an "Exclusion Condition"
10
+ * was hit so return `null` builder with a `reason` for exclusion.
11
+ */
12
+ export declare function detectFileSystemAPI({ files, projectSettings, builders, vercelConfig, pkg, tag, enableFlag, }: {
13
+ files: {
14
+ [relPath: string]: any;
15
+ };
16
+ projectSettings: ProjectSettings;
17
+ builders: Builder[];
18
+ vercelConfig: {
19
+ builds?: Builder[];
20
+ functions?: BuilderFunctions;
21
+ } | null | undefined;
22
+ pkg: PackageJson | null | undefined;
23
+ tag: string | undefined;
24
+ enableFlag: boolean | undefined;
25
+ }): Promise<{
26
+ metadata: Metadata;
27
+ fsApiBuilder: Builder;
28
+ reason: null;
29
+ } | {
30
+ metadata: Metadata;
31
+ fsApiBuilder: null;
32
+ reason: string;
33
+ }>;
34
+ export {};