@vercel/build-utils 13.12.0 → 13.12.2
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-uncompressed-size.d.ts +6 -0
- package/dist/collect-uncompressed-size.js +59 -0
- package/dist/finalize-lambda.d.ts +43 -0
- package/dist/finalize-lambda.js +82 -0
- package/dist/fs/read-config-file.js +2 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1836 -2604
- package/dist/validate-lambda-size.d.ts +46 -0
- package/dist/validate-lambda-size.js +117 -0
- package/package.json +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @vercel/build-utils
|
|
2
2
|
|
|
3
|
+
## 13.12.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Extract finalize/validate function utils for build-utils ([#15776](https://github.com/vercel/vercel/pull/15776))
|
|
8
|
+
|
|
9
|
+
## 13.12.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Switch to using smol-toml for toml parsing ([#15730](https://github.com/vercel/vercel/pull/15730))
|
|
14
|
+
|
|
3
15
|
## 13.12.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Files } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Collects the total uncompressed size of a set of Lambda files.
|
|
4
|
+
* Handles both FileBlob (in-memory) and FileFsRef (on-disk) file types.
|
|
5
|
+
*/
|
|
6
|
+
export declare const collectUncompressedSize: (files: Files, ignoreFn?: ((fileKey: string) => boolean) | undefined) => Promise<number>;
|
|
@@ -0,0 +1,59 @@
|
|
|
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 collect_uncompressed_size_exports = {};
|
|
20
|
+
__export(collect_uncompressed_size_exports, {
|
|
21
|
+
collectUncompressedSize: () => collectUncompressedSize
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(collect_uncompressed_size_exports);
|
|
24
|
+
var import_promises = require("fs/promises");
|
|
25
|
+
const fileSizeCache = /* @__PURE__ */ new Map();
|
|
26
|
+
const getFileSize = (path) => {
|
|
27
|
+
if (!path)
|
|
28
|
+
return Promise.resolve(0);
|
|
29
|
+
const cached = fileSizeCache.get(path);
|
|
30
|
+
if (cached) {
|
|
31
|
+
return cached;
|
|
32
|
+
}
|
|
33
|
+
const promise = (0, import_promises.lstat)(path).then((stats) => stats.size);
|
|
34
|
+
fileSizeCache.set(path, promise);
|
|
35
|
+
return promise;
|
|
36
|
+
};
|
|
37
|
+
const collectUncompressedSize = async (files, ignoreFn) => {
|
|
38
|
+
let size = 0;
|
|
39
|
+
await Promise.all(
|
|
40
|
+
Object.keys(files).map(async (fileKey) => {
|
|
41
|
+
if (ignoreFn?.(fileKey)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const file = files[fileKey];
|
|
45
|
+
if (file.type === "FileBlob") {
|
|
46
|
+
size += file.data.length;
|
|
47
|
+
} else if (file.type === "FileFsRef") {
|
|
48
|
+
const fsRef = file;
|
|
49
|
+
const curSize = fsRef.size ?? await getFileSize(fsRef.fsPath);
|
|
50
|
+
size += curSize;
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
);
|
|
54
|
+
return size;
|
|
55
|
+
};
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
collectUncompressedSize
|
|
59
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Lambda } from './lambda';
|
|
3
|
+
import type { NodejsLambda } from './nodejs-lambda';
|
|
4
|
+
import type { BytecodeCachingOptions } from './process-serverless/get-lambda-preload-scripts';
|
|
5
|
+
import type { SupportsStreamingResult } from './process-serverless/get-lambda-supports-streaming';
|
|
6
|
+
/**
|
|
7
|
+
* Optional wrapper around async work, allowing callers to inject tracing
|
|
8
|
+
* (e.g. dd-trace spans) without coupling the shared code to a tracer.
|
|
9
|
+
*/
|
|
10
|
+
export type TraceFn = <T>(name: string, fn: () => Promise<T>) => Promise<T>;
|
|
11
|
+
export interface FinalizeLambdaParams {
|
|
12
|
+
lambda: Lambda | NodejsLambda;
|
|
13
|
+
encryptedEnvFilename?: string;
|
|
14
|
+
encryptedEnvContent?: string;
|
|
15
|
+
bytecodeCachingOptions: BytecodeCachingOptions;
|
|
16
|
+
forceStreamingRuntime: boolean;
|
|
17
|
+
/** When true, collect the uncompressed size of lambda files before zipping. */
|
|
18
|
+
enableUncompressedLambdaSizeCheck?: boolean;
|
|
19
|
+
/** Optional tracing wrapper for `collectUncompressedSize` and `createZip`. */
|
|
20
|
+
trace?: TraceFn;
|
|
21
|
+
}
|
|
22
|
+
export interface FinalizeLambdaResult {
|
|
23
|
+
buffer: Buffer;
|
|
24
|
+
digest: string;
|
|
25
|
+
uncompressedBytes: number;
|
|
26
|
+
/** Non-fatal streaming detection error, if any. Caller decides how to log. */
|
|
27
|
+
streamingError?: SupportsStreamingResult['error'];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Core Lambda finalization logic shared between BYOF and build-container.
|
|
31
|
+
*
|
|
32
|
+
* This function:
|
|
33
|
+
* 1. Injects encrypted env file into lambda.files when provided
|
|
34
|
+
* 2. Collects uncompressed size when enabled
|
|
35
|
+
* 3. Creates the ZIP buffer
|
|
36
|
+
* 4. Computes SHA-256 digest
|
|
37
|
+
* 5. Merges environment variables (bytecode caching, helpers, etc.)
|
|
38
|
+
* 6. Detects streaming support
|
|
39
|
+
*
|
|
40
|
+
* Note: This function mutates the `lambda` (files, environment,
|
|
41
|
+
* supportsResponseStreaming).
|
|
42
|
+
*/
|
|
43
|
+
export declare function finalizeLambda(params: FinalizeLambdaParams): Promise<FinalizeLambdaResult>;
|
|
@@ -0,0 +1,82 @@
|
|
|
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 finalize_lambda_exports = {};
|
|
20
|
+
__export(finalize_lambda_exports, {
|
|
21
|
+
finalizeLambda: () => finalizeLambda
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(finalize_lambda_exports);
|
|
24
|
+
var import_get_encrypted_env_file = require("./process-serverless/get-encrypted-env-file");
|
|
25
|
+
var import_get_lambda_environment = require("./process-serverless/get-lambda-environment");
|
|
26
|
+
var import_get_lambda_supports_streaming = require("./process-serverless/get-lambda-supports-streaming");
|
|
27
|
+
var import_stream_to_digest_async = require("./fs/stream-to-digest-async");
|
|
28
|
+
var import_collect_uncompressed_size = require("./collect-uncompressed-size");
|
|
29
|
+
const defaultTrace = (_name, fn) => fn();
|
|
30
|
+
async function finalizeLambda(params) {
|
|
31
|
+
const {
|
|
32
|
+
lambda,
|
|
33
|
+
encryptedEnvFilename,
|
|
34
|
+
encryptedEnvContent,
|
|
35
|
+
bytecodeCachingOptions,
|
|
36
|
+
forceStreamingRuntime,
|
|
37
|
+
enableUncompressedLambdaSizeCheck,
|
|
38
|
+
trace = defaultTrace
|
|
39
|
+
} = params;
|
|
40
|
+
const encryptedEnv = (0, import_get_encrypted_env_file.getEncryptedEnv)(
|
|
41
|
+
encryptedEnvFilename,
|
|
42
|
+
encryptedEnvContent
|
|
43
|
+
);
|
|
44
|
+
if (encryptedEnv) {
|
|
45
|
+
const [envFilename, envFile] = encryptedEnv;
|
|
46
|
+
lambda.zipBuffer = void 0;
|
|
47
|
+
lambda.files = {
|
|
48
|
+
...lambda.files,
|
|
49
|
+
[envFilename]: envFile
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
let uncompressedBytes = 0;
|
|
53
|
+
if (enableUncompressedLambdaSizeCheck) {
|
|
54
|
+
if (lambda.files) {
|
|
55
|
+
uncompressedBytes = await trace(
|
|
56
|
+
"collectUncompressedSize",
|
|
57
|
+
() => (0, import_collect_uncompressed_size.collectUncompressedSize)(lambda.files ?? {})
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const buffer = lambda.zipBuffer || await trace("createZip", () => lambda.createZip());
|
|
62
|
+
const digest = (0, import_stream_to_digest_async.sha256)(buffer);
|
|
63
|
+
lambda.environment = {
|
|
64
|
+
...lambda.environment,
|
|
65
|
+
...(0, import_get_lambda_environment.getLambdaEnvironment)(lambda, buffer, bytecodeCachingOptions)
|
|
66
|
+
};
|
|
67
|
+
const streamingResult = await (0, import_get_lambda_supports_streaming.getLambdaSupportsStreaming)(
|
|
68
|
+
lambda,
|
|
69
|
+
forceStreamingRuntime
|
|
70
|
+
);
|
|
71
|
+
lambda.supportsResponseStreaming = streamingResult.supportsStreaming;
|
|
72
|
+
return {
|
|
73
|
+
buffer,
|
|
74
|
+
digest,
|
|
75
|
+
uncompressedBytes,
|
|
76
|
+
streamingError: streamingResult.error
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
80
|
+
0 && (module.exports = {
|
|
81
|
+
finalizeLambda
|
|
82
|
+
});
|
|
@@ -33,7 +33,7 @@ __export(read_config_file_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(read_config_file_exports);
|
|
35
35
|
var import_js_yaml = __toESM(require("js-yaml"));
|
|
36
|
-
var
|
|
36
|
+
var import_smol_toml = require("smol-toml");
|
|
37
37
|
var import_fs_extra = require("fs-extra");
|
|
38
38
|
var import_error_utils = require("@vercel/error-utils");
|
|
39
39
|
var import_path = require("path");
|
|
@@ -61,7 +61,7 @@ async function readConfigFile(files) {
|
|
|
61
61
|
if (name.endsWith(".json")) {
|
|
62
62
|
return JSON.parse(str);
|
|
63
63
|
} else if (name.endsWith(".toml")) {
|
|
64
|
-
return
|
|
64
|
+
return (0, import_smol_toml.parse)(str);
|
|
65
65
|
} else if (name.endsWith(".yaml") || name.endsWith(".yml")) {
|
|
66
66
|
return import_js_yaml.default.safeLoad(str, { filename: name });
|
|
67
67
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -46,3 +46,6 @@ export { getLambdaByOutputPath } from './collect-build-result/get-lambda-by-outp
|
|
|
46
46
|
export { isRouteMiddleware } from './collect-build-result/is-route-middleware';
|
|
47
47
|
export { getPrerenderChain } from './collect-build-result/get-prerender-chain';
|
|
48
48
|
export { streamWithExtendedPayload, type ExtendedBodyData, } from './collect-build-result/stream-with-extended-payload';
|
|
49
|
+
export { collectUncompressedSize } from './collect-uncompressed-size';
|
|
50
|
+
export { finalizeLambda, type FinalizeLambdaParams, type FinalizeLambdaResult, type TraceFn, } from './finalize-lambda';
|
|
51
|
+
export { validateLambdaSize, validateUncompressedLambdaSize, FunctionSizeError, MAX_LAMBDA_SIZE, MAX_LAMBDA_UNCOMPRESSED_SIZE, validateEnvWrapperSupport, ENV_WRAPPER_SUPPORTED_FAMILIES, } from './validate-lambda-size';
|