@vercel/build-utils 2.12.3-canary.7 → 2.13.1-canary.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/.turbo/turbo-build.log +32 -0
- package/dist/convert-runtime-to-plugin.d.ts +65 -0
- package/dist/convert-runtime-to-plugin.js +298 -0
- package/dist/detect-builders.d.ts +8 -9
- package/dist/detect-builders.js +58 -5
- package/dist/detect-file-system-api.d.ts +34 -0
- package/dist/detect-file-system-api.js +173 -0
- package/dist/fs/glob.js +2 -1
- package/dist/fs/normalize-path.d.ts +4 -0
- package/dist/fs/normalize-path.js +11 -0
- package/dist/get-ignore-filter.d.ts +1 -0
- package/dist/get-ignore-filter.js +59 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +2402 -986
- package/dist/lambda.d.ts +7 -3
- package/dist/lambda.js +14 -4
- package/dist/prerender.d.ts +3 -1
- package/dist/prerender.js +10 -1
- package/dist/types.d.ts +18 -2
- package/package.json +6 -6
@@ -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
|
+
3kB dist/main/fs/run-user-scripts.d.ts
|
30
|
+
9kB dist/main/types.d.ts
|
31
|
+
1244kB dist/main/index.js
|
32
|
+
1272kB [8092ms] - 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,298 @@
|
|
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 lambda_1 = require("./lambda");
|
12
|
+
const _1 = require(".");
|
13
|
+
// `.output` was already created by the Build Command, so we have
|
14
|
+
// to ensure its contents don't get bundled into the Lambda. Similarily,
|
15
|
+
// we don't want to bundle anything from `.vercel` either. Lastly,
|
16
|
+
// Builders/Runtimes didn't have `vercel.json` or `now.json`.
|
17
|
+
const ignoredPaths = ['.output', '.vercel', 'vercel.json', 'now.json'];
|
18
|
+
const shouldIgnorePath = (file, ignoreFilter, ignoreFile) => {
|
19
|
+
const isNative = ignoredPaths.some(item => {
|
20
|
+
return file.startsWith(item);
|
21
|
+
});
|
22
|
+
if (!ignoreFile) {
|
23
|
+
return isNative;
|
24
|
+
}
|
25
|
+
return isNative || ignoreFilter(file);
|
26
|
+
};
|
27
|
+
const getSourceFiles = async (workPath, ignoreFilter) => {
|
28
|
+
const list = await glob_1.default('**', {
|
29
|
+
cwd: workPath,
|
30
|
+
});
|
31
|
+
// We're not passing this as an `ignore` filter to the `glob` function above,
|
32
|
+
// so that we can re-use exactly the same `getIgnoreFilter` method that the
|
33
|
+
// Build Step uses (literally the same code). Note that this exclusion only applies
|
34
|
+
// when deploying. Locally, another exclusion is needed, which is handled
|
35
|
+
// further below in the `convertRuntimeToPlugin` function.
|
36
|
+
for (const file in list) {
|
37
|
+
if (shouldIgnorePath(file, ignoreFilter, true)) {
|
38
|
+
delete list[file];
|
39
|
+
}
|
40
|
+
}
|
41
|
+
return list;
|
42
|
+
};
|
43
|
+
/**
|
44
|
+
* Convert legacy Runtime to a Plugin.
|
45
|
+
* @param buildRuntime - a legacy build() function from a Runtime
|
46
|
+
* @param packageName - the name of the package, for example `vercel-plugin-python`
|
47
|
+
* @param ext - the file extension, for example `.py`
|
48
|
+
*/
|
49
|
+
function _experimental_convertRuntimeToPlugin(buildRuntime, packageName, ext) {
|
50
|
+
// This `build()` signature should match `plugin.build()` signature in `vercel build`.
|
51
|
+
return async function build({ workPath }) {
|
52
|
+
// We also don't want to provide any files to Runtimes that were ignored
|
53
|
+
// through `.vercelignore` or `.nowignore`, because the Build Step does the same.
|
54
|
+
const ignoreFilter = await _1.getIgnoreFilter(workPath);
|
55
|
+
// Retrieve the files that are currently available on the File System,
|
56
|
+
// before the Legacy Runtime has even started to build.
|
57
|
+
const sourceFilesPreBuild = await getSourceFiles(workPath, ignoreFilter);
|
58
|
+
// Instead of doing another `glob` to get all the matching source files,
|
59
|
+
// we'll filter the list of existing files down to only the ones
|
60
|
+
// that are matching the entrypoint pattern, so we're first creating
|
61
|
+
// a clean new list to begin.
|
62
|
+
const entrypoints = Object.assign({}, sourceFilesPreBuild);
|
63
|
+
const entrypointMatch = new RegExp(`^api/.*${ext}$`);
|
64
|
+
// Up next, we'll strip out the files from the list of entrypoints
|
65
|
+
// that aren't actually considered entrypoints.
|
66
|
+
for (const file in entrypoints) {
|
67
|
+
if (!entrypointMatch.test(file)) {
|
68
|
+
delete entrypoints[file];
|
69
|
+
}
|
70
|
+
}
|
71
|
+
const pages = {};
|
72
|
+
const pluginName = packageName.replace('vercel-plugin-', '');
|
73
|
+
const outputPath = path_1.join(workPath, '.output');
|
74
|
+
const traceDir = path_1.join(outputPath, `inputs`,
|
75
|
+
// Legacy Runtimes can only provide API Routes, so that's
|
76
|
+
// why we can use this prefix for all of them. Here, we have to
|
77
|
+
// make sure to not use a cryptic hash name, because people
|
78
|
+
// need to be able to easily inspect the output.
|
79
|
+
`api-routes-${pluginName}`);
|
80
|
+
await fs_extra_1.default.ensureDir(traceDir);
|
81
|
+
const entryRoot = path_1.join(outputPath, 'server', 'pages');
|
82
|
+
for (const entrypoint of Object.keys(entrypoints)) {
|
83
|
+
const { output } = await buildRuntime({
|
84
|
+
files: sourceFilesPreBuild,
|
85
|
+
entrypoint,
|
86
|
+
workPath,
|
87
|
+
config: {
|
88
|
+
zeroConfig: true,
|
89
|
+
},
|
90
|
+
meta: {
|
91
|
+
avoidTopLevelInstall: true,
|
92
|
+
skipDownload: true,
|
93
|
+
},
|
94
|
+
});
|
95
|
+
// @ts-ignore This symbol is a private API
|
96
|
+
const lambdaFiles = output[lambda_1.FILES_SYMBOL];
|
97
|
+
// When deploying, the `files` that are passed to the Legacy Runtimes already
|
98
|
+
// have certain files that are ignored stripped, but locally, that list of
|
99
|
+
// files isn't used by the Legacy Runtimes, so we need to apply the filters
|
100
|
+
// to the outputs that they are returning instead.
|
101
|
+
for (const file in lambdaFiles) {
|
102
|
+
if (shouldIgnorePath(file, ignoreFilter, false)) {
|
103
|
+
delete lambdaFiles[file];
|
104
|
+
}
|
105
|
+
}
|
106
|
+
let handlerFileBase = output.handler;
|
107
|
+
let handlerFile = lambdaFiles[handlerFileBase];
|
108
|
+
let handlerHasImport = false;
|
109
|
+
const { handler } = output;
|
110
|
+
const handlerMethod = handler.split('.').pop();
|
111
|
+
const handlerFileName = handler.replace(`.${handlerMethod}`, '');
|
112
|
+
// For compiled languages, the launcher file for the Lambda generated
|
113
|
+
// by the Legacy Runtime matches the `handler` defined for it, but for
|
114
|
+
// interpreted languages, the `handler` consists of the launcher file name
|
115
|
+
// without an extension, plus the name of the method inside of that file
|
116
|
+
// that should be invoked, so we have to construct the file path explicitly.
|
117
|
+
if (!handlerFile) {
|
118
|
+
handlerFileBase = handlerFileName + ext;
|
119
|
+
handlerFile = lambdaFiles[handlerFileBase];
|
120
|
+
handlerHasImport = true;
|
121
|
+
}
|
122
|
+
if (!handlerFile || !handlerFile.fsPath) {
|
123
|
+
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\`.`);
|
124
|
+
}
|
125
|
+
const handlerExtName = path_1.extname(handlerFile.fsPath);
|
126
|
+
const entryBase = path_1.basename(entrypoint).replace(ext, handlerExtName);
|
127
|
+
const entryPath = path_1.join(path_1.dirname(entrypoint), entryBase);
|
128
|
+
const entry = path_1.join(entryRoot, entryPath);
|
129
|
+
// Create the parent directory of the API Route that will be created
|
130
|
+
// for the current entrypoint inside of `.output/server/pages/api`.
|
131
|
+
await fs_extra_1.default.ensureDir(path_1.dirname(entry));
|
132
|
+
// For compiled languages, the launcher file will be binary and therefore
|
133
|
+
// won't try to import a user-provided request handler (instead, it will
|
134
|
+
// contain it). But for interpreted languages, the launcher might try to
|
135
|
+
// load a user-provided request handler from the source file instead of bundling
|
136
|
+
// it, so we have to adjust the import statement inside the launcher to point
|
137
|
+
// to the respective source file. Previously, Legacy Runtimes simply expected
|
138
|
+
// the user-provided request-handler to be copied right next to the launcher,
|
139
|
+
// but with the new File System API, files won't be moved around unnecessarily.
|
140
|
+
if (handlerHasImport) {
|
141
|
+
const { fsPath } = handlerFile;
|
142
|
+
const encoding = 'utf-8';
|
143
|
+
// This is the true directory of the user-provided request handler in the
|
144
|
+
// source files, so that's what we will use as an import path in the launcher.
|
145
|
+
const locationPrefix = path_1.relative(entry, outputPath);
|
146
|
+
let handlerContent = await fs_extra_1.default.readFile(fsPath, encoding);
|
147
|
+
const importPaths = [
|
148
|
+
// This is the full entrypoint path, like `./api/test.py`. In our tests
|
149
|
+
// Python didn't support importing from a parent directory without using different
|
150
|
+
// code in the launcher that registers it as a location for modules and then changing
|
151
|
+
// the importing syntax, but continuing to import it like before seems to work. If
|
152
|
+
// other languages need this, we should consider excluding Python explicitly.
|
153
|
+
// `./${entrypoint}`,
|
154
|
+
// This is the entrypoint path without extension, like `api/test`
|
155
|
+
entrypoint.slice(0, -ext.length),
|
156
|
+
];
|
157
|
+
// Generate a list of regular expressions that we can use for
|
158
|
+
// finding matches, but only allow matches if the import path is
|
159
|
+
// wrapped inside single (') or double quotes (").
|
160
|
+
const patterns = importPaths.map(path => {
|
161
|
+
// eslint-disable-next-line no-useless-escape
|
162
|
+
return new RegExp(`('|")(${path.replace(/\./g, '\\.')})('|")`, 'g');
|
163
|
+
});
|
164
|
+
let replacedMatch = null;
|
165
|
+
for (const pattern of patterns) {
|
166
|
+
const newContent = handlerContent.replace(pattern, (_, p1, p2, p3) => {
|
167
|
+
return `${p1}${path_1.join(locationPrefix, p2)}${p3}`;
|
168
|
+
});
|
169
|
+
if (newContent !== handlerContent) {
|
170
|
+
_1.debug(`Replaced "${pattern}" inside "${entry}" to ensure correct import of user-provided request handler`);
|
171
|
+
handlerContent = newContent;
|
172
|
+
replacedMatch = true;
|
173
|
+
}
|
174
|
+
}
|
175
|
+
if (!replacedMatch) {
|
176
|
+
new Error(`No replacable matches for "${importPaths[0]}" or "${importPaths[1]}" found in "${fsPath}"`);
|
177
|
+
}
|
178
|
+
await fs_extra_1.default.writeFile(entry, handlerContent, encoding);
|
179
|
+
}
|
180
|
+
else {
|
181
|
+
await fs_extra_1.default.copy(handlerFile.fsPath, entry);
|
182
|
+
}
|
183
|
+
// Legacy Runtimes based on interpreted languages will create a new launcher file
|
184
|
+
// for every entrypoint, but they will create each one inside `workPath`, which means that
|
185
|
+
// the launcher for one entrypoint will overwrite the launcher provided for the previous
|
186
|
+
// entrypoint. That's why, above, we copy the file contents into the new destination (and
|
187
|
+
// optionally transform them along the way), instead of linking. We then also want to remove
|
188
|
+
// the copy origin right here, so that the `workPath` doesn't contain a useless launcher file
|
189
|
+
// once the build has finished running.
|
190
|
+
await fs_extra_1.default.remove(handlerFile.fsPath);
|
191
|
+
_1.debug(`Removed temporary file "${handlerFile.fsPath}"`);
|
192
|
+
const nft = `${entry}.nft.json`;
|
193
|
+
const json = JSON.stringify({
|
194
|
+
version: 2,
|
195
|
+
files: Object.keys(lambdaFiles)
|
196
|
+
.map(file => {
|
197
|
+
const { fsPath } = lambdaFiles[file];
|
198
|
+
if (!fsPath) {
|
199
|
+
throw new Error(`File "${file}" is missing valid \`fsPath\` property`);
|
200
|
+
}
|
201
|
+
// The handler was already moved into position above.
|
202
|
+
if (file === handlerFileBase) {
|
203
|
+
return;
|
204
|
+
}
|
205
|
+
return normalize_path_1.normalizePath(path_1.relative(path_1.dirname(nft), fsPath));
|
206
|
+
})
|
207
|
+
.filter(Boolean),
|
208
|
+
});
|
209
|
+
await fs_extra_1.default.writeFile(nft, json);
|
210
|
+
// Add an entry that will later on be added to the `functions-manifest.json`
|
211
|
+
// file that is placed inside of the `.output` directory.
|
212
|
+
pages[normalize_path_1.normalizePath(entryPath)] = {
|
213
|
+
// Because the underlying file used as a handler was placed
|
214
|
+
// inside `.output/server/pages/api`, it no longer has the name it originally
|
215
|
+
// had and is now named after the API Route that it's responsible for,
|
216
|
+
// so we have to adjust the name of the Lambda handler accordingly.
|
217
|
+
handler: handler.replace(handlerFileName, path_1.parse(entry).name),
|
218
|
+
runtime: output.runtime,
|
219
|
+
memory: output.memory,
|
220
|
+
maxDuration: output.maxDuration,
|
221
|
+
environment: output.environment,
|
222
|
+
allowQuery: output.allowQuery,
|
223
|
+
};
|
224
|
+
}
|
225
|
+
// Add any Serverless Functions that were exposed by the Legacy Runtime
|
226
|
+
// to the `functions-manifest.json` file provided in `.output`.
|
227
|
+
await _experimental_updateFunctionsManifest({ workPath, pages });
|
228
|
+
};
|
229
|
+
}
|
230
|
+
exports._experimental_convertRuntimeToPlugin = _experimental_convertRuntimeToPlugin;
|
231
|
+
async function readJson(filePath) {
|
232
|
+
try {
|
233
|
+
const str = await fs_extra_1.default.readFile(filePath, 'utf8');
|
234
|
+
return JSON.parse(str);
|
235
|
+
}
|
236
|
+
catch (err) {
|
237
|
+
if (err.code === 'ENOENT') {
|
238
|
+
return {};
|
239
|
+
}
|
240
|
+
throw err;
|
241
|
+
}
|
242
|
+
}
|
243
|
+
/**
|
244
|
+
* If `.output/functions-manifest.json` exists, append to the pages
|
245
|
+
* property. Otherwise write a new file.
|
246
|
+
*/
|
247
|
+
async function _experimental_updateFunctionsManifest({ workPath, pages, }) {
|
248
|
+
const functionsManifestPath = path_1.join(workPath, '.output', 'functions-manifest.json');
|
249
|
+
const functionsManifest = await readJson(functionsManifestPath);
|
250
|
+
if (!functionsManifest.version)
|
251
|
+
functionsManifest.version = 2;
|
252
|
+
if (!functionsManifest.pages)
|
253
|
+
functionsManifest.pages = {};
|
254
|
+
for (const [pageKey, pageConfig] of Object.entries(pages)) {
|
255
|
+
functionsManifest.pages[pageKey] = { ...pageConfig };
|
256
|
+
}
|
257
|
+
await fs_extra_1.default.writeFile(functionsManifestPath, JSON.stringify(functionsManifest));
|
258
|
+
}
|
259
|
+
exports._experimental_updateFunctionsManifest = _experimental_updateFunctionsManifest;
|
260
|
+
/**
|
261
|
+
* Append routes to the `routes-manifest.json` file.
|
262
|
+
* If the file does not exist, it will be created.
|
263
|
+
*/
|
264
|
+
async function _experimental_updateRoutesManifest({ workPath, redirects, rewrites, headers, dynamicRoutes, staticRoutes, }) {
|
265
|
+
const routesManifestPath = path_1.join(workPath, '.output', 'routes-manifest.json');
|
266
|
+
const routesManifest = await readJson(routesManifestPath);
|
267
|
+
if (!routesManifest.version)
|
268
|
+
routesManifest.version = 3;
|
269
|
+
if (routesManifest.pages404 === undefined)
|
270
|
+
routesManifest.pages404 = true;
|
271
|
+
if (redirects) {
|
272
|
+
if (!routesManifest.redirects)
|
273
|
+
routesManifest.redirects = [];
|
274
|
+
routesManifest.redirects.push(...redirects);
|
275
|
+
}
|
276
|
+
if (rewrites) {
|
277
|
+
if (!routesManifest.rewrites)
|
278
|
+
routesManifest.rewrites = [];
|
279
|
+
routesManifest.rewrites.push(...rewrites);
|
280
|
+
}
|
281
|
+
if (headers) {
|
282
|
+
if (!routesManifest.headers)
|
283
|
+
routesManifest.headers = [];
|
284
|
+
routesManifest.headers.push(...headers);
|
285
|
+
}
|
286
|
+
if (dynamicRoutes) {
|
287
|
+
if (!routesManifest.dynamicRoutes)
|
288
|
+
routesManifest.dynamicRoutes = [];
|
289
|
+
routesManifest.dynamicRoutes.push(...dynamicRoutes);
|
290
|
+
}
|
291
|
+
if (staticRoutes) {
|
292
|
+
if (!routesManifest.staticRoutes)
|
293
|
+
routesManifest.staticRoutes = [];
|
294
|
+
routesManifest.staticRoutes.push(...staticRoutes);
|
295
|
+
}
|
296
|
+
await fs_extra_1.default.writeFile(routesManifestPath, JSON.stringify(routesManifest));
|
297
|
+
}
|
298
|
+
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 {};
|
package/dist/detect-builders.js
CHANGED
@@ -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
|
717
|
+
const extGroup = `(?:\\.(?:${Array.from(extSet)
|
687
718
|
.map(ext => ext.slice(1))
|
688
|
-
.join('|')
|
689
|
-
const
|
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 {};
|