@netlify/build 29.42.6 → 29.44.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/lib/core/build.js CHANGED
@@ -382,6 +382,8 @@ const runBuild = async function ({ childProcesses, pluginsOptions, netlifyConfig
382
382
  debug,
383
383
  verbose,
384
384
  netlifyConfig,
385
+ featureFlags,
386
+ systemLog,
385
387
  });
386
388
  const { steps, events } = timeline === 'dev' ? getDevSteps(devCommand, pluginsSteps, eventHandlers) : getSteps(pluginsSteps, eventHandlers);
387
389
  if (dry) {
@@ -17,4 +17,5 @@ export const DEFAULT_FEATURE_FLAGS = {
17
17
  edge_functions_system_logger: false,
18
18
  netlify_build_reduced_output: false,
19
19
  netlify_build_updated_plugin_compatibility: false,
20
+ netlify_build_plugin_system_log: false,
20
21
  };
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  import { Transform } from 'stream';
3
+ import type { StandardStreams } from './stream.js';
3
4
  declare const flusherSymbol: unique symbol;
4
5
  /**
5
6
  * Utility class for conditionally rendering certain output only if additional
@@ -21,4 +22,5 @@ export declare class OutputFlusherTransform extends Transform {
21
22
  constructor(flusher: OutputFlusher);
22
23
  _transform(chunk: any, _: string, callback: () => void): void;
23
24
  }
25
+ export declare const getStandardStreams: (outputFlusher?: OutputFlusher) => StandardStreams;
24
26
  export {};
@@ -1,3 +1,4 @@
1
+ import { stdout, stderr } from 'process';
1
2
  import { Transform } from 'stream';
2
3
  const flusherSymbol = Symbol.for('@netlify/output-gate');
3
4
  /**
@@ -35,3 +36,16 @@ export class OutputFlusherTransform extends Transform {
35
36
  callback();
36
37
  }
37
38
  }
39
+ export const getStandardStreams = (outputFlusher) => {
40
+ if (!outputFlusher) {
41
+ return {
42
+ stdout,
43
+ stderr,
44
+ };
45
+ }
46
+ return {
47
+ outputFlusher,
48
+ stdout: new OutputFlusherTransform(outputFlusher).pipe(stdout),
49
+ stderr: new OutputFlusherTransform(outputFlusher).pipe(stderr),
50
+ };
51
+ };
@@ -1,10 +1,23 @@
1
- export function getBuildCommandStdio(logs: any): "pipe" | "inherit";
2
- export function handleBuildCommandOutput({ stdout: commandStdout, stderr: commandStderr }: {
3
- stdout: any;
4
- stderr: any;
5
- }, logs: any): void;
6
- export function pipePluginOutput(childProcess: any, logs: any, outputFlusher: any): void | {
7
- stdoutListener: any;
8
- stderrListener: any;
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ /// <reference types="node" resolution-mode="require"/>
3
+ import type { ChildProcess } from '../plugins/spawn.js';
4
+ import { Logs } from './logger.js';
5
+ import type { OutputFlusher } from './output_flusher.js';
6
+ export type StandardStreams = {
7
+ stderr: NodeJS.WriteStream;
8
+ stdout: NodeJS.WriteStream;
9
+ outputFlusher?: OutputFlusher;
9
10
  };
10
- export function unpipePluginOutput(childProcess: any, logs: any, listeners: any): Promise<void>;
11
+ type LogsListener = (logs: string[], outputFlusher: OutputFlusher | undefined, chunk: Buffer) => void;
12
+ type LogsListeners = {
13
+ stderrListener: LogsListener;
14
+ stdoutListener: LogsListener;
15
+ };
16
+ export declare const getBuildCommandStdio: (logs: Logs) => "pipe" | "inherit";
17
+ export declare const handleBuildCommandOutput: ({ stdout: commandStdout, stderr: commandStderr }: {
18
+ stdout: string;
19
+ stderr: string;
20
+ }, logs: Logs) => void;
21
+ export declare const pipePluginOutput: (childProcess: ChildProcess, logs: Logs, standardStreams: StandardStreams) => void | LogsListeners;
22
+ export declare const unpipePluginOutput: (childProcess: ChildProcess, logs: Logs, listeners: LogsListeners, standardStreams: StandardStreams) => Promise<void>;
23
+ export {};
package/lib/log/stream.js CHANGED
@@ -1,7 +1,5 @@
1
- import { stdout, stderr } from 'process';
2
1
  import { promisify } from 'util';
3
2
  import { logsAreBuffered } from './logger.js';
4
- import { OutputFlusherTransform } from './output_flusher.js';
5
3
  // TODO: replace with `timers/promises` after dropping Node < 15.0.0
6
4
  const pSetTimeout = promisify(setTimeout);
7
5
  // We try to use `stdio: inherit` because it keeps `stdout/stderr` as `TTY`,
@@ -29,41 +27,36 @@ const pushBuildCommandOutput = function (output, logsArray) {
29
27
  logsArray.push(output);
30
28
  };
31
29
  // Start plugin step output
32
- export const pipePluginOutput = function (childProcess, logs, outputFlusher) {
30
+ export const pipePluginOutput = function (childProcess, logs, standardStreams) {
33
31
  if (!logsAreBuffered(logs)) {
34
- return streamOutput(childProcess, outputFlusher);
32
+ return streamOutput(childProcess, standardStreams);
35
33
  }
36
- return pushOutputToLogs(childProcess, logs, outputFlusher);
34
+ return pushOutputToLogs(childProcess, logs, standardStreams.outputFlusher);
37
35
  };
38
36
  // Stop streaming/buffering plugin step output
39
- export const unpipePluginOutput = async function (childProcess, logs, listeners) {
37
+ export const unpipePluginOutput = async function (childProcess, logs, listeners, standardStreams) {
40
38
  // Let `childProcess` `stdout` and `stderr` flush before stopping redirecting
41
39
  await pSetTimeout(0);
42
40
  if (!logsAreBuffered(logs)) {
43
- return unstreamOutput(childProcess);
41
+ return unstreamOutput(childProcess, standardStreams);
44
42
  }
45
- unpushOutputToLogs(childProcess, logs, listeners);
43
+ unpushOutputToLogs(childProcess, listeners.stdoutListener, listeners.stderrListener);
46
44
  };
47
45
  // Usually, we stream stdout/stderr because it is more efficient
48
- const streamOutput = function (childProcess, outputFlusher) {
49
- if (outputFlusher) {
50
- childProcess.stdout.pipe(new OutputFlusherTransform(outputFlusher)).pipe(stdout);
51
- childProcess.stderr.pipe(new OutputFlusherTransform(outputFlusher)).pipe(stderr);
52
- return;
53
- }
54
- childProcess.stdout.pipe(stdout);
55
- childProcess.stderr.pipe(stderr);
46
+ const streamOutput = function (childProcess, standardStreams) {
47
+ childProcess.stdout?.pipe(standardStreams.stdout);
48
+ childProcess.stderr?.pipe(standardStreams.stderr);
56
49
  };
57
- const unstreamOutput = function (childProcess) {
58
- childProcess.stdout.unpipe(stdout);
59
- childProcess.stderr.unpipe(stderr);
50
+ const unstreamOutput = function (childProcess, standardStreams) {
51
+ childProcess.stdout?.unpipe(standardStreams.stdout);
52
+ childProcess.stderr?.unpipe(standardStreams.stderr);
60
53
  };
61
54
  // In tests, we push to the `logs` array instead
62
55
  const pushOutputToLogs = function (childProcess, logs, outputFlusher) {
63
56
  const stdoutListener = logsListener.bind(null, logs.stdout, outputFlusher);
64
57
  const stderrListener = logsListener.bind(null, logs.stderr, outputFlusher);
65
- childProcess.stdout.on('data', stdoutListener);
66
- childProcess.stderr.on('data', stderrListener);
58
+ childProcess.stdout?.on('data', stdoutListener);
59
+ childProcess.stderr?.on('data', stderrListener);
67
60
  return { stdoutListener, stderrListener };
68
61
  };
69
62
  const logsListener = function (logs, outputFlusher, chunk) {
@@ -72,7 +65,7 @@ const logsListener = function (logs, outputFlusher, chunk) {
72
65
  }
73
66
  logs.push(chunk.toString().trimEnd());
74
67
  };
75
- const unpushOutputToLogs = function (childProcess, logs, { stdoutListener, stderrListener }) {
76
- childProcess.stdout.removeListener('data', stdoutListener);
77
- childProcess.stderr.removeListener('data', stderrListener);
68
+ const unpushOutputToLogs = function (childProcess, stdoutListener, stderrListener) {
69
+ childProcess.stdout?.removeListener('data', stdoutListener);
70
+ childProcess.stderr?.removeListener('data', stderrListener);
78
71
  };
@@ -1,4 +1,4 @@
1
- export function loadPlugins({ pluginsOptions, childProcesses, packageJson, timers, logs, debug, verbose, netlifyConfig, }: {
1
+ export function loadPlugins({ pluginsOptions, childProcesses, packageJson, timers, logs, debug, verbose, netlifyConfig, featureFlags, systemLog, }: {
2
2
  pluginsOptions: any;
3
3
  childProcesses: any;
4
4
  packageJson: any;
@@ -7,4 +7,6 @@ export function loadPlugins({ pluginsOptions, childProcesses, packageJson, timer
7
7
  debug: any;
8
8
  verbose: any;
9
9
  netlifyConfig: any;
10
+ featureFlags: any;
11
+ systemLog: any;
10
12
  }): Promise<any>;
@@ -1,16 +1,39 @@
1
+ import { promisify } from 'util';
1
2
  import { addErrorInfo } from '../error/info.js';
2
3
  import { addPluginLoadErrorStatus } from '../status/load_error.js';
3
4
  import { measureDuration } from '../time/main.js';
4
5
  import { callChild } from './ipc.js';
6
+ const pSetTimeout = promisify(setTimeout);
5
7
  // Retrieve all plugins steps
6
8
  // Can use either a module name or a file path to the plugin.
7
- export const loadPlugins = async function ({ pluginsOptions, childProcesses, packageJson, timers, logs, debug, verbose, netlifyConfig, }) {
9
+ export const loadPlugins = async function ({ pluginsOptions, childProcesses, packageJson, timers, logs, debug, verbose, netlifyConfig, featureFlags, systemLog, }) {
8
10
  return pluginsOptions.length === 0
9
11
  ? { pluginsSteps: [], timers }
10
- : await loadAllPlugins({ pluginsOptions, childProcesses, packageJson, timers, logs, debug, verbose, netlifyConfig });
12
+ : await loadAllPlugins({
13
+ pluginsOptions,
14
+ childProcesses,
15
+ packageJson,
16
+ timers,
17
+ logs,
18
+ debug,
19
+ verbose,
20
+ netlifyConfig,
21
+ featureFlags,
22
+ systemLog,
23
+ });
11
24
  };
12
- const tLoadAllPlugins = async function ({ pluginsOptions, childProcesses, packageJson, logs, debug, verbose, netlifyConfig, }) {
13
- const pluginsSteps = await Promise.all(pluginsOptions.map((pluginOptions, index) => loadPlugin(pluginOptions, { childProcesses, index, packageJson, logs, debug, verbose, netlifyConfig })));
25
+ const tLoadAllPlugins = async function ({ pluginsOptions, childProcesses, packageJson, logs, debug, verbose, netlifyConfig, featureFlags, systemLog, }) {
26
+ const pluginsSteps = await Promise.all(pluginsOptions.map((pluginOptions, index) => loadPlugin(pluginOptions, {
27
+ childProcesses,
28
+ index,
29
+ packageJson,
30
+ logs,
31
+ debug,
32
+ verbose,
33
+ netlifyConfig,
34
+ featureFlags,
35
+ systemLog,
36
+ })));
14
37
  const pluginsStepsA = pluginsSteps.flat();
15
38
  return { pluginsSteps: pluginsStepsA };
16
39
  };
@@ -18,9 +41,19 @@ const tLoadAllPlugins = async function ({ pluginsOptions, childProcesses, packag
18
41
  const loadAllPlugins = measureDuration(tLoadAllPlugins, 'load_plugins');
19
42
  // Retrieve plugin steps for one plugin.
20
43
  // Do it by executing the plugin `load` event handler.
21
- const loadPlugin = async function ({ packageName, pluginPackageJson, pluginPackageJson: { version } = {}, pluginPath, inputs, loadedFrom, origin }, { childProcesses, index, packageJson, logs, debug, verbose, netlifyConfig }) {
44
+ const loadPlugin = async function ({ packageName, pluginPackageJson, pluginPackageJson: { version } = {}, pluginPath, inputs, loadedFrom, origin }, { childProcesses, index, packageJson, logs, debug, verbose, netlifyConfig, featureFlags, systemLog }) {
22
45
  const { childProcess } = childProcesses[index];
23
46
  const loadEvent = 'load';
47
+ // A buffer for any data piped into the child process' stderr. We'll pipe
48
+ // this to system logs if we fail to load the plugin.
49
+ const bufferedStdErr = [];
50
+ let bufferedStdListener;
51
+ if (featureFlags.netlify_build_plugin_system_log && childProcess.stderr) {
52
+ bufferedStdListener = (data) => {
53
+ bufferedStdErr.push(data.toString().trimEnd());
54
+ };
55
+ childProcess.stderr.on('data', bufferedStdListener);
56
+ }
24
57
  try {
25
58
  const { events } = await callChild({
26
59
  childProcess,
@@ -40,6 +73,13 @@ const loadPlugin = async function ({ packageName, pluginPackageJson, pluginPacka
40
73
  return pluginSteps;
41
74
  }
42
75
  catch (error) {
76
+ if (featureFlags.netlify_build_plugin_system_log) {
77
+ // Wait for stderr to be flushed.
78
+ await pSetTimeout(0);
79
+ bufferedStdErr.forEach((line) => {
80
+ systemLog(line);
81
+ });
82
+ }
43
83
  addErrorInfo(error, {
44
84
  plugin: { packageName, pluginPackageJson },
45
85
  location: { event: loadEvent, packageName, loadedFrom, origin },
@@ -47,4 +87,9 @@ const loadPlugin = async function ({ packageName, pluginPackageJson, pluginPacka
47
87
  addPluginLoadErrorStatus({ error, packageName, version, debug });
48
88
  throw error;
49
89
  }
90
+ finally {
91
+ if (bufferedStdListener) {
92
+ childProcess.stderr.removeListener('data', bufferedStdListener);
93
+ }
94
+ }
50
95
  };
@@ -2,6 +2,7 @@ import { ExecaChildProcess } from 'execa';
2
2
  import { NetlifyConfig } from '../index.js';
3
3
  import { BufferedLogs } from '../log/logger.js';
4
4
  import { PluginsOptions } from './node_version.js';
5
+ export type ChildProcess = ExecaChildProcess<string>;
5
6
  export declare const startPlugins: any;
6
7
  export declare const stopPlugins: ({ childProcesses, logs, verbose, pluginOptions, netlifyConfig, }: {
7
8
  logs: BufferedLogs;
@@ -2,6 +2,7 @@ import { context, propagation } from '@opentelemetry/api';
2
2
  import { addErrorInfo } from '../error/info.js';
3
3
  import { addOutputFlusher } from '../log/logger.js';
4
4
  import { logStepCompleted } from '../log/messages/ipc.js';
5
+ import { getStandardStreams } from '../log/output_flusher.js';
5
6
  import { pipePluginOutput, unpipePluginOutput } from '../log/stream.js';
6
7
  import { callChild } from '../plugins/ipc.js';
7
8
  import { getSuccessStatus } from '../status/success.js';
@@ -10,10 +11,11 @@ import { updateNetlifyConfig, listConfigSideFiles } from './update_config.js';
10
11
  export const isTrustedPlugin = (packageName) => packageName?.startsWith('@netlify/');
11
12
  // Fire a plugin step
12
13
  export const firePluginStep = async function ({ event, childProcess, packageName, packagePath, pluginPackageJson, loadedFrom, origin, envChanges, errorParams, configOpts, netlifyConfig, configMutations, headersPath, redirectsPath, constants, steps, error, logs, outputFlusher, systemLog, featureFlags, debug, verbose, }) {
13
- const listeners = pipePluginOutput(childProcess, logs, outputFlusher);
14
+ const standardStreams = getStandardStreams(outputFlusher);
15
+ const listeners = pipePluginOutput(childProcess, logs, standardStreams);
14
16
  const otelCarrier = {};
15
17
  propagation.inject(context.active(), otelCarrier);
16
- const logsA = addOutputFlusher(logs, outputFlusher);
18
+ const logsA = outputFlusher ? addOutputFlusher(logs, outputFlusher) : logs;
17
19
  try {
18
20
  const configSideFiles = await listConfigSideFiles([headersPath, redirectsPath]);
19
21
  const { newEnvChanges, configMutations: newConfigMutations, status, } = await callChild({
@@ -28,7 +30,7 @@ export const firePluginStep = async function ({ event, childProcess, packageName
28
30
  constants,
29
31
  otelCarrier,
30
32
  },
31
- logs,
33
+ logs: logsA,
32
34
  verbose,
33
35
  });
34
36
  const { netlifyConfig: netlifyConfigA, configMutations: configMutationsA, headersPath: headersPathA, redirectsPath: redirectsPathA, } = await updateNetlifyConfig({
@@ -66,7 +68,7 @@ export const firePluginStep = async function ({ event, childProcess, packageName
66
68
  return { newError };
67
69
  }
68
70
  finally {
69
- await unpipePluginOutput(childProcess, logs, listeners);
71
+ await unpipePluginOutput(childProcess, logs, listeners, standardStreams);
70
72
  logStepCompleted(logs, verbose);
71
73
  }
72
74
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/build",
3
- "version": "29.42.6",
3
+ "version": "29.44.0",
4
4
  "description": "Netlify build module",
5
5
  "type": "module",
6
6
  "exports": "./lib/index.js",
@@ -165,5 +165,5 @@
165
165
  "engines": {
166
166
  "node": "^14.16.0 || >=16.0.0"
167
167
  },
168
- "gitHead": "be380af1c62fd62a202bbca551a30f290b0d3f99"
168
+ "gitHead": "bd868b81a1ead42e337bea8bebfee0d51307e078"
169
169
  }