@vercel/build-utils 9.2.0 → 9.3.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,17 @@
1
1
  # @vercel/build-utils
2
2
 
3
+ ## 9.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Support process tracing ([#12894](https://github.com/vercel/vercel/pull/12894))
8
+
9
+ ## 9.2.1
10
+
11
+ ### Patch Changes
12
+
13
+ - Add tracer utility to @vercel/build-utils ([#13013](https://github.com/vercel/vercel/pull/13013))
14
+
3
15
  ## 9.2.0
4
16
 
5
17
  ### Minor Changes
@@ -198,7 +198,7 @@ export declare function runCustomInstallCommand({ destPath, installCommand, node
198
198
  export declare function runPackageJsonScript(destPath: string, scriptNames: string | Iterable<string>, spawnOpts?: SpawnOptions): Promise<boolean>;
199
199
  export declare function runBundleInstall(destPath: string, args?: string[], spawnOpts?: SpawnOptions, meta?: Meta): Promise<void>;
200
200
  export declare function runPipInstall(destPath: string, args?: string[], spawnOpts?: SpawnOptions, meta?: Meta): Promise<void>;
201
- export declare function getScriptName(pkg: Pick<PackageJson, 'scripts'> | null | undefined, possibleNames: Iterable<string>): string | null;
201
+ export declare function getScriptName(pkg: Pick<PackageJson, 'scripts'> | null | undefined, possibleNames: Iterable<string>): string | undefined;
202
202
  /**
203
203
  * @deprecate installDependencies() is deprecated.
204
204
  * Please use runNpmInstall() instead.
@@ -909,7 +909,7 @@ function getScriptName(pkg, possibleNames) {
909
909
  }
910
910
  }
911
911
  }
912
- return null;
912
+ return void 0;
913
913
  }
914
914
  const installDependencies = (0, import_util.deprecate)(
915
915
  runNpmInstall,
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@ import download, { downloadFile, DownloadedFiles, isSymbolicLink, isDirectory }
8
8
  import getWriteableDirectory from './fs/get-writable-directory';
9
9
  import glob, { GlobOptions } from './fs/glob';
10
10
  import rename from './fs/rename';
11
- import { spawnAsync, execCommand, spawnCommand, walkParentDirs, getScriptName, installDependencies, runPackageJsonScript, runNpmInstall, runBundleInstall, runPipInstall, runShellScript, runCustomInstallCommand, getEnvForPackageManager, getNodeVersion, getPathForPackageManager, getSpawnOptions, getNodeBinPath, getNodeBinPaths, scanParentDirs, traverseUpDirectories } from './fs/run-user-scripts';
11
+ import { spawnAsync, execCommand, spawnCommand, walkParentDirs, getScriptName, installDependencies, runPackageJsonScript, runNpmInstall, runBundleInstall, runPipInstall, runShellScript, runCustomInstallCommand, getEnvForPackageManager, getNodeVersion, getPathForPackageManager, detectPackageManager, getSpawnOptions, getNodeBinPath, getNodeBinPaths, scanParentDirs, traverseUpDirectories } from './fs/run-user-scripts';
12
12
  import { getLatestNodeVersion, getDiscontinuedNodeVersions, getSupportedNodeVersion } from './fs/node-version';
13
13
  import streamToBuffer, { streamToBufferChunks } from './fs/stream-to-buffer';
14
14
  import debug from './debug';
@@ -18,7 +18,7 @@ import { getPrefixedEnvVars } from './get-prefixed-env-vars';
18
18
  import { cloneEnv } from './clone-env';
19
19
  import { hardLinkDir } from './hard-link-dir';
20
20
  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, runNpmInstall, runBundleInstall, runPipInstall, runShellScript, runCustomInstallCommand, getEnvForPackageManager, getNodeVersion, getPathForPackageManager, getLatestNodeVersion, getDiscontinuedNodeVersions, getSpawnOptions, getPlatformEnv, getPrefixedEnvVars, streamToBuffer, streamToBufferChunks, debug, isSymbolicLink, isDirectory, getLambdaOptionsFromFunction, scanParentDirs, getIgnoreFilter, cloneEnv, hardLinkDir, traverseUpDirectories, validateNpmrc, };
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, detectPackageManager, runNpmInstall, runBundleInstall, runPipInstall, runShellScript, runCustomInstallCommand, getEnvForPackageManager, getNodeVersion, getPathForPackageManager, getLatestNodeVersion, getDiscontinuedNodeVersions, getSpawnOptions, getPlatformEnv, getPrefixedEnvVars, streamToBuffer, streamToBufferChunks, debug, isSymbolicLink, isDirectory, getLambdaOptionsFromFunction, scanParentDirs, getIgnoreFilter, cloneEnv, hardLinkDir, traverseUpDirectories, validateNpmrc, };
22
22
  export { EdgeFunction } from './edge-function';
23
23
  export { readConfigFile } from './fs/read-config-file';
24
24
  export { normalizePath } from './fs/normalize-path';
@@ -27,6 +27,7 @@ export * from './should-serve';
27
27
  export * from './schemas';
28
28
  export * from './types';
29
29
  export * from './errors';
30
+ export * from './trace';
30
31
  export { NODE_VERSIONS } from './fs/node-version';
31
32
  export { getInstalledPackageVersion } from './get-installed-package-version';
32
33
  export { defaultCachePathGlob } from './default-cache-path-glob';
package/dist/index.js CHANGED
@@ -21845,6 +21845,8 @@ var require_ignore = __commonJS({
21845
21845
  // src/index.ts
21846
21846
  var src_exports = {};
21847
21847
  __export(src_exports, {
21848
+ BUILDER_COMPILE_STEP: () => BUILDER_COMPILE_STEP,
21849
+ BUILDER_INSTALLER_STEP: () => BUILDER_INSTALLER_STEP,
21848
21850
  EdgeFunction: () => EdgeFunction,
21849
21851
  FileBlob: () => FileBlob,
21850
21852
  FileFsRef: () => file_fs_ref_default,
@@ -21855,12 +21857,14 @@ __export(src_exports, {
21855
21857
  NodejsLambda: () => NodejsLambda,
21856
21858
  NowBuildError: () => NowBuildError,
21857
21859
  Prerender: () => Prerender,
21860
+ Span: () => Span,
21858
21861
  Version: () => Version,
21859
21862
  buildsSchema: () => buildsSchema,
21860
21863
  cloneEnv: () => cloneEnv,
21861
21864
  createLambda: () => createLambda,
21862
21865
  debug: () => debug,
21863
21866
  defaultCachePathGlob: () => defaultCachePathGlob,
21867
+ detectPackageManager: () => detectPackageManager,
21864
21868
  download: () => download,
21865
21869
  downloadFile: () => downloadFile,
21866
21870
  execCommand: () => execCommand,
@@ -23918,7 +23922,7 @@ function getScriptName(pkg, possibleNames) {
23918
23922
  }
23919
23923
  }
23920
23924
  }
23921
- return null;
23925
+ return void 0;
23922
23926
  }
23923
23927
  var installDependencies = (0, import_util2.deprecate)(
23924
23928
  runNpmInstall,
@@ -24225,6 +24229,77 @@ var buildsSchema = {
24225
24229
  }
24226
24230
  };
24227
24231
 
24232
+ // src/trace/trace.ts
24233
+ var import_node_crypto = require("crypto");
24234
+ var NUM_OF_MICROSEC_IN_NANOSEC = BigInt("1000");
24235
+ function mapUndefinedAttributes(attrs) {
24236
+ return Object.fromEntries(
24237
+ Object.entries(attrs ?? {}).filter(
24238
+ (attr) => !!attr[1]
24239
+ )
24240
+ );
24241
+ }
24242
+ var Span = class _Span {
24243
+ constructor({
24244
+ name,
24245
+ parentId,
24246
+ attrs,
24247
+ reporter
24248
+ }) {
24249
+ this.name = name;
24250
+ this.parentId = parentId;
24251
+ this.attrs = mapUndefinedAttributes(attrs);
24252
+ this.status = "started";
24253
+ this.id = (0, import_node_crypto.randomUUID)();
24254
+ this._reporter = reporter;
24255
+ this.now = Date.now();
24256
+ this._start = process.hrtime.bigint();
24257
+ }
24258
+ stop() {
24259
+ if (this.status === "stopped") {
24260
+ throw new Error(`Cannot stop a span which is already stopped`);
24261
+ }
24262
+ this.status = "stopped";
24263
+ const end = process.hrtime.bigint();
24264
+ const duration = Number((end - this._start) / NUM_OF_MICROSEC_IN_NANOSEC);
24265
+ const timestamp = Number(this._start / NUM_OF_MICROSEC_IN_NANOSEC);
24266
+ const traceEvent = {
24267
+ name: this.name,
24268
+ duration,
24269
+ timestamp,
24270
+ id: this.id,
24271
+ parentId: this.parentId,
24272
+ tags: this.attrs,
24273
+ startTime: this.now
24274
+ };
24275
+ if (this._reporter) {
24276
+ this._reporter.report(traceEvent);
24277
+ }
24278
+ }
24279
+ setAttributes(attrs) {
24280
+ Object.assign(this.attrs, mapUndefinedAttributes(attrs));
24281
+ }
24282
+ child(name, attrs) {
24283
+ return new _Span({
24284
+ name,
24285
+ parentId: this.id,
24286
+ attrs,
24287
+ reporter: this._reporter
24288
+ });
24289
+ }
24290
+ async trace(fn) {
24291
+ try {
24292
+ return await fn(this);
24293
+ } finally {
24294
+ this.stop();
24295
+ }
24296
+ }
24297
+ };
24298
+
24299
+ // src/trace/constants.ts
24300
+ var BUILDER_INSTALLER_STEP = "vc.builder.install";
24301
+ var BUILDER_COMPILE_STEP = "vc.builder.build";
24302
+
24228
24303
  // src/get-installed-package-version.ts
24229
24304
  async function getInstalledPackageVersion(packageName, path7) {
24230
24305
  try {
@@ -24246,6 +24321,8 @@ async function getInstalledPackageVersion(packageName, path7) {
24246
24321
  var defaultCachePathGlob = "**/{node_modules,.yarn/cache}/**";
24247
24322
  // Annotate the CommonJS export names for ESM import in node:
24248
24323
  0 && (module.exports = {
24324
+ BUILDER_COMPILE_STEP,
24325
+ BUILDER_INSTALLER_STEP,
24249
24326
  EdgeFunction,
24250
24327
  FileBlob,
24251
24328
  FileFsRef,
@@ -24256,12 +24333,14 @@ var defaultCachePathGlob = "**/{node_modules,.yarn/cache}/**";
24256
24333
  NodejsLambda,
24257
24334
  NowBuildError,
24258
24335
  Prerender,
24336
+ Span,
24259
24337
  Version,
24260
24338
  buildsSchema,
24261
24339
  cloneEnv,
24262
24340
  createLambda,
24263
24341
  debug,
24264
24342
  defaultCachePathGlob,
24343
+ detectPackageManager,
24265
24344
  download,
24266
24345
  downloadFile,
24267
24346
  execCommand,
@@ -0,0 +1,2 @@
1
+ export declare const BUILDER_INSTALLER_STEP = "vc.builder.install";
2
+ export declare const BUILDER_COMPILE_STEP = "vc.builder.build";
@@ -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 constants_exports = {};
20
+ __export(constants_exports, {
21
+ BUILDER_COMPILE_STEP: () => BUILDER_COMPILE_STEP,
22
+ BUILDER_INSTALLER_STEP: () => BUILDER_INSTALLER_STEP
23
+ });
24
+ module.exports = __toCommonJS(constants_exports);
25
+ const BUILDER_INSTALLER_STEP = "vc.builder.install";
26
+ const BUILDER_COMPILE_STEP = "vc.builder.build";
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ BUILDER_COMPILE_STEP,
30
+ BUILDER_INSTALLER_STEP
31
+ });
@@ -0,0 +1,3 @@
1
+ export { Span } from './trace';
2
+ export { BUILDER_COMPILE_STEP, BUILDER_INSTALLER_STEP } from './constants';
3
+ export type { SpanId, TraceEvent, Reporter } from './trace';
@@ -0,0 +1,33 @@
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 trace_exports = {};
20
+ __export(trace_exports, {
21
+ BUILDER_COMPILE_STEP: () => import_constants.BUILDER_COMPILE_STEP,
22
+ BUILDER_INSTALLER_STEP: () => import_constants.BUILDER_INSTALLER_STEP,
23
+ Span: () => import_trace.Span
24
+ });
25
+ module.exports = __toCommonJS(trace_exports);
26
+ var import_trace = require("./trace");
27
+ var import_constants = require("./constants");
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {
30
+ BUILDER_COMPILE_STEP,
31
+ BUILDER_INSTALLER_STEP,
32
+ Span
33
+ });
@@ -0,0 +1,37 @@
1
+ export type SpanId = string;
2
+ export type TraceEvent = {
3
+ parentId?: SpanId;
4
+ name: string;
5
+ id: SpanId;
6
+ timestamp: number;
7
+ duration: number;
8
+ tags: Record<string, string>;
9
+ startTime: number;
10
+ };
11
+ export type Reporter = {
12
+ report: (event: TraceEvent) => void;
13
+ };
14
+ interface Attributes {
15
+ [key: string]: string | undefined;
16
+ }
17
+ export declare class Span {
18
+ private name;
19
+ private id;
20
+ private parentId?;
21
+ private attrs;
22
+ private status;
23
+ private _start;
24
+ private now;
25
+ private _reporter;
26
+ constructor({ name, parentId, attrs, reporter, }: {
27
+ name: string;
28
+ parentId?: SpanId;
29
+ attrs?: Attributes;
30
+ reporter?: Reporter;
31
+ });
32
+ stop(): void;
33
+ setAttributes(attrs: Attributes): void;
34
+ child(name: string, attrs?: Attributes): Span;
35
+ trace<T>(fn: (span: Span) => T | Promise<T>): Promise<T>;
36
+ }
37
+ export {};
@@ -0,0 +1,92 @@
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 trace_exports = {};
20
+ __export(trace_exports, {
21
+ Span: () => Span
22
+ });
23
+ module.exports = __toCommonJS(trace_exports);
24
+ var import_node_crypto = require("node:crypto");
25
+ const NUM_OF_MICROSEC_IN_NANOSEC = BigInt("1000");
26
+ function mapUndefinedAttributes(attrs) {
27
+ return Object.fromEntries(
28
+ Object.entries(attrs ?? {}).filter(
29
+ (attr) => !!attr[1]
30
+ )
31
+ );
32
+ }
33
+ class Span {
34
+ constructor({
35
+ name,
36
+ parentId,
37
+ attrs,
38
+ reporter
39
+ }) {
40
+ this.name = name;
41
+ this.parentId = parentId;
42
+ this.attrs = mapUndefinedAttributes(attrs);
43
+ this.status = "started";
44
+ this.id = (0, import_node_crypto.randomUUID)();
45
+ this._reporter = reporter;
46
+ this.now = Date.now();
47
+ this._start = process.hrtime.bigint();
48
+ }
49
+ stop() {
50
+ if (this.status === "stopped") {
51
+ throw new Error(`Cannot stop a span which is already stopped`);
52
+ }
53
+ this.status = "stopped";
54
+ const end = process.hrtime.bigint();
55
+ const duration = Number((end - this._start) / NUM_OF_MICROSEC_IN_NANOSEC);
56
+ const timestamp = Number(this._start / NUM_OF_MICROSEC_IN_NANOSEC);
57
+ const traceEvent = {
58
+ name: this.name,
59
+ duration,
60
+ timestamp,
61
+ id: this.id,
62
+ parentId: this.parentId,
63
+ tags: this.attrs,
64
+ startTime: this.now
65
+ };
66
+ if (this._reporter) {
67
+ this._reporter.report(traceEvent);
68
+ }
69
+ }
70
+ setAttributes(attrs) {
71
+ Object.assign(this.attrs, mapUndefinedAttributes(attrs));
72
+ }
73
+ child(name, attrs) {
74
+ return new Span({
75
+ name,
76
+ parentId: this.id,
77
+ attrs,
78
+ reporter: this._reporter
79
+ });
80
+ }
81
+ async trace(fn) {
82
+ try {
83
+ return await fn(this);
84
+ } finally {
85
+ this.stop();
86
+ }
87
+ }
88
+ }
89
+ // Annotate the CommonJS export names for ESM import in node:
90
+ 0 && (module.exports = {
91
+ Span
92
+ });
package/dist/types.d.ts CHANGED
@@ -5,6 +5,7 @@ import type FileBlob from './file-blob';
5
5
  import type { Lambda } from './lambda';
6
6
  import type { Prerender } from './prerender';
7
7
  import type { EdgeFunction } from './edge-function';
8
+ import type { Span } from './trace';
8
9
  export interface Env {
9
10
  [name: string]: string | undefined;
10
11
  }
@@ -102,6 +103,10 @@ export interface BuildOptions {
102
103
  * fully processed
103
104
  */
104
105
  buildCallback?: (opts: Omit<BuildOptions, 'buildCallback'>) => Promise<void>;
106
+ /**
107
+ * The current trace state from the internal vc tracing
108
+ */
109
+ span?: Span;
105
110
  }
106
111
  export interface PrepareCacheOptions {
107
112
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/build-utils",
3
- "version": "9.2.0",
3
+ "version": "9.3.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.js",