@vercel/build-utils 2.12.3-canary.34 → 2.12.3-canary.35
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 +30 -21
- package/dist/index.js +30 -21
- package/package.json +2 -2
@@ -98,14 +98,6 @@ function convertRuntimeToPlugin(buildRuntime, packageName, ext) {
|
|
98
98
|
// so we don't want to pollute this space unnecessarily. That means we have to clean
|
99
99
|
// up files that were created by the build, which is done further below.
|
100
100
|
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
101
|
// @ts-ignore This symbol is a private API
|
110
102
|
const lambdaFiles = output[lambda_1.FILES_SYMBOL];
|
111
103
|
// When deploying, the `files` that are passed to the Legacy Runtimes already
|
@@ -117,20 +109,34 @@ function convertRuntimeToPlugin(buildRuntime, packageName, ext) {
|
|
117
109
|
delete lambdaFiles[file];
|
118
110
|
}
|
119
111
|
}
|
120
|
-
|
121
|
-
|
122
|
-
}
|
123
|
-
const
|
124
|
-
|
125
|
-
|
112
|
+
let handlerFileBase = output.handler;
|
113
|
+
let handlerFile = lambdaFiles[handlerFileBase];
|
114
|
+
const { handler } = output;
|
115
|
+
const handlerMethod = handler.split('.').pop();
|
116
|
+
const handlerFileName = handler.replace(`.${handlerMethod}`, '');
|
117
|
+
// For compiled languages, the launcher file for the Lambda generated
|
118
|
+
// by the Legacy Runtime matches the `handler` defined for it, but for
|
119
|
+
// interpreted languages, the `handler` consists of the launcher file name
|
120
|
+
// without an extension, plus the name of the method inside of that file
|
121
|
+
// that should be invoked, so we have to construct the file path explicitly.
|
122
|
+
if (!handlerFile) {
|
123
|
+
handlerFileBase = handlerFileName + ext;
|
124
|
+
handlerFile = lambdaFiles[handlerFileBase];
|
125
|
+
}
|
126
|
+
if (!handlerFile || !handlerFile.fsPath) {
|
127
|
+
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\`.`);
|
126
128
|
}
|
127
|
-
const
|
129
|
+
const handlerExtName = path_1.extname(handlerFile.fsPath);
|
130
|
+
const entryRoot = path_1.join(workPath, '.output', 'server', 'pages');
|
131
|
+
const entryBase = path_1.basename(entrypoint).replace(ext, handlerExtName);
|
132
|
+
const entryPath = path_1.join(path_1.dirname(entrypoint), entryBase);
|
133
|
+
const entry = path_1.join(entryRoot, entryPath);
|
128
134
|
// We never want to link here, only copy, because the launcher
|
129
135
|
// file often has the same name for every entrypoint, which means that
|
130
136
|
// every build for every entrypoint overwrites the launcher of the previous
|
131
137
|
// one, so linking would end with a broken reference.
|
132
138
|
await fs_extra_1.default.ensureDir(path_1.dirname(entry));
|
133
|
-
await fs_extra_1.default.copy(
|
139
|
+
await fs_extra_1.default.copy(handlerFile.fsPath, entry);
|
134
140
|
const newFilesEntrypoint = [];
|
135
141
|
const newDirectoriesEntrypoint = [];
|
136
142
|
const preBuildFiles = Object.values(sourceFilesPreBuild).map(file => {
|
@@ -181,7 +187,7 @@ function convertRuntimeToPlugin(buildRuntime, packageName, ext) {
|
|
181
187
|
const linkers = Object.entries(lambdaFiles).map(async ([relPath, file]) => {
|
182
188
|
const newPath = path_1.join(traceDir, relPath);
|
183
189
|
// The handler was already moved into position above.
|
184
|
-
if (relPath ===
|
190
|
+
if (relPath === handlerFileBase) {
|
185
191
|
return;
|
186
192
|
}
|
187
193
|
tracedFiles.push({ absolutePath: newPath, relativePath: relPath });
|
@@ -218,7 +224,7 @@ function convertRuntimeToPlugin(buildRuntime, packageName, ext) {
|
|
218
224
|
}
|
219
225
|
});
|
220
226
|
linkersRuntime = linkersRuntime.concat(linkers);
|
221
|
-
const nft =
|
227
|
+
const nft = `${entry}.nft.json`;
|
222
228
|
const json = JSON.stringify({
|
223
229
|
version: 1,
|
224
230
|
files: tracedFiles.map(file => ({
|
@@ -236,11 +242,14 @@ function convertRuntimeToPlugin(buildRuntime, packageName, ext) {
|
|
236
242
|
...newFilesEntrypoint,
|
237
243
|
...newDirectoriesEntrypoint,
|
238
244
|
]);
|
239
|
-
const apiRouteHandler = `${path_1.parse(entry).name}.${handlerMethod}`;
|
240
245
|
// Add an entry that will later on be added to the `functions-manifest.json`
|
241
246
|
// file that is placed inside of the `.output` directory.
|
242
|
-
pages[
|
243
|
-
handler
|
247
|
+
pages[normalize_path_1.normalizePath(entryPath)] = {
|
248
|
+
// Because the underlying file used as a handler was placed
|
249
|
+
// inside `.output/server/pages/api`, it no longer has the name it originally
|
250
|
+
// had and is now named after the API Route that it's responsible for,
|
251
|
+
// so we have to adjust the name of the Lambda handler accordingly.
|
252
|
+
handler: handler.replace(handlerFileName, path_1.parse(entry).name),
|
244
253
|
runtime: output.runtime,
|
245
254
|
memory: output.memory,
|
246
255
|
maxDuration: output.maxDuration,
|
package/dist/index.js
CHANGED
@@ -32845,14 +32845,6 @@ function convertRuntimeToPlugin(buildRuntime, packageName, ext) {
|
|
32845
32845
|
// so we don't want to pollute this space unnecessarily. That means we have to clean
|
32846
32846
|
// up files that were created by the build, which is done further below.
|
32847
32847
|
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
32848
|
// @ts-ignore This symbol is a private API
|
32857
32849
|
const lambdaFiles = output[lambda_1.FILES_SYMBOL];
|
32858
32850
|
// When deploying, the `files` that are passed to the Legacy Runtimes already
|
@@ -32864,20 +32856,34 @@ function convertRuntimeToPlugin(buildRuntime, packageName, ext) {
|
|
32864
32856
|
delete lambdaFiles[file];
|
32865
32857
|
}
|
32866
32858
|
}
|
32867
|
-
|
32868
|
-
|
32869
|
-
}
|
32870
|
-
const
|
32871
|
-
|
32872
|
-
|
32859
|
+
let handlerFileBase = output.handler;
|
32860
|
+
let handlerFile = lambdaFiles[handlerFileBase];
|
32861
|
+
const { handler } = output;
|
32862
|
+
const handlerMethod = handler.split('.').pop();
|
32863
|
+
const handlerFileName = handler.replace(`.${handlerMethod}`, '');
|
32864
|
+
// For compiled languages, the launcher file for the Lambda generated
|
32865
|
+
// by the Legacy Runtime matches the `handler` defined for it, but for
|
32866
|
+
// interpreted languages, the `handler` consists of the launcher file name
|
32867
|
+
// without an extension, plus the name of the method inside of that file
|
32868
|
+
// that should be invoked, so we have to construct the file path explicitly.
|
32869
|
+
if (!handlerFile) {
|
32870
|
+
handlerFileBase = handlerFileName + ext;
|
32871
|
+
handlerFile = lambdaFiles[handlerFileBase];
|
32872
|
+
}
|
32873
|
+
if (!handlerFile || !handlerFile.fsPath) {
|
32874
|
+
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\`.`);
|
32873
32875
|
}
|
32874
|
-
const
|
32876
|
+
const handlerExtName = path_1.extname(handlerFile.fsPath);
|
32877
|
+
const entryRoot = path_1.join(workPath, '.output', 'server', 'pages');
|
32878
|
+
const entryBase = path_1.basename(entrypoint).replace(ext, handlerExtName);
|
32879
|
+
const entryPath = path_1.join(path_1.dirname(entrypoint), entryBase);
|
32880
|
+
const entry = path_1.join(entryRoot, entryPath);
|
32875
32881
|
// We never want to link here, only copy, because the launcher
|
32876
32882
|
// file often has the same name for every entrypoint, which means that
|
32877
32883
|
// every build for every entrypoint overwrites the launcher of the previous
|
32878
32884
|
// one, so linking would end with a broken reference.
|
32879
32885
|
await fs_extra_1.default.ensureDir(path_1.dirname(entry));
|
32880
|
-
await fs_extra_1.default.copy(
|
32886
|
+
await fs_extra_1.default.copy(handlerFile.fsPath, entry);
|
32881
32887
|
const newFilesEntrypoint = [];
|
32882
32888
|
const newDirectoriesEntrypoint = [];
|
32883
32889
|
const preBuildFiles = Object.values(sourceFilesPreBuild).map(file => {
|
@@ -32928,7 +32934,7 @@ function convertRuntimeToPlugin(buildRuntime, packageName, ext) {
|
|
32928
32934
|
const linkers = Object.entries(lambdaFiles).map(async ([relPath, file]) => {
|
32929
32935
|
const newPath = path_1.join(traceDir, relPath);
|
32930
32936
|
// The handler was already moved into position above.
|
32931
|
-
if (relPath ===
|
32937
|
+
if (relPath === handlerFileBase) {
|
32932
32938
|
return;
|
32933
32939
|
}
|
32934
32940
|
tracedFiles.push({ absolutePath: newPath, relativePath: relPath });
|
@@ -32965,7 +32971,7 @@ function convertRuntimeToPlugin(buildRuntime, packageName, ext) {
|
|
32965
32971
|
}
|
32966
32972
|
});
|
32967
32973
|
linkersRuntime = linkersRuntime.concat(linkers);
|
32968
|
-
const nft =
|
32974
|
+
const nft = `${entry}.nft.json`;
|
32969
32975
|
const json = JSON.stringify({
|
32970
32976
|
version: 1,
|
32971
32977
|
files: tracedFiles.map(file => ({
|
@@ -32983,11 +32989,14 @@ function convertRuntimeToPlugin(buildRuntime, packageName, ext) {
|
|
32983
32989
|
...newFilesEntrypoint,
|
32984
32990
|
...newDirectoriesEntrypoint,
|
32985
32991
|
]);
|
32986
|
-
const apiRouteHandler = `${path_1.parse(entry).name}.${handlerMethod}`;
|
32987
32992
|
// Add an entry that will later on be added to the `functions-manifest.json`
|
32988
32993
|
// file that is placed inside of the `.output` directory.
|
32989
|
-
pages[
|
32990
|
-
handler
|
32994
|
+
pages[normalize_path_1.normalizePath(entryPath)] = {
|
32995
|
+
// Because the underlying file used as a handler was placed
|
32996
|
+
// inside `.output/server/pages/api`, it no longer has the name it originally
|
32997
|
+
// had and is now named after the API Route that it's responsible for,
|
32998
|
+
// so we have to adjust the name of the Lambda handler accordingly.
|
32999
|
+
handler: handler.replace(handlerFileName, path_1.parse(entry).name),
|
32991
33000
|
runtime: output.runtime,
|
32992
33001
|
memory: output.memory,
|
32993
33002
|
maxDuration: output.maxDuration,
|
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.35",
|
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": "2c3ddffaacb370eb4c0893815b3bc7417f92d432"
|
53
53
|
}
|