@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
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { NowBuildError } from './errors';
|
|
3
|
+
/**
|
|
4
|
+
* Max compressed ZIP size (300 MB).
|
|
5
|
+
* Limit is 250 MB uncompressed; we set 300 MB compressed as a safety
|
|
6
|
+
* buffer. Python is exempt because AI workloads commonly exceed this.
|
|
7
|
+
*/
|
|
8
|
+
export declare const MAX_LAMBDA_SIZE: number;
|
|
9
|
+
/**
|
|
10
|
+
* Max uncompressed size (250 MB).
|
|
11
|
+
*/
|
|
12
|
+
export declare const MAX_LAMBDA_UNCOMPRESSED_SIZE: number;
|
|
13
|
+
/**
|
|
14
|
+
* Error thrown when a Lambda's compressed ZIP exceeds the allowed size.
|
|
15
|
+
*/
|
|
16
|
+
export declare class FunctionSizeError extends NowBuildError {
|
|
17
|
+
size: number;
|
|
18
|
+
maxSize: number;
|
|
19
|
+
constructor(outputPath: string, size: number);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Validates the compressed size of a Lambda function.
|
|
23
|
+
* Python runtimes are exempt because AI workloads commonly exceed 300 MB.
|
|
24
|
+
*/
|
|
25
|
+
export declare function validateLambdaSize(outputPath: string, runtime: string, size: number): void;
|
|
26
|
+
/**
|
|
27
|
+
* Validates the uncompressed size of a Lambda function.
|
|
28
|
+
*/
|
|
29
|
+
export declare function validateUncompressedLambdaSize(outputPath: string, uncompressedBytes: number): void;
|
|
30
|
+
/**
|
|
31
|
+
* Runtimes that support env wrapper.
|
|
32
|
+
*/
|
|
33
|
+
export declare const ENV_WRAPPER_SUPPORTED_FAMILIES: string[];
|
|
34
|
+
interface LambdaLikeForEnvWrapper {
|
|
35
|
+
createZip?: () => Promise<Buffer>;
|
|
36
|
+
runtime: string;
|
|
37
|
+
supportsWrapper?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* When the function requires a file for the encrypted environment variables,
|
|
41
|
+
* it needs to support wrappers. Also, the function must have a `createZip`
|
|
42
|
+
* function since we need to "re-compress" to include the file in the final
|
|
43
|
+
* lambda.
|
|
44
|
+
*/
|
|
45
|
+
export declare function validateEnvWrapperSupport(encryptedEnvFilename: string | undefined, encryptedEnvContent: string | undefined, lambda: LambdaLikeForEnvWrapper): void;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,117 @@
|
|
|
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 validate_lambda_size_exports = {};
|
|
30
|
+
__export(validate_lambda_size_exports, {
|
|
31
|
+
ENV_WRAPPER_SUPPORTED_FAMILIES: () => ENV_WRAPPER_SUPPORTED_FAMILIES,
|
|
32
|
+
FunctionSizeError: () => FunctionSizeError,
|
|
33
|
+
MAX_LAMBDA_SIZE: () => MAX_LAMBDA_SIZE,
|
|
34
|
+
MAX_LAMBDA_UNCOMPRESSED_SIZE: () => MAX_LAMBDA_UNCOMPRESSED_SIZE,
|
|
35
|
+
validateEnvWrapperSupport: () => validateEnvWrapperSupport,
|
|
36
|
+
validateLambdaSize: () => validateLambdaSize,
|
|
37
|
+
validateUncompressedLambdaSize: () => validateUncompressedLambdaSize
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(validate_lambda_size_exports);
|
|
40
|
+
var import_errors = require("./errors");
|
|
41
|
+
var import_bytes = __toESM(require("bytes"));
|
|
42
|
+
const MAX_LAMBDA_SIZE = (0, import_bytes.default)("300mb");
|
|
43
|
+
const MAX_LAMBDA_UNCOMPRESSED_SIZE = 250 * 1024 * 1024;
|
|
44
|
+
class FunctionSizeError extends import_errors.NowBuildError {
|
|
45
|
+
constructor(outputPath, size) {
|
|
46
|
+
super({
|
|
47
|
+
code: "NOW_SANDBOX_WORKER_MAX_LAMBDA_SIZE",
|
|
48
|
+
message: `The Vercel Function "${outputPath}" is ${(0, import_bytes.default)(
|
|
49
|
+
size
|
|
50
|
+
).toLowerCase()} which exceeds the maximum size limit of ${(0, import_bytes.default)(
|
|
51
|
+
MAX_LAMBDA_SIZE
|
|
52
|
+
).toLowerCase()}.`,
|
|
53
|
+
link: "https://vercel.link/serverless-function-size",
|
|
54
|
+
action: "Learn More"
|
|
55
|
+
});
|
|
56
|
+
this.size = size;
|
|
57
|
+
this.maxSize = MAX_LAMBDA_SIZE;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function validateLambdaSize(outputPath, runtime, size) {
|
|
61
|
+
if (runtime.startsWith("python")) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (size > MAX_LAMBDA_SIZE) {
|
|
65
|
+
throw new FunctionSizeError(outputPath, size);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function validateUncompressedLambdaSize(outputPath, uncompressedBytes) {
|
|
69
|
+
if (uncompressedBytes >= MAX_LAMBDA_UNCOMPRESSED_SIZE) {
|
|
70
|
+
throw new import_errors.NowBuildError({
|
|
71
|
+
code: "NOW_SANDBOX_WORKER_MAX_UNCOMPRESSED_LAMBDA_SIZE",
|
|
72
|
+
message: `The Vercel Function "${outputPath}" is ${(0, import_bytes.default)(
|
|
73
|
+
uncompressedBytes
|
|
74
|
+
).toLowerCase()} uncompressed which exceeds the maximum uncompressed size limit of ${(0, import_bytes.default)(
|
|
75
|
+
MAX_LAMBDA_UNCOMPRESSED_SIZE
|
|
76
|
+
).toLowerCase()}.`,
|
|
77
|
+
link: "https://vercel.link/serverless-function-size",
|
|
78
|
+
action: "Learn More"
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const ENV_WRAPPER_SUPPORTED_FAMILIES = [
|
|
83
|
+
"nodejs",
|
|
84
|
+
"python",
|
|
85
|
+
"ruby",
|
|
86
|
+
"java",
|
|
87
|
+
"dotnetcore",
|
|
88
|
+
"bun",
|
|
89
|
+
"executable"
|
|
90
|
+
];
|
|
91
|
+
function validateEnvWrapperSupport(encryptedEnvFilename, encryptedEnvContent, lambda) {
|
|
92
|
+
if (!encryptedEnvFilename || !encryptedEnvContent) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (!lambda.supportsWrapper && !ENV_WRAPPER_SUPPORTED_FAMILIES.some(
|
|
96
|
+
(family) => lambda.runtime.startsWith(family)
|
|
97
|
+
)) {
|
|
98
|
+
throw new Error(
|
|
99
|
+
`Serverless Function runtime ${lambda.runtime} does not support more than 4KB for environment variables`
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
if (typeof lambda.createZip !== "function") {
|
|
103
|
+
throw new Error(
|
|
104
|
+
`Serverless Function with runtime ${lambda.runtime} has no createZip function`
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
109
|
+
0 && (module.exports = {
|
|
110
|
+
ENV_WRAPPER_SUPPORTED_FAMILIES,
|
|
111
|
+
FunctionSizeError,
|
|
112
|
+
MAX_LAMBDA_SIZE,
|
|
113
|
+
MAX_LAMBDA_UNCOMPRESSED_SIZE,
|
|
114
|
+
validateEnvWrapperSupport,
|
|
115
|
+
validateLambdaSize,
|
|
116
|
+
validateUncompressedLambdaSize
|
|
117
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/build-utils",
|
|
3
|
-
"version": "13.12.
|
|
3
|
+
"version": "13.12.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.js",
|
|
@@ -16,8 +16,10 @@
|
|
|
16
16
|
"@vercel/python-analysis": "0.11.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"
|
|
19
|
+
"bytes": "3.1.2",
|
|
20
|
+
"smol-toml": "1.5.2",
|
|
20
21
|
"@types/async-retry": "^1.2.1",
|
|
22
|
+
"@types/bytes": "3.1.1",
|
|
21
23
|
"@types/cross-spawn": "6.0.0",
|
|
22
24
|
"@types/end-of-stream": "^1.4.0",
|
|
23
25
|
"@types/fs-extra": "9.0.13",
|