@netlify/build 29.28.0 → 29.28.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.
@@ -169,6 +169,11 @@ export const FLAGS: {
169
169
  describe: string;
170
170
  hidden: boolean;
171
171
  };
172
+ 'tracing.preloadingEnabled': {
173
+ boolean: boolean;
174
+ describe: string;
175
+ hidden: boolean;
176
+ };
172
177
  'tracing.apiKey': {
173
178
  string: boolean;
174
179
  describe: string;
package/lib/core/flags.js CHANGED
@@ -202,6 +202,11 @@ Default: false`,
202
202
  describe: 'Enable distributed tracing for build',
203
203
  hidden: true,
204
204
  },
205
+ 'tracing.preloadingEnabled': {
206
+ boolean: true,
207
+ describe: 'Enable distributed tracing for build via module preloading, to be removed once fully rolled out',
208
+ hidden: true,
209
+ },
205
210
  'tracing.apiKey': {
206
211
  string: true,
207
212
  describe: 'API Key for the tracing backend provider',
@@ -58,6 +58,7 @@ const getDefaultFlags = function ({ env: envOpt = {} }, combinedEnv) {
58
58
  // honeycomb directly - https://github.com/honeycombio/honeycomb-opentelemetry-node/issues/201
59
59
  tracing: {
60
60
  enabled: false,
61
+ preloadingEnabled: false,
61
62
  apiKey: '-',
62
63
  // defaults to always sample
63
64
  sampleRate: 1,
@@ -76,6 +76,7 @@ export type ErrorParam = {
76
76
  };
77
77
  export type TracingOptions = {
78
78
  enabled: boolean;
79
+ preloadingEnabled: boolean;
79
80
  httpProtocol: string;
80
81
  host: string;
81
82
  port: number;
@@ -1,16 +1,13 @@
1
- export function serializeErrorStatus({ fullErrorInfo: { title, message, locationInfo, errorProps, errorMetadata }, state, }: {
2
- fullErrorInfo: {
3
- title: any;
4
- message: any;
5
- locationInfo: any;
6
- errorProps: any;
7
- errorMetadata: any;
8
- };
9
- state: any;
10
- }): {
11
- state: any;
12
- title: any;
13
- summary: any;
1
+ import type { BuildError } from '../types.js';
2
+ type ErrorState = 'failed_build' | 'failed_plugin' | 'canceled_build';
3
+ export declare const serializeErrorStatus: ({ fullErrorInfo: { title, message, locationInfo, errorProps, errorMetadata }, state, }: {
4
+ fullErrorInfo: BuildError;
5
+ state: ErrorState;
6
+ }) => {
7
+ state: ErrorState;
8
+ title: string | (import("../types.js").TitleFunction & string);
9
+ summary: string;
14
10
  text: string | undefined;
15
11
  extraData: any;
16
12
  };
13
+ export {};
@@ -1,4 +1,4 @@
1
- // Serialize an error object to `statuses` properties
1
+ /* Serialize an error object to `statuses` properties */
2
2
  export const serializeErrorStatus = function ({ fullErrorInfo: { title, message, locationInfo, errorProps, errorMetadata }, state, }) {
3
3
  const text = getText({ locationInfo, errorProps });
4
4
  return { state, title, summary: message, text, extraData: errorMetadata };
@@ -165,10 +165,11 @@ declare const ErrorTypeMap: {
165
165
  readonly pluginInternal: "pluginInternal";
166
166
  readonly ipc: "ipc";
167
167
  readonly corePlugin: "corePlugin";
168
+ readonly trustedPlugin: "trustedPlugin";
168
169
  readonly coreStep: "coreStep";
169
170
  readonly api: "api";
170
171
  readonly exception: "exception";
171
172
  readonly telemetry: "telemetry";
172
173
  };
173
- type ErrorTypes = keyof typeof ErrorTypeMap;
174
+ export type ErrorTypes = keyof typeof ErrorTypeMap;
174
175
  export {};
@@ -141,6 +141,7 @@ const ErrorTypeMap = {
141
141
  pluginInternal: 'pluginInternal',
142
142
  ipc: 'ipc',
143
143
  corePlugin: 'corePlugin',
144
+ trustedPlugin: 'trustedPlugin',
144
145
  coreStep: 'coreStep',
145
146
  api: 'api',
146
147
  exception: 'exception',
@@ -293,6 +294,17 @@ const TYPES = {
293
294
  locationType: 'buildFail',
294
295
  severity: 'error',
295
296
  },
297
+ /**
298
+ * Trusted plugin internal error (all of our `@netlify/*` plugins).
299
+ */
300
+ trustedPlugin: {
301
+ title: ({ location: { packageName } }) => `Plugin "${packageName}" internal error`,
302
+ stackType: 'stack',
303
+ showErrorProps: true,
304
+ rawStack: true,
305
+ locationType: 'buildFail',
306
+ severity: 'error',
307
+ },
296
308
  /**
297
309
  * Core step internal error
298
310
  */
@@ -31,10 +31,14 @@ const startPlugin = async function ({ pluginDir, nodePath, buildDir, childEnv, s
31
31
  preferLocal: true,
32
32
  localDir: pluginDir,
33
33
  nodePath,
34
+ // make sure we don't pass build's node cli properties for now (e.g. --import)
35
+ nodeOptions: [],
34
36
  execPath: nodePath,
35
37
  env: childEnv,
36
38
  extendEnv: false,
37
- stdio: isTrustedPlugin(pluginPackageJson) && systemLogFile ? ['pipe', 'pipe', 'pipe', 'ipc', systemLogFile] : undefined,
39
+ stdio: isTrustedPlugin(pluginPackageJson?.name) && systemLogFile
40
+ ? ['pipe', 'pipe', 'pipe', 'ipc', systemLogFile]
41
+ : undefined,
38
42
  });
39
43
  try {
40
44
  await getEventFromChild(childProcess, 'ready');
@@ -1,4 +1,14 @@
1
- export function handleStepError({ event, newError, childEnv, mode, api, errorMonitor, deployId, coreStep, netlifyConfig, logs, debug, testOpts, }: {
1
+ import { ErrorTypes } from '../error/types.js';
2
+ /**
3
+ * Handle build command errors and plugin errors:
4
+ * - usually, propagate the error to make the build stop.
5
+ * - `utils.build.cancelBuild()` also cancels the build by calling the API
6
+ * - `utils.build.failPlugin()` or post-deploy errors do not make the build
7
+ * stop, but are still reported, and prevent future events from the same
8
+ * plugin.
9
+ * This also computes error statuses that are sent to the API.
10
+ */
11
+ export declare const handleStepError: ({ event, newError, childEnv, mode, api, errorMonitor, deployId, coreStep, netlifyConfig, logs, debug, testOpts, }: {
2
12
  event: any;
3
13
  newError: any;
4
14
  childEnv: any;
@@ -11,38 +21,36 @@ export function handleStepError({ event, newError, childEnv, mode, api, errorMon
11
21
  logs: any;
12
22
  debug: any;
13
23
  testOpts: any;
14
- }): Promise<{
15
- failedPlugin: any[];
24
+ }) => Promise<{
25
+ failedPlugin: string[];
16
26
  newStatus: {
17
- state: any;
18
- title: any;
19
- summary: any;
27
+ state: "failed_build" | "failed_plugin" | "canceled_build";
28
+ title: string | (import("../error/types.js").TitleFunction & string);
29
+ summary: string;
20
30
  text: string | undefined;
21
31
  extraData: any;
22
32
  };
23
33
  }> | Promise<{
24
34
  newError: any;
25
35
  newStatus: {
26
- state: any;
27
- title: any;
28
- summary: any;
36
+ state: "failed_build" | "failed_plugin" | "canceled_build";
37
+ title: string | (import("../error/types.js").TitleFunction & string);
38
+ summary: string;
29
39
  text: string | undefined;
30
40
  extraData: any;
31
41
  };
32
42
  }> | {
33
43
  newError: any;
34
44
  newStatus: {
35
- state: any;
36
- title: any;
37
- summary: any;
45
+ state: "failed_build" | "failed_plugin" | "canceled_build";
46
+ title: string | (import("../error/types.js").TitleFunction & string);
47
+ summary: string;
38
48
  text: string | undefined;
39
49
  extraData: any;
40
50
  };
41
51
  } | {
42
52
  newError: any;
43
53
  };
44
- export function getPluginErrorType(error: any, loadedFrom: any): {
45
- type?: undefined;
46
- } | {
47
- type: string;
54
+ export declare const getPluginErrorType: (error: Error, loadedFrom: string, packageName?: string) => {
55
+ type?: ErrorTypes;
48
56
  };
@@ -2,15 +2,19 @@ import { cancelBuild } from '../error/cancel.js';
2
2
  import { handleBuildError } from '../error/handle.js';
3
3
  import { getFullErrorInfo, parseErrorInfo } from '../error/parse/parse.js';
4
4
  import { serializeErrorStatus } from '../error/parse/serialize_status.js';
5
+ import { isPluginLocation } from '../error/types.js';
5
6
  import { isSoftFailEvent } from '../plugins/events.js';
6
7
  import { addErrorToActiveSpan, addEventToActiveSpan } from '../tracing/main.js';
7
- // Handle build command errors and plugin errors:
8
- // - usually, propagate the error to make the build stop.
9
- // - `utils.build.cancelBuild()` also cancels the build by calling the API
10
- // - `utils.build.failPlugin()` or post-deploy errors do not make the build
11
- // stop, but are still reported, and prevent future events from the same
12
- // plugin.
13
- // This also computes error statuses that are sent to the API.
8
+ import { isTrustedPlugin } from './plugin.js';
9
+ /**
10
+ * Handle build command errors and plugin errors:
11
+ * - usually, propagate the error to make the build stop.
12
+ * - `utils.build.cancelBuild()` also cancels the build by calling the API
13
+ * - `utils.build.failPlugin()` or post-deploy errors do not make the build
14
+ * stop, but are still reported, and prevent future events from the same
15
+ * plugin.
16
+ * This also computes error statuses that are sent to the API.
17
+ */
14
18
  export const handleStepError = function ({ event, newError, childEnv, mode, api, errorMonitor, deployId, coreStep, netlifyConfig, logs, debug, testOpts, }) {
15
19
  addErrorToActiveSpan(newError);
16
20
  // Core steps do not report error statuses
@@ -18,7 +22,7 @@ export const handleStepError = function ({ event, newError, childEnv, mode, api,
18
22
  return { newError };
19
23
  }
20
24
  const fullErrorInfo = getFullErrorInfo({ error: newError, colors: false, debug });
21
- const { errorInfo: { location: { packageName } = {} }, message, title, type, } = fullErrorInfo;
25
+ const { errorInfo, message, title, type } = fullErrorInfo;
22
26
  if (type === 'failPlugin' || isSoftFailEvent(event)) {
23
27
  return handleFailPlugin({
24
28
  fullErrorInfo,
@@ -36,32 +40,40 @@ export const handleStepError = function ({ event, newError, childEnv, mode, api,
36
40
  const cancellationAttributes = {
37
41
  'build.cancellation.title': title,
38
42
  'build.cancellation.message': message,
39
- 'build.cancellation.packageName': packageName,
40
43
  };
44
+ if (isPluginLocation(errorInfo.location)) {
45
+ cancellationAttributes['build.cancellation.packageName'] = errorInfo.location.packageName;
46
+ }
41
47
  addEventToActiveSpan('build.cancelled', cancellationAttributes);
42
48
  return handleCancelBuild({ fullErrorInfo, newError, api, deployId });
43
49
  }
44
50
  return handleFailBuild({ fullErrorInfo, newError });
45
51
  };
46
- // On `utils.build.failPlugin()` or during `onSuccess` or `onEnd`
47
- const handleFailPlugin = async function ({ fullErrorInfo, fullErrorInfo: { errorInfo: { location: { packageName } = {} }, }, newError, childEnv, mode, errorMonitor, netlifyConfig, logs, debug, testOpts, }) {
52
+ /* On `utils.build.failPlugin()` or during `onSuccess` or `onEnd` */
53
+ const handleFailPlugin = async function ({ fullErrorInfo, newError, childEnv, mode, errorMonitor, netlifyConfig, logs, debug, testOpts, }) {
48
54
  const newStatus = serializeErrorStatus({ fullErrorInfo, state: 'failed_plugin' });
49
55
  await handleBuildError(newError, { errorMonitor, netlifyConfig, childEnv, mode, logs, debug, testOpts });
50
- return { failedPlugin: [packageName], newStatus };
56
+ // TODO we should probably use type guard here, but due to the way we build these errorInfo objects I'm not 100%
57
+ // confident we have all the properties currently required by the type
58
+ const location = fullErrorInfo.errorInfo.location;
59
+ return { failedPlugin: [location.packageName], newStatus };
51
60
  };
52
- // On `utils.build.cancelBuild()`
61
+ /* On `utils.build.cancelBuild()` */
53
62
  const handleCancelBuild = async function ({ fullErrorInfo, newError, api, deployId }) {
54
63
  const newStatus = serializeErrorStatus({ fullErrorInfo, state: 'canceled_build' });
55
64
  await cancelBuild({ api, deployId });
56
65
  return { newError, newStatus };
57
66
  };
58
- // On `utils.build.failBuild()` or uncaught exception
67
+ /* On `utils.build.failBuild()` or uncaught exception */
59
68
  const handleFailBuild = function ({ fullErrorInfo, newError }) {
60
69
  const newStatus = serializeErrorStatus({ fullErrorInfo, state: 'failed_build' });
61
70
  return { newError, newStatus };
62
71
  };
63
- // Unlike community plugins, core plugin bugs should be handled as system errors
64
- export const getPluginErrorType = function (error, loadedFrom) {
72
+ /* Unlike community plugins, core plugin and trusted plugin bugs should be handled as system errors */
73
+ export const getPluginErrorType = function (error, loadedFrom, packageName) {
74
+ if (isTrustedPluginBug(error, packageName)) {
75
+ return { type: 'trustedPlugin' };
76
+ }
65
77
  if (!isCorePluginBug(error, loadedFrom)) {
66
78
  return {};
67
79
  }
@@ -71,3 +83,7 @@ const isCorePluginBug = function (error, loadedFrom) {
71
83
  const { severity } = parseErrorInfo(error);
72
84
  return severity === 'warning' && loadedFrom === 'core';
73
85
  };
86
+ const isTrustedPluginBug = function (error, packageName) {
87
+ const { severity } = parseErrorInfo(error);
88
+ return severity === 'warning' && isTrustedPlugin(packageName);
89
+ };
@@ -1,4 +1,4 @@
1
- export function isTrustedPlugin(pluginPackageJson: any): any;
1
+ export function isTrustedPlugin(packageName: any): any;
2
2
  export function firePluginStep({ event, childProcess, packageName, packagePath, pluginPackageJson, loadedFrom, origin, envChanges, errorParams, configOpts, netlifyConfig, configMutations, headersPath, redirectsPath, constants, steps, error, logs, featureFlags, debug, verbose, }: {
3
3
  event: any;
4
4
  childProcess: any;
@@ -5,7 +5,7 @@ import { callChild } from '../plugins/ipc.js';
5
5
  import { getSuccessStatus } from '../status/success.js';
6
6
  import { getPluginErrorType } from './error.js';
7
7
  import { updateNetlifyConfig, listConfigSideFiles } from './update_config.js';
8
- export const isTrustedPlugin = (pluginPackageJson) => pluginPackageJson?.name?.startsWith('@netlify/');
8
+ export const isTrustedPlugin = (packageName) => packageName?.startsWith('@netlify/');
9
9
  // Fire a plugin step
10
10
  export const firePluginStep = async function ({ event, childProcess, packageName, packagePath, pluginPackageJson, loadedFrom, origin, envChanges, errorParams, configOpts, netlifyConfig, configMutations, headersPath, redirectsPath, constants, steps, error, logs, featureFlags, debug, verbose, }) {
11
11
  const listeners = pipePluginOutput(childProcess, logs);
@@ -18,7 +18,7 @@ export const firePluginStep = async function ({ event, childProcess, packageName
18
18
  event,
19
19
  error,
20
20
  envChanges,
21
- featureFlags: isTrustedPlugin(pluginPackageJson) ? featureFlags : undefined,
21
+ featureFlags: isTrustedPlugin(pluginPackageJson?.name) ? featureFlags : undefined,
22
22
  netlifyConfig,
23
23
  constants,
24
24
  },
@@ -49,7 +49,7 @@ export const firePluginStep = async function ({ event, childProcess, packageName
49
49
  };
50
50
  }
51
51
  catch (newError) {
52
- const errorType = getPluginErrorType(newError, loadedFrom);
52
+ const errorType = getPluginErrorType(newError, loadedFrom, packageName);
53
53
  addErrorInfo(newError, {
54
54
  ...errorType,
55
55
  plugin: { pluginPackageJson, packageName },
@@ -24,20 +24,20 @@ export function getStepReturn({ event, packageName, newError, newEnvChanges, new
24
24
  quiet: any;
25
25
  metrics: any;
26
26
  }): Promise<{
27
- failedPlugin: any[];
27
+ failedPlugin: string[];
28
28
  newStatus: {
29
- state: any;
30
- title: any;
31
- summary: any;
29
+ state: "failed_build" | "failed_plugin" | "canceled_build";
30
+ title: string | (import("../error/types.js").TitleFunction & string);
31
+ summary: string;
32
32
  text: string | undefined;
33
33
  extraData: any;
34
34
  };
35
35
  }> | Promise<{
36
36
  newError: any;
37
37
  newStatus: {
38
- state: any;
39
- title: any;
40
- summary: any;
38
+ state: "failed_build" | "failed_plugin" | "canceled_build";
39
+ title: string | (import("../error/types.js").TitleFunction & string);
40
+ summary: string;
41
41
  text: string | undefined;
42
42
  extraData: any;
43
43
  };
@@ -1,18 +1,29 @@
1
+ import { Context } from '@opentelemetry/api';
1
2
  import type { TracingOptions } from '../core/types.js';
3
+ /**
4
+ * Gets the global context to be used when initialising our root span
5
+ * TODO this will move to a shared package (opentelemetry-utils) to scope the usage of this global property there
6
+ */
7
+ export declare const getGlobalContext: () => Context;
8
+ /**
9
+ * Sets global context to be used when initialising our root span
10
+ * TODO this will move to a shared package (opentelemetry-utils) to scope the usage of this global property there
11
+ */
12
+ export declare const setGlobalContext: (ctx: Context) => void;
2
13
  /** Starts the tracing SDK, if there's already a tracing service this will be a no-op */
3
- export declare const startTracing: (options: TracingOptions, logger: (...args: any[]) => void) => import("@opentelemetry/api").Context | undefined;
14
+ export declare const startTracing: (options: TracingOptions, logger: (...args: any[]) => void) => Context | undefined;
4
15
  /** Stops the tracing service if there's one running. This will flush any ongoing events */
5
16
  export declare const stopTracing: () => Promise<void>;
6
17
  /** Sets attributes to be propagated across child spans under the current active context */
7
18
  export declare const setMultiSpanAttributes: (attributes: {
8
19
  [key: string]: string;
9
- }) => import("@opentelemetry/api").Context;
20
+ }) => Context;
10
21
  /** Add error information to the current active span (if any) */
11
22
  export declare const addErrorToActiveSpan: (error: Error) => void;
12
23
  export declare const addEventToActiveSpan: (eventName: string, attributes?: {
13
24
  [key: string]: string;
14
25
  } | undefined) => void;
15
- export declare const loadBaggageFromFile: (baggageFilePath: string) => import("@opentelemetry/api").Context;
26
+ export declare const loadBaggageFromFile: (baggageFilePath: string) => Context;
16
27
  /** Attributes used for the root span of our execution */
17
28
  export type RootExecutionAttributes = {
18
29
  'build.id': string;
@@ -1,6 +1,6 @@
1
1
  import { readFileSync } from 'node:fs';
2
2
  import { HoneycombSDK } from '@honeycombio/opentelemetry-node';
3
- import { context, trace, propagation, SpanStatusCode, diag, DiagLogLevel } from '@opentelemetry/api';
3
+ import { context, trace, propagation, SpanStatusCode, diag, DiagLogLevel, } from '@opentelemetry/api';
4
4
  import { parseKeyPairsIntoRecord } from '@opentelemetry/core/build/src/baggage/utils.js';
5
5
  import { isBuildError } from '../error/info.js';
6
6
  import { parseErrorInfo } from '../error/parse/parse.js';
@@ -22,8 +22,30 @@ const getOtelLogger = function (logger) {
22
22
  warn: otelLogger,
23
23
  };
24
24
  };
25
+ /**
26
+ * Gets the global context to be used when initialising our root span
27
+ * TODO this will move to a shared package (opentelemetry-utils) to scope the usage of this global property there
28
+ */
29
+ export const getGlobalContext = function () {
30
+ if (global['NETLIFY_GLOBAL_CONTEXT'] === undefined) {
31
+ return context.active();
32
+ }
33
+ return global['NETLIFY_GLOBAL_CONTEXT'];
34
+ };
35
+ /**
36
+ * Sets global context to be used when initialising our root span
37
+ * TODO this will move to a shared package (opentelemetry-utils) to scope the usage of this global property there
38
+ */
39
+ export const setGlobalContext = function (ctx) {
40
+ global['NETLIFY_GLOBAL_CONTEXT'] = ctx;
41
+ };
25
42
  /** Starts the tracing SDK, if there's already a tracing service this will be a no-op */
26
43
  export const startTracing = function (options, logger) {
44
+ // As we roll out the new way to initialise the SDK, if we detect preloading is enabled,
45
+ // it means we're using `@netlify/opentelemetry-sdk-setup` so we must get the initial context from the global store
46
+ if (options.preloadingEnabled) {
47
+ return getGlobalContext();
48
+ }
27
49
  if (!options.enabled)
28
50
  return;
29
51
  if (sdk)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/build",
3
- "version": "29.28.0",
3
+ "version": "29.28.2",
4
4
  "description": "Netlify build module",
5
5
  "type": "module",
6
6
  "exports": "./lib/index.js",
@@ -70,11 +70,11 @@
70
70
  "@netlify/config": "^20.10.0",
71
71
  "@netlify/edge-bundler": "10.1.3",
72
72
  "@netlify/framework-info": "^9.8.10",
73
- "@netlify/functions-utils": "^5.2.41",
73
+ "@netlify/functions-utils": "^5.2.42",
74
74
  "@netlify/git-utils": "^5.1.1",
75
75
  "@netlify/plugins-list": "^6.72.0",
76
76
  "@netlify/run-utils": "^5.1.1",
77
- "@netlify/zip-it-and-ship-it": "9.26.2",
77
+ "@netlify/zip-it-and-ship-it": "9.26.4",
78
78
  "@opentelemetry/api": "^1.4.1",
79
79
  "@opentelemetry/core": "^1.17.1",
80
80
  "@sindresorhus/slugify": "^2.0.0",
@@ -140,11 +140,19 @@
140
140
  "process-exists": "^5.0.0",
141
141
  "sinon": "^13.0.0",
142
142
  "tmp-promise": "^3.0.2",
143
- "tsd": "^0.28.0",
143
+ "tsd": "^0.29.0",
144
144
  "yarn": "^1.22.4"
145
145
  },
146
+ "peerDependencies": {
147
+ "@netlify/opentelemetry-sdk-setup": "^1.0.1"
148
+ },
149
+ "peerDependenciesMeta": {
150
+ "@netlify/opentelemetry-sdk-setup": {
151
+ "optional": true
152
+ }
153
+ },
146
154
  "engines": {
147
155
  "node": "^14.16.0 || >=16.0.0"
148
156
  },
149
- "gitHead": "4731f03bc8ba9cc1a8e42f95777ed24497c727b5"
157
+ "gitHead": "db2b375439203dc1c7ec1e68b24b8460c8f0ffc3"
150
158
  }