@vercel/build-utils 13.10.0 → 13.12.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/CHANGELOG.md +12 -0
- package/dist/collect-build-result/get-build-result-metadata.d.ts +33 -0
- package/dist/collect-build-result/get-build-result-metadata.js +99 -0
- package/dist/collect-build-result/get-lambda-by-output-path.d.ts +13 -0
- package/dist/collect-build-result/get-lambda-by-output-path.js +31 -0
- package/dist/collect-build-result/get-prerender-chain.d.ts +8 -0
- package/dist/collect-build-result/get-prerender-chain.js +44 -0
- package/dist/collect-build-result/is-route-middleware.d.ts +4 -0
- package/dist/collect-build-result/is-route-middleware.js +30 -0
- package/dist/collect-build-result/stream-with-extended-payload.d.ts +6 -0
- package/dist/collect-build-result/stream-with-extended-payload.js +49 -0
- package/dist/fs/stream-to-digest-async.d.ts +10 -0
- package/dist/fs/stream-to-digest-async.js +62 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +516 -90
- package/dist/process-serverless/get-encrypted-env-file.d.ts +11 -0
- package/dist/process-serverless/get-encrypted-env-file.js +47 -0
- package/dist/process-serverless/get-lambda-environment.d.ts +18 -0
- package/dist/process-serverless/get-lambda-environment.js +53 -0
- package/dist/process-serverless/get-lambda-preload-scripts.d.ts +21 -0
- package/dist/process-serverless/get-lambda-preload-scripts.js +43 -0
- package/dist/process-serverless/get-lambda-supports-streaming.d.ts +23 -0
- package/dist/process-serverless/get-lambda-supports-streaming.js +98 -0
- package/package.json +3 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import FileBlob from '../file-blob';
|
|
2
|
+
/**
|
|
3
|
+
* A type to represent the encrypted environment file that needs to be
|
|
4
|
+
* attached to Lambdas with ENV > 4kb
|
|
5
|
+
*/
|
|
6
|
+
export type EncryptedEnvFile = [string, FileBlob];
|
|
7
|
+
/**
|
|
8
|
+
* Get the encrypted environment file from the environment variables if it
|
|
9
|
+
* exists and it is supported by the runtime.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getEncryptedEnv(envFilename: string | undefined, envContent: string | undefined): EncryptedEnvFile | undefined;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var get_encrypted_env_file_exports = {};
|
|
30
|
+
__export(get_encrypted_env_file_exports, {
|
|
31
|
+
getEncryptedEnv: () => getEncryptedEnv
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(get_encrypted_env_file_exports);
|
|
34
|
+
var import_file_blob = __toESM(require("../file-blob"));
|
|
35
|
+
function getEncryptedEnv(envFilename, envContent) {
|
|
36
|
+
if (!envFilename || !envContent) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
return [
|
|
40
|
+
envFilename,
|
|
41
|
+
new import_file_blob.default({ data: Buffer.from(envContent, "base64") })
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
getEncryptedEnv
|
|
47
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { type BytecodeCachingOptions } from './get-lambda-preload-scripts';
|
|
3
|
+
interface LambdaLike {
|
|
4
|
+
awsLambdaHandler?: string;
|
|
5
|
+
launcherType?: string;
|
|
6
|
+
runtime: string;
|
|
7
|
+
shouldAddHelpers?: boolean;
|
|
8
|
+
shouldAddSourcemapSupport?: boolean;
|
|
9
|
+
useWebApi?: boolean;
|
|
10
|
+
shouldDisableAutomaticFetchInstrumentation?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Extract system environment variables that need to be injected in the Lambda.
|
|
14
|
+
* Buffer is required just to determine if Bytecode Caching should be enabled
|
|
15
|
+
* but it doesn't need to be super precise.
|
|
16
|
+
*/
|
|
17
|
+
export declare function getLambdaEnvironment(lambda: LambdaLike, buffer: Buffer, options: BytecodeCachingOptions): Record<string, string>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var get_lambda_environment_exports = {};
|
|
20
|
+
__export(get_lambda_environment_exports, {
|
|
21
|
+
getLambdaEnvironment: () => getLambdaEnvironment
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(get_lambda_environment_exports);
|
|
24
|
+
var import_get_lambda_preload_scripts = require("./get-lambda-preload-scripts");
|
|
25
|
+
function getLambdaEnvironment(lambda, buffer, options) {
|
|
26
|
+
const environment = {};
|
|
27
|
+
if ("launcherType" in lambda && lambda.launcherType === "Nodejs") {
|
|
28
|
+
if (lambda.awsLambdaHandler) {
|
|
29
|
+
environment.AWS_LAMBDA_HANDLER = lambda.awsLambdaHandler;
|
|
30
|
+
}
|
|
31
|
+
if (lambda.shouldAddHelpers) {
|
|
32
|
+
environment.VERCEL_SHOULD_ADD_HELPERS = "1";
|
|
33
|
+
}
|
|
34
|
+
if (lambda.useWebApi === true) {
|
|
35
|
+
environment.VERCEL_USE_WEB_API = "1";
|
|
36
|
+
}
|
|
37
|
+
if (lambda.shouldAddSourcemapSupport) {
|
|
38
|
+
environment.VERCEL_SOURCE_MAP = "1";
|
|
39
|
+
}
|
|
40
|
+
if (lambda.shouldDisableAutomaticFetchInstrumentation) {
|
|
41
|
+
environment.VERCEL_TRACING_DISABLE_AUTOMATIC_FETCH_INSTRUMENTATION = "1";
|
|
42
|
+
}
|
|
43
|
+
const scripts = (0, import_get_lambda_preload_scripts.getLambdaPreloadScripts)(lambda, buffer, options);
|
|
44
|
+
if (scripts.length > 0) {
|
|
45
|
+
environment.VERCEL_NODE_PRELOAD_SCRIPTS = scripts.join(",");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return environment;
|
|
49
|
+
}
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
getLambdaEnvironment
|
|
53
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export interface BytecodeCachingOptions {
|
|
3
|
+
vercelEnv: string | undefined;
|
|
4
|
+
useBytecodeCaching: string | undefined;
|
|
5
|
+
useNativeBytecodeCaching: string | undefined;
|
|
6
|
+
bytecodeCachingThreshold: string | undefined;
|
|
7
|
+
}
|
|
8
|
+
interface LambdaLike {
|
|
9
|
+
framework?: {
|
|
10
|
+
slug: string;
|
|
11
|
+
};
|
|
12
|
+
runtime: string;
|
|
13
|
+
shouldAddSourcemapSupport?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Returns an array of scripts that should be preloaded in Node.js Lambdas.
|
|
17
|
+
* The `buffer` parameter is needed to decide wether or not to enable Bytecode
|
|
18
|
+
* Caching so it doesn't **need** to be exact (we can leave out the env layer)
|
|
19
|
+
*/
|
|
20
|
+
export declare function getLambdaPreloadScripts(lambda: LambdaLike, buffer: Buffer, options: BytecodeCachingOptions): string[];
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var get_lambda_preload_scripts_exports = {};
|
|
20
|
+
__export(get_lambda_preload_scripts_exports, {
|
|
21
|
+
getLambdaPreloadScripts: () => getLambdaPreloadScripts
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(get_lambda_preload_scripts_exports);
|
|
24
|
+
function getLambdaPreloadScripts(lambda, buffer, options) {
|
|
25
|
+
const scripts = [];
|
|
26
|
+
if (lambda.shouldAddSourcemapSupport) {
|
|
27
|
+
scripts.push("/opt/rust/source-map-support.js");
|
|
28
|
+
}
|
|
29
|
+
const BYTECODE_MIN_SIZE_BYTES = (Number.parseInt(options.bytecodeCachingThreshold || "", 10) || 400) * 1024;
|
|
30
|
+
if (options.vercelEnv === "production" && options.useBytecodeCaching === "1" && ["nodejs20.x", "nodejs22.x", "nodejs24.x"].includes(lambda.runtime) && buffer.byteLength >= BYTECODE_MIN_SIZE_BYTES) {
|
|
31
|
+
scripts.push(
|
|
32
|
+
["nodejs22.x", "nodejs24.x"].includes(lambda.runtime) && options.useNativeBytecodeCaching === "1" ? "/opt/rust/bytecode-native.js" : "/opt/rust/bytecode.js"
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
if (lambda.framework?.slug === "nextjs") {
|
|
36
|
+
scripts.push("/opt/rust/next-data.js");
|
|
37
|
+
}
|
|
38
|
+
return scripts;
|
|
39
|
+
}
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
getLambdaPreloadScripts
|
|
43
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Files } from '../types';
|
|
2
|
+
interface LambdaLike {
|
|
3
|
+
files?: Files;
|
|
4
|
+
handler: string;
|
|
5
|
+
launcherType?: string;
|
|
6
|
+
runtime: string;
|
|
7
|
+
supportsResponseStreaming?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface SupportsStreamingResult {
|
|
10
|
+
supportsStreaming: boolean | undefined;
|
|
11
|
+
error?: {
|
|
12
|
+
handler: string;
|
|
13
|
+
message: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Determines if a Lambda should have streaming enabled. If
|
|
18
|
+
* `forceStreamingRuntime` is true, streaming is always enabled. If the
|
|
19
|
+
* setting is defined it will be honored. For Node.js it checks the handler
|
|
20
|
+
* exports which is why it needs to be asynchronous.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getLambdaSupportsStreaming(lambda: LambdaLike, forceStreamingRuntime: boolean): Promise<SupportsStreamingResult>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var get_lambda_supports_streaming_exports = {};
|
|
20
|
+
__export(get_lambda_supports_streaming_exports, {
|
|
21
|
+
getLambdaSupportsStreaming: () => getLambdaSupportsStreaming
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(get_lambda_supports_streaming_exports);
|
|
24
|
+
var import_cjs_module_lexer = require("cjs-module-lexer");
|
|
25
|
+
var import_es_module_lexer = require("es-module-lexer");
|
|
26
|
+
async function getLambdaSupportsStreaming(lambda, forceStreamingRuntime) {
|
|
27
|
+
if (forceStreamingRuntime) {
|
|
28
|
+
return { supportsStreaming: true };
|
|
29
|
+
}
|
|
30
|
+
if (typeof lambda.supportsResponseStreaming === "boolean") {
|
|
31
|
+
return { supportsStreaming: lambda.supportsResponseStreaming };
|
|
32
|
+
}
|
|
33
|
+
if ("launcherType" in lambda && lambda.launcherType === "Nodejs") {
|
|
34
|
+
return lambdaShouldStream(lambda);
|
|
35
|
+
}
|
|
36
|
+
return { supportsStreaming: void 0 };
|
|
37
|
+
}
|
|
38
|
+
const HTTP_METHODS = [
|
|
39
|
+
"GET",
|
|
40
|
+
"HEAD",
|
|
41
|
+
"OPTIONS",
|
|
42
|
+
"POST",
|
|
43
|
+
"PUT",
|
|
44
|
+
"DELETE",
|
|
45
|
+
"PATCH"
|
|
46
|
+
];
|
|
47
|
+
async function lambdaShouldStream(lambda) {
|
|
48
|
+
const stream = lambda.files?.[lambda.handler]?.toStream();
|
|
49
|
+
if (!stream) {
|
|
50
|
+
return { supportsStreaming: void 0 };
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
const buffer = await streamToBuffer(stream);
|
|
54
|
+
const names = await getFileExports(lambda.handler, buffer.toString("utf8"));
|
|
55
|
+
for (const name of names) {
|
|
56
|
+
if (HTTP_METHODS.includes(name)) {
|
|
57
|
+
return { supportsStreaming: true };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
} catch (err) {
|
|
61
|
+
return {
|
|
62
|
+
supportsStreaming: void 0,
|
|
63
|
+
error: { handler: lambda.handler, message: String(err) }
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return { supportsStreaming: void 0 };
|
|
67
|
+
}
|
|
68
|
+
async function getFileExports(filename, content) {
|
|
69
|
+
if (filename.endsWith(".mjs")) {
|
|
70
|
+
await import_es_module_lexer.init;
|
|
71
|
+
return (0, import_es_module_lexer.parse)(content)[1].map((specifier) => specifier.n);
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
await (0, import_cjs_module_lexer.init)();
|
|
75
|
+
return (0, import_cjs_module_lexer.parse)(content).exports;
|
|
76
|
+
} catch {
|
|
77
|
+
await import_es_module_lexer.init;
|
|
78
|
+
return (0, import_es_module_lexer.parse)(content)[1].map((specifier) => specifier.n);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function streamToBuffer(stream) {
|
|
82
|
+
return new Promise((resolve, reject) => {
|
|
83
|
+
const buffers = [];
|
|
84
|
+
stream.on("error", (err) => {
|
|
85
|
+
reject(err);
|
|
86
|
+
});
|
|
87
|
+
stream.on("data", (buffer) => {
|
|
88
|
+
buffers.push(buffer);
|
|
89
|
+
});
|
|
90
|
+
stream.on("end", () => {
|
|
91
|
+
resolve(Buffer.concat(buffers));
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
96
|
+
0 && (module.exports = {
|
|
97
|
+
getLambdaSupportsStreaming
|
|
98
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/build-utils",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.12.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.js",
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
"directory": "packages/now-build-utils"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
+
"cjs-module-lexer": "1.2.3",
|
|
15
|
+
"es-module-lexer": "1.5.0",
|
|
14
16
|
"@vercel/python-analysis": "0.11.0"
|
|
15
17
|
},
|
|
16
18
|
"devDependencies": {
|