@vercel/build-utils 2.12.3-canary.33 → 2.12.3-canary.37
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/convert-runtime-to-plugin.js +47 -35
- package/dist/index.js +47 -35
- package/package.json +2 -2
@@ -79,6 +79,8 @@ function convertRuntimeToPlugin(buildRuntime, packageName, ext) {
|
|
79
79
|
await fs_extra_1.default.ensureDir(traceDir);
|
80
80
|
let newPathsRuntime = new Set();
|
81
81
|
let linkersRuntime = [];
|
82
|
+
const entryDir = path_1.join('.output', 'server', 'pages');
|
83
|
+
const entryRoot = path_1.join(workPath, entryDir);
|
82
84
|
for (const entrypoint of Object.keys(entrypoints)) {
|
83
85
|
const { output } = await buildRuntime({
|
84
86
|
files: sourceFilesPreBuild,
|
@@ -98,22 +100,6 @@ function convertRuntimeToPlugin(buildRuntime, packageName, ext) {
|
|
98
100
|
// so we don't want to pollute this space unnecessarily. That means we have to clean
|
99
101
|
// up files that were created by the build, which is done further below.
|
100
102
|
const sourceFilesAfterBuild = await getSourceFiles(workPath, ignoreFilter);
|
101
|
-
// Further down, we will need the filename of the Lambda handler
|
102
|
-
// for placing it inside `server/pages/api`, but because Legacy Runtimes
|
103
|
-
// don't expose the filename directly, we have to construct it
|
104
|
-
// from the handler name, and then find the matching file further below,
|
105
|
-
// because we don't yet know its extension here.
|
106
|
-
const handler = output.handler;
|
107
|
-
const handlerMethod = handler.split('.').reverse()[0];
|
108
|
-
const handlerFileName = handler.replace(`.${handlerMethod}`, '');
|
109
|
-
pages[entrypoint] = {
|
110
|
-
handler: handler,
|
111
|
-
runtime: output.runtime,
|
112
|
-
memory: output.memory,
|
113
|
-
maxDuration: output.maxDuration,
|
114
|
-
environment: output.environment,
|
115
|
-
allowQuery: output.allowQuery,
|
116
|
-
};
|
117
103
|
// @ts-ignore This symbol is a private API
|
118
104
|
const lambdaFiles = output[lambda_1.FILES_SYMBOL];
|
119
105
|
// When deploying, the `files` that are passed to the Legacy Runtimes already
|
@@ -125,16 +111,33 @@ function convertRuntimeToPlugin(buildRuntime, packageName, ext) {
|
|
125
111
|
delete lambdaFiles[file];
|
126
112
|
}
|
127
113
|
}
|
128
|
-
|
129
|
-
|
130
|
-
}
|
131
|
-
const
|
132
|
-
|
133
|
-
|
114
|
+
let handlerFileBase = output.handler;
|
115
|
+
let handlerFile = lambdaFiles[handlerFileBase];
|
116
|
+
const { handler } = output;
|
117
|
+
const handlerMethod = handler.split('.').pop();
|
118
|
+
const handlerFileName = handler.replace(`.${handlerMethod}`, '');
|
119
|
+
// For compiled languages, the launcher file for the Lambda generated
|
120
|
+
// by the Legacy Runtime matches the `handler` defined for it, but for
|
121
|
+
// interpreted languages, the `handler` consists of the launcher file name
|
122
|
+
// without an extension, plus the name of the method inside of that file
|
123
|
+
// that should be invoked, so we have to construct the file path explicitly.
|
124
|
+
if (!handlerFile) {
|
125
|
+
handlerFileBase = handlerFileName + ext;
|
126
|
+
handlerFile = lambdaFiles[handlerFileBase];
|
134
127
|
}
|
135
|
-
|
128
|
+
if (!handlerFile || !handlerFile.fsPath) {
|
129
|
+
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\`.`);
|
130
|
+
}
|
131
|
+
const handlerExtName = path_1.extname(handlerFile.fsPath);
|
132
|
+
const entryBase = path_1.basename(entrypoint).replace(ext, handlerExtName);
|
133
|
+
const entryPath = path_1.join(path_1.dirname(entrypoint), entryBase);
|
134
|
+
const entry = path_1.join(entryRoot, entryPath);
|
135
|
+
// We never want to link here, only copy, because the launcher
|
136
|
+
// file often has the same name for every entrypoint, which means that
|
137
|
+
// every build for every entrypoint overwrites the launcher of the previous
|
138
|
+
// one, so linking would end with a broken reference.
|
136
139
|
await fs_extra_1.default.ensureDir(path_1.dirname(entry));
|
137
|
-
await
|
140
|
+
await fs_extra_1.default.copy(handlerFile.fsPath, entry);
|
138
141
|
const newFilesEntrypoint = [];
|
139
142
|
const newDirectoriesEntrypoint = [];
|
140
143
|
const preBuildFiles = Object.values(sourceFilesPreBuild).map(file => {
|
@@ -185,7 +188,7 @@ function convertRuntimeToPlugin(buildRuntime, packageName, ext) {
|
|
185
188
|
const linkers = Object.entries(lambdaFiles).map(async ([relPath, file]) => {
|
186
189
|
const newPath = path_1.join(traceDir, relPath);
|
187
190
|
// The handler was already moved into position above.
|
188
|
-
if (relPath ===
|
191
|
+
if (relPath === handlerFileBase) {
|
189
192
|
return;
|
190
193
|
}
|
191
194
|
tracedFiles.push({ absolutePath: newPath, relativePath: relPath });
|
@@ -222,12 +225,14 @@ function convertRuntimeToPlugin(buildRuntime, packageName, ext) {
|
|
222
225
|
}
|
223
226
|
});
|
224
227
|
linkersRuntime = linkersRuntime.concat(linkers);
|
225
|
-
const nft =
|
228
|
+
const nft = `${entry}.nft.json`;
|
226
229
|
const json = JSON.stringify({
|
227
230
|
version: 1,
|
228
231
|
files: tracedFiles.map(file => ({
|
229
232
|
input: normalize_path_1.normalizePath(path_1.relative(path_1.dirname(nft), file.absolutePath)),
|
230
|
-
|
233
|
+
// We'd like to place all the dependency files right next
|
234
|
+
// to the final launcher file inside of the Lambda.
|
235
|
+
output: normalize_path_1.normalizePath(path_1.join(entryDir, 'api', file.relativePath)),
|
231
236
|
})),
|
232
237
|
});
|
233
238
|
await fs_extra_1.default.ensureDir(path_1.dirname(nft));
|
@@ -240,6 +245,20 @@ function convertRuntimeToPlugin(buildRuntime, packageName, ext) {
|
|
240
245
|
...newFilesEntrypoint,
|
241
246
|
...newDirectoriesEntrypoint,
|
242
247
|
]);
|
248
|
+
// Add an entry that will later on be added to the `functions-manifest.json`
|
249
|
+
// file that is placed inside of the `.output` directory.
|
250
|
+
pages[normalize_path_1.normalizePath(entryPath)] = {
|
251
|
+
// Because the underlying file used as a handler was placed
|
252
|
+
// inside `.output/server/pages/api`, it no longer has the name it originally
|
253
|
+
// had and is now named after the API Route that it's responsible for,
|
254
|
+
// so we have to adjust the name of the Lambda handler accordingly.
|
255
|
+
handler: handler.replace(handlerFileName, path_1.parse(entry).name),
|
256
|
+
runtime: output.runtime,
|
257
|
+
memory: output.memory,
|
258
|
+
maxDuration: output.maxDuration,
|
259
|
+
environment: output.environment,
|
260
|
+
allowQuery: output.allowQuery,
|
261
|
+
};
|
243
262
|
}
|
244
263
|
// Instead of of waiting for all of the linking to be done for every
|
245
264
|
// entrypoint before processing the next one, we immediately handle all
|
@@ -265,14 +284,7 @@ function convertRuntimeToPlugin(buildRuntime, packageName, ext) {
|
|
265
284
|
}
|
266
285
|
exports.convertRuntimeToPlugin = convertRuntimeToPlugin;
|
267
286
|
async function linkOrCopy(existingPath, newPath) {
|
268
|
-
|
269
|
-
await fs_extra_1.default.createLink(existingPath, newPath);
|
270
|
-
}
|
271
|
-
catch (err) {
|
272
|
-
if (err.code !== 'EEXIST') {
|
273
|
-
await fs_extra_1.default.copyFile(existingPath, newPath);
|
274
|
-
}
|
275
|
-
}
|
287
|
+
await fs_extra_1.default.copyFile(existingPath, newPath);
|
276
288
|
}
|
277
289
|
async function readJson(filePath) {
|
278
290
|
try {
|
package/dist/index.js
CHANGED
@@ -32826,6 +32826,8 @@ function convertRuntimeToPlugin(buildRuntime, packageName, ext) {
|
|
32826
32826
|
await fs_extra_1.default.ensureDir(traceDir);
|
32827
32827
|
let newPathsRuntime = new Set();
|
32828
32828
|
let linkersRuntime = [];
|
32829
|
+
const entryDir = path_1.join('.output', 'server', 'pages');
|
32830
|
+
const entryRoot = path_1.join(workPath, entryDir);
|
32829
32831
|
for (const entrypoint of Object.keys(entrypoints)) {
|
32830
32832
|
const { output } = await buildRuntime({
|
32831
32833
|
files: sourceFilesPreBuild,
|
@@ -32845,22 +32847,6 @@ function convertRuntimeToPlugin(buildRuntime, packageName, ext) {
|
|
32845
32847
|
// so we don't want to pollute this space unnecessarily. That means we have to clean
|
32846
32848
|
// up files that were created by the build, which is done further below.
|
32847
32849
|
const sourceFilesAfterBuild = await getSourceFiles(workPath, ignoreFilter);
|
32848
|
-
// Further down, we will need the filename of the Lambda handler
|
32849
|
-
// for placing it inside `server/pages/api`, but because Legacy Runtimes
|
32850
|
-
// don't expose the filename directly, we have to construct it
|
32851
|
-
// from the handler name, and then find the matching file further below,
|
32852
|
-
// because we don't yet know its extension here.
|
32853
|
-
const handler = output.handler;
|
32854
|
-
const handlerMethod = handler.split('.').reverse()[0];
|
32855
|
-
const handlerFileName = handler.replace(`.${handlerMethod}`, '');
|
32856
|
-
pages[entrypoint] = {
|
32857
|
-
handler: handler,
|
32858
|
-
runtime: output.runtime,
|
32859
|
-
memory: output.memory,
|
32860
|
-
maxDuration: output.maxDuration,
|
32861
|
-
environment: output.environment,
|
32862
|
-
allowQuery: output.allowQuery,
|
32863
|
-
};
|
32864
32850
|
// @ts-ignore This symbol is a private API
|
32865
32851
|
const lambdaFiles = output[lambda_1.FILES_SYMBOL];
|
32866
32852
|
// When deploying, the `files` that are passed to the Legacy Runtimes already
|
@@ -32872,16 +32858,33 @@ function convertRuntimeToPlugin(buildRuntime, packageName, ext) {
|
|
32872
32858
|
delete lambdaFiles[file];
|
32873
32859
|
}
|
32874
32860
|
}
|
32875
|
-
|
32876
|
-
|
32877
|
-
}
|
32878
|
-
const
|
32879
|
-
|
32880
|
-
|
32861
|
+
let handlerFileBase = output.handler;
|
32862
|
+
let handlerFile = lambdaFiles[handlerFileBase];
|
32863
|
+
const { handler } = output;
|
32864
|
+
const handlerMethod = handler.split('.').pop();
|
32865
|
+
const handlerFileName = handler.replace(`.${handlerMethod}`, '');
|
32866
|
+
// For compiled languages, the launcher file for the Lambda generated
|
32867
|
+
// by the Legacy Runtime matches the `handler` defined for it, but for
|
32868
|
+
// interpreted languages, the `handler` consists of the launcher file name
|
32869
|
+
// without an extension, plus the name of the method inside of that file
|
32870
|
+
// that should be invoked, so we have to construct the file path explicitly.
|
32871
|
+
if (!handlerFile) {
|
32872
|
+
handlerFileBase = handlerFileName + ext;
|
32873
|
+
handlerFile = lambdaFiles[handlerFileBase];
|
32881
32874
|
}
|
32882
|
-
|
32875
|
+
if (!handlerFile || !handlerFile.fsPath) {
|
32876
|
+
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\`.`);
|
32877
|
+
}
|
32878
|
+
const handlerExtName = path_1.extname(handlerFile.fsPath);
|
32879
|
+
const entryBase = path_1.basename(entrypoint).replace(ext, handlerExtName);
|
32880
|
+
const entryPath = path_1.join(path_1.dirname(entrypoint), entryBase);
|
32881
|
+
const entry = path_1.join(entryRoot, entryPath);
|
32882
|
+
// We never want to link here, only copy, because the launcher
|
32883
|
+
// file often has the same name for every entrypoint, which means that
|
32884
|
+
// every build for every entrypoint overwrites the launcher of the previous
|
32885
|
+
// one, so linking would end with a broken reference.
|
32883
32886
|
await fs_extra_1.default.ensureDir(path_1.dirname(entry));
|
32884
|
-
await
|
32887
|
+
await fs_extra_1.default.copy(handlerFile.fsPath, entry);
|
32885
32888
|
const newFilesEntrypoint = [];
|
32886
32889
|
const newDirectoriesEntrypoint = [];
|
32887
32890
|
const preBuildFiles = Object.values(sourceFilesPreBuild).map(file => {
|
@@ -32932,7 +32935,7 @@ function convertRuntimeToPlugin(buildRuntime, packageName, ext) {
|
|
32932
32935
|
const linkers = Object.entries(lambdaFiles).map(async ([relPath, file]) => {
|
32933
32936
|
const newPath = path_1.join(traceDir, relPath);
|
32934
32937
|
// The handler was already moved into position above.
|
32935
|
-
if (relPath ===
|
32938
|
+
if (relPath === handlerFileBase) {
|
32936
32939
|
return;
|
32937
32940
|
}
|
32938
32941
|
tracedFiles.push({ absolutePath: newPath, relativePath: relPath });
|
@@ -32969,12 +32972,14 @@ function convertRuntimeToPlugin(buildRuntime, packageName, ext) {
|
|
32969
32972
|
}
|
32970
32973
|
});
|
32971
32974
|
linkersRuntime = linkersRuntime.concat(linkers);
|
32972
|
-
const nft =
|
32975
|
+
const nft = `${entry}.nft.json`;
|
32973
32976
|
const json = JSON.stringify({
|
32974
32977
|
version: 1,
|
32975
32978
|
files: tracedFiles.map(file => ({
|
32976
32979
|
input: normalize_path_1.normalizePath(path_1.relative(path_1.dirname(nft), file.absolutePath)),
|
32977
|
-
|
32980
|
+
// We'd like to place all the dependency files right next
|
32981
|
+
// to the final launcher file inside of the Lambda.
|
32982
|
+
output: normalize_path_1.normalizePath(path_1.join(entryDir, 'api', file.relativePath)),
|
32978
32983
|
})),
|
32979
32984
|
});
|
32980
32985
|
await fs_extra_1.default.ensureDir(path_1.dirname(nft));
|
@@ -32987,6 +32992,20 @@ function convertRuntimeToPlugin(buildRuntime, packageName, ext) {
|
|
32987
32992
|
...newFilesEntrypoint,
|
32988
32993
|
...newDirectoriesEntrypoint,
|
32989
32994
|
]);
|
32995
|
+
// Add an entry that will later on be added to the `functions-manifest.json`
|
32996
|
+
// file that is placed inside of the `.output` directory.
|
32997
|
+
pages[normalize_path_1.normalizePath(entryPath)] = {
|
32998
|
+
// Because the underlying file used as a handler was placed
|
32999
|
+
// inside `.output/server/pages/api`, it no longer has the name it originally
|
33000
|
+
// had and is now named after the API Route that it's responsible for,
|
33001
|
+
// so we have to adjust the name of the Lambda handler accordingly.
|
33002
|
+
handler: handler.replace(handlerFileName, path_1.parse(entry).name),
|
33003
|
+
runtime: output.runtime,
|
33004
|
+
memory: output.memory,
|
33005
|
+
maxDuration: output.maxDuration,
|
33006
|
+
environment: output.environment,
|
33007
|
+
allowQuery: output.allowQuery,
|
33008
|
+
};
|
32990
33009
|
}
|
32991
33010
|
// Instead of of waiting for all of the linking to be done for every
|
32992
33011
|
// entrypoint before processing the next one, we immediately handle all
|
@@ -33012,14 +33031,7 @@ function convertRuntimeToPlugin(buildRuntime, packageName, ext) {
|
|
33012
33031
|
}
|
33013
33032
|
exports.convertRuntimeToPlugin = convertRuntimeToPlugin;
|
33014
33033
|
async function linkOrCopy(existingPath, newPath) {
|
33015
|
-
|
33016
|
-
await fs_extra_1.default.createLink(existingPath, newPath);
|
33017
|
-
}
|
33018
|
-
catch (err) {
|
33019
|
-
if (err.code !== 'EEXIST') {
|
33020
|
-
await fs_extra_1.default.copyFile(existingPath, newPath);
|
33021
|
-
}
|
33022
|
-
}
|
33034
|
+
await fs_extra_1.default.copyFile(existingPath, newPath);
|
33023
33035
|
}
|
33024
33036
|
async function readJson(filePath) {
|
33025
33037
|
try {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vercel/build-utils",
|
3
|
-
"version": "2.12.3-canary.
|
3
|
+
"version": "2.12.3-canary.37",
|
4
4
|
"license": "MIT",
|
5
5
|
"main": "./dist/index.js",
|
6
6
|
"types": "./dist/index.d.js",
|
@@ -49,5 +49,5 @@
|
|
49
49
|
"typescript": "4.3.4",
|
50
50
|
"yazl": "2.4.3"
|
51
51
|
},
|
52
|
-
"gitHead": "
|
52
|
+
"gitHead": "fe43c9c4b2e8fdefbc4b35778e4593a55feddac0"
|
53
53
|
}
|