@netlify/build 27.20.4 → 27.20.5

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.
Files changed (133) hide show
  1. package/lib/core/bin.js +42 -59
  2. package/lib/core/build.js +333 -536
  3. package/lib/core/config.js +94 -159
  4. package/lib/core/constants.js +95 -135
  5. package/lib/core/dev.js +26 -30
  6. package/lib/core/dry.js +18 -36
  7. package/lib/core/feature_flags.js +13 -16
  8. package/lib/core/flags.js +168 -169
  9. package/lib/core/lingering.js +44 -61
  10. package/lib/core/main.js +94 -136
  11. package/lib/core/missing_side_file.js +12 -24
  12. package/lib/core/normalize_flags.js +52 -63
  13. package/lib/core/severity.js +13 -15
  14. package/lib/core/user_node_version.js +26 -35
  15. package/lib/env/changes.js +29 -37
  16. package/lib/env/main.js +10 -15
  17. package/lib/env/metadata.js +63 -76
  18. package/lib/error/api.js +31 -40
  19. package/lib/error/build.js +27 -38
  20. package/lib/error/cancel.js +5 -6
  21. package/lib/error/colors.js +7 -9
  22. package/lib/error/handle.js +38 -49
  23. package/lib/error/info.js +26 -35
  24. package/lib/error/monitor/location.js +12 -17
  25. package/lib/error/monitor/normalize.js +75 -85
  26. package/lib/error/monitor/print.js +19 -41
  27. package/lib/error/monitor/report.js +102 -121
  28. package/lib/error/monitor/start.js +43 -56
  29. package/lib/error/parse/clean_stack.js +52 -69
  30. package/lib/error/parse/location.js +40 -52
  31. package/lib/error/parse/normalize.js +18 -23
  32. package/lib/error/parse/parse.js +59 -93
  33. package/lib/error/parse/plugin.js +42 -57
  34. package/lib/error/parse/properties.js +13 -20
  35. package/lib/error/parse/serialize_log.js +29 -37
  36. package/lib/error/parse/serialize_status.js +15 -23
  37. package/lib/error/parse/stack.js +29 -38
  38. package/lib/error/type.js +132 -150
  39. package/lib/install/functions.js +16 -24
  40. package/lib/install/local.js +31 -48
  41. package/lib/install/main.js +52 -66
  42. package/lib/install/missing.js +40 -53
  43. package/lib/log/colors.js +15 -22
  44. package/lib/log/description.js +16 -21
  45. package/lib/log/header.js +11 -13
  46. package/lib/log/header_func.js +11 -15
  47. package/lib/log/logger.js +88 -119
  48. package/lib/log/messages/compatibility.js +100 -158
  49. package/lib/log/messages/config.js +76 -92
  50. package/lib/log/messages/core.js +40 -60
  51. package/lib/log/messages/core_steps.js +63 -92
  52. package/lib/log/messages/dry.js +31 -53
  53. package/lib/log/messages/install.js +21 -28
  54. package/lib/log/messages/ipc.js +21 -30
  55. package/lib/log/messages/mutations.js +51 -71
  56. package/lib/log/messages/plugins.js +18 -31
  57. package/lib/log/messages/status.js +12 -14
  58. package/lib/log/messages/steps.js +14 -18
  59. package/lib/log/old_version.js +23 -32
  60. package/lib/log/serialize.js +7 -10
  61. package/lib/log/stream.js +48 -65
  62. package/lib/log/theme.js +22 -23
  63. package/lib/plugins/child/diff.js +31 -40
  64. package/lib/plugins/child/error.js +20 -26
  65. package/lib/plugins/child/lazy.js +11 -14
  66. package/lib/plugins/child/load.js +15 -22
  67. package/lib/plugins/child/logic.js +51 -58
  68. package/lib/plugins/child/main.js +32 -46
  69. package/lib/plugins/child/run.js +18 -27
  70. package/lib/plugins/child/status.js +52 -63
  71. package/lib/plugins/child/typescript.js +19 -36
  72. package/lib/plugins/child/utils.js +36 -49
  73. package/lib/plugins/child/validate.js +25 -28
  74. package/lib/plugins/compatibility.js +64 -92
  75. package/lib/plugins/error.js +29 -35
  76. package/lib/plugins/events.js +7 -12
  77. package/lib/plugins/expected_version.js +61 -99
  78. package/lib/plugins/ipc.js +79 -102
  79. package/lib/plugins/list.js +49 -62
  80. package/lib/plugins/load.js +44 -64
  81. package/lib/plugins/manifest/check.js +64 -85
  82. package/lib/plugins/manifest/load.js +34 -37
  83. package/lib/plugins/manifest/main.js +16 -21
  84. package/lib/plugins/manifest/path.js +18 -25
  85. package/lib/plugins/manifest/validate.js +77 -94
  86. package/lib/plugins/node_version.js +22 -42
  87. package/lib/plugins/options.js +45 -78
  88. package/lib/plugins/pinned_version.js +58 -106
  89. package/lib/plugins/resolve.js +91 -133
  90. package/lib/plugins/spawn.js +43 -61
  91. package/lib/plugins_core/add.js +26 -40
  92. package/lib/plugins_core/build_command.js +47 -72
  93. package/lib/plugins_core/deploy/buildbot_client.js +61 -87
  94. package/lib/plugins_core/deploy/index.js +47 -71
  95. package/lib/plugins_core/edge_functions/index.js +73 -116
  96. package/lib/plugins_core/edge_functions/lib/error.js +13 -17
  97. package/lib/plugins_core/edge_functions/lib/internal_manifest.js +45 -55
  98. package/lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +65 -80
  99. package/lib/plugins_core/functions/error.js +88 -128
  100. package/lib/plugins_core/functions/feature_flags.js +5 -5
  101. package/lib/plugins_core/functions/index.js +98 -145
  102. package/lib/plugins_core/functions/utils.js +36 -57
  103. package/lib/plugins_core/functions/zisi.js +35 -52
  104. package/lib/plugins_core/functions_install/index.js +8 -11
  105. package/lib/plugins_core/list.js +15 -22
  106. package/lib/status/add.js +26 -32
  107. package/lib/status/colors.js +14 -19
  108. package/lib/status/load_error.js +8 -9
  109. package/lib/status/report.js +72 -126
  110. package/lib/status/success.js +10 -14
  111. package/lib/steps/core_step.js +54 -89
  112. package/lib/steps/error.js +50 -87
  113. package/lib/steps/get.js +33 -41
  114. package/lib/steps/plugin.js +53 -83
  115. package/lib/steps/return.js +24 -51
  116. package/lib/steps/run_core_steps.js +119 -171
  117. package/lib/steps/run_step.js +154 -270
  118. package/lib/steps/run_steps.js +91 -174
  119. package/lib/steps/update_config.js +45 -72
  120. package/lib/telemetry/main.js +89 -128
  121. package/lib/time/aggregate.js +84 -110
  122. package/lib/time/main.js +23 -34
  123. package/lib/time/measure.js +11 -15
  124. package/lib/time/report.js +32 -44
  125. package/lib/utils/errors.js +10 -9
  126. package/lib/utils/json.js +11 -15
  127. package/lib/utils/omit.js +3 -4
  128. package/lib/utils/package.js +19 -22
  129. package/lib/utils/remove_falsy.js +5 -7
  130. package/lib/utils/resolve.js +30 -34
  131. package/lib/utils/runtime.js +4 -4
  132. package/lib/utils/semver.js +19 -25
  133. package/package.json +13 -6
package/lib/core/main.js CHANGED
@@ -1,14 +1,11 @@
1
- import { handleBuildError } from '../error/handle.js'
2
- import { logTimer, logBuildSuccess } from '../log/messages/core.js'
3
- import { trackBuildComplete } from '../telemetry/main.js'
4
- import { reportTimers } from '../time/report.js'
5
-
6
- import { execBuild, startBuild } from './build.js'
7
- import { getSeverity } from './severity.js'
8
-
9
- export { startDev } from './dev.js'
10
- export { runCoreSteps } from '../steps/run_core_steps.js'
11
-
1
+ import { handleBuildError } from '../error/handle.js';
2
+ import { logTimer, logBuildSuccess } from '../log/messages/core.js';
3
+ import { trackBuildComplete } from '../telemetry/main.js';
4
+ import { reportTimers } from '../time/report.js';
5
+ import { execBuild, startBuild } from './build.js';
6
+ import { getSeverity } from './severity.js';
7
+ export { startDev } from './dev.js';
8
+ export { runCoreSteps } from '../steps/run_core_steps.js';
12
9
  /**
13
10
  * Main entry point of Netlify Build.
14
11
  * Runs a builds and returns whether it succeeded or not.
@@ -34,132 +31,93 @@ export { runCoreSteps } from '../steps/run_core_steps.js'
34
31
  * @returns {string[]} buildResult.logs - When using the `buffer` option, all log messages
35
32
  */
36
33
  export default async function buildSite(flags = {}) {
37
- const {
38
- errorMonitor,
39
- framework,
40
- mode,
41
- logs,
42
- debug,
43
- systemLogFile,
44
- testOpts,
45
- statsdOpts,
46
- dry,
47
- telemetry,
48
- buildId,
49
- deployId,
50
- ...flagsA
51
- } = startBuild(flags)
52
- const errorParams = { errorMonitor, mode, logs, debug, testOpts }
53
-
54
- try {
55
- const {
56
- pluginsOptions,
57
- netlifyConfig: netlifyConfigA,
58
- siteInfo,
59
- userNodeVersion,
60
- stepsCount,
61
- timers,
62
- durationNs,
63
- configMutations,
64
- } = await execBuild({
65
- ...flagsA,
66
- buildId,
67
- systemLogFile,
68
- deployId,
69
- dry,
70
- errorMonitor,
71
- mode,
72
- logs,
73
- debug,
74
- testOpts,
75
- errorParams,
76
- })
77
- await handleBuildSuccess({
78
- framework,
79
- dry,
80
- logs,
81
- timers,
82
- durationNs,
83
- statsdOpts,
84
- })
85
- const { success, severityCode, status } = getSeverity('success')
86
- await telemetryReport({
87
- buildId,
88
- deployId,
89
- status,
90
- stepsCount,
91
- pluginsOptions,
92
- durationNs,
93
- siteInfo,
94
- telemetry,
95
- userNodeVersion,
96
- framework,
97
- testOpts,
98
- errorParams,
99
- })
100
- return { success, severityCode, netlifyConfig: netlifyConfigA, logs, configMutations }
101
- } catch (error) {
102
- const { severity } = await handleBuildError(error, errorParams)
103
- const { pluginsOptions, siteInfo, userNodeVersion } = errorParams
104
- const { success, severityCode, status } = getSeverity(severity)
105
- await telemetryReport({
106
- buildId,
107
- deployId,
108
- status,
109
- pluginsOptions,
110
- siteInfo,
111
- telemetry,
112
- userNodeVersion,
113
- framework,
114
- testOpts,
115
- errorParams,
116
- })
117
- return { success, severityCode, logs }
118
- }
34
+ const { errorMonitor, framework, mode, logs, debug, systemLogFile, testOpts, statsdOpts, dry, telemetry, buildId, deployId, ...flagsA } = startBuild(flags);
35
+ const errorParams = { errorMonitor, mode, logs, debug, testOpts };
36
+ try {
37
+ const { pluginsOptions, netlifyConfig: netlifyConfigA, siteInfo, userNodeVersion, stepsCount, timers, durationNs, configMutations, } = await execBuild({
38
+ ...flagsA,
39
+ buildId,
40
+ systemLogFile,
41
+ deployId,
42
+ dry,
43
+ errorMonitor,
44
+ mode,
45
+ logs,
46
+ debug,
47
+ testOpts,
48
+ errorParams,
49
+ });
50
+ await handleBuildSuccess({
51
+ framework,
52
+ dry,
53
+ logs,
54
+ timers,
55
+ durationNs,
56
+ statsdOpts,
57
+ });
58
+ const { success, severityCode, status } = getSeverity('success');
59
+ await telemetryReport({
60
+ buildId,
61
+ deployId,
62
+ status,
63
+ stepsCount,
64
+ pluginsOptions,
65
+ durationNs,
66
+ siteInfo,
67
+ telemetry,
68
+ userNodeVersion,
69
+ framework,
70
+ testOpts,
71
+ errorParams,
72
+ });
73
+ return { success, severityCode, netlifyConfig: netlifyConfigA, logs, configMutations };
74
+ }
75
+ catch (error) {
76
+ const { severity } = await handleBuildError(error, errorParams);
77
+ const { pluginsOptions, siteInfo, userNodeVersion } = errorParams;
78
+ const { success, severityCode, status } = getSeverity(severity);
79
+ await telemetryReport({
80
+ buildId,
81
+ deployId,
82
+ status,
83
+ pluginsOptions,
84
+ siteInfo,
85
+ telemetry,
86
+ userNodeVersion,
87
+ framework,
88
+ testOpts,
89
+ errorParams,
90
+ });
91
+ return { success, severityCode, logs };
92
+ }
119
93
  }
120
-
121
94
  // Logs and reports that a build successfully ended
122
95
  const handleBuildSuccess = async function ({ framework, dry, logs, timers, durationNs, statsdOpts }) {
123
- if (dry) {
124
- return
125
- }
126
-
127
- logBuildSuccess(logs)
128
-
129
- logTimer(logs, durationNs, 'Netlify Build')
130
- await reportTimers({ timers, statsdOpts, framework })
131
- }
132
-
96
+ if (dry) {
97
+ return;
98
+ }
99
+ logBuildSuccess(logs);
100
+ logTimer(logs, durationNs, 'Netlify Build');
101
+ await reportTimers({ timers, statsdOpts, framework });
102
+ };
133
103
  // Handles the calls and errors of telemetry reports
134
- const telemetryReport = async function ({
135
- deployId,
136
- buildId,
137
- status,
138
- stepsCount,
139
- pluginsOptions,
140
- durationNs,
141
- siteInfo,
142
- telemetry,
143
- userNodeVersion,
144
- framework,
145
- testOpts,
146
- errorParams,
147
- }) {
148
- try {
149
- await trackBuildComplete({
150
- deployId,
151
- buildId,
152
- status,
153
- stepsCount,
154
- pluginsOptions,
155
- durationNs,
156
- siteInfo,
157
- telemetry,
158
- userNodeVersion,
159
- framework,
160
- testOpts,
161
- })
162
- } catch (error) {
163
- await handleBuildError(error, errorParams)
164
- }
165
- }
104
+ const telemetryReport = async function ({ deployId, buildId, status, stepsCount, pluginsOptions, durationNs, siteInfo, telemetry, userNodeVersion, framework, testOpts, errorParams, }) {
105
+ try {
106
+ await trackBuildComplete({
107
+ deployId,
108
+ buildId,
109
+ status,
110
+ stepsCount,
111
+ pluginsOptions,
112
+ durationNs,
113
+ siteInfo,
114
+ telemetry,
115
+ userNodeVersion,
116
+ framework,
117
+ testOpts,
118
+ });
119
+ }
120
+ catch (error) {
121
+ await handleBuildError(error, errorParams);
122
+ }
123
+ };
@@ -1,29 +1,17 @@
1
- import { relative } from 'path'
2
-
3
- import { pathExists } from 'path-exists'
4
-
5
- import { logMissingSideFile } from '../log/messages/core.js'
6
-
1
+ import { relative } from 'path';
2
+ import { pathExists } from 'path-exists';
3
+ import { logMissingSideFile } from '../log/messages/core.js';
7
4
  // Some files like `_headers` and `_redirects` must be copied to the publish
8
5
  // directory to be used in production. When those are present in the repository
9
6
  // but not in the publish directory, this most likely indicates that the build
10
7
  // command accidentally forgot to copy those. We then print a warning message.
11
- export const warnOnMissingSideFiles = async function ({
12
- buildDir,
13
- netlifyConfig: {
14
- build: { publish },
15
- },
16
- logs,
17
- }) {
18
- await Promise.all(SIDE_FILES.map((sideFile) => warnOnMissingSideFile({ logs, sideFile, buildDir, publish })))
19
- }
20
-
21
- const SIDE_FILES = ['_headers', '_redirects']
22
-
8
+ export const warnOnMissingSideFiles = async function ({ buildDir, netlifyConfig: { build: { publish }, }, logs, }) {
9
+ await Promise.all(SIDE_FILES.map((sideFile) => warnOnMissingSideFile({ logs, sideFile, buildDir, publish })));
10
+ };
11
+ const SIDE_FILES = ['_headers', '_redirects'];
23
12
  const warnOnMissingSideFile = async function ({ logs, sideFile, buildDir, publish }) {
24
- if (!(await pathExists(`${buildDir}/${sideFile}`)) || (await pathExists(`${publish}/${sideFile}`))) {
25
- return
26
- }
27
-
28
- logMissingSideFile(logs, sideFile, relative(buildDir, publish))
29
- }
13
+ if (!(await pathExists(`${buildDir}/${sideFile}`)) || (await pathExists(`${publish}/${sideFile}`))) {
14
+ return;
15
+ }
16
+ logMissingSideFile(logs, sideFile, relative(buildDir, publish));
17
+ };
@@ -1,70 +1,59 @@
1
- import { env, execPath } from 'process'
2
-
3
- import { logFlags } from '../log/messages/config.js'
4
- import { removeFalsy } from '../utils/remove_falsy.js'
5
-
6
- import { DEFAULT_FEATURE_FLAGS } from './feature_flags.js'
7
-
1
+ import { env, execPath } from 'process';
2
+ import { logFlags } from '../log/messages/config.js';
3
+ import { removeFalsy } from '../utils/remove_falsy.js';
4
+ import { DEFAULT_FEATURE_FLAGS } from './feature_flags.js';
8
5
  // Normalize CLI flags
9
6
  export const normalizeFlags = function (flags, logs) {
10
- const rawFlags = removeFalsy(flags)
11
-
12
- // Combine the flags object env with the process.env
13
- const combinedEnv = { ...env, ...rawFlags.env }
14
- const defaultFlags = getDefaultFlags(rawFlags, combinedEnv)
15
-
16
- // The telemetry flag requires specific logic to compute
17
- const telemetryFlag = computeTelemetry(rawFlags, combinedEnv)
18
-
19
- const mergedFlags = {
20
- ...defaultFlags,
21
- ...rawFlags,
22
- ...telemetryFlag,
23
- statsdOpts: { ...defaultFlags.statsd, ...rawFlags.statsd },
24
- featureFlags: { ...defaultFlags.featureFlags, ...rawFlags.featureFlags },
25
- }
26
- const normalizedFlags = removeFalsy(mergedFlags)
27
-
28
- logFlags(logs, rawFlags, normalizedFlags)
29
-
30
- return normalizedFlags
31
- }
32
-
7
+ const rawFlags = removeFalsy(flags);
8
+ // Combine the flags object env with the process.env
9
+ const combinedEnv = { ...env, ...rawFlags.env };
10
+ const defaultFlags = getDefaultFlags(rawFlags, combinedEnv);
11
+ // The telemetry flag requires specific logic to compute
12
+ const telemetryFlag = computeTelemetry(rawFlags, combinedEnv);
13
+ const mergedFlags = {
14
+ ...defaultFlags,
15
+ ...rawFlags,
16
+ ...telemetryFlag,
17
+ statsdOpts: { ...defaultFlags.statsd, ...rawFlags.statsd },
18
+ featureFlags: { ...defaultFlags.featureFlags, ...rawFlags.featureFlags },
19
+ };
20
+ const normalizedFlags = removeFalsy(mergedFlags);
21
+ logFlags(logs, rawFlags, normalizedFlags);
22
+ return normalizedFlags;
23
+ };
33
24
  // Default values of CLI flags
34
25
  const getDefaultFlags = function ({ env: envOpt = {} }, combinedEnv) {
35
- return {
36
- env: envOpt,
37
- nodePath: execPath,
38
- token: combinedEnv.NETLIFY_AUTH_TOKEN,
39
- mode: REQUIRE_MODE,
40
- offline: false,
41
- telemetry: false,
42
- verbose: Boolean(combinedEnv.NETLIFY_BUILD_DEBUG),
43
- functionsDistDir: DEFAULT_FUNCTIONS_DIST,
44
- edgeFunctionsDistDir: DEFAULT_EDGE_FUNCTIONS_DIST,
45
- cacheDir: DEFAULT_CACHE_DIR,
46
- deployId: combinedEnv.DEPLOY_ID,
47
- buildId: combinedEnv.BUILD_ID,
48
- debug: Boolean(combinedEnv.NETLIFY_BUILD_DEBUG),
49
- bugsnagKey: combinedEnv.BUGSNAG_KEY,
50
- sendStatus: false,
51
- saveConfig: false,
52
- apiHost: 'api.netlify.com',
53
- testOpts: {},
54
- featureFlags: DEFAULT_FEATURE_FLAGS,
55
- statsd: { port: DEFAULT_STATSD_PORT },
56
- timeline: 'build',
57
- }
58
- }
59
-
26
+ return {
27
+ env: envOpt,
28
+ nodePath: execPath,
29
+ token: combinedEnv.NETLIFY_AUTH_TOKEN,
30
+ mode: REQUIRE_MODE,
31
+ offline: false,
32
+ telemetry: false,
33
+ verbose: Boolean(combinedEnv.NETLIFY_BUILD_DEBUG),
34
+ functionsDistDir: DEFAULT_FUNCTIONS_DIST,
35
+ edgeFunctionsDistDir: DEFAULT_EDGE_FUNCTIONS_DIST,
36
+ cacheDir: DEFAULT_CACHE_DIR,
37
+ deployId: combinedEnv.DEPLOY_ID,
38
+ buildId: combinedEnv.BUILD_ID,
39
+ debug: Boolean(combinedEnv.NETLIFY_BUILD_DEBUG),
40
+ bugsnagKey: combinedEnv.BUGSNAG_KEY,
41
+ sendStatus: false,
42
+ saveConfig: false,
43
+ apiHost: 'api.netlify.com',
44
+ testOpts: {},
45
+ featureFlags: DEFAULT_FEATURE_FLAGS,
46
+ statsd: { port: DEFAULT_STATSD_PORT },
47
+ timeline: 'build',
48
+ };
49
+ };
60
50
  // Compute the telemetry flag, it's disabled by default and we want to always disable it
61
51
  // if BUILD_TELEMETRY_DISABLED is passed.
62
52
  const computeTelemetry = function (flags, envOpts) {
63
- return envOpts.BUILD_TELEMETRY_DISABLED ? { telemetry: false } : { telemetry: flags.telemetry }
64
- }
65
-
66
- const REQUIRE_MODE = 'require'
67
- const DEFAULT_EDGE_FUNCTIONS_DIST = '.netlify/edge-functions-dist/'
68
- const DEFAULT_FUNCTIONS_DIST = '.netlify/functions/'
69
- const DEFAULT_CACHE_DIR = '.netlify/cache/'
70
- const DEFAULT_STATSD_PORT = 8125
53
+ return envOpts.BUILD_TELEMETRY_DISABLED ? { telemetry: false } : { telemetry: flags.telemetry };
54
+ };
55
+ const REQUIRE_MODE = 'require';
56
+ const DEFAULT_EDGE_FUNCTIONS_DIST = '.netlify/edge-functions-dist/';
57
+ const DEFAULT_FUNCTIONS_DIST = '.netlify/functions/';
58
+ const DEFAULT_CACHE_DIR = '.netlify/cache/';
59
+ const DEFAULT_STATSD_PORT = 8125;
@@ -1,22 +1,20 @@
1
1
  // Used to extract exit codes and respective status strings
2
2
  // 1|2|3 indicate whether this was a user|plugin|system error.
3
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
-
4
+ const severityEntry = severity in SEVERITY_MAP ? SEVERITY_MAP[severity] : FALLBACK_SEVERITY_ENTRY;
5
+ const success = severity === SUCCESS_SEVERITY;
6
+ return { success, ...severityEntry };
7
+ };
9
8
  // Map error severities to exit codes and status (used for telemetry purposes)
10
-
11
9
  const SEVERITY_MAP = {
12
- success: { severityCode: 0, status: 'success' },
13
- none: { severityCode: 1, status: 'cancelled' },
14
- info: { severityCode: 2, status: 'user-error' },
15
- warning: { severityCode: 3, status: 'plugin-error' },
16
- error: { severityCode: 4, status: 'system-error' },
17
- }
10
+ success: { severityCode: 0, status: 'success' },
11
+ none: { severityCode: 1, status: 'cancelled' },
12
+ info: { severityCode: 2, status: 'user-error' },
13
+ warning: { severityCode: 3, status: 'plugin-error' },
14
+ error: { severityCode: 4, status: 'system-error' },
15
+ };
18
16
  /* eslint-enable no-magic-numbers */
19
- const SUCCESS_SEVERITY = 'success'
17
+ const SUCCESS_SEVERITY = 'success';
20
18
  // Indicates a bug in our codebase
21
- const FALLBACK_SEVERITY = 'error'
22
- export const FALLBACK_SEVERITY_ENTRY = SEVERITY_MAP[FALLBACK_SEVERITY]
19
+ const FALLBACK_SEVERITY = 'error';
20
+ export const FALLBACK_SEVERITY_ENTRY = SEVERITY_MAP[FALLBACK_SEVERITY];
@@ -1,41 +1,32 @@
1
- import { version as currentVersion, execPath } from 'process'
2
-
3
- import { execa } from 'execa'
4
- import semver from 'semver'
5
-
6
- import { addErrorInfo } from '../error/info.js'
7
-
1
+ import { version as currentVersion, execPath } from 'process';
2
+ import { execa } from 'execa';
3
+ import semver from 'semver';
4
+ import { addErrorInfo } from '../error/info.js';
8
5
  // Retrieve Node.js version if the Node.js path is using nvm.
9
6
  // `node.exe` on Windows, `bin/node` on Unix.
10
- const NVM_NODE_VERSION_REGEXP = /[/\\]v(\d+\.\d+\.\d+)[/\\](bin[/\\]node|node.exe)$/
11
-
7
+ const NVM_NODE_VERSION_REGEXP = /[/\\]v(\d+\.\d+\.\d+)[/\\](bin[/\\]node|node.exe)$/;
12
8
  // Retrieve Node.js version from current process
13
9
  const getCurrentNodeVersion = function () {
14
- return semver.clean(currentVersion)
15
- }
16
-
10
+ return semver.clean(currentVersion);
11
+ };
17
12
  // Retrieve Node.js version from `--node-path` or fallback to extracting the current Node.js process version
18
13
  export const getUserNodeVersion = async function (nodePath) {
19
- // No `--node-path` CLI flag, use the current node process version
20
- if (nodePath === execPath) {
21
- return getCurrentNodeVersion()
22
- }
23
-
24
- // Extract version from path
25
- const result = NVM_NODE_VERSION_REGEXP.exec(nodePath)
26
- if (result !== null) {
27
- return result[1]
28
- }
29
-
30
- // Fallback to actually running `node --version` with the given nodePath
31
- const { stdout } = await execa(nodePath, ['--version'], { reject: false })
32
- const version = semver.clean(stdout)
33
-
34
- if (version === null) {
35
- const error = new Error(`Invalid --node-path CLI flag: ${nodePath}`)
36
- addErrorInfo(error, { type: 'resolveConfig' })
37
- throw error
38
- }
39
-
40
- return version
41
- }
14
+ // No `--node-path` CLI flag, use the current node process version
15
+ if (nodePath === execPath) {
16
+ return getCurrentNodeVersion();
17
+ }
18
+ // Extract version from path
19
+ const result = NVM_NODE_VERSION_REGEXP.exec(nodePath);
20
+ if (result !== null) {
21
+ return result[1];
22
+ }
23
+ // Fallback to actually running `node --version` with the given nodePath
24
+ const { stdout } = await execa(nodePath, ['--version'], { reject: false });
25
+ const version = semver.clean(stdout);
26
+ if (version === null) {
27
+ const error = new Error(`Invalid --node-path CLI flag: ${nodePath}`);
28
+ addErrorInfo(error, { type: 'resolveConfig' });
29
+ throw error;
30
+ }
31
+ return version;
32
+ };
@@ -1,51 +1,43 @@
1
- import { env } from 'process'
2
-
3
- import filterObj from 'filter-obj'
4
- import mapObj from 'map-obj'
5
-
1
+ import { env } from 'process';
2
+ import filterObj from 'filter-obj';
3
+ import mapObj from 'map-obj';
6
4
  // If plugins modify `process.env`, this is propagated in other plugins and in
7
5
  // `build.command`. Since those are different processes, we figure out when they
8
6
  // do this and communicate the new `process.env` to other processes.
9
7
  export const getNewEnvChanges = function (envBefore, netlifyConfig, netlifyConfigCopy) {
10
- const processEnvChanges = diffEnv(envBefore, env)
11
- const netlifyConfigEnvChanges = diffEnv(netlifyConfig.build.environment, netlifyConfigCopy.build.environment)
12
- return { ...processEnvChanges, ...netlifyConfigEnvChanges }
13
- }
14
-
8
+ const processEnvChanges = diffEnv(envBefore, env);
9
+ const netlifyConfigEnvChanges = diffEnv(netlifyConfig.build.environment, netlifyConfigCopy.build.environment);
10
+ return { ...processEnvChanges, ...netlifyConfigEnvChanges };
11
+ };
15
12
  const diffEnv = function (envBefore, envAfter) {
16
- const envChanges = filterObj(envAfter, (name, value) => value !== envBefore[name])
17
- const deletedEnv = filterObj(envBefore, (name) => envAfter[name] === undefined)
18
- const deletedEnvA = mapObj(deletedEnv, setToNull)
19
- return { ...envChanges, ...deletedEnvA }
20
- }
21
-
13
+ const envChanges = filterObj(envAfter, (name, value) => value !== envBefore[name]);
14
+ const deletedEnv = filterObj(envBefore, (name) => envAfter[name] === undefined);
15
+ const deletedEnvA = mapObj(deletedEnv, setToNull);
16
+ return { ...envChanges, ...deletedEnvA };
17
+ };
22
18
  // `undefined` is not JSON-serializable (which is used in process IPC), so we
23
19
  // convert it to `null`
24
20
  // Note: `process.env[name] = undefined` actually does
25
21
  // `process.env[name] = 'undefined'` in Node.js.
26
22
  const setToNull = function (name) {
27
- return [name, null]
28
- }
29
-
23
+ return [name, null];
24
+ };
30
25
  // Set `process.env` changes from a previous different plugin.
31
26
  // Can also merge with a `currentEnv` plain object instead of `process.env`.
32
27
  export const setEnvChanges = function (envChanges, currentEnv = env) {
33
- Object.entries(envChanges).forEach(([name, value]) => {
34
- setEnvChange(name, value, currentEnv)
35
- })
36
- return { ...currentEnv }
37
- }
38
-
28
+ Object.entries(envChanges).forEach(([name, value]) => {
29
+ setEnvChange(name, value, currentEnv);
30
+ });
31
+ return { ...currentEnv };
32
+ };
39
33
  const setEnvChange = function (name, value, currentEnv) {
40
- if (currentEnv[name] === value) {
41
- return
42
- }
43
-
44
- if (value === null) {
45
- // `currentEnv` is a mutable variable
46
- delete currentEnv[name]
47
- return
48
- }
49
-
50
- currentEnv[name] = value
51
- }
34
+ if (currentEnv[name] === value) {
35
+ return;
36
+ }
37
+ if (value === null) {
38
+ // `currentEnv` is a mutable variable
39
+ delete currentEnv[name];
40
+ return;
41
+ }
42
+ currentEnv[name] = value;
43
+ };
package/lib/env/main.js CHANGED
@@ -1,19 +1,14 @@
1
- import { env } from 'process'
2
-
3
- import filterObj from 'filter-obj'
4
-
5
- import { getParentColorEnv } from '../log/colors.js'
6
-
1
+ import { env } from 'process';
2
+ import filterObj from 'filter-obj';
3
+ import { getParentColorEnv } from '../log/colors.js';
7
4
  // Retrieve the environment variables passed to plugins and `build.command`
8
5
  // When run locally, this tries to emulate the production environment.
9
6
  export const getChildEnv = function ({ envOpt, env: allConfigEnv }) {
10
- const parentColorEnv = getParentColorEnv()
11
- const parentEnv = { ...env, ...allConfigEnv, ...envOpt, ...parentColorEnv }
12
- return filterObj(parentEnv, shouldKeepEnv)
13
- }
14
-
7
+ const parentColorEnv = getParentColorEnv();
8
+ const parentEnv = { ...env, ...allConfigEnv, ...envOpt, ...parentColorEnv };
9
+ return filterObj(parentEnv, shouldKeepEnv);
10
+ };
15
11
  const shouldKeepEnv = function (key) {
16
- return !REMOVED_PARENT_ENV.has(key.toLowerCase())
17
- }
18
-
19
- const REMOVED_PARENT_ENV = new Set(['bugsnag_key'])
12
+ return !REMOVED_PARENT_ENV.has(key.toLowerCase());
13
+ };
14
+ const REMOVED_PARENT_ENV = new Set(['bugsnag_key']);