@vercel/build-utils 13.3.1 → 13.3.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 CHANGED
@@ -1,5 +1,16 @@
1
1
  # @vercel/build-utils
2
2
 
3
+ ## 13.3.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Improve memory efficiency in `FileBlob.fromStream()` by avoiding unnecessary buffer copies when chunks are already Buffers ([#14701](https://github.com/vercel/vercel/pull/14701))
8
+
9
+ - [services] build time service url env vars ([#14893](https://github.com/vercel/vercel/pull/14893))
10
+
11
+ - Updated dependencies [[`7a747344dfb778a650da2ee5f7fba8c974098b42`](https://github.com/vercel/vercel/commit/7a747344dfb778a650da2ee5f7fba8c974098b42)]:
12
+ - @vercel/python-analysis@0.3.1
13
+
3
14
  ## 13.3.1
4
15
 
5
16
  ### Patch Changes
package/dist/file-blob.js CHANGED
@@ -51,7 +51,14 @@ class FileBlob {
51
51
  (0, import_assert.default)(typeof stream.pipe === "function");
52
52
  const chunks = [];
53
53
  await new Promise((resolve, reject) => {
54
- stream.on("data", (chunk) => chunks.push(Buffer.from(chunk)));
54
+ stream.on(
55
+ "data",
56
+ (chunk) => (
57
+ // Usually the chunks we receive here are already buffers, so we
58
+ // avoid the extra buffer copy in those cases to save memory
59
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk))
60
+ )
61
+ );
55
62
  stream.on("error", (error) => reject(error));
56
63
  stream.on("end", () => resolve());
57
64
  });
@@ -0,0 +1,28 @@
1
+ import type { Service } from './types';
2
+ type Envs = {
3
+ [key: string]: string | undefined;
4
+ };
5
+ interface FrameworkInfo {
6
+ slug: string | null;
7
+ envPrefix?: string;
8
+ }
9
+ export interface GetServiceUrlEnvVarsOptions {
10
+ services: Service[];
11
+ frameworkList: readonly FrameworkInfo[];
12
+ currentEnv?: Envs;
13
+ deploymentUrl?: string;
14
+ }
15
+ /**
16
+ * Generate environment variables for service URLs.
17
+ *
18
+ * For each web service, generates:
19
+ * 1. A base env var (e.g., BACKEND_URL)
20
+ * 2. Framework-prefixed versions for each frontend framework in the deployment
21
+ * (e.g., VITE_BACKEND_URL, NEXT_PUBLIC_BACKEND_URL) so they can be accessed
22
+ * in client-side code.
23
+ *
24
+ * Environment variables that are already set in `currentEnv` will NOT be overwritten,
25
+ * allowing user-defined values to take precedence.
26
+ */
27
+ export declare function getServiceUrlEnvVars(options: GetServiceUrlEnvVarsOptions): Record<string, string>;
28
+ export {};
@@ -0,0 +1,76 @@
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_service_url_env_vars_exports = {};
20
+ __export(get_service_url_env_vars_exports, {
21
+ getServiceUrlEnvVars: () => getServiceUrlEnvVars
22
+ });
23
+ module.exports = __toCommonJS(get_service_url_env_vars_exports);
24
+ function serviceNameToEnvVar(name) {
25
+ return `${name.replace(/-/g, "_").toUpperCase()}_URL`;
26
+ }
27
+ function computeServiceUrl(deploymentUrl, routePrefix) {
28
+ if (routePrefix === "/") {
29
+ return `https://${deploymentUrl}`;
30
+ }
31
+ const normalizedPrefix = routePrefix.startsWith("/") ? routePrefix.slice(1) : routePrefix;
32
+ return `https://${deploymentUrl}/${normalizedPrefix}`;
33
+ }
34
+ function getFrameworkEnvPrefix(frameworkSlug, frameworkList) {
35
+ if (!frameworkSlug)
36
+ return void 0;
37
+ const framework = frameworkList.find(
38
+ (f) => f.slug !== null && f.slug === frameworkSlug
39
+ );
40
+ return framework?.envPrefix;
41
+ }
42
+ function getServiceUrlEnvVars(options) {
43
+ const { services, frameworkList, currentEnv = {}, deploymentUrl } = options;
44
+ if (!deploymentUrl || !services || services.length === 0) {
45
+ return {};
46
+ }
47
+ const envVars = {};
48
+ const frameworkPrefixes = /* @__PURE__ */ new Set();
49
+ for (const service of services) {
50
+ const prefix = getFrameworkEnvPrefix(service.framework, frameworkList);
51
+ if (prefix) {
52
+ frameworkPrefixes.add(prefix);
53
+ }
54
+ }
55
+ for (const service of services) {
56
+ if (service.type !== "web" || !service.routePrefix) {
57
+ continue;
58
+ }
59
+ const baseEnvVarName = serviceNameToEnvVar(service.name);
60
+ const url = computeServiceUrl(deploymentUrl, service.routePrefix);
61
+ if (!(baseEnvVarName in currentEnv)) {
62
+ envVars[baseEnvVarName] = url;
63
+ }
64
+ for (const prefix of frameworkPrefixes) {
65
+ const prefixedEnvVarName = `${prefix}${baseEnvVarName}`;
66
+ if (!(prefixedEnvVarName in currentEnv)) {
67
+ envVars[prefixedEnvVarName] = url;
68
+ }
69
+ }
70
+ }
71
+ return envVars;
72
+ }
73
+ // Annotate the CommonJS export names for ESM import in node:
74
+ 0 && (module.exports = {
75
+ getServiceUrlEnvVars
76
+ });
package/dist/index.d.ts CHANGED
@@ -15,10 +15,11 @@ import debug from './debug';
15
15
  import getIgnoreFilter from './get-ignore-filter';
16
16
  import { getPlatformEnv } from './get-platform-env';
17
17
  import { getPrefixedEnvVars } from './get-prefixed-env-vars';
18
+ import { getServiceUrlEnvVars } from './get-service-url-env-vars';
18
19
  import { cloneEnv } from './clone-env';
19
20
  import { hardLinkDir } from './hard-link-dir';
20
21
  import { validateNpmrc } from './validate-npmrc';
21
- export { FileBlob, FileFsRef, FileRef, Lambda, NodejsLambda, createLambda, Prerender, download, downloadFile, DownloadedFiles, getWriteableDirectory, glob, GlobOptions, rename, spawnAsync, getScriptName, installDependencies, runPackageJsonScript, execCommand, spawnCommand, walkParentDirs, getNodeBinPath, getNodeBinPaths, getSupportedNodeVersion, isBunVersion, getSupportedBunVersion, detectPackageManager, runNpmInstall, runBundleInstall, runPipInstall, PipInstallResult, runShellScript, runCustomInstallCommand, resetCustomInstallCommandSet, getEnvForPackageManager, getNodeVersion, getPathForPackageManager, getLatestNodeVersion, getDiscontinuedNodeVersions, getSpawnOptions, getPlatformEnv, getPrefixedEnvVars, streamToBuffer, streamToBufferChunks, debug, isSymbolicLink, isDirectory, getLambdaOptionsFromFunction, scanParentDirs, findPackageJson, getIgnoreFilter, cloneEnv, hardLinkDir, traverseUpDirectories, validateNpmrc, };
22
+ export { FileBlob, FileFsRef, FileRef, Lambda, NodejsLambda, createLambda, Prerender, download, downloadFile, DownloadedFiles, getWriteableDirectory, glob, GlobOptions, rename, spawnAsync, getScriptName, installDependencies, runPackageJsonScript, execCommand, spawnCommand, walkParentDirs, getNodeBinPath, getNodeBinPaths, getSupportedNodeVersion, isBunVersion, getSupportedBunVersion, detectPackageManager, runNpmInstall, runBundleInstall, runPipInstall, PipInstallResult, runShellScript, runCustomInstallCommand, resetCustomInstallCommandSet, getEnvForPackageManager, getNodeVersion, getPathForPackageManager, getLatestNodeVersion, getDiscontinuedNodeVersions, getSpawnOptions, getPlatformEnv, getPrefixedEnvVars, getServiceUrlEnvVars, streamToBuffer, streamToBufferChunks, debug, isSymbolicLink, isDirectory, getLambdaOptionsFromFunction, scanParentDirs, findPackageJson, getIgnoreFilter, cloneEnv, hardLinkDir, traverseUpDirectories, validateNpmrc, };
22
23
  export { EdgeFunction } from './edge-function';
23
24
  export { readConfigFile, getPackageJson } from './fs/read-config-file';
24
25
  export { normalizePath } from './fs/normalize-path';
package/dist/index.js CHANGED
@@ -21865,6 +21865,7 @@ __export(src_exports, {
21865
21865
  getPrettyError: () => getPrettyError,
21866
21866
  getProvidedRuntime: () => getProvidedRuntime,
21867
21867
  getScriptName: () => getScriptName,
21868
+ getServiceUrlEnvVars: () => getServiceUrlEnvVars,
21868
21869
  getSpawnOptions: () => getSpawnOptions,
21869
21870
  getSupportedBunVersion: () => getSupportedBunVersion,
21870
21871
  getSupportedNodeVersion: () => getSupportedNodeVersion,
@@ -21925,7 +21926,14 @@ var FileBlob = class _FileBlob {
21925
21926
  (0, import_assert.default)(typeof stream.pipe === "function");
21926
21927
  const chunks = [];
21927
21928
  await new Promise((resolve, reject) => {
21928
- stream.on("data", (chunk) => chunks.push(Buffer.from(chunk)));
21929
+ stream.on(
21930
+ "data",
21931
+ (chunk) => (
21932
+ // Usually the chunks we receive here are already buffers, so we
21933
+ // avoid the extra buffer copy in those cases to save memory
21934
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk))
21935
+ )
21936
+ );
21929
21937
  stream.on("error", (error) => reject(error));
21930
21938
  stream.on("end", () => resolve());
21931
21939
  });
@@ -24351,6 +24359,57 @@ function getPrefixedEnvVars({
24351
24359
  return newEnvs;
24352
24360
  }
24353
24361
 
24362
+ // src/get-service-url-env-vars.ts
24363
+ function serviceNameToEnvVar(name) {
24364
+ return `${name.replace(/-/g, "_").toUpperCase()}_URL`;
24365
+ }
24366
+ function computeServiceUrl(deploymentUrl, routePrefix) {
24367
+ if (routePrefix === "/") {
24368
+ return `https://${deploymentUrl}`;
24369
+ }
24370
+ const normalizedPrefix = routePrefix.startsWith("/") ? routePrefix.slice(1) : routePrefix;
24371
+ return `https://${deploymentUrl}/${normalizedPrefix}`;
24372
+ }
24373
+ function getFrameworkEnvPrefix(frameworkSlug, frameworkList) {
24374
+ if (!frameworkSlug)
24375
+ return void 0;
24376
+ const framework = frameworkList.find(
24377
+ (f) => f.slug !== null && f.slug === frameworkSlug
24378
+ );
24379
+ return framework?.envPrefix;
24380
+ }
24381
+ function getServiceUrlEnvVars(options) {
24382
+ const { services, frameworkList, currentEnv = {}, deploymentUrl } = options;
24383
+ if (!deploymentUrl || !services || services.length === 0) {
24384
+ return {};
24385
+ }
24386
+ const envVars = {};
24387
+ const frameworkPrefixes = /* @__PURE__ */ new Set();
24388
+ for (const service of services) {
24389
+ const prefix = getFrameworkEnvPrefix(service.framework, frameworkList);
24390
+ if (prefix) {
24391
+ frameworkPrefixes.add(prefix);
24392
+ }
24393
+ }
24394
+ for (const service of services) {
24395
+ if (service.type !== "web" || !service.routePrefix) {
24396
+ continue;
24397
+ }
24398
+ const baseEnvVarName = serviceNameToEnvVar(service.name);
24399
+ const url = computeServiceUrl(deploymentUrl, service.routePrefix);
24400
+ if (!(baseEnvVarName in currentEnv)) {
24401
+ envVars[baseEnvVarName] = url;
24402
+ }
24403
+ for (const prefix of frameworkPrefixes) {
24404
+ const prefixedEnvVarName = `${prefix}${baseEnvVarName}`;
24405
+ if (!(prefixedEnvVarName in currentEnv)) {
24406
+ envVars[prefixedEnvVarName] = url;
24407
+ }
24408
+ }
24409
+ }
24410
+ return envVars;
24411
+ }
24412
+
24354
24413
  // src/hard-link-dir.ts
24355
24414
  var import_path8 = __toESM(require("path"));
24356
24415
  var import_fs2 = require("fs");
@@ -24985,6 +25044,7 @@ async function isPythonEntrypoint(file) {
24985
25044
  getPrettyError,
24986
25045
  getProvidedRuntime,
24987
25046
  getScriptName,
25047
+ getServiceUrlEnvVars,
24988
25048
  getSpawnOptions,
24989
25049
  getSupportedBunVersion,
24990
25050
  getSupportedNodeVersion,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/build-utils",
3
- "version": "13.3.1",
3
+ "version": "13.3.2",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.js",
@@ -11,7 +11,7 @@
11
11
  "directory": "packages/now-build-utils"
12
12
  },
13
13
  "dependencies": {
14
- "@vercel/python-analysis": "0.3.0"
14
+ "@vercel/python-analysis": "0.3.1"
15
15
  },
16
16
  "devDependencies": {
17
17
  "@iarna/toml": "2.2.3",
@@ -50,8 +50,8 @@
50
50
  "yazl": "2.5.1",
51
51
  "vitest": "2.0.1",
52
52
  "json5": "2.2.3",
53
- "@vercel/error-utils": "2.0.3",
54
- "@vercel/routing-utils": "5.3.2"
53
+ "@vercel/routing-utils": "5.3.2",
54
+ "@vercel/error-utils": "2.0.3"
55
55
  },
56
56
  "scripts": {
57
57
  "build": "node build.mjs",