Socket
Book a DemoSign in
Socket

@vercel/build-utils

Package Overview
Dependencies
Maintainers
2
Versions
408
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vercel/build-utils - npm Package Compare versions

Comparing version
13.11.0
to
13.12.0
+33
dist/collect-build-result/get-build-result-metadata.d.ts
import type { Route } from '@vercel/routing-utils';
import type { EdgeFunction } from '../edge-function';
import type { File } from '../types';
import type { Lambda } from '../lambda';
import type { Prerender } from '../prerender';
export interface BuildResultMetadata {
middleware: Map<string, MiddlewareMeta>;
ppr: Map<string, boolean>;
}
/**
* Extract metadata about the build result that depend on the relationship
* between components in the build output. This data is later used to map to
* the infrastructure that we need to create.
*/
export declare function getBuildResultMetadata(params: {
buildOutputMap: Record<string, EdgeFunction | Lambda | Prerender | File>;
routes: Route[];
}): BuildResultMetadata;
type MiddlewareMeta = {
type: 'middleware';
middlewarePath: string;
outputPath: string;
match: Set<string>;
edgeFunction: EdgeFunction;
index: number;
} | {
type: 'middleware-lambda';
middlewarePath: string;
outputPath: string;
match: Set<string>;
index: number;
};
export {};
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var get_build_result_metadata_exports = {};
__export(get_build_result_metadata_exports, {
getBuildResultMetadata: () => getBuildResultMetadata
});
module.exports = __toCommonJS(get_build_result_metadata_exports);
var import_errors = require("../errors");
var import_get_lambda_by_output_path = require("./get-lambda-by-output-path");
var import_get_prerender_chain = require("./get-prerender-chain");
var import_is_route_middleware = require("./is-route-middleware");
function getBuildResultMetadata(params) {
return {
middleware: getMiddlewareMetadata(params),
ppr: new Map(
Object.entries(params.buildOutputMap).flatMap(([_outputPath, output]) => {
if (output.type === "Prerender") {
const chain = (0, import_get_prerender_chain.getPrerenderChain)(output);
if (chain) {
const maybeLambda = (0, import_get_lambda_by_output_path.getLambdaByOutputPath)({
buildOutputMap: params.buildOutputMap,
outputPath: chain.outputPath
});
if (maybeLambda) {
return [[chain.outputPath, true]];
}
}
}
return [];
})
)
};
}
function getMiddlewareMetadata(params) {
const deduped = new Map(
params.routes.filter(import_is_route_middleware.isRouteMiddleware).map(
(route) => toMiddlewareTuple({
buildOutputMap: params.buildOutputMap,
middlewarePath: route.middlewarePath
})
)
);
return new Map(
Array.from(deduped, ([outputPath, metadata], index) => [
outputPath,
{ ...metadata, index }
])
);
}
function toMiddlewareTuple(params) {
const keys = [
params.middlewarePath,
params.middlewarePath.replace(/^\//, "")
];
const [outputPath, output] = Object.entries(params.buildOutputMap).find(
(entry) => keys.includes(entry[0]) && (entry[1].type === "EdgeFunction" || entry[1].type === "Lambda")
) ?? [];
if (!outputPath || !output) {
throw new import_errors.NowBuildError({
message: `Mapping ${params.middlewarePath} not found. Maybe you provided a wrong middlewarePath?`,
code: "middleware_path_not_found"
});
}
return [
outputPath,
output.type === "EdgeFunction" ? {
edgeFunction: output,
match: new Set(keys),
middlewarePath: params.middlewarePath,
outputPath,
type: "middleware"
} : {
match: new Set(keys),
middlewarePath: params.middlewarePath,
outputPath,
type: "middleware-lambda"
}
];
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getBuildResultMetadata
});
import type { EdgeFunction } from '../edge-function';
import type { File } from '../types';
import type { Lambda } from '../lambda';
import type { Prerender } from '../prerender';
/**
* A Prerender can hold references to a Lambda or another Prerender when
* using PPR. This function retrieves the Lambda or Prerender from the
* build output map ensuring its type.
*/
export declare function getLambdaByOutputPath(params: {
buildOutputMap: Record<string, EdgeFunction | Lambda | Prerender | File>;
outputPath: string;
}): Lambda | undefined;
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var get_lambda_by_output_path_exports = {};
__export(get_lambda_by_output_path_exports, {
getLambdaByOutputPath: () => getLambdaByOutputPath
});
module.exports = __toCommonJS(get_lambda_by_output_path_exports);
function getLambdaByOutputPath(params) {
const output = params.buildOutputMap[params.outputPath];
return output?.type === "Lambda" ? output : output?.type === "Prerender" ? output.lambda : void 0;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getLambdaByOutputPath
});
import type { Chain } from '../types';
import type { Prerender } from '../prerender';
/**
* The Prerender chain can be defined as a `chain` property or as a flag
* `experimentalStreamingLambdaPath`. This function normalizes the chain
* to a single structure.
*/
export declare function getPrerenderChain(prerender: Prerender): Chain | undefined;
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var get_prerender_chain_exports = {};
__export(get_prerender_chain_exports, {
getPrerenderChain: () => getPrerenderChain
});
module.exports = __toCommonJS(get_prerender_chain_exports);
function getPrerenderChain(prerender) {
if (prerender.chain) {
return {
outputPath: prerender.chain.outputPath,
headers: prerender.chain.headers
};
}
if (prerender.experimentalStreamingLambdaPath) {
return {
outputPath: prerender.experimentalStreamingLambdaPath,
headers: {
"x-matched-path": prerender.experimentalStreamingLambdaPath
}
};
}
return void 0;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getPrerenderChain
});
import type { Route } from '@vercel/routing-utils';
export declare function isRouteMiddleware(route: Route): route is Route & {
middlewarePath: string;
};
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var is_route_middleware_exports = {};
__export(is_route_middleware_exports, {
isRouteMiddleware: () => isRouteMiddleware
});
module.exports = __toCommonJS(is_route_middleware_exports);
function isRouteMiddleware(route) {
return "middlewarePath" in route && typeof route.middlewarePath === "string";
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
isRouteMiddleware
});
/// <reference types="node" />
export interface ExtendedBodyData {
prefix: string;
suffix: string;
}
export declare function streamWithExtendedPayload(stream: NodeJS.ReadableStream, data?: ExtendedBodyData): NodeJS.ReadableStream;
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var stream_with_extended_payload_exports = {};
__export(stream_with_extended_payload_exports, {
streamWithExtendedPayload: () => streamWithExtendedPayload
});
module.exports = __toCommonJS(stream_with_extended_payload_exports);
var import_stream = require("stream");
function streamWithExtendedPayload(stream, data) {
return data ? new MultipartContentStream(stream, data) : stream;
}
class MultipartContentStream extends import_stream.Readable {
constructor(stream, data) {
super();
stream.on("error", (err) => {
this.emit("error", err);
});
stream.on("end", () => {
this.push(data.suffix);
this.push(null);
});
this.push(data.prefix);
stream.on("data", (chunk) => {
this.push(chunk);
});
}
_read() {
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
streamWithExtendedPayload
});
/// <reference types="node" />
/// <reference types="node" />
export interface FileDigest {
md5: string;
sha256: string;
size: number;
}
export declare function streamToDigestAsync(stream: NodeJS.ReadableStream): Promise<FileDigest>;
export declare function sha256(value: any): string;
export declare function md5(value: Buffer): string;
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var stream_to_digest_async_exports = {};
__export(stream_to_digest_async_exports, {
md5: () => md5,
sha256: () => sha256,
streamToDigestAsync: () => streamToDigestAsync
});
module.exports = __toCommonJS(stream_to_digest_async_exports);
var import_crypto = require("crypto");
async function streamToDigestAsync(stream) {
return await new Promise((resolve, reject) => {
stream.once("error", reject);
let count = 0;
const sha2562 = (0, import_crypto.createHash)("sha256");
const md52 = (0, import_crypto.createHash)("md5");
stream.on("end", () => {
const res = {
sha256: sha2562.digest("hex"),
md5: md52.digest("hex"),
size: count
};
resolve(res);
});
stream.on("readable", () => {
let chunk;
while (null !== (chunk = stream.read())) {
md52.update(chunk);
sha2562.update(chunk);
count += chunk.length;
}
});
});
}
function sha256(value) {
return (0, import_crypto.createHash)("sha256").update(value).digest("hex");
}
function md5(value) {
return (0, import_crypto.createHash)("md5").update(value).digest("hex");
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
md5,
sha256,
streamToDigestAsync
});
+6
-0
# @vercel/build-utils
## 13.12.0
### Minor Changes
- 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))
## 13.11.0

@@ -4,0 +10,0 @@

@@ -43,1 +43,7 @@ import FileBlob from './file-blob';

export { getLambdaSupportsStreaming, type SupportsStreamingResult, } from './process-serverless/get-lambda-supports-streaming';
export { streamToDigestAsync, sha256, md5, type FileDigest, } from './fs/stream-to-digest-async';
export { getBuildResultMetadata, type BuildResultMetadata, } from './collect-build-result/get-build-result-metadata';
export { getLambdaByOutputPath } from './collect-build-result/get-lambda-by-output-path';
export { isRouteMiddleware } from './collect-build-result/is-route-middleware';
export { getPrerenderChain } from './collect-build-result/get-prerender-chain';
export { streamWithExtendedPayload, type ExtendedBodyData, } from './collect-build-result/stream-with-extended-payload';
+3
-3
{
"name": "@vercel/build-utils",
"version": "13.11.0",
"version": "13.12.0",
"license": "Apache-2.0",

@@ -55,4 +55,4 @@ "main": "./dist/index.js",

"json5": "2.2.3",
"@vercel/routing-utils": "6.1.1",
"@vercel/error-utils": "2.0.3"
"@vercel/error-utils": "2.0.3",
"@vercel/routing-utils": "6.1.1"
},

@@ -59,0 +59,0 @@ "scripts": {

Sorry, the diff of this file is too big to display