@netlify/build 29.42.6 → 29.43.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/log/output_flusher.d.ts +2 -0
- package/lib/log/output_flusher.js +14 -0
- package/lib/log/stream.d.ts +22 -9
- package/lib/log/stream.js +17 -24
- package/lib/plugins/spawn.d.ts +1 -0
- package/lib/steps/plugin.js +6 -4
- package/package.json +2 -2
|
@@ -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
|
+
};
|
package/lib/log/stream.d.ts
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
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,
|
|
30
|
+
export const pipePluginOutput = function (childProcess, logs, standardStreams) {
|
|
33
31
|
if (!logsAreBuffered(logs)) {
|
|
34
|
-
return streamOutput(childProcess,
|
|
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,
|
|
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,
|
|
49
|
-
|
|
50
|
-
|
|
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
|
|
59
|
-
childProcess.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
|
|
66
|
-
childProcess.stderr
|
|
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,
|
|
76
|
-
childProcess.stdout
|
|
77
|
-
childProcess.stderr
|
|
68
|
+
const unpushOutputToLogs = function (childProcess, stdoutListener, stderrListener) {
|
|
69
|
+
childProcess.stdout?.removeListener('data', stdoutListener);
|
|
70
|
+
childProcess.stderr?.removeListener('data', stderrListener);
|
|
78
71
|
};
|
package/lib/plugins/spawn.d.ts
CHANGED
|
@@ -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;
|
package/lib/steps/plugin.js
CHANGED
|
@@ -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
|
|
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.
|
|
3
|
+
"version": "29.43.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": "
|
|
168
|
+
"gitHead": "5c7e4326ca1e4f0134506295281f76ed842d31f5"
|
|
169
169
|
}
|