@netlify/build 28.0.0 → 28.0.1
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/main.js +1 -19
- package/lib/core/severity.js +11 -10
- package/lib/core/types.js +8 -0
- package/lib/error/monitor/start.js +4 -1
- package/lib/log/logger.js +33 -23
- package/lib/steps/run_core_steps.js +0 -21
- package/package.json +10 -9
package/lib/core/main.js
CHANGED
|
@@ -10,25 +10,7 @@ export { runCoreSteps } from '../steps/run_core_steps.js';
|
|
|
10
10
|
* Main entry point of Netlify Build.
|
|
11
11
|
* Runs a builds and returns whether it succeeded or not.
|
|
12
12
|
*
|
|
13
|
-
* @param
|
|
14
|
-
* @param {string} [flags.config] - Path to the configuration file
|
|
15
|
-
* @param {string} [flags.cwd] - Current directory. Used to retrieve the configuration file
|
|
16
|
-
* @param {string} [flags.repositoryRoot] - Git repository root directory. Used to retrieve the configuration file.
|
|
17
|
-
* @param {string} [flags.apiHost] - Netlify API endpoint
|
|
18
|
-
* @param {string} [flags.token] - Netlify API token for authentication
|
|
19
|
-
* @param {string} [flags.siteId] - Netlify Site ID
|
|
20
|
-
* @param {string} [flags.deployId] - Netlify Deploy ID
|
|
21
|
-
* @param {string} [flags.context] - Build context
|
|
22
|
-
* @param {string} [flags.branch] - Repository branch
|
|
23
|
-
* @param {boolean} [flags.dry=false] - Run in dry mode, i.e. printing steps without executing them
|
|
24
|
-
* @param {string} [flags.nodePath] - Path to the Node.js binary to use in the build command and plugins
|
|
25
|
-
* @param {boolean} [flags.buffer=false] - Buffer output instead of printing it
|
|
26
|
-
*
|
|
27
|
-
* @returns {object} buildResult
|
|
28
|
-
* @returns {boolean} buildResult.success - Whether build succeeded or failed
|
|
29
|
-
* @returns {number} buildResult.severityCode - Build success/failure status among:
|
|
30
|
-
* 0 (success), 1 (build cancelled), 2 (user error), 3 (plugin error), 4 (system error). Can be used as exit code.
|
|
31
|
-
* @returns {string[]} buildResult.logs - When using the `buffer` option, all log messages
|
|
13
|
+
* @param flags - build configuration CLI flags
|
|
32
14
|
*/
|
|
33
15
|
export default async function buildSite(flags = {}) {
|
|
34
16
|
const { errorMonitor, framework, mode, logs, debug, systemLogFile, testOpts, statsdOpts, dry, telemetry, buildId, deployId, ...flagsA } = startBuild(flags);
|
package/lib/core/severity.js
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
// Used to extract exit codes and respective status strings
|
|
2
|
-
// 1|2|3 indicate whether this was a user|plugin|system error.
|
|
3
|
-
export const getSeverity = function (severity = FALLBACK_SEVERITY) {
|
|
4
|
-
const severityEntry = severity in SEVERITY_MAP ? SEVERITY_MAP[severity] : FALLBACK_SEVERITY_ENTRY;
|
|
5
|
-
const success = severity === SUCCESS_SEVERITY;
|
|
6
|
-
return { success, ...severityEntry };
|
|
7
|
-
};
|
|
8
|
-
// Map error severities to exit codes and status (used for telemetry purposes)
|
|
9
1
|
const SEVERITY_MAP = {
|
|
10
2
|
success: { severityCode: 0, status: 'success' },
|
|
11
3
|
none: { severityCode: 1, status: 'cancelled' },
|
|
@@ -13,8 +5,17 @@ const SEVERITY_MAP = {
|
|
|
13
5
|
warning: { severityCode: 3, status: 'plugin-error' },
|
|
14
6
|
error: { severityCode: 4, status: 'system-error' },
|
|
15
7
|
};
|
|
16
|
-
/* eslint-enable no-magic-numbers */
|
|
17
8
|
const SUCCESS_SEVERITY = 'success';
|
|
18
|
-
|
|
9
|
+
/** Indicates a bug in our codebase */
|
|
19
10
|
const FALLBACK_SEVERITY = 'error';
|
|
11
|
+
/** Map error severities to exit codes and status (used for telemetry purposes) */
|
|
20
12
|
export const FALLBACK_SEVERITY_ENTRY = SEVERITY_MAP[FALLBACK_SEVERITY];
|
|
13
|
+
/**
|
|
14
|
+
* Used to extract exit codes and respective status strings
|
|
15
|
+
* 1|2|3 indicate whether this was a user|plugin|system error.
|
|
16
|
+
*/
|
|
17
|
+
export const getSeverity = (severity = FALLBACK_SEVERITY) => {
|
|
18
|
+
const severityEntry = severity in SEVERITY_MAP ? SEVERITY_MAP[severity] : FALLBACK_SEVERITY_ENTRY;
|
|
19
|
+
const success = severity === SUCCESS_SEVERITY;
|
|
20
|
+
return { success, ...severityEntry };
|
|
21
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export var SeverityCode;
|
|
2
|
+
(function (SeverityCode) {
|
|
3
|
+
SeverityCode[SeverityCode["success"] = 1] = "success";
|
|
4
|
+
SeverityCode[SeverityCode["buildCancelled"] = 2] = "buildCancelled";
|
|
5
|
+
SeverityCode[SeverityCode["userError"] = 3] = "userError";
|
|
6
|
+
SeverityCode[SeverityCode["pluginError"] = 4] = "pluginError";
|
|
7
|
+
SeverityCode[SeverityCode["systemError"] = 5] = "systemError";
|
|
8
|
+
})(SeverityCode = SeverityCode || (SeverityCode = {}));
|
|
@@ -5,7 +5,8 @@ import { log } from '../../log/logger.js';
|
|
|
5
5
|
import { ROOT_PACKAGE_JSON } from '../../utils/json.js';
|
|
6
6
|
const projectRoot = fileURLToPath(new URL('../../..', import.meta.url));
|
|
7
7
|
// Start a client to monitor errors
|
|
8
|
-
export const startErrorMonitor = function (
|
|
8
|
+
export const startErrorMonitor = function (config) {
|
|
9
|
+
const { flags: { mode }, logs, bugsnagKey, } = config;
|
|
9
10
|
if (!bugsnagKey) {
|
|
10
11
|
return;
|
|
11
12
|
}
|
|
@@ -39,6 +40,8 @@ const BUGSNAG_TEST_KEY = '00000000000000000000000000000000';
|
|
|
39
40
|
// Bugsnag.start() caches a global instance and warns on duplicate calls.
|
|
40
41
|
// This ensures the warning message is not shown when calling the main function
|
|
41
42
|
// several times.
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
44
|
+
// @ts-ignore
|
|
42
45
|
const startBugsnag = memoizeOne(Bugsnag.start.bind(Bugsnag), () => true);
|
|
43
46
|
// Based the release stage on the `mode`
|
|
44
47
|
const getReleaseStage = function (mode = DEFAULT_RELEASE_STAGE) {
|
package/lib/log/logger.js
CHANGED
|
@@ -4,9 +4,19 @@ import indentString from 'indent-string';
|
|
|
4
4
|
import { getHeader } from './header.js';
|
|
5
5
|
import { serializeObject, serializeArray } from './serialize.js';
|
|
6
6
|
import { THEME } from './theme.js';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const INDENT_SIZE = 2;
|
|
8
|
+
/**
|
|
9
|
+
* We need to add a zero width space character in empty lines. Otherwise the
|
|
10
|
+
* buildbot removes those due to a bug: https://github.com/netlify/buildbot/issues/595
|
|
11
|
+
*/
|
|
12
|
+
const EMPTY_LINES_REGEXP = /^\s*$/gm;
|
|
13
|
+
const EMPTY_LINE = '\u{200B}';
|
|
14
|
+
/**
|
|
15
|
+
* When the `buffer` option is true, we return logs instead of printing them
|
|
16
|
+
* on the console. The logs are accumulated in a `logs` array variable.
|
|
17
|
+
*/
|
|
18
|
+
export const getBufferLogs = (config) => {
|
|
19
|
+
const { buffer = false } = config;
|
|
10
20
|
if (!buffer) {
|
|
11
21
|
return;
|
|
12
22
|
}
|
|
@@ -15,7 +25,8 @@ export const getBufferLogs = function ({ buffer = false }) {
|
|
|
15
25
|
// Core logging utility, used by the other methods.
|
|
16
26
|
// This should be used instead of `console.log()` as it allows us to instrument
|
|
17
27
|
// how any build logs is being printed.
|
|
18
|
-
export const log = function (logs, string,
|
|
28
|
+
export const log = function (logs, string, config = {}) {
|
|
29
|
+
const { indent = false, color } = config;
|
|
19
30
|
const stringA = indent ? indentString(string, INDENT_SIZE) : string;
|
|
20
31
|
const stringB = String(stringA).replace(EMPTY_LINES_REGEXP, EMPTY_LINE);
|
|
21
32
|
const stringC = color === undefined ? stringB : color(stringB);
|
|
@@ -26,25 +37,20 @@ export const log = function (logs, string, { indent = false, color } = {}) {
|
|
|
26
37
|
}
|
|
27
38
|
console.log(stringC);
|
|
28
39
|
};
|
|
29
|
-
const INDENT_SIZE = 2;
|
|
30
|
-
// We need to add a zero width space character in empty lines. Otherwise the
|
|
31
|
-
// buildbot removes those due to a bug: https://github.com/netlify/buildbot/issues/595
|
|
32
|
-
const EMPTY_LINES_REGEXP = /^\s*$/gm;
|
|
33
|
-
const EMPTY_LINE = '\u{200B}';
|
|
34
40
|
const serializeIndentedArray = function (array) {
|
|
35
41
|
return serializeArray(array.map(serializeIndentedItem));
|
|
36
42
|
};
|
|
37
43
|
const serializeIndentedItem = function (item) {
|
|
38
44
|
return indentString(item, INDENT_SIZE + 1).trimStart();
|
|
39
45
|
};
|
|
40
|
-
export const logError = function (logs, string, opts) {
|
|
46
|
+
export const logError = function (logs, string, opts = {}) {
|
|
41
47
|
log(logs, string, { color: THEME.errorLine, ...opts });
|
|
42
48
|
};
|
|
43
|
-
export const logWarning = function (logs, string, opts) {
|
|
49
|
+
export const logWarning = function (logs, string, opts = {}) {
|
|
44
50
|
log(logs, string, { color: THEME.warningLine, ...opts });
|
|
45
51
|
};
|
|
46
52
|
// Print a message that is under a header/subheader, i.e. indented
|
|
47
|
-
export const logMessage = function (logs, string, opts) {
|
|
53
|
+
export const logMessage = function (logs, string, opts = {}) {
|
|
48
54
|
log(logs, string, { indent: true, ...opts });
|
|
49
55
|
};
|
|
50
56
|
// Print an object
|
|
@@ -52,35 +58,35 @@ export const logObject = function (logs, object, opts) {
|
|
|
52
58
|
logMessage(logs, serializeObject(object), opts);
|
|
53
59
|
};
|
|
54
60
|
// Print an array
|
|
55
|
-
export const logArray = function (logs, array, opts) {
|
|
61
|
+
export const logArray = function (logs, array, opts = {}) {
|
|
56
62
|
logMessage(logs, serializeIndentedArray(array), { color: THEME.none, ...opts });
|
|
57
63
|
};
|
|
58
64
|
// Print an array of errors
|
|
59
|
-
export const logErrorArray = function (logs, array, opts) {
|
|
65
|
+
export const logErrorArray = function (logs, array, opts = {}) {
|
|
60
66
|
logMessage(logs, serializeIndentedArray(array), { color: THEME.errorLine, ...opts });
|
|
61
67
|
};
|
|
62
68
|
// Print an array of warnings
|
|
63
|
-
export const logWarningArray = function (logs, array, opts) {
|
|
69
|
+
export const logWarningArray = function (logs, array, opts = {}) {
|
|
64
70
|
logMessage(logs, serializeIndentedArray(array), { color: THEME.warningLine, ...opts });
|
|
65
71
|
};
|
|
66
72
|
// Print a main section header
|
|
67
|
-
export const logHeader = function (logs, string, opts) {
|
|
73
|
+
export const logHeader = function (logs, string, opts = {}) {
|
|
68
74
|
log(logs, `\n${getHeader(string)}`, { color: THEME.header, ...opts });
|
|
69
75
|
};
|
|
70
76
|
// Print a main section header, when an error happened
|
|
71
|
-
export const logErrorHeader = function (logs, string, opts) {
|
|
77
|
+
export const logErrorHeader = function (logs, string, opts = {}) {
|
|
72
78
|
logHeader(logs, string, { color: THEME.errorHeader, ...opts });
|
|
73
79
|
};
|
|
74
80
|
// Print a sub-section header
|
|
75
|
-
export const logSubHeader = function (logs, string, opts) {
|
|
81
|
+
export const logSubHeader = function (logs, string, opts = {}) {
|
|
76
82
|
log(logs, `\n${figures.pointer} ${string}`, { color: THEME.subHeader, ...opts });
|
|
77
83
|
};
|
|
78
84
|
// Print a sub-section header, when an error happened
|
|
79
|
-
export const logErrorSubHeader = function (logs, string, opts) {
|
|
85
|
+
export const logErrorSubHeader = function (logs, string, opts = {}) {
|
|
80
86
|
logSubHeader(logs, string, { color: THEME.errorSubHeader, ...opts });
|
|
81
87
|
};
|
|
82
88
|
// Print a sub-section header, when a warning happened
|
|
83
|
-
export const logWarningSubHeader = function (logs, string, opts) {
|
|
89
|
+
export const logWarningSubHeader = function (logs, string, opts = {}) {
|
|
84
90
|
logSubHeader(logs, string, { color: THEME.warningSubHeader, ...opts });
|
|
85
91
|
};
|
|
86
92
|
// Combines an array of elements into a single string, separated by a space,
|
|
@@ -105,9 +111,13 @@ const reduceLogLines = function (lines) {
|
|
|
105
111
|
})
|
|
106
112
|
.join(' ');
|
|
107
113
|
};
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
114
|
+
/**
|
|
115
|
+
* Builds a function for logging data to the system logger (i.e. hidden from
|
|
116
|
+
* the user-facing build logs)
|
|
117
|
+
*/
|
|
118
|
+
export const getSystemLogger = function (logs, debug,
|
|
119
|
+
/** A system log file descriptor, if non is provided it will be a noop logger */
|
|
120
|
+
systemLogFile) {
|
|
111
121
|
// If the `debug` flag is used, we return a function that pipes system logs
|
|
112
122
|
// to the regular logger, as the intention is for them to end up in stdout.
|
|
113
123
|
if (debug) {
|
|
@@ -12,27 +12,6 @@ import { getSteps } from './get.js';
|
|
|
12
12
|
import { runSteps } from './run_steps.js';
|
|
13
13
|
/**
|
|
14
14
|
* Runs specific core steps for a build and returns whether it succeeded or not.
|
|
15
|
-
*
|
|
16
|
-
* @param {string[]} [buildSteps] - a string array of build steps to run
|
|
17
|
-
* @param {object} [flags] - build configuration CLI flags
|
|
18
|
-
* @param {string} [flags.config] - Path to the configuration file
|
|
19
|
-
* @param {string} [flags.cwd] - Current directory. Used to retrieve the configuration file
|
|
20
|
-
* @param {string} [flags.repositoryRoot] - Git repository root directory. Used to retrieve the configuration file.
|
|
21
|
-
* @param {string} [flags.apiHost] - Netlify API endpoint
|
|
22
|
-
* @param {string} [flags.token] - Netlify API token for authentication
|
|
23
|
-
* @param {string} [flags.siteId] - Netlify Site ID
|
|
24
|
-
* @param {string} [flags.deployId] - Netlify Deploy ID
|
|
25
|
-
* @param {string} [flags.context] - Build context
|
|
26
|
-
* @param {string} [flags.branch] - Repository branch
|
|
27
|
-
* @param {boolean} [flags.dry=false] - Run in dry mode, i.e. printing steps without executing them
|
|
28
|
-
* @param {string} [flags.nodePath] - Path to the Node.js binary to use in the build command and plugins
|
|
29
|
-
* @param {boolean} [flags.buffer=false] - Buffer output instead of printing it
|
|
30
|
-
*
|
|
31
|
-
* @returns {object} buildResult
|
|
32
|
-
* @returns {boolean} buildResult.success - Whether build succeeded or failed
|
|
33
|
-
* @returns {number} buildResult.severityCode - Build success/failure status among:
|
|
34
|
-
* 0 (success), 1 (build cancelled), 2 (user error), 3 (plugin error), 4 (system error). Can be used as exit code.
|
|
35
|
-
* @returns {string[]} buildResult.logs - When using the `buffer` option, all log messages
|
|
36
15
|
*/
|
|
37
16
|
export const runCoreSteps = async (buildSteps, flags = {}) => {
|
|
38
17
|
const { errorMonitor, mode, logs, debug, ...flagsA } = startBuild(flags);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/build",
|
|
3
|
-
"version": "28.0.
|
|
3
|
+
"version": "28.0.1",
|
|
4
4
|
"description": "Netlify build module",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./lib/core/main.js",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"build": "tsc",
|
|
27
27
|
"pretest": "tsd .",
|
|
28
28
|
"test": "ava",
|
|
29
|
+
"test:dev": "ava -w",
|
|
29
30
|
"test:ci": "c8 -r lcovonly -r text -r json ava",
|
|
30
31
|
"test:measure": "../../tools/tests-duration.js"
|
|
31
32
|
},
|
|
@@ -63,13 +64,13 @@
|
|
|
63
64
|
"license": "MIT",
|
|
64
65
|
"dependencies": {
|
|
65
66
|
"@bugsnag/js": "^7.0.0",
|
|
66
|
-
"@netlify/cache-utils": "^5.0.
|
|
67
|
-
"@netlify/config": "^19.0.
|
|
68
|
-
"@netlify/edge-bundler": "^2.
|
|
69
|
-
"@netlify/functions-utils": "^5.0.
|
|
70
|
-
"@netlify/git-utils": "^5.0.
|
|
71
|
-
"@netlify/plugins-list": "^6.
|
|
72
|
-
"@netlify/run-utils": "^5.0.
|
|
67
|
+
"@netlify/cache-utils": "^5.0.1",
|
|
68
|
+
"@netlify/config": "^19.0.1",
|
|
69
|
+
"@netlify/edge-bundler": "^2.8.0",
|
|
70
|
+
"@netlify/functions-utils": "^5.0.1",
|
|
71
|
+
"@netlify/git-utils": "^5.0.1",
|
|
72
|
+
"@netlify/plugins-list": "^6.50.0",
|
|
73
|
+
"@netlify/run-utils": "^5.0.1",
|
|
73
74
|
"@netlify/zip-it-and-ship-it": "^7.1.2",
|
|
74
75
|
"@sindresorhus/slugify": "^2.0.0",
|
|
75
76
|
"ajv": "^8.11.0",
|
|
@@ -149,5 +150,5 @@
|
|
|
149
150
|
"module": "commonjs"
|
|
150
151
|
}
|
|
151
152
|
},
|
|
152
|
-
"gitHead": "
|
|
153
|
+
"gitHead": "701e883d4e19c048e8de9801e49e21de5c891a18"
|
|
153
154
|
}
|