@vercel/build-utils 13.11.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @vercel/build-utils
2
2
 
3
+ ## 13.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Add hash utilities (`streamToDigestAsync`, `sha256`, `md5`) and build result helpers (`getBuildResultMetadata`, `getLambdaByOutputPath`, `isRouteMiddleware`, `getPrerenderChain`, `streamWithExtendedPayload`) for shared use. ([#15726](https://github.com/vercel/vercel/pull/15726))
8
+
3
9
  ## 13.11.0
4
10
 
5
11
  ### Minor Changes
@@ -0,0 +1,33 @@
1
+ import type { Route } from '@vercel/routing-utils';
2
+ import type { EdgeFunction } from '../edge-function';
3
+ import type { File } from '../types';
4
+ import type { Lambda } from '../lambda';
5
+ import type { Prerender } from '../prerender';
6
+ export interface BuildResultMetadata {
7
+ middleware: Map<string, MiddlewareMeta>;
8
+ ppr: Map<string, boolean>;
9
+ }
10
+ /**
11
+ * Extract metadata about the build result that depend on the relationship
12
+ * between components in the build output. This data is later used to map to
13
+ * the infrastructure that we need to create.
14
+ */
15
+ export declare function getBuildResultMetadata(params: {
16
+ buildOutputMap: Record<string, EdgeFunction | Lambda | Prerender | File>;
17
+ routes: Route[];
18
+ }): BuildResultMetadata;
19
+ type MiddlewareMeta = {
20
+ type: 'middleware';
21
+ middlewarePath: string;
22
+ outputPath: string;
23
+ match: Set<string>;
24
+ edgeFunction: EdgeFunction;
25
+ index: number;
26
+ } | {
27
+ type: 'middleware-lambda';
28
+ middlewarePath: string;
29
+ outputPath: string;
30
+ match: Set<string>;
31
+ index: number;
32
+ };
33
+ export {};
@@ -0,0 +1,99 @@
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_build_result_metadata_exports = {};
20
+ __export(get_build_result_metadata_exports, {
21
+ getBuildResultMetadata: () => getBuildResultMetadata
22
+ });
23
+ module.exports = __toCommonJS(get_build_result_metadata_exports);
24
+ var import_errors = require("../errors");
25
+ var import_get_lambda_by_output_path = require("./get-lambda-by-output-path");
26
+ var import_get_prerender_chain = require("./get-prerender-chain");
27
+ var import_is_route_middleware = require("./is-route-middleware");
28
+ function getBuildResultMetadata(params) {
29
+ return {
30
+ middleware: getMiddlewareMetadata(params),
31
+ ppr: new Map(
32
+ Object.entries(params.buildOutputMap).flatMap(([_outputPath, output]) => {
33
+ if (output.type === "Prerender") {
34
+ const chain = (0, import_get_prerender_chain.getPrerenderChain)(output);
35
+ if (chain) {
36
+ const maybeLambda = (0, import_get_lambda_by_output_path.getLambdaByOutputPath)({
37
+ buildOutputMap: params.buildOutputMap,
38
+ outputPath: chain.outputPath
39
+ });
40
+ if (maybeLambda) {
41
+ return [[chain.outputPath, true]];
42
+ }
43
+ }
44
+ }
45
+ return [];
46
+ })
47
+ )
48
+ };
49
+ }
50
+ function getMiddlewareMetadata(params) {
51
+ const deduped = new Map(
52
+ params.routes.filter(import_is_route_middleware.isRouteMiddleware).map(
53
+ (route) => toMiddlewareTuple({
54
+ buildOutputMap: params.buildOutputMap,
55
+ middlewarePath: route.middlewarePath
56
+ })
57
+ )
58
+ );
59
+ return new Map(
60
+ Array.from(deduped, ([outputPath, metadata], index) => [
61
+ outputPath,
62
+ { ...metadata, index }
63
+ ])
64
+ );
65
+ }
66
+ function toMiddlewareTuple(params) {
67
+ const keys = [
68
+ params.middlewarePath,
69
+ params.middlewarePath.replace(/^\//, "")
70
+ ];
71
+ const [outputPath, output] = Object.entries(params.buildOutputMap).find(
72
+ (entry) => keys.includes(entry[0]) && (entry[1].type === "EdgeFunction" || entry[1].type === "Lambda")
73
+ ) ?? [];
74
+ if (!outputPath || !output) {
75
+ throw new import_errors.NowBuildError({
76
+ message: `Mapping ${params.middlewarePath} not found. Maybe you provided a wrong middlewarePath?`,
77
+ code: "middleware_path_not_found"
78
+ });
79
+ }
80
+ return [
81
+ outputPath,
82
+ output.type === "EdgeFunction" ? {
83
+ edgeFunction: output,
84
+ match: new Set(keys),
85
+ middlewarePath: params.middlewarePath,
86
+ outputPath,
87
+ type: "middleware"
88
+ } : {
89
+ match: new Set(keys),
90
+ middlewarePath: params.middlewarePath,
91
+ outputPath,
92
+ type: "middleware-lambda"
93
+ }
94
+ ];
95
+ }
96
+ // Annotate the CommonJS export names for ESM import in node:
97
+ 0 && (module.exports = {
98
+ getBuildResultMetadata
99
+ });
@@ -0,0 +1,13 @@
1
+ import type { EdgeFunction } from '../edge-function';
2
+ import type { File } from '../types';
3
+ import type { Lambda } from '../lambda';
4
+ import type { Prerender } from '../prerender';
5
+ /**
6
+ * A Prerender can hold references to a Lambda or another Prerender when
7
+ * using PPR. This function retrieves the Lambda or Prerender from the
8
+ * build output map ensuring its type.
9
+ */
10
+ export declare function getLambdaByOutputPath(params: {
11
+ buildOutputMap: Record<string, EdgeFunction | Lambda | Prerender | File>;
12
+ outputPath: string;
13
+ }): Lambda | undefined;
@@ -0,0 +1,31 @@
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_by_output_path_exports = {};
20
+ __export(get_lambda_by_output_path_exports, {
21
+ getLambdaByOutputPath: () => getLambdaByOutputPath
22
+ });
23
+ module.exports = __toCommonJS(get_lambda_by_output_path_exports);
24
+ function getLambdaByOutputPath(params) {
25
+ const output = params.buildOutputMap[params.outputPath];
26
+ return output?.type === "Lambda" ? output : output?.type === "Prerender" ? output.lambda : void 0;
27
+ }
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {
30
+ getLambdaByOutputPath
31
+ });
@@ -0,0 +1,8 @@
1
+ import type { Chain } from '../types';
2
+ import type { Prerender } from '../prerender';
3
+ /**
4
+ * The Prerender chain can be defined as a `chain` property or as a flag
5
+ * `experimentalStreamingLambdaPath`. This function normalizes the chain
6
+ * to a single structure.
7
+ */
8
+ export declare function getPrerenderChain(prerender: Prerender): Chain | undefined;
@@ -0,0 +1,44 @@
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_prerender_chain_exports = {};
20
+ __export(get_prerender_chain_exports, {
21
+ getPrerenderChain: () => getPrerenderChain
22
+ });
23
+ module.exports = __toCommonJS(get_prerender_chain_exports);
24
+ function getPrerenderChain(prerender) {
25
+ if (prerender.chain) {
26
+ return {
27
+ outputPath: prerender.chain.outputPath,
28
+ headers: prerender.chain.headers
29
+ };
30
+ }
31
+ if (prerender.experimentalStreamingLambdaPath) {
32
+ return {
33
+ outputPath: prerender.experimentalStreamingLambdaPath,
34
+ headers: {
35
+ "x-matched-path": prerender.experimentalStreamingLambdaPath
36
+ }
37
+ };
38
+ }
39
+ return void 0;
40
+ }
41
+ // Annotate the CommonJS export names for ESM import in node:
42
+ 0 && (module.exports = {
43
+ getPrerenderChain
44
+ });
@@ -0,0 +1,4 @@
1
+ import type { Route } from '@vercel/routing-utils';
2
+ export declare function isRouteMiddleware(route: Route): route is Route & {
3
+ middlewarePath: string;
4
+ };
@@ -0,0 +1,30 @@
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 is_route_middleware_exports = {};
20
+ __export(is_route_middleware_exports, {
21
+ isRouteMiddleware: () => isRouteMiddleware
22
+ });
23
+ module.exports = __toCommonJS(is_route_middleware_exports);
24
+ function isRouteMiddleware(route) {
25
+ return "middlewarePath" in route && typeof route.middlewarePath === "string";
26
+ }
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ isRouteMiddleware
30
+ });
@@ -0,0 +1,6 @@
1
+ /// <reference types="node" />
2
+ export interface ExtendedBodyData {
3
+ prefix: string;
4
+ suffix: string;
5
+ }
6
+ export declare function streamWithExtendedPayload(stream: NodeJS.ReadableStream, data?: ExtendedBodyData): NodeJS.ReadableStream;
@@ -0,0 +1,49 @@
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 stream_with_extended_payload_exports = {};
20
+ __export(stream_with_extended_payload_exports, {
21
+ streamWithExtendedPayload: () => streamWithExtendedPayload
22
+ });
23
+ module.exports = __toCommonJS(stream_with_extended_payload_exports);
24
+ var import_stream = require("stream");
25
+ function streamWithExtendedPayload(stream, data) {
26
+ return data ? new MultipartContentStream(stream, data) : stream;
27
+ }
28
+ class MultipartContentStream extends import_stream.Readable {
29
+ constructor(stream, data) {
30
+ super();
31
+ stream.on("error", (err) => {
32
+ this.emit("error", err);
33
+ });
34
+ stream.on("end", () => {
35
+ this.push(data.suffix);
36
+ this.push(null);
37
+ });
38
+ this.push(data.prefix);
39
+ stream.on("data", (chunk) => {
40
+ this.push(chunk);
41
+ });
42
+ }
43
+ _read() {
44
+ }
45
+ }
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ streamWithExtendedPayload
49
+ });
@@ -0,0 +1,10 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ export interface FileDigest {
4
+ md5: string;
5
+ sha256: string;
6
+ size: number;
7
+ }
8
+ export declare function streamToDigestAsync(stream: NodeJS.ReadableStream): Promise<FileDigest>;
9
+ export declare function sha256(value: any): string;
10
+ export declare function md5(value: Buffer): string;
@@ -0,0 +1,62 @@
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 stream_to_digest_async_exports = {};
20
+ __export(stream_to_digest_async_exports, {
21
+ md5: () => md5,
22
+ sha256: () => sha256,
23
+ streamToDigestAsync: () => streamToDigestAsync
24
+ });
25
+ module.exports = __toCommonJS(stream_to_digest_async_exports);
26
+ var import_crypto = require("crypto");
27
+ async function streamToDigestAsync(stream) {
28
+ return await new Promise((resolve, reject) => {
29
+ stream.once("error", reject);
30
+ let count = 0;
31
+ const sha2562 = (0, import_crypto.createHash)("sha256");
32
+ const md52 = (0, import_crypto.createHash)("md5");
33
+ stream.on("end", () => {
34
+ const res = {
35
+ sha256: sha2562.digest("hex"),
36
+ md5: md52.digest("hex"),
37
+ size: count
38
+ };
39
+ resolve(res);
40
+ });
41
+ stream.on("readable", () => {
42
+ let chunk;
43
+ while (null !== (chunk = stream.read())) {
44
+ md52.update(chunk);
45
+ sha2562.update(chunk);
46
+ count += chunk.length;
47
+ }
48
+ });
49
+ });
50
+ }
51
+ function sha256(value) {
52
+ return (0, import_crypto.createHash)("sha256").update(value).digest("hex");
53
+ }
54
+ function md5(value) {
55
+ return (0, import_crypto.createHash)("md5").update(value).digest("hex");
56
+ }
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ md5,
60
+ sha256,
61
+ streamToDigestAsync
62
+ });
package/dist/index.d.ts CHANGED
@@ -40,3 +40,9 @@ export { getEncryptedEnv, type EncryptedEnvFile, } from './process-serverless/ge
40
40
  export { getLambdaEnvironment } from './process-serverless/get-lambda-environment';
41
41
  export { getLambdaPreloadScripts, type BytecodeCachingOptions, } from './process-serverless/get-lambda-preload-scripts';
42
42
  export { getLambdaSupportsStreaming, type SupportsStreamingResult, } from './process-serverless/get-lambda-supports-streaming';
43
+ export { streamToDigestAsync, sha256, md5, type FileDigest, } from './fs/stream-to-digest-async';
44
+ export { getBuildResultMetadata, type BuildResultMetadata, } from './collect-build-result/get-build-result-metadata';
45
+ export { getLambdaByOutputPath } from './collect-build-result/get-lambda-by-output-path';
46
+ export { isRouteMiddleware } from './collect-build-result/is-route-middleware';
47
+ export { getPrerenderChain } from './collect-build-result/get-prerender-chain';
48
+ export { streamWithExtendedPayload, type ExtendedBodyData, } from './collect-build-result/stream-with-extended-payload';
package/dist/index.js CHANGED
@@ -911,9 +911,9 @@ var require_stream_duplex = __commonJS({
911
911
  module2.exports = Duplex;
912
912
  var util = Object.create(require_util());
913
913
  util.inherits = require_inherits();
914
- var Readable = require_stream_readable();
914
+ var Readable2 = require_stream_readable();
915
915
  var Writable = require_stream_writable();
916
- util.inherits(Duplex, Readable);
916
+ util.inherits(Duplex, Readable2);
917
917
  {
918
918
  keys = objectKeys(Writable.prototype);
919
919
  for (v = 0; v < keys.length; v++) {
@@ -928,7 +928,7 @@ var require_stream_duplex = __commonJS({
928
928
  function Duplex(options) {
929
929
  if (!(this instanceof Duplex))
930
930
  return new Duplex(options);
931
- Readable.call(this, options);
931
+ Readable2.call(this, options);
932
932
  Writable.call(this, options);
933
933
  if (options && options.readable === false)
934
934
  this.readable = false;
@@ -1244,10 +1244,10 @@ var require_stream_readable = __commonJS({
1244
1244
  "../../node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/_stream_readable.js"(exports2, module2) {
1245
1245
  "use strict";
1246
1246
  var pna = require_process_nextick_args();
1247
- module2.exports = Readable;
1247
+ module2.exports = Readable2;
1248
1248
  var isArray = require_isarray();
1249
1249
  var Duplex;
1250
- Readable.ReadableState = ReadableState;
1250
+ Readable2.ReadableState = ReadableState;
1251
1251
  var EE = require("events").EventEmitter;
1252
1252
  var EElistenerCount = function(emitter, type) {
1253
1253
  return emitter.listeners(type).length;
@@ -1275,7 +1275,7 @@ var require_stream_readable = __commonJS({
1275
1275
  var BufferList = require_BufferList();
1276
1276
  var destroyImpl = require_destroy();
1277
1277
  var StringDecoder;
1278
- util.inherits(Readable, Stream);
1278
+ util.inherits(Readable2, Stream);
1279
1279
  var kProxyEvents = ["error", "close", "destroy", "pause", "resume"];
1280
1280
  function prependListener(emitter, event, fn) {
1281
1281
  if (typeof emitter.prependListener === "function")
@@ -1330,10 +1330,10 @@ var require_stream_readable = __commonJS({
1330
1330
  this.encoding = options.encoding;
1331
1331
  }
1332
1332
  }
1333
- function Readable(options) {
1333
+ function Readable2(options) {
1334
1334
  Duplex = Duplex || require_stream_duplex();
1335
- if (!(this instanceof Readable))
1336
- return new Readable(options);
1335
+ if (!(this instanceof Readable2))
1336
+ return new Readable2(options);
1337
1337
  this._readableState = new ReadableState(options, this);
1338
1338
  this.readable = true;
1339
1339
  if (options) {
@@ -1344,7 +1344,7 @@ var require_stream_readable = __commonJS({
1344
1344
  }
1345
1345
  Stream.call(this);
1346
1346
  }
1347
- Object.defineProperty(Readable.prototype, "destroyed", {
1347
+ Object.defineProperty(Readable2.prototype, "destroyed", {
1348
1348
  get: function() {
1349
1349
  if (this._readableState === void 0) {
1350
1350
  return false;
@@ -1358,13 +1358,13 @@ var require_stream_readable = __commonJS({
1358
1358
  this._readableState.destroyed = value;
1359
1359
  }
1360
1360
  });
1361
- Readable.prototype.destroy = destroyImpl.destroy;
1362
- Readable.prototype._undestroy = destroyImpl.undestroy;
1363
- Readable.prototype._destroy = function(err, cb) {
1361
+ Readable2.prototype.destroy = destroyImpl.destroy;
1362
+ Readable2.prototype._undestroy = destroyImpl.undestroy;
1363
+ Readable2.prototype._destroy = function(err, cb) {
1364
1364
  this.push(null);
1365
1365
  cb(err);
1366
1366
  };
1367
- Readable.prototype.push = function(chunk, encoding) {
1367
+ Readable2.prototype.push = function(chunk, encoding) {
1368
1368
  var state = this._readableState;
1369
1369
  var skipChunkCheck;
1370
1370
  if (!state.objectMode) {
@@ -1381,7 +1381,7 @@ var require_stream_readable = __commonJS({
1381
1381
  }
1382
1382
  return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
1383
1383
  };
1384
- Readable.prototype.unshift = function(chunk) {
1384
+ Readable2.prototype.unshift = function(chunk) {
1385
1385
  return readableAddChunk(this, chunk, null, true, false);
1386
1386
  };
1387
1387
  function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
@@ -1449,10 +1449,10 @@ var require_stream_readable = __commonJS({
1449
1449
  function needMoreData(state) {
1450
1450
  return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
1451
1451
  }
1452
- Readable.prototype.isPaused = function() {
1452
+ Readable2.prototype.isPaused = function() {
1453
1453
  return this._readableState.flowing === false;
1454
1454
  };
1455
- Readable.prototype.setEncoding = function(enc) {
1455
+ Readable2.prototype.setEncoding = function(enc) {
1456
1456
  if (!StringDecoder)
1457
1457
  StringDecoder = require_string_decoder().StringDecoder;
1458
1458
  this._readableState.decoder = new StringDecoder(enc);
@@ -1495,7 +1495,7 @@ var require_stream_readable = __commonJS({
1495
1495
  }
1496
1496
  return state.length;
1497
1497
  }
1498
- Readable.prototype.read = function(n) {
1498
+ Readable2.prototype.read = function(n) {
1499
1499
  debug2("read", n);
1500
1500
  n = parseInt(n, 10);
1501
1501
  var state = this._readableState;
@@ -1605,10 +1605,10 @@ var require_stream_readable = __commonJS({
1605
1605
  }
1606
1606
  state.readingMore = false;
1607
1607
  }
1608
- Readable.prototype._read = function(n) {
1608
+ Readable2.prototype._read = function(n) {
1609
1609
  this.emit("error", new Error("_read() is not implemented"));
1610
1610
  };
1611
- Readable.prototype.pipe = function(dest, pipeOpts) {
1611
+ Readable2.prototype.pipe = function(dest, pipeOpts) {
1612
1612
  var src = this;
1613
1613
  var state = this._readableState;
1614
1614
  switch (state.pipesCount) {
@@ -1718,7 +1718,7 @@ var require_stream_readable = __commonJS({
1718
1718
  }
1719
1719
  };
1720
1720
  }
1721
- Readable.prototype.unpipe = function(dest) {
1721
+ Readable2.prototype.unpipe = function(dest) {
1722
1722
  var state = this._readableState;
1723
1723
  var unpipeInfo = { hasUnpiped: false };
1724
1724
  if (state.pipesCount === 0)
@@ -1756,7 +1756,7 @@ var require_stream_readable = __commonJS({
1756
1756
  dest.emit("unpipe", this, unpipeInfo);
1757
1757
  return this;
1758
1758
  };
1759
- Readable.prototype.on = function(ev, fn) {
1759
+ Readable2.prototype.on = function(ev, fn) {
1760
1760
  var res = Stream.prototype.on.call(this, ev, fn);
1761
1761
  if (ev === "data") {
1762
1762
  if (this._readableState.flowing !== false)
@@ -1775,12 +1775,12 @@ var require_stream_readable = __commonJS({
1775
1775
  }
1776
1776
  return res;
1777
1777
  };
1778
- Readable.prototype.addListener = Readable.prototype.on;
1778
+ Readable2.prototype.addListener = Readable2.prototype.on;
1779
1779
  function nReadingNextTick(self2) {
1780
1780
  debug2("readable nexttick read 0");
1781
1781
  self2.read(0);
1782
1782
  }
1783
- Readable.prototype.resume = function() {
1783
+ Readable2.prototype.resume = function() {
1784
1784
  var state = this._readableState;
1785
1785
  if (!state.flowing) {
1786
1786
  debug2("resume");
@@ -1807,7 +1807,7 @@ var require_stream_readable = __commonJS({
1807
1807
  if (state.flowing && !state.reading)
1808
1808
  stream.read(0);
1809
1809
  }
1810
- Readable.prototype.pause = function() {
1810
+ Readable2.prototype.pause = function() {
1811
1811
  debug2("call pause flowing=%j", this._readableState.flowing);
1812
1812
  if (false !== this._readableState.flowing) {
1813
1813
  debug2("pause");
@@ -1822,7 +1822,7 @@ var require_stream_readable = __commonJS({
1822
1822
  while (state.flowing && stream.read() !== null) {
1823
1823
  }
1824
1824
  }
1825
- Readable.prototype.wrap = function(stream) {
1825
+ Readable2.prototype.wrap = function(stream) {
1826
1826
  var _this = this;
1827
1827
  var state = this._readableState;
1828
1828
  var paused = false;
@@ -1870,7 +1870,7 @@ var require_stream_readable = __commonJS({
1870
1870
  };
1871
1871
  return this;
1872
1872
  };
1873
- Object.defineProperty(Readable.prototype, "readableHighWaterMark", {
1873
+ Object.defineProperty(Readable2.prototype, "readableHighWaterMark", {
1874
1874
  // making it explicit this property is not enumerable
1875
1875
  // because otherwise some prototype manipulation in
1876
1876
  // userland will fail
@@ -1879,7 +1879,7 @@ var require_stream_readable = __commonJS({
1879
1879
  return this._readableState.highWaterMark;
1880
1880
  }
1881
1881
  });
1882
- Readable._fromList = fromList;
1882
+ Readable2._fromList = fromList;
1883
1883
  function fromList(n, state) {
1884
1884
  if (state.length === 0)
1885
1885
  return null;
@@ -2152,7 +2152,7 @@ var require_readable = __commonJS({
2152
2152
  // ../../node_modules/.pnpm/from2@2.3.0/node_modules/from2/index.js
2153
2153
  var require_from2 = __commonJS({
2154
2154
  "../../node_modules/.pnpm/from2@2.3.0/node_modules/from2/index.js"(exports2, module2) {
2155
- var Readable = require_readable().Readable;
2155
+ var Readable2 = require_readable().Readable;
2156
2156
  var inherits = require_inherits();
2157
2157
  module2.exports = from2;
2158
2158
  from2.ctor = ctor;
@@ -2185,14 +2185,14 @@ var require_from2 = __commonJS({
2185
2185
  opts = {};
2186
2186
  }
2187
2187
  opts = defaults(opts);
2188
- inherits(Class, Readable);
2188
+ inherits(Class, Readable2);
2189
2189
  function Class(override) {
2190
2190
  if (!(this instanceof Class))
2191
2191
  return new Class(override);
2192
2192
  this._reading = false;
2193
2193
  this._callback = check;
2194
2194
  this.destroyed = false;
2195
- Readable.call(this, override || opts);
2195
+ Readable2.call(this, override || opts);
2196
2196
  var self2 = this;
2197
2197
  var hwm = this._readableState.highWaterMark;
2198
2198
  function check(err, data) {
@@ -7203,7 +7203,7 @@ var require_lib3 = __commonJS({
7203
7203
  var whatwgUrl = _interopDefault(require_public_api());
7204
7204
  var https = _interopDefault(require("https"));
7205
7205
  var zlib = _interopDefault(require("zlib"));
7206
- var Readable = Stream.Readable;
7206
+ var Readable2 = Stream.Readable;
7207
7207
  var BUFFER = Symbol("buffer");
7208
7208
  var TYPE = Symbol("type");
7209
7209
  var Blob = class _Blob {
@@ -7255,7 +7255,7 @@ var require_lib3 = __commonJS({
7255
7255
  return Promise.resolve(ab);
7256
7256
  }
7257
7257
  stream() {
7258
- const readable = new Readable();
7258
+ const readable = new Readable2();
7259
7259
  readable._read = function() {
7260
7260
  };
7261
7261
  readable.push(this[BUFFER]);
@@ -21848,11 +21848,13 @@ __export(src_exports, {
21848
21848
  findPackageJson: () => findPackageJson,
21849
21849
  functionsSchema: () => functionsSchema,
21850
21850
  generateNodeBuilderFunctions: () => generateNodeBuilderFunctions,
21851
+ getBuildResultMetadata: () => getBuildResultMetadata,
21851
21852
  getDiscontinuedNodeVersions: () => getDiscontinuedNodeVersions,
21852
21853
  getEncryptedEnv: () => getEncryptedEnv,
21853
21854
  getEnvForPackageManager: () => getEnvForPackageManager,
21854
21855
  getIgnoreFilter: () => get_ignore_filter_default,
21855
21856
  getInstalledPackageVersion: () => getInstalledPackageVersion,
21857
+ getLambdaByOutputPath: () => getLambdaByOutputPath,
21856
21858
  getLambdaEnvironment: () => getLambdaEnvironment,
21857
21859
  getLambdaOptionsFromFunction: () => getLambdaOptionsFromFunction,
21858
21860
  getLambdaPreloadScripts: () => getLambdaPreloadScripts,
@@ -21866,6 +21868,7 @@ __export(src_exports, {
21866
21868
  getPathForPackageManager: () => getPathForPackageManager,
21867
21869
  getPlatformEnv: () => getPlatformEnv,
21868
21870
  getPrefixedEnvVars: () => getPrefixedEnvVars,
21871
+ getPrerenderChain: () => getPrerenderChain,
21869
21872
  getPrettyError: () => getPrettyError,
21870
21873
  getProvidedRuntime: () => getProvidedRuntime,
21871
21874
  getScriptName: () => getScriptName,
@@ -21887,7 +21890,9 @@ __export(src_exports, {
21887
21890
  isNodeBackendFramework: () => isNodeBackendFramework,
21888
21891
  isPythonEntrypoint: () => isPythonEntrypoint,
21889
21892
  isPythonFramework: () => isPythonFramework,
21893
+ isRouteMiddleware: () => isRouteMiddleware,
21890
21894
  isSymbolicLink: () => isSymbolicLink,
21895
+ md5: () => md5,
21891
21896
  normalizePath: () => normalizePath,
21892
21897
  packageManifestSchema: () => packageManifestSchema,
21893
21898
  readConfigFile: () => readConfigFile,
@@ -21901,12 +21906,15 @@ __export(src_exports, {
21901
21906
  runShellScript: () => runShellScript,
21902
21907
  sanitizeConsumerName: () => sanitizeConsumerName,
21903
21908
  scanParentDirs: () => scanParentDirs,
21909
+ sha256: () => sha256,
21904
21910
  shouldServe: () => shouldServe,
21905
21911
  shouldUseExperimentalBackends: () => shouldUseExperimentalBackends,
21906
21912
  spawnAsync: () => spawnAsync,
21907
21913
  spawnCommand: () => spawnCommand,
21908
21914
  streamToBuffer: () => streamToBuffer,
21909
21915
  streamToBufferChunks: () => streamToBufferChunks,
21916
+ streamToDigestAsync: () => streamToDigestAsync,
21917
+ streamWithExtendedPayload: () => streamWithExtendedPayload,
21910
21918
  traverseUpDirectories: () => traverseUpDirectories,
21911
21919
  validateNpmrc: () => validateNpmrc,
21912
21920
  walkParentDirs: () => walkParentDirs
@@ -25479,6 +25487,163 @@ function streamToBuffer2(stream) {
25479
25487
  });
25480
25488
  });
25481
25489
  }
25490
+
25491
+ // src/fs/stream-to-digest-async.ts
25492
+ var import_crypto = require("crypto");
25493
+ async function streamToDigestAsync(stream) {
25494
+ return await new Promise((resolve, reject) => {
25495
+ stream.once("error", reject);
25496
+ let count = 0;
25497
+ const sha2562 = (0, import_crypto.createHash)("sha256");
25498
+ const md52 = (0, import_crypto.createHash)("md5");
25499
+ stream.on("end", () => {
25500
+ const res = {
25501
+ sha256: sha2562.digest("hex"),
25502
+ md5: md52.digest("hex"),
25503
+ size: count
25504
+ };
25505
+ resolve(res);
25506
+ });
25507
+ stream.on("readable", () => {
25508
+ let chunk;
25509
+ while (null !== (chunk = stream.read())) {
25510
+ md52.update(chunk);
25511
+ sha2562.update(chunk);
25512
+ count += chunk.length;
25513
+ }
25514
+ });
25515
+ });
25516
+ }
25517
+ function sha256(value) {
25518
+ return (0, import_crypto.createHash)("sha256").update(value).digest("hex");
25519
+ }
25520
+ function md5(value) {
25521
+ return (0, import_crypto.createHash)("md5").update(value).digest("hex");
25522
+ }
25523
+
25524
+ // src/collect-build-result/get-lambda-by-output-path.ts
25525
+ function getLambdaByOutputPath(params) {
25526
+ const output = params.buildOutputMap[params.outputPath];
25527
+ return output?.type === "Lambda" ? output : output?.type === "Prerender" ? output.lambda : void 0;
25528
+ }
25529
+
25530
+ // src/collect-build-result/get-prerender-chain.ts
25531
+ function getPrerenderChain(prerender) {
25532
+ if (prerender.chain) {
25533
+ return {
25534
+ outputPath: prerender.chain.outputPath,
25535
+ headers: prerender.chain.headers
25536
+ };
25537
+ }
25538
+ if (prerender.experimentalStreamingLambdaPath) {
25539
+ return {
25540
+ outputPath: prerender.experimentalStreamingLambdaPath,
25541
+ headers: {
25542
+ "x-matched-path": prerender.experimentalStreamingLambdaPath
25543
+ }
25544
+ };
25545
+ }
25546
+ return void 0;
25547
+ }
25548
+
25549
+ // src/collect-build-result/is-route-middleware.ts
25550
+ function isRouteMiddleware(route) {
25551
+ return "middlewarePath" in route && typeof route.middlewarePath === "string";
25552
+ }
25553
+
25554
+ // src/collect-build-result/get-build-result-metadata.ts
25555
+ function getBuildResultMetadata(params) {
25556
+ return {
25557
+ middleware: getMiddlewareMetadata(params),
25558
+ ppr: new Map(
25559
+ Object.entries(params.buildOutputMap).flatMap(([_outputPath, output]) => {
25560
+ if (output.type === "Prerender") {
25561
+ const chain = getPrerenderChain(output);
25562
+ if (chain) {
25563
+ const maybeLambda = getLambdaByOutputPath({
25564
+ buildOutputMap: params.buildOutputMap,
25565
+ outputPath: chain.outputPath
25566
+ });
25567
+ if (maybeLambda) {
25568
+ return [[chain.outputPath, true]];
25569
+ }
25570
+ }
25571
+ }
25572
+ return [];
25573
+ })
25574
+ )
25575
+ };
25576
+ }
25577
+ function getMiddlewareMetadata(params) {
25578
+ const deduped = new Map(
25579
+ params.routes.filter(isRouteMiddleware).map(
25580
+ (route) => toMiddlewareTuple({
25581
+ buildOutputMap: params.buildOutputMap,
25582
+ middlewarePath: route.middlewarePath
25583
+ })
25584
+ )
25585
+ );
25586
+ return new Map(
25587
+ Array.from(deduped, ([outputPath, metadata], index) => [
25588
+ outputPath,
25589
+ { ...metadata, index }
25590
+ ])
25591
+ );
25592
+ }
25593
+ function toMiddlewareTuple(params) {
25594
+ const keys = [
25595
+ params.middlewarePath,
25596
+ params.middlewarePath.replace(/^\//, "")
25597
+ ];
25598
+ const [outputPath, output] = Object.entries(params.buildOutputMap).find(
25599
+ (entry) => keys.includes(entry[0]) && (entry[1].type === "EdgeFunction" || entry[1].type === "Lambda")
25600
+ ) ?? [];
25601
+ if (!outputPath || !output) {
25602
+ throw new NowBuildError({
25603
+ message: `Mapping ${params.middlewarePath} not found. Maybe you provided a wrong middlewarePath?`,
25604
+ code: "middleware_path_not_found"
25605
+ });
25606
+ }
25607
+ return [
25608
+ outputPath,
25609
+ output.type === "EdgeFunction" ? {
25610
+ edgeFunction: output,
25611
+ match: new Set(keys),
25612
+ middlewarePath: params.middlewarePath,
25613
+ outputPath,
25614
+ type: "middleware"
25615
+ } : {
25616
+ match: new Set(keys),
25617
+ middlewarePath: params.middlewarePath,
25618
+ outputPath,
25619
+ type: "middleware-lambda"
25620
+ }
25621
+ ];
25622
+ }
25623
+
25624
+ // src/collect-build-result/stream-with-extended-payload.ts
25625
+ var import_stream = require("stream");
25626
+ function streamWithExtendedPayload(stream, data) {
25627
+ return data ? new MultipartContentStream(stream, data) : stream;
25628
+ }
25629
+ var MultipartContentStream = class extends import_stream.Readable {
25630
+ constructor(stream, data) {
25631
+ super();
25632
+ stream.on("error", (err) => {
25633
+ this.emit("error", err);
25634
+ });
25635
+ stream.on("end", () => {
25636
+ this.push(data.suffix);
25637
+ this.push(null);
25638
+ });
25639
+ this.push(data.prefix);
25640
+ stream.on("data", (chunk) => {
25641
+ this.push(chunk);
25642
+ });
25643
+ }
25644
+ _read() {
25645
+ }
25646
+ };
25482
25647
  // Annotate the CommonJS export names for ESM import in node:
25483
25648
  0 && (module.exports = {
25484
25649
  BACKEND_BUILDERS,
@@ -25512,11 +25677,13 @@ function streamToBuffer2(stream) {
25512
25677
  findPackageJson,
25513
25678
  functionsSchema,
25514
25679
  generateNodeBuilderFunctions,
25680
+ getBuildResultMetadata,
25515
25681
  getDiscontinuedNodeVersions,
25516
25682
  getEncryptedEnv,
25517
25683
  getEnvForPackageManager,
25518
25684
  getIgnoreFilter,
25519
25685
  getInstalledPackageVersion,
25686
+ getLambdaByOutputPath,
25520
25687
  getLambdaEnvironment,
25521
25688
  getLambdaOptionsFromFunction,
25522
25689
  getLambdaPreloadScripts,
@@ -25530,6 +25697,7 @@ function streamToBuffer2(stream) {
25530
25697
  getPathForPackageManager,
25531
25698
  getPlatformEnv,
25532
25699
  getPrefixedEnvVars,
25700
+ getPrerenderChain,
25533
25701
  getPrettyError,
25534
25702
  getProvidedRuntime,
25535
25703
  getScriptName,
@@ -25551,7 +25719,9 @@ function streamToBuffer2(stream) {
25551
25719
  isNodeBackendFramework,
25552
25720
  isPythonEntrypoint,
25553
25721
  isPythonFramework,
25722
+ isRouteMiddleware,
25554
25723
  isSymbolicLink,
25724
+ md5,
25555
25725
  normalizePath,
25556
25726
  packageManifestSchema,
25557
25727
  readConfigFile,
@@ -25565,12 +25735,15 @@ function streamToBuffer2(stream) {
25565
25735
  runShellScript,
25566
25736
  sanitizeConsumerName,
25567
25737
  scanParentDirs,
25738
+ sha256,
25568
25739
  shouldServe,
25569
25740
  shouldUseExperimentalBackends,
25570
25741
  spawnAsync,
25571
25742
  spawnCommand,
25572
25743
  streamToBuffer,
25573
25744
  streamToBufferChunks,
25745
+ streamToDigestAsync,
25746
+ streamWithExtendedPayload,
25574
25747
  traverseUpDirectories,
25575
25748
  validateNpmrc,
25576
25749
  walkParentDirs
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/build-utils",
3
- "version": "13.11.0",
3
+ "version": "13.12.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.js",
@@ -52,8 +52,8 @@
52
52
  "yazl": "2.5.1",
53
53
  "vitest": "2.0.1",
54
54
  "json5": "2.2.3",
55
- "@vercel/routing-utils": "6.1.1",
56
- "@vercel/error-utils": "2.0.3"
55
+ "@vercel/error-utils": "2.0.3",
56
+ "@vercel/routing-utils": "6.1.1"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "node build.mjs",