@vercel/build-utils 15.4.2 → 15.5.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 +25 -0
- package/dist/container-image.d.ts +2 -1
- package/dist/container-image.js +1 -0
- package/dist/edge-function.d.ts +6 -0
- package/dist/edge-function.js +1 -0
- package/dist/index.js +4 -4
- package/dist/lambda.d.ts +9 -1
- package/dist/lambda.js +11 -1
- package/dist/schedules.d.ts +24 -3
- package/dist/schedules.js +32 -0
- package/dist/schemas.d.ts +8 -0
- package/dist/schemas.js +4 -0
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
package/dist/lambda.d.ts
CHANGED
|
@@ -65,6 +65,10 @@ export interface LambdaOptionsBase {
|
|
|
65
65
|
* When true, the Lambda runtime can be terminated mid-execution if the request is cancelled.
|
|
66
66
|
*/
|
|
67
67
|
supportsCancellation?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* ID of the perimeter (`pmtr_...`) this function runs inside.
|
|
70
|
+
*/
|
|
71
|
+
perimeter?: string;
|
|
68
72
|
/**
|
|
69
73
|
* Whether to disable automatic fetch instrumentation.
|
|
70
74
|
* When true, the Function runtime will not automatically instrument fetch calls.
|
|
@@ -144,6 +148,10 @@ export declare class Lambda {
|
|
|
144
148
|
* When true, the Lambda runtime can be terminated mid-execution if the request is cancelled.
|
|
145
149
|
*/
|
|
146
150
|
supportsCancellation?: boolean;
|
|
151
|
+
/**
|
|
152
|
+
* ID of the perimeter (`pmtr_...`) this function runs inside.
|
|
153
|
+
*/
|
|
154
|
+
perimeter?: string;
|
|
147
155
|
/**
|
|
148
156
|
* Whether to disable automatic fetch instrumentation.
|
|
149
157
|
* When true, the Function runtime will not automatically instrument fetch calls.
|
|
@@ -171,4 +179,4 @@ export declare function findMatchingFunction(functions: BuilderFunctions | undef
|
|
|
171
179
|
pattern: string;
|
|
172
180
|
functionConfig: BuilderFunctions[string];
|
|
173
181
|
} | undefined;
|
|
174
|
-
export declare function getLambdaOptionsFromFunction({ sourceFile, config, isScheduleEntrypoint, }: GetLambdaOptionsFromFunctionOptions): Promise<Pick<LambdaOptions, 'architecture' | 'memory' | 'maxDuration' | 'affinity' | 'maxConcurrency' | 'regions' | 'functionFailoverRegions' | 'experimentalTriggers' | 'supportsCancellation'>>;
|
|
182
|
+
export declare function getLambdaOptionsFromFunction({ sourceFile, config, isScheduleEntrypoint, }: GetLambdaOptionsFromFunctionOptions): Promise<Pick<LambdaOptions, 'architecture' | 'memory' | 'maxDuration' | 'affinity' | 'maxConcurrency' | 'regions' | 'functionFailoverRegions' | 'experimentalTriggers' | 'supportsCancellation' | 'perimeter'>>;
|
package/dist/lambda.js
CHANGED
|
@@ -61,6 +61,7 @@ function sanitizeConsumerName(functionPath) {
|
|
|
61
61
|
}
|
|
62
62
|
return result;
|
|
63
63
|
}
|
|
64
|
+
const PERIMETER_ID_PATTERN = /^pmtr_[a-z0-9]{28}$/;
|
|
64
65
|
function getDefaultLambdaArchitecture(architecture) {
|
|
65
66
|
if (architecture) {
|
|
66
67
|
return architecture;
|
|
@@ -98,6 +99,7 @@ class Lambda {
|
|
|
98
99
|
framework,
|
|
99
100
|
experimentalTriggers,
|
|
100
101
|
supportsCancellation,
|
|
102
|
+
perimeter,
|
|
101
103
|
shouldDisableAutomaticFetchInstrumentation
|
|
102
104
|
} = opts;
|
|
103
105
|
if ("files" in opts) {
|
|
@@ -271,6 +273,12 @@ class Lambda {
|
|
|
271
273
|
'"supportsCancellation" is not a boolean'
|
|
272
274
|
);
|
|
273
275
|
}
|
|
276
|
+
if (perimeter !== void 0) {
|
|
277
|
+
(0, import_assert.default)(
|
|
278
|
+
typeof perimeter === "string" && PERIMETER_ID_PATTERN.test(perimeter),
|
|
279
|
+
'"perimeter" must be a perimeter ID ("pmtr_" followed by 28 lowercase letters or digits)'
|
|
280
|
+
);
|
|
281
|
+
}
|
|
274
282
|
this.type = "Lambda";
|
|
275
283
|
this.operationType = operationType;
|
|
276
284
|
this.files = "files" in opts ? opts.files : void 0;
|
|
@@ -294,6 +302,7 @@ class Lambda {
|
|
|
294
302
|
this.experimentalAllowBundling = "experimentalAllowBundling" in opts ? opts.experimentalAllowBundling : void 0;
|
|
295
303
|
this.experimentalTriggers = experimentalTriggers;
|
|
296
304
|
this.supportsCancellation = supportsCancellation;
|
|
305
|
+
this.perimeter = perimeter;
|
|
297
306
|
this.shouldDisableAutomaticFetchInstrumentation = shouldDisableAutomaticFetchInstrumentation;
|
|
298
307
|
}
|
|
299
308
|
async createZip() {
|
|
@@ -413,7 +422,8 @@ async function getLambdaOptionsFromFunction({
|
|
|
413
422
|
regions: fn.regions,
|
|
414
423
|
functionFailoverRegions: fn.functionFailoverRegions,
|
|
415
424
|
experimentalTriggers: isScheduleEntrypoint ? [{ type: "schedule/v1beta" }] : experimentalTriggers,
|
|
416
|
-
supportsCancellation: fn.supportsCancellation
|
|
425
|
+
supportsCancellation: fn.supportsCancellation,
|
|
426
|
+
perimeter: fn.perimeter
|
|
417
427
|
};
|
|
418
428
|
}
|
|
419
429
|
return isScheduleEntrypoint ? { experimentalTriggers: [{ type: "schedule/v1beta" }] } : {};
|
package/dist/schedules.d.ts
CHANGED
|
@@ -12,12 +12,13 @@ export type VercelJsonScheduleDefinition = ScheduleDefinition | (Pick<ScheduleDe
|
|
|
12
12
|
root: string;
|
|
13
13
|
}) | {
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
* jitter of the schedules it creates, like `jobs.tasks`.
|
|
17
|
-
* JavaScript or TypeScript file, like `cleanup.ts`, whose
|
|
15
|
+
* With `python`, a module whose `@schedule` handlers set the cron,
|
|
16
|
+
* timezone and jitter of the schedules it creates, like `jobs.tasks`.
|
|
17
|
+
* With `node`, a JavaScript or TypeScript file, like `cleanup.ts`, whose
|
|
18
18
|
* `export const config` sets them.
|
|
19
19
|
*/
|
|
20
20
|
entrypoint: string;
|
|
21
|
+
runtime: 'python' | 'node';
|
|
21
22
|
/** Directory of the schedule's service; `entrypoint` is relative to it. */
|
|
22
23
|
root: string;
|
|
23
24
|
};
|
|
@@ -46,6 +47,26 @@ export declare function getServiceScheduleName(service: string, name: string): {
|
|
|
46
47
|
deployedName: string;
|
|
47
48
|
error?: string;
|
|
48
49
|
};
|
|
50
|
+
/**
|
|
51
|
+
* Function that serves the schedules of a schedule service that set no
|
|
52
|
+
* function settings. The scheduler requests it by this path, which the
|
|
53
|
+
* runtime logs show.
|
|
54
|
+
*/
|
|
55
|
+
export declare const SCHEDULES_FUNCTION_PATH = "schedules";
|
|
56
|
+
/** A function of a schedule service, and the settings its schedules share. */
|
|
57
|
+
export interface ScheduleFunctionSettings {
|
|
58
|
+
path: string;
|
|
59
|
+
/** In seconds. */
|
|
60
|
+
maxDuration?: number;
|
|
61
|
+
regions?: string[];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Schedules with exactly the same function settings share a function, named
|
|
65
|
+
* after the settings it sets: `schedules`, `schedules-fra1`, `schedules-15m`,
|
|
66
|
+
* `schedules-fra1-iad1-90s`. A name stays the same when schedules are added or
|
|
67
|
+
* removed. Settings that can't form a name use a hash of them instead.
|
|
68
|
+
*/
|
|
69
|
+
export declare function getScheduleFunction(maxDuration: number | null, regions: string[] | null): ScheduleFunctionSettings;
|
|
49
70
|
/** Named schedules keyed by name, for `schedules` in Build Output. */
|
|
50
71
|
export declare function toScheduleRecord(schedules: readonly Schedule[]): Schedules;
|
|
51
72
|
export declare function toScheduleRecord(schedules: readonly VercelJsonSchedule[]): VercelJsonSchedules;
|
package/dist/schedules.js
CHANGED
|
@@ -18,12 +18,15 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var schedules_exports = {};
|
|
20
20
|
__export(schedules_exports, {
|
|
21
|
+
SCHEDULES_FUNCTION_PATH: () => SCHEDULES_FUNCTION_PATH,
|
|
21
22
|
getNamedSchedules: () => getNamedSchedules,
|
|
23
|
+
getScheduleFunction: () => getScheduleFunction,
|
|
22
24
|
getServiceScheduleName: () => getServiceScheduleName,
|
|
23
25
|
isServiceSchedule: () => isServiceSchedule,
|
|
24
26
|
toScheduleRecord: () => toScheduleRecord
|
|
25
27
|
});
|
|
26
28
|
module.exports = __toCommonJS(schedules_exports);
|
|
29
|
+
var import_crypto = require("crypto");
|
|
27
30
|
function isServiceSchedule(schedule) {
|
|
28
31
|
return "entrypoint" in schedule || "run" in schedule;
|
|
29
32
|
}
|
|
@@ -45,6 +48,33 @@ function getServiceScheduleName(service, name) {
|
|
|
45
48
|
error: `the schedule name "${deployedName}" is invalid. Names can have at most ${MAX_SCHEDULE_NAME_LENGTH} characters, and contain only letters, numbers, ".", "_" and "-".`
|
|
46
49
|
};
|
|
47
50
|
}
|
|
51
|
+
const SCHEDULES_FUNCTION_PATH = "schedules";
|
|
52
|
+
const REGION_ID_RE = /^[a-z]{3}[0-9]$/;
|
|
53
|
+
const MAX_FUNCTION_NAME_LENGTH = 64;
|
|
54
|
+
function formatMaxDuration(seconds) {
|
|
55
|
+
if (seconds % 3600 === 0)
|
|
56
|
+
return `${seconds / 3600}h`;
|
|
57
|
+
if (seconds % 60 === 0)
|
|
58
|
+
return `${seconds / 60}m`;
|
|
59
|
+
return `${seconds}s`;
|
|
60
|
+
}
|
|
61
|
+
function getScheduleFunction(maxDuration, regions) {
|
|
62
|
+
const sortedRegions = regions && [...new Set(regions)].sort();
|
|
63
|
+
const parts = [
|
|
64
|
+
...sortedRegions ?? [],
|
|
65
|
+
...maxDuration === null ? [] : [formatMaxDuration(maxDuration)]
|
|
66
|
+
];
|
|
67
|
+
let path = [SCHEDULES_FUNCTION_PATH, ...parts].join("-");
|
|
68
|
+
if (!(sortedRegions ?? []).every((region) => REGION_ID_RE.test(region)) || path.length > MAX_FUNCTION_NAME_LENGTH) {
|
|
69
|
+
const hash = (0, import_crypto.createHash)("sha256").update(JSON.stringify([maxDuration, sortedRegions])).digest("hex").slice(0, 8);
|
|
70
|
+
path = `${SCHEDULES_FUNCTION_PATH}-${hash}`;
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
path,
|
|
74
|
+
...maxDuration !== null && { maxDuration },
|
|
75
|
+
...sortedRegions !== null && { regions: sortedRegions }
|
|
76
|
+
};
|
|
77
|
+
}
|
|
48
78
|
function toScheduleRecord(schedules) {
|
|
49
79
|
return Object.fromEntries(
|
|
50
80
|
schedules.map(({ name, ...schedule }) => [name, schedule])
|
|
@@ -52,7 +82,9 @@ function toScheduleRecord(schedules) {
|
|
|
52
82
|
}
|
|
53
83
|
// Annotate the CommonJS export names for ESM import in node:
|
|
54
84
|
0 && (module.exports = {
|
|
85
|
+
SCHEDULES_FUNCTION_PATH,
|
|
55
86
|
getNamedSchedules,
|
|
87
|
+
getScheduleFunction,
|
|
56
88
|
getServiceScheduleName,
|
|
57
89
|
isServiceSchedule,
|
|
58
90
|
toScheduleRecord
|
package/dist/schemas.d.ts
CHANGED
|
@@ -90,6 +90,10 @@ export declare const getFunctionsSchema: () => {
|
|
|
90
90
|
supportsCancellation: {
|
|
91
91
|
type: string;
|
|
92
92
|
};
|
|
93
|
+
perimeter: {
|
|
94
|
+
type: string;
|
|
95
|
+
pattern: string;
|
|
96
|
+
};
|
|
93
97
|
};
|
|
94
98
|
};
|
|
95
99
|
};
|
|
@@ -192,6 +196,10 @@ export declare const functionsSchema: {
|
|
|
192
196
|
supportsCancellation: {
|
|
193
197
|
type: string;
|
|
194
198
|
};
|
|
199
|
+
perimeter: {
|
|
200
|
+
type: string;
|
|
201
|
+
pattern: string;
|
|
202
|
+
};
|
|
195
203
|
};
|
|
196
204
|
};
|
|
197
205
|
};
|
package/dist/schemas.js
CHANGED
package/dist/types.d.ts
CHANGED