@vercel/build-utils 2.12.3-canary.16 → 2.12.3-canary.17

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.
@@ -7,6 +7,6 @@ import type { BuildOptions } from './types';
7
7
  */
8
8
  export declare function convertRuntimeToPlugin(buildRuntime: (options: BuildOptions) => Promise<{
9
9
  output: Lambda;
10
- }>, ext: string): Promise<({ workPath }: {
10
+ }>, ext: string): ({ workPath }: {
11
11
  workPath: string;
12
- }) => Promise<void>>;
12
+ }) => Promise<void>;
@@ -15,7 +15,7 @@ const minimatch_1 = __importDefault(require("minimatch"));
15
15
  * @param buildRuntime - a legacy build() function from a Runtime
16
16
  * @param ext - the file extension, for example `.py`
17
17
  */
18
- async function convertRuntimeToPlugin(buildRuntime, ext) {
18
+ function convertRuntimeToPlugin(buildRuntime, ext) {
19
19
  return async function build({ workPath }) {
20
20
  const opts = { cwd: workPath };
21
21
  const files = await glob_1.default('**', opts);
package/dist/index.d.ts CHANGED
@@ -18,6 +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
22
  export * from './schemas';
22
23
  export * from './types';
23
24
  export * from './errors';
package/dist/index.js CHANGED
@@ -32235,6 +32235,122 @@ module.exports = new Type('tag:yaml.org,2002:timestamp', {
32235
32235
  });
32236
32236
 
32237
32237
 
32238
+ /***/ }),
32239
+
32240
+ /***/ 7276:
32241
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
32242
+
32243
+ "use strict";
32244
+
32245
+ var __importDefault = (this && this.__importDefault) || function (mod) {
32246
+ return (mod && mod.__esModule) ? mod : { "default": mod };
32247
+ };
32248
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
32249
+ exports.convertRuntimeToPlugin = void 0;
32250
+ const fs_extra_1 = __importDefault(__webpack_require__(5392));
32251
+ const path_1 = __webpack_require__(5622);
32252
+ const glob_1 = __importDefault(__webpack_require__(4240));
32253
+ const normalize_path_1 = __webpack_require__(6261);
32254
+ const lambda_1 = __webpack_require__(6721);
32255
+ const minimatch_1 = __importDefault(__webpack_require__(9566));
32256
+ /**
32257
+ * Convert legacy Runtime to a Plugin.
32258
+ * @param buildRuntime - a legacy build() function from a Runtime
32259
+ * @param ext - the file extension, for example `.py`
32260
+ */
32261
+ function convertRuntimeToPlugin(buildRuntime, ext) {
32262
+ return async function build({ workPath }) {
32263
+ const opts = { cwd: workPath };
32264
+ const files = await glob_1.default('**', opts);
32265
+ delete files['vercel.json']; // Builders/Runtimes didn't have vercel.json
32266
+ const entrypoints = await glob_1.default(`api/**/*${ext}`, opts);
32267
+ const functionsManifest = {};
32268
+ const functions = await readVercelConfigFunctions(workPath);
32269
+ const traceDir = path_1.join(workPath, '.output', 'runtime-traced-files');
32270
+ await fs_extra_1.default.ensureDir(traceDir);
32271
+ for (const entrypoint of Object.keys(entrypoints)) {
32272
+ const key = Object.keys(functions).find(src => src === entrypoint || minimatch_1.default(entrypoint, src)) || '';
32273
+ const config = functions[key] || {};
32274
+ const { output } = await buildRuntime({
32275
+ files,
32276
+ entrypoint,
32277
+ workPath,
32278
+ config: {
32279
+ zeroConfig: true,
32280
+ includeFiles: config.includeFiles,
32281
+ excludeFiles: config.excludeFiles,
32282
+ },
32283
+ });
32284
+ functionsManifest[entrypoint] = {
32285
+ handler: output.handler,
32286
+ runtime: output.runtime,
32287
+ memory: config.memory || output.memory,
32288
+ maxDuration: config.maxDuration || output.maxDuration,
32289
+ environment: output.environment,
32290
+ allowQuery: output.allowQuery,
32291
+ regions: output.regions,
32292
+ };
32293
+ // @ts-ignore This symbol is a private API
32294
+ const lambdaFiles = output[lambda_1.FILES_SYMBOL];
32295
+ const entry = path_1.join(workPath, '.output', 'server', 'pages', entrypoint);
32296
+ await fs_extra_1.default.ensureDir(path_1.dirname(entry));
32297
+ await linkOrCopy(files[entrypoint].fsPath, entry);
32298
+ const tracedFiles = [];
32299
+ Object.entries(lambdaFiles).forEach(async ([relPath, file]) => {
32300
+ const newPath = path_1.join(traceDir, relPath);
32301
+ tracedFiles.push({ absolutePath: newPath, relativePath: relPath });
32302
+ if (file.fsPath) {
32303
+ await linkOrCopy(file.fsPath, newPath);
32304
+ }
32305
+ else if (file.type === 'FileBlob') {
32306
+ const { data, mode } = file;
32307
+ await fs_extra_1.default.writeFile(newPath, data, { mode });
32308
+ }
32309
+ else {
32310
+ throw new Error(`Unknown file type: ${file.type}`);
32311
+ }
32312
+ });
32313
+ const nft = path_1.join(workPath, '.output', 'server', 'pages', `${entrypoint}.nft.json`);
32314
+ const json = JSON.stringify({
32315
+ version: 1,
32316
+ files: tracedFiles.map(f => ({
32317
+ input: normalize_path_1.normalizePath(path_1.relative(nft, f.absolutePath)),
32318
+ output: normalize_path_1.normalizePath(f.relativePath),
32319
+ })),
32320
+ });
32321
+ await fs_extra_1.default.ensureDir(path_1.dirname(nft));
32322
+ await fs_extra_1.default.writeFile(nft, json);
32323
+ }
32324
+ await fs_extra_1.default.writeFile(path_1.join(workPath, '.output', 'functions-manifest.json'), JSON.stringify(functionsManifest));
32325
+ };
32326
+ }
32327
+ exports.convertRuntimeToPlugin = convertRuntimeToPlugin;
32328
+ async function linkOrCopy(existingPath, newPath) {
32329
+ try {
32330
+ await fs_extra_1.default.createLink(existingPath, newPath);
32331
+ }
32332
+ catch (err) {
32333
+ if (err.code !== 'EEXIST') {
32334
+ await fs_extra_1.default.copyFile(existingPath, newPath);
32335
+ }
32336
+ }
32337
+ }
32338
+ async function readVercelConfigFunctions(workPath) {
32339
+ const vercelJsonPath = path_1.join(workPath, 'vercel.json');
32340
+ try {
32341
+ const str = await fs_extra_1.default.readFile(vercelJsonPath, 'utf8');
32342
+ const obj = JSON.parse(str);
32343
+ return obj.functions || {};
32344
+ }
32345
+ catch (err) {
32346
+ if (err.code === 'ENOENT') {
32347
+ return {};
32348
+ }
32349
+ throw err;
32350
+ }
32351
+ }
32352
+
32353
+
32238
32354
  /***/ }),
32239
32355
 
32240
32356
  /***/ 1868:
@@ -34205,7 +34321,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
34205
34321
  return (mod && mod.__esModule) ? mod : { "default": mod };
34206
34322
  };
34207
34323
  Object.defineProperty(exports, "__esModule", ({ value: true }));
34208
- exports.getPlatformEnv = exports.isStaticRuntime = exports.isOfficialRuntime = 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;
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;
34209
34325
  const file_blob_1 = __importDefault(__webpack_require__(2397));
34210
34326
  exports.FileBlob = file_blob_1.default;
34211
34327
  const file_fs_ref_1 = __importDefault(__webpack_require__(9331));
@@ -34267,6 +34383,8 @@ var read_config_file_1 = __webpack_require__(7792);
34267
34383
  Object.defineProperty(exports, "readConfigFile", ({ enumerable: true, get: function () { return read_config_file_1.readConfigFile; } }));
34268
34384
  var normalize_path_1 = __webpack_require__(6261);
34269
34385
  Object.defineProperty(exports, "normalizePath", ({ enumerable: true, get: function () { return normalize_path_1.normalizePath; } }));
34386
+ var convert_runtime_to_plugin_1 = __webpack_require__(7276);
34387
+ Object.defineProperty(exports, "convertRuntimeToPlugin", ({ enumerable: true, get: function () { return convert_runtime_to_plugin_1.convertRuntimeToPlugin; } }));
34270
34388
  __exportStar(__webpack_require__(2416), exports);
34271
34389
  __exportStar(__webpack_require__(5748), exports);
34272
34390
  __exportStar(__webpack_require__(3983), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/build-utils",
3
- "version": "2.12.3-canary.16",
3
+ "version": "2.12.3-canary.17",
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": "2a8588a0c5606d38f7488818e2598d4249b71abc"
52
+ "gitHead": "ed1dacd27698f3bb181f32b516af6953655b37e9"
53
53
  }