@vercel/build-utils 2.12.3-canary.17 → 2.12.3-canary.18
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.d.ts +11 -0
- package/dist/convert-runtime-to-plugin.js +42 -12
- package/dist/index.d.ts +1 -1
- package/dist/index.js +44 -13
- package/dist/lambda.d.ts +1 -1
- package/package.json +2 -2
@@ -10,3 +10,14 @@ export declare function convertRuntimeToPlugin(buildRuntime: (options: BuildOpti
|
|
10
10
|
}>, ext: string): ({ workPath }: {
|
11
11
|
workPath: string;
|
12
12
|
}) => Promise<void>;
|
13
|
+
/**
|
14
|
+
* If `.output/functions-manifest.json` exists, append to the pages
|
15
|
+
* property. Otherwise write a new file. This will also read `vercel.json`
|
16
|
+
* and apply relevant `functions` property config.
|
17
|
+
*/
|
18
|
+
export declare function updateFunctionsManifest({ workPath, pages, }: {
|
19
|
+
workPath: string;
|
20
|
+
pages: {
|
21
|
+
[key: string]: any;
|
22
|
+
};
|
23
|
+
}): Promise<void>;
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.convertRuntimeToPlugin = void 0;
|
6
|
+
exports.updateFunctionsManifest = exports.convertRuntimeToPlugin = void 0;
|
7
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
8
8
|
const path_1 = require("path");
|
9
9
|
const glob_1 = __importDefault(require("./fs/glob"));
|
@@ -21,8 +21,8 @@ function convertRuntimeToPlugin(buildRuntime, ext) {
|
|
21
21
|
const files = await glob_1.default('**', opts);
|
22
22
|
delete files['vercel.json']; // Builders/Runtimes didn't have vercel.json
|
23
23
|
const entrypoints = await glob_1.default(`api/**/*${ext}`, opts);
|
24
|
-
const
|
25
|
-
const functions = await
|
24
|
+
const pages = {};
|
25
|
+
const { functions = {} } = await readVercelConfig(workPath);
|
26
26
|
const traceDir = path_1.join(workPath, '.output', 'runtime-traced-files');
|
27
27
|
await fs_extra_1.default.ensureDir(traceDir);
|
28
28
|
for (const entrypoint of Object.keys(entrypoints)) {
|
@@ -38,11 +38,11 @@ function convertRuntimeToPlugin(buildRuntime, ext) {
|
|
38
38
|
excludeFiles: config.excludeFiles,
|
39
39
|
},
|
40
40
|
});
|
41
|
-
|
41
|
+
pages[entrypoint] = {
|
42
42
|
handler: output.handler,
|
43
43
|
runtime: output.runtime,
|
44
|
-
memory:
|
45
|
-
maxDuration:
|
44
|
+
memory: output.memory,
|
45
|
+
maxDuration: output.maxDuration,
|
46
46
|
environment: output.environment,
|
47
47
|
allowQuery: output.allowQuery,
|
48
48
|
regions: output.regions,
|
@@ -78,7 +78,7 @@ function convertRuntimeToPlugin(buildRuntime, ext) {
|
|
78
78
|
await fs_extra_1.default.ensureDir(path_1.dirname(nft));
|
79
79
|
await fs_extra_1.default.writeFile(nft, json);
|
80
80
|
}
|
81
|
-
await
|
81
|
+
await updateFunctionsManifest({ workPath, pages });
|
82
82
|
};
|
83
83
|
}
|
84
84
|
exports.convertRuntimeToPlugin = convertRuntimeToPlugin;
|
@@ -92,12 +92,10 @@ async function linkOrCopy(existingPath, newPath) {
|
|
92
92
|
}
|
93
93
|
}
|
94
94
|
}
|
95
|
-
async function
|
96
|
-
const vercelJsonPath = path_1.join(workPath, 'vercel.json');
|
95
|
+
async function readJson(filePath) {
|
97
96
|
try {
|
98
|
-
const str = await fs_extra_1.default.readFile(
|
99
|
-
|
100
|
-
return obj.functions || {};
|
97
|
+
const str = await fs_extra_1.default.readFile(filePath, 'utf8');
|
98
|
+
return JSON.parse(str);
|
101
99
|
}
|
102
100
|
catch (err) {
|
103
101
|
if (err.code === 'ENOENT') {
|
@@ -106,3 +104,35 @@ async function readVercelConfigFunctions(workPath) {
|
|
106
104
|
throw err;
|
107
105
|
}
|
108
106
|
}
|
107
|
+
async function readVercelConfig(workPath) {
|
108
|
+
const vercelJsonPath = path_1.join(workPath, 'vercel.json');
|
109
|
+
return readJson(vercelJsonPath);
|
110
|
+
}
|
111
|
+
/**
|
112
|
+
* If `.output/functions-manifest.json` exists, append to the pages
|
113
|
+
* property. Otherwise write a new file. This will also read `vercel.json`
|
114
|
+
* and apply relevant `functions` property config.
|
115
|
+
*/
|
116
|
+
async function updateFunctionsManifest({ workPath, pages, }) {
|
117
|
+
const functionsManifestPath = path_1.join(workPath, '.output', 'functions-manifest.json');
|
118
|
+
const vercelConfig = await readVercelConfig(workPath);
|
119
|
+
const functionsManifest = await readJson(functionsManifestPath);
|
120
|
+
if (!functionsManifest.version)
|
121
|
+
functionsManifest.version = 1;
|
122
|
+
if (!functionsManifest.pages)
|
123
|
+
functionsManifest.pages = {};
|
124
|
+
for (const [pageKey, pageConfig] of Object.entries(pages)) {
|
125
|
+
const fnConfig = await lambda_1.getLambdaOptionsFromFunction({
|
126
|
+
sourceFile: pageKey,
|
127
|
+
config: vercelConfig,
|
128
|
+
});
|
129
|
+
functionsManifest.pages[pageKey] = {
|
130
|
+
...pageConfig,
|
131
|
+
memory: fnConfig.memory || pageConfig.memory,
|
132
|
+
maxDuration: fnConfig.maxDuration || pageConfig.maxDuration,
|
133
|
+
regions: vercelConfig.regions || pageConfig.regions,
|
134
|
+
};
|
135
|
+
}
|
136
|
+
await fs_extra_1.default.writeFile(functionsManifestPath, JSON.stringify(functionsManifest));
|
137
|
+
}
|
138
|
+
exports.updateFunctionsManifest = updateFunctionsManifest;
|
package/dist/index.d.ts
CHANGED
@@ -18,7 +18,7 @@ export { detectFramework } from './detect-framework';
|
|
18
18
|
export { DetectorFilesystem } from './detectors/filesystem';
|
19
19
|
export { readConfigFile } from './fs/read-config-file';
|
20
20
|
export { normalizePath } from './fs/normalize-path';
|
21
|
-
export { convertRuntimeToPlugin } from './convert-runtime-to-plugin';
|
21
|
+
export { convertRuntimeToPlugin, updateFunctionsManifest, } from './convert-runtime-to-plugin';
|
22
22
|
export * from './schemas';
|
23
23
|
export * from './types';
|
24
24
|
export * from './errors';
|
package/dist/index.js
CHANGED
@@ -32246,7 +32246,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
32246
32246
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
32247
32247
|
};
|
32248
32248
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
32249
|
-
exports.convertRuntimeToPlugin = void 0;
|
32249
|
+
exports.updateFunctionsManifest = exports.convertRuntimeToPlugin = void 0;
|
32250
32250
|
const fs_extra_1 = __importDefault(__webpack_require__(5392));
|
32251
32251
|
const path_1 = __webpack_require__(5622);
|
32252
32252
|
const glob_1 = __importDefault(__webpack_require__(4240));
|
@@ -32264,8 +32264,8 @@ function convertRuntimeToPlugin(buildRuntime, ext) {
|
|
32264
32264
|
const files = await glob_1.default('**', opts);
|
32265
32265
|
delete files['vercel.json']; // Builders/Runtimes didn't have vercel.json
|
32266
32266
|
const entrypoints = await glob_1.default(`api/**/*${ext}`, opts);
|
32267
|
-
const
|
32268
|
-
const functions = await
|
32267
|
+
const pages = {};
|
32268
|
+
const { functions = {} } = await readVercelConfig(workPath);
|
32269
32269
|
const traceDir = path_1.join(workPath, '.output', 'runtime-traced-files');
|
32270
32270
|
await fs_extra_1.default.ensureDir(traceDir);
|
32271
32271
|
for (const entrypoint of Object.keys(entrypoints)) {
|
@@ -32281,11 +32281,11 @@ function convertRuntimeToPlugin(buildRuntime, ext) {
|
|
32281
32281
|
excludeFiles: config.excludeFiles,
|
32282
32282
|
},
|
32283
32283
|
});
|
32284
|
-
|
32284
|
+
pages[entrypoint] = {
|
32285
32285
|
handler: output.handler,
|
32286
32286
|
runtime: output.runtime,
|
32287
|
-
memory:
|
32288
|
-
maxDuration:
|
32287
|
+
memory: output.memory,
|
32288
|
+
maxDuration: output.maxDuration,
|
32289
32289
|
environment: output.environment,
|
32290
32290
|
allowQuery: output.allowQuery,
|
32291
32291
|
regions: output.regions,
|
@@ -32321,7 +32321,7 @@ function convertRuntimeToPlugin(buildRuntime, ext) {
|
|
32321
32321
|
await fs_extra_1.default.ensureDir(path_1.dirname(nft));
|
32322
32322
|
await fs_extra_1.default.writeFile(nft, json);
|
32323
32323
|
}
|
32324
|
-
await
|
32324
|
+
await updateFunctionsManifest({ workPath, pages });
|
32325
32325
|
};
|
32326
32326
|
}
|
32327
32327
|
exports.convertRuntimeToPlugin = convertRuntimeToPlugin;
|
@@ -32335,12 +32335,10 @@ async function linkOrCopy(existingPath, newPath) {
|
|
32335
32335
|
}
|
32336
32336
|
}
|
32337
32337
|
}
|
32338
|
-
async function
|
32339
|
-
const vercelJsonPath = path_1.join(workPath, 'vercel.json');
|
32338
|
+
async function readJson(filePath) {
|
32340
32339
|
try {
|
32341
|
-
const str = await fs_extra_1.default.readFile(
|
32342
|
-
|
32343
|
-
return obj.functions || {};
|
32340
|
+
const str = await fs_extra_1.default.readFile(filePath, 'utf8');
|
32341
|
+
return JSON.parse(str);
|
32344
32342
|
}
|
32345
32343
|
catch (err) {
|
32346
32344
|
if (err.code === 'ENOENT') {
|
@@ -32349,6 +32347,38 @@ async function readVercelConfigFunctions(workPath) {
|
|
32349
32347
|
throw err;
|
32350
32348
|
}
|
32351
32349
|
}
|
32350
|
+
async function readVercelConfig(workPath) {
|
32351
|
+
const vercelJsonPath = path_1.join(workPath, 'vercel.json');
|
32352
|
+
return readJson(vercelJsonPath);
|
32353
|
+
}
|
32354
|
+
/**
|
32355
|
+
* If `.output/functions-manifest.json` exists, append to the pages
|
32356
|
+
* property. Otherwise write a new file. This will also read `vercel.json`
|
32357
|
+
* and apply relevant `functions` property config.
|
32358
|
+
*/
|
32359
|
+
async function updateFunctionsManifest({ workPath, pages, }) {
|
32360
|
+
const functionsManifestPath = path_1.join(workPath, '.output', 'functions-manifest.json');
|
32361
|
+
const vercelConfig = await readVercelConfig(workPath);
|
32362
|
+
const functionsManifest = await readJson(functionsManifestPath);
|
32363
|
+
if (!functionsManifest.version)
|
32364
|
+
functionsManifest.version = 1;
|
32365
|
+
if (!functionsManifest.pages)
|
32366
|
+
functionsManifest.pages = {};
|
32367
|
+
for (const [pageKey, pageConfig] of Object.entries(pages)) {
|
32368
|
+
const fnConfig = await lambda_1.getLambdaOptionsFromFunction({
|
32369
|
+
sourceFile: pageKey,
|
32370
|
+
config: vercelConfig,
|
32371
|
+
});
|
32372
|
+
functionsManifest.pages[pageKey] = {
|
32373
|
+
...pageConfig,
|
32374
|
+
memory: fnConfig.memory || pageConfig.memory,
|
32375
|
+
maxDuration: fnConfig.maxDuration || pageConfig.maxDuration,
|
32376
|
+
regions: vercelConfig.regions || pageConfig.regions,
|
32377
|
+
};
|
32378
|
+
}
|
32379
|
+
await fs_extra_1.default.writeFile(functionsManifestPath, JSON.stringify(functionsManifest));
|
32380
|
+
}
|
32381
|
+
exports.updateFunctionsManifest = updateFunctionsManifest;
|
32352
32382
|
|
32353
32383
|
|
32354
32384
|
/***/ }),
|
@@ -34321,7 +34351,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
34321
34351
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
34322
34352
|
};
|
34323
34353
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
34324
|
-
exports.getPlatformEnv = exports.isStaticRuntime = exports.isOfficialRuntime = exports.convertRuntimeToPlugin = exports.normalizePath = exports.readConfigFile = exports.DetectorFilesystem = exports.detectFramework = exports.detectApiExtensions = exports.detectApiDirectory = exports.detectOutputDirectory = exports.detectBuilders = exports.scanParentDirs = exports.getLambdaOptionsFromFunction = exports.isSymbolicLink = exports.debug = exports.shouldServe = exports.streamToBuffer = exports.getSpawnOptions = exports.getDiscontinuedNodeVersions = exports.getLatestNodeVersion = exports.getNodeVersion = exports.runShellScript = exports.runPipInstall = exports.runBundleInstall = exports.runNpmInstall = exports.getNodeBinPath = exports.walkParentDirs = exports.spawnCommand = exports.execCommand = exports.runPackageJsonScript = exports.installDependencies = exports.getScriptName = exports.spawnAsync = exports.execAsync = exports.rename = exports.glob = exports.getWriteableDirectory = exports.download = exports.Prerender = exports.createLambda = exports.Lambda = exports.FileRef = exports.FileFsRef = exports.FileBlob = void 0;
|
34354
|
+
exports.getPlatformEnv = exports.isStaticRuntime = exports.isOfficialRuntime = exports.updateFunctionsManifest = exports.convertRuntimeToPlugin = exports.normalizePath = exports.readConfigFile = exports.DetectorFilesystem = exports.detectFramework = exports.detectApiExtensions = exports.detectApiDirectory = exports.detectOutputDirectory = exports.detectBuilders = exports.scanParentDirs = exports.getLambdaOptionsFromFunction = exports.isSymbolicLink = exports.debug = exports.shouldServe = exports.streamToBuffer = exports.getSpawnOptions = exports.getDiscontinuedNodeVersions = exports.getLatestNodeVersion = exports.getNodeVersion = exports.runShellScript = exports.runPipInstall = exports.runBundleInstall = exports.runNpmInstall = exports.getNodeBinPath = exports.walkParentDirs = exports.spawnCommand = exports.execCommand = exports.runPackageJsonScript = exports.installDependencies = exports.getScriptName = exports.spawnAsync = exports.execAsync = exports.rename = exports.glob = exports.getWriteableDirectory = exports.download = exports.Prerender = exports.createLambda = exports.Lambda = exports.FileRef = exports.FileFsRef = exports.FileBlob = void 0;
|
34325
34355
|
const file_blob_1 = __importDefault(__webpack_require__(2397));
|
34326
34356
|
exports.FileBlob = file_blob_1.default;
|
34327
34357
|
const file_fs_ref_1 = __importDefault(__webpack_require__(9331));
|
@@ -34385,6 +34415,7 @@ var normalize_path_1 = __webpack_require__(6261);
|
|
34385
34415
|
Object.defineProperty(exports, "normalizePath", ({ enumerable: true, get: function () { return normalize_path_1.normalizePath; } }));
|
34386
34416
|
var convert_runtime_to_plugin_1 = __webpack_require__(7276);
|
34387
34417
|
Object.defineProperty(exports, "convertRuntimeToPlugin", ({ enumerable: true, get: function () { return convert_runtime_to_plugin_1.convertRuntimeToPlugin; } }));
|
34418
|
+
Object.defineProperty(exports, "updateFunctionsManifest", ({ enumerable: true, get: function () { return convert_runtime_to_plugin_1.updateFunctionsManifest; } }));
|
34388
34419
|
__exportStar(__webpack_require__(2416), exports);
|
34389
34420
|
__exportStar(__webpack_require__(5748), exports);
|
34390
34421
|
__exportStar(__webpack_require__(3983), exports);
|
package/dist/lambda.d.ts
CHANGED
@@ -25,7 +25,7 @@ interface CreateLambdaOptions {
|
|
25
25
|
}
|
26
26
|
interface GetLambdaOptionsFromFunctionOptions {
|
27
27
|
sourceFile: string;
|
28
|
-
config?: Config
|
28
|
+
config?: Pick<Config, 'functions'>;
|
29
29
|
}
|
30
30
|
export declare const FILES_SYMBOL: unique symbol;
|
31
31
|
export declare class Lambda {
|
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.18",
|
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": "c3abf73f581c23c1c39f91249a21fd9f261f7519"
|
53
53
|
}
|