@netlify/build 28.0.1-beta → 28.1.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.
Files changed (262) hide show
  1. package/bin.js +5 -0
  2. package/lib/core/bin.js +66 -0
  3. package/lib/core/build.js +355 -0
  4. package/lib/core/config.js +121 -0
  5. package/lib/core/constants.js +116 -0
  6. package/lib/core/dev.js +27 -0
  7. package/lib/core/dry.js +21 -0
  8. package/lib/core/feature_flags.js +19 -0
  9. package/lib/core/flags.js +201 -0
  10. package/lib/core/lingering.js +68 -0
  11. package/lib/core/main.js +107 -0
  12. package/lib/core/missing_side_file.js +17 -0
  13. package/lib/core/normalize_flags.js +59 -0
  14. package/lib/core/severity.js +21 -0
  15. package/lib/core/types.js +8 -0
  16. package/lib/core/user_node_version.js +32 -0
  17. package/lib/env/changes.js +43 -0
  18. package/lib/env/main.js +14 -0
  19. package/lib/env/metadata.js +68 -0
  20. package/lib/error/api.js +37 -0
  21. package/lib/error/build.js +36 -0
  22. package/{src → lib}/error/cancel.js +5 -6
  23. package/lib/error/colors.js +9 -0
  24. package/lib/error/handle.js +46 -0
  25. package/lib/error/info.js +37 -0
  26. package/lib/error/monitor/location.js +16 -0
  27. package/lib/error/monitor/normalize.js +86 -0
  28. package/lib/error/monitor/print.js +20 -0
  29. package/lib/error/monitor/report.js +120 -0
  30. package/lib/error/monitor/start.js +61 -0
  31. package/lib/error/parse/clean_stack.js +70 -0
  32. package/lib/error/parse/location.js +50 -0
  33. package/lib/error/parse/normalize.js +24 -0
  34. package/lib/error/parse/parse.js +67 -0
  35. package/lib/error/parse/plugin.js +55 -0
  36. package/lib/error/parse/properties.js +16 -0
  37. package/lib/error/parse/serialize_log.js +34 -0
  38. package/lib/error/parse/serialize_status.js +18 -0
  39. package/lib/error/parse/stack.js +34 -0
  40. package/lib/error/report.js +27 -0
  41. package/lib/error/type.js +171 -0
  42. package/lib/install/functions.js +20 -0
  43. package/lib/install/local.js +45 -0
  44. package/lib/install/main.js +67 -0
  45. package/lib/install/missing.js +54 -0
  46. package/{src → lib}/log/colors.js +15 -22
  47. package/lib/log/description.js +21 -0
  48. package/lib/log/header.js +14 -0
  49. package/lib/log/header_func.js +13 -0
  50. package/lib/log/logger.js +140 -0
  51. package/lib/log/messages/compatibility.js +120 -0
  52. package/lib/log/messages/config.js +91 -0
  53. package/lib/log/messages/core.js +50 -0
  54. package/lib/log/messages/core_steps.js +75 -0
  55. package/lib/log/messages/dry.js +41 -0
  56. package/lib/log/messages/install.js +25 -0
  57. package/lib/log/messages/ipc.js +29 -0
  58. package/lib/log/messages/mutations.js +62 -0
  59. package/{src → lib}/log/messages/plugins.js +18 -32
  60. package/lib/log/messages/status.js +14 -0
  61. package/lib/log/messages/steps.js +18 -0
  62. package/lib/log/old_version.js +32 -0
  63. package/lib/log/serialize.js +10 -0
  64. package/lib/log/stream.js +68 -0
  65. package/lib/log/theme.js +25 -0
  66. package/lib/plugins/child/diff.js +46 -0
  67. package/lib/plugins/child/error.js +26 -0
  68. package/lib/plugins/child/lazy.js +15 -0
  69. package/lib/plugins/child/load.js +22 -0
  70. package/lib/plugins/child/logic.js +57 -0
  71. package/lib/plugins/child/main.js +37 -0
  72. package/lib/plugins/child/run.js +19 -0
  73. package/lib/plugins/child/status.js +63 -0
  74. package/lib/plugins/child/typescript.js +28 -0
  75. package/lib/plugins/child/utils.js +42 -0
  76. package/lib/plugins/child/validate.js +31 -0
  77. package/lib/plugins/compatibility.js +104 -0
  78. package/{src → lib}/plugins/error.js +31 -35
  79. package/{src → lib}/plugins/events.js +7 -12
  80. package/lib/plugins/expected_version.js +81 -0
  81. package/lib/plugins/internal.js +10 -0
  82. package/lib/plugins/ipc.js +120 -0
  83. package/lib/plugins/list.js +73 -0
  84. package/lib/plugins/load.js +50 -0
  85. package/lib/plugins/manifest/check.js +85 -0
  86. package/lib/plugins/manifest/load.js +38 -0
  87. package/lib/plugins/manifest/main.js +17 -0
  88. package/lib/plugins/manifest/path.js +24 -0
  89. package/lib/plugins/manifest/validate.js +91 -0
  90. package/lib/plugins/node_version.js +30 -0
  91. package/lib/plugins/options.js +55 -0
  92. package/lib/plugins/pinned_version.js +83 -0
  93. package/lib/plugins/resolve.js +110 -0
  94. package/lib/plugins/spawn.js +54 -0
  95. package/lib/plugins_core/add.js +35 -0
  96. package/lib/plugins_core/build_command.js +50 -0
  97. package/lib/plugins_core/deploy/buildbot_client.js +87 -0
  98. package/lib/plugins_core/deploy/index.js +49 -0
  99. package/{src → lib}/plugins_core/deploy/manifest.yml +0 -0
  100. package/lib/plugins_core/edge_functions/index.js +79 -0
  101. package/lib/plugins_core/edge_functions/lib/error.js +17 -0
  102. package/lib/plugins_core/edge_functions/lib/internal_manifest.js +50 -0
  103. package/lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +75 -0
  104. package/lib/plugins_core/functions/error.js +123 -0
  105. package/lib/plugins_core/functions/feature_flags.js +6 -0
  106. package/lib/plugins_core/functions/index.js +114 -0
  107. package/lib/plugins_core/functions/utils.js +45 -0
  108. package/lib/plugins_core/functions/zisi.js +39 -0
  109. package/{src → lib}/plugins_core/functions_install/index.js +8 -11
  110. package/{src → lib}/plugins_core/functions_install/manifest.yml +0 -0
  111. package/lib/plugins_core/list.js +20 -0
  112. package/lib/report/statsd.js +31 -0
  113. package/lib/status/add.js +30 -0
  114. package/lib/status/colors.js +18 -0
  115. package/lib/status/load_error.js +10 -0
  116. package/lib/status/report.js +83 -0
  117. package/lib/status/success.js +14 -0
  118. package/lib/steps/core_step.js +59 -0
  119. package/lib/steps/error.js +65 -0
  120. package/lib/steps/get.js +43 -0
  121. package/lib/steps/plugin.js +55 -0
  122. package/lib/steps/return.js +25 -0
  123. package/lib/steps/run_core_steps.js +126 -0
  124. package/lib/steps/run_step.js +189 -0
  125. package/lib/steps/run_steps.js +96 -0
  126. package/lib/steps/update_config.js +66 -0
  127. package/lib/telemetry/main.js +97 -0
  128. package/lib/time/aggregate.js +109 -0
  129. package/lib/time/main.js +31 -0
  130. package/lib/time/measure.js +18 -0
  131. package/lib/time/report.js +24 -0
  132. package/lib/utils/errors.js +13 -0
  133. package/lib/utils/json.js +15 -0
  134. package/{src → lib}/utils/omit.js +3 -4
  135. package/lib/utils/package.js +22 -0
  136. package/lib/utils/remove_falsy.js +8 -0
  137. package/lib/utils/resolve.js +41 -0
  138. package/lib/utils/runtime.js +5 -0
  139. package/lib/utils/semver.js +28 -0
  140. package/package.json +41 -20
  141. package/types/config/netlify_config.d.ts +4 -4
  142. package/types/netlify_plugin_constants.d.ts +8 -8
  143. package/src/core/bin.js +0 -83
  144. package/src/core/config.js +0 -186
  145. package/src/core/constants.js +0 -156
  146. package/src/core/dry.js +0 -39
  147. package/src/core/feature_flags.js +0 -21
  148. package/src/core/flags.js +0 -194
  149. package/src/core/lingering.js +0 -85
  150. package/src/core/main.js +0 -692
  151. package/src/core/missing_side_file.js +0 -29
  152. package/src/core/normalize_flags.js +0 -69
  153. package/src/core/severity.js +0 -22
  154. package/src/core/user_node_version.js +0 -41
  155. package/src/env/changes.js +0 -52
  156. package/src/env/main.js +0 -19
  157. package/src/env/metadata.js +0 -81
  158. package/src/error/api.js +0 -46
  159. package/src/error/build.js +0 -50
  160. package/src/error/colors.js +0 -11
  161. package/src/error/handle.js +0 -57
  162. package/src/error/info.js +0 -46
  163. package/src/error/monitor/location.js +0 -21
  164. package/src/error/monitor/normalize.js +0 -77
  165. package/src/error/monitor/print.js +0 -42
  166. package/src/error/monitor/report.js +0 -133
  167. package/src/error/monitor/start.js +0 -69
  168. package/src/error/parse/clean_stack.js +0 -87
  169. package/src/error/parse/location.js +0 -58
  170. package/src/error/parse/normalize.js +0 -29
  171. package/src/error/parse/parse.js +0 -97
  172. package/src/error/parse/plugin.js +0 -70
  173. package/src/error/parse/properties.js +0 -23
  174. package/src/error/parse/serialize_log.js +0 -42
  175. package/src/error/parse/serialize_status.js +0 -23
  176. package/src/error/parse/stack.js +0 -43
  177. package/src/error/type.js +0 -182
  178. package/src/install/functions.js +0 -28
  179. package/src/install/local.js +0 -62
  180. package/src/install/main.js +0 -81
  181. package/src/install/missing.js +0 -67
  182. package/src/log/description.js +0 -26
  183. package/src/log/header.js +0 -16
  184. package/src/log/header_func.js +0 -17
  185. package/src/log/logger.js +0 -107
  186. package/src/log/messages/compatibility.js +0 -164
  187. package/src/log/messages/config.js +0 -105
  188. package/src/log/messages/core.js +0 -70
  189. package/src/log/messages/core_steps.js +0 -104
  190. package/src/log/messages/dry.js +0 -63
  191. package/src/log/messages/install.js +0 -20
  192. package/src/log/messages/ipc.js +0 -38
  193. package/src/log/messages/mutations.js +0 -82
  194. package/src/log/messages/status.js +0 -16
  195. package/src/log/messages/steps.js +0 -22
  196. package/src/log/old_version.js +0 -41
  197. package/src/log/serialize.js +0 -13
  198. package/src/log/stream.js +0 -85
  199. package/src/log/theme.js +0 -26
  200. package/src/plugins/child/diff.js +0 -55
  201. package/src/plugins/child/error.js +0 -32
  202. package/src/plugins/child/lazy.js +0 -18
  203. package/src/plugins/child/load.js +0 -29
  204. package/src/plugins/child/logic.js +0 -57
  205. package/src/plugins/child/main.js +0 -51
  206. package/src/plugins/child/run.js +0 -28
  207. package/src/plugins/child/status.js +0 -67
  208. package/src/plugins/child/typescript.js +0 -45
  209. package/src/plugins/child/utils.js +0 -56
  210. package/src/plugins/child/validate.js +0 -34
  211. package/src/plugins/compatibility.js +0 -128
  212. package/src/plugins/expected_version.js +0 -119
  213. package/src/plugins/ipc.js +0 -145
  214. package/src/plugins/list.js +0 -86
  215. package/src/plugins/load.js +0 -70
  216. package/src/plugins/manifest/check.js +0 -106
  217. package/src/plugins/manifest/load.js +0 -41
  218. package/src/plugins/manifest/main.js +0 -22
  219. package/src/plugins/manifest/path.js +0 -31
  220. package/src/plugins/manifest/validate.js +0 -108
  221. package/src/plugins/node_version.js +0 -50
  222. package/src/plugins/options.js +0 -88
  223. package/src/plugins/pinned_version.js +0 -131
  224. package/src/plugins/resolve.js +0 -152
  225. package/src/plugins/spawn.js +0 -66
  226. package/src/plugins_core/add.js +0 -49
  227. package/src/plugins_core/build_command.js +0 -75
  228. package/src/plugins_core/deploy/buildbot_client.js +0 -102
  229. package/src/plugins_core/deploy/index.js +0 -73
  230. package/src/plugins_core/edge_functions/index.js +0 -107
  231. package/src/plugins_core/edge_functions/lib/internal_manifest.js +0 -54
  232. package/src/plugins_core/functions/error.js +0 -163
  233. package/src/plugins_core/functions/feature_flags.js +0 -6
  234. package/src/plugins_core/functions/index.js +0 -160
  235. package/src/plugins_core/functions/utils.js +0 -66
  236. package/src/plugins_core/functions/zisi.js +0 -53
  237. package/src/plugins_core/list.js +0 -27
  238. package/src/status/add.js +0 -36
  239. package/src/status/colors.js +0 -23
  240. package/src/status/load_error.js +0 -11
  241. package/src/status/report.js +0 -128
  242. package/src/status/success.js +0 -18
  243. package/src/steps/core_step.js +0 -90
  244. package/src/steps/error.js +0 -102
  245. package/src/steps/get.js +0 -32
  246. package/src/steps/plugin.js +0 -85
  247. package/src/steps/return.js +0 -52
  248. package/src/steps/run_core_steps.js +0 -194
  249. package/src/steps/run_step.js +0 -300
  250. package/src/steps/run_steps.js +0 -179
  251. package/src/steps/update_config.js +0 -93
  252. package/src/telemetry/main.js +0 -136
  253. package/src/time/aggregate.js +0 -146
  254. package/src/time/main.js +0 -48
  255. package/src/time/measure.js +0 -22
  256. package/src/time/report.js +0 -59
  257. package/src/utils/errors.js +0 -12
  258. package/src/utils/json.js +0 -19
  259. package/src/utils/package.js +0 -23
  260. package/src/utils/remove_falsy.js +0 -10
  261. package/src/utils/resolve.js +0 -46
  262. package/src/utils/semver.js +0 -34
@@ -0,0 +1,25 @@
1
+ import { logTimer } from '../log/messages/core.js';
2
+ import { logStepSuccess } from '../log/messages/steps.js';
3
+ import { handleStepError } from './error.js';
4
+ // Retrieve the return value of a step
5
+ export const getStepReturn = function ({ event, packageName, newError, newEnvChanges, newStatus, coreStep, coreStepName: timerName = `${packageName} ${event}`, childEnv, mode, api, errorMonitor, deployId, netlifyConfig, configMutations, headersPath, redirectsPath, logs, debug, timers, durationNs, testOpts, }) {
6
+ if (newError !== undefined) {
7
+ return handleStepError({
8
+ event,
9
+ newError,
10
+ childEnv,
11
+ mode,
12
+ api,
13
+ errorMonitor,
14
+ deployId,
15
+ coreStep,
16
+ netlifyConfig,
17
+ logs,
18
+ debug,
19
+ testOpts,
20
+ });
21
+ }
22
+ logStepSuccess(logs);
23
+ logTimer(logs, durationNs, timerName);
24
+ return { newEnvChanges, netlifyConfig, configMutations, headersPath, redirectsPath, newStatus, timers };
25
+ };
@@ -0,0 +1,126 @@
1
+ import { getConfigOpts, loadConfig } from '../core/config.js';
2
+ import { getConstants } from '../core/constants.js';
3
+ import { normalizeFlags } from '../core/normalize_flags.js';
4
+ import { getSeverity } from '../core/severity.js';
5
+ import { handleBuildError } from '../error/handle.js';
6
+ import { getErrorInfo } from '../error/info.js';
7
+ import { startErrorMonitor } from '../error/monitor/start.js';
8
+ import { getBufferLogs, getSystemLogger } from '../log/logger.js';
9
+ import { logBuildStart } from '../log/messages/core.js';
10
+ import { reportStatuses } from '../status/report.js';
11
+ import { getSteps } from './get.js';
12
+ import { runSteps } from './run_steps.js';
13
+ /**
14
+ * Runs specific core steps for a build and returns whether it succeeded or not.
15
+ */
16
+ export const runCoreSteps = async (buildSteps, flags = {}) => {
17
+ const { errorMonitor, mode, logs, debug, ...flagsA } = startBuild(flags);
18
+ const errorParams = { errorMonitor, mode, logs, debug };
19
+ const systemLog = getSystemLogger(logs, debug);
20
+ try {
21
+ const { netlifyConfig: netlifyConfigA, configMutations } = await executeBuildStep({
22
+ ...flagsA,
23
+ errorMonitor,
24
+ mode,
25
+ logs,
26
+ debug,
27
+ errorParams,
28
+ buildSteps,
29
+ systemLog,
30
+ });
31
+ const { success, severityCode } = getSeverity('success');
32
+ return { success, severityCode, netlifyConfig: netlifyConfigA, configMutations, logs };
33
+ }
34
+ catch (error) {
35
+ const { severity } = await handleBuildError(error, errorParams);
36
+ const { success, severityCode } = getSeverity(severity);
37
+ return { success, severityCode, logs };
38
+ }
39
+ };
40
+ const startBuild = function (flags) {
41
+ const logs = getBufferLogs(flags);
42
+ logBuildStart(logs);
43
+ const { bugsnagKey, ...flagsA } = normalizeFlags(flags, logs);
44
+ const errorMonitor = startErrorMonitor({ flags: flagsA, logs, bugsnagKey });
45
+ return { ...flagsA, errorMonitor, logs };
46
+ };
47
+ const getBuildSteps = function (buildSteps) {
48
+ const allSteps = getSteps([]).steps.filter(({ coreStepId }) => buildSteps.includes(coreStepId));
49
+ return allSteps;
50
+ };
51
+ const executeBuildStep = async function ({ config, defaultConfig, cachedConfig, debug, nodePath, functionsDistDir, edgeFunctionsDistDir, errorMonitor, mode, logs, errorParams, featureFlags, buildSteps, repositoryRoot, systemLog, }) {
52
+ const configOpts = getConfigOpts({
53
+ config,
54
+ defaultConfig,
55
+ featureFlags,
56
+ mode,
57
+ repositoryRoot,
58
+ });
59
+ const { netlifyConfig, buildDir, siteInfo, childEnv, userNodeVersion, repositoryRoot: repositoryRootA, } = await loadConfig({
60
+ configOpts,
61
+ cachedConfig,
62
+ debug,
63
+ logs,
64
+ nodePath,
65
+ timers: [],
66
+ });
67
+ const constants = await getConstants({
68
+ buildDir,
69
+ functionsDistDir,
70
+ edgeFunctionsDistDir,
71
+ netlifyConfig,
72
+ siteInfo,
73
+ mode,
74
+ });
75
+ Object.assign(errorParams, { netlifyConfig, siteInfo, childEnv, userNodeVersion });
76
+ try {
77
+ const { netlifyConfig: netlifyConfigA, configMutations } = await runBuildStep({
78
+ netlifyConfig,
79
+ buildDir,
80
+ nodePath,
81
+ logs,
82
+ debug,
83
+ constants,
84
+ featureFlags,
85
+ childEnv,
86
+ buildSteps,
87
+ repositoryRoot: repositoryRootA,
88
+ systemLog,
89
+ });
90
+ return {
91
+ netlifyConfig: netlifyConfigA,
92
+ configMutations,
93
+ };
94
+ }
95
+ catch (error) {
96
+ const [{ statuses }] = getErrorInfo(error);
97
+ await reportStatuses({
98
+ statuses,
99
+ childEnv,
100
+ mode,
101
+ netlifyConfig,
102
+ errorMonitor,
103
+ logs,
104
+ debug,
105
+ pluginsOptions: [],
106
+ });
107
+ throw error;
108
+ }
109
+ };
110
+ const runBuildStep = async function ({ netlifyConfig, buildDir, nodePath, constants, logs, debug, featureFlags, childEnv, buildSteps, repositoryRoot, systemLog, }) {
111
+ const { netlifyConfig: netlifyConfigA, configMutations } = await runSteps({
112
+ steps: getBuildSteps(buildSteps),
113
+ buildDir,
114
+ nodePath,
115
+ constants,
116
+ netlifyConfig,
117
+ logs,
118
+ debug,
119
+ timers: [],
120
+ featureFlags,
121
+ childEnv,
122
+ repositoryRoot,
123
+ systemLog,
124
+ });
125
+ return { netlifyConfig: netlifyConfigA, configMutations };
126
+ };
@@ -0,0 +1,189 @@
1
+ import { addMutableConstants } from '../core/constants.js';
2
+ import { logStepStart } from '../log/messages/steps.js';
3
+ import { runsAlsoOnBuildFailure, runsOnlyOnBuildFailure } from '../plugins/events.js';
4
+ import { normalizeTagName } from '../report/statsd.js';
5
+ import { measureDuration } from '../time/main.js';
6
+ import { fireCoreStep } from './core_step.js';
7
+ import { firePluginStep } from './plugin.js';
8
+ import { getStepReturn } from './return.js';
9
+ // Run a step (core, build command or plugin)
10
+ export const runStep = async function ({ event, childProcess, packageName, coreStep, coreStepId, coreStepName, coreStepDescription, pluginPackageJson, loadedFrom, origin, condition, configPath, buildDir, repositoryRoot, nodePath, index, childEnv, context, branch, envChanges, constants, steps, buildbotServerSocket, events, mode, api, errorMonitor, deployId, errorParams, error, failedPlugins, configOpts, netlifyConfig, configMutations, headersPath, redirectsPath, logs, debug, systemLog, verbose, saveConfig, timers, testOpts, featureFlags, }) {
11
+ const constantsA = await addMutableConstants({ constants, buildDir, netlifyConfig });
12
+ if (!(await shouldRunStep({
13
+ event,
14
+ packageName,
15
+ error,
16
+ failedPlugins,
17
+ netlifyConfig,
18
+ condition,
19
+ constants: constantsA,
20
+ buildbotServerSocket,
21
+ buildDir,
22
+ }))) {
23
+ return {};
24
+ }
25
+ logStepStart({ logs, event, packageName, coreStepDescription, index, error, netlifyConfig });
26
+ const fireStep = getFireStep(packageName, coreStepId, event);
27
+ const { newEnvChanges, netlifyConfig: netlifyConfigA = netlifyConfig, configMutations: configMutationsA = configMutations, headersPath: headersPathA = headersPath, redirectsPath: redirectsPathA = redirectsPath, newError, newStatus, timers: timersA, durationNs, } = await fireStep({
28
+ event,
29
+ childProcess,
30
+ packageName,
31
+ pluginPackageJson,
32
+ loadedFrom,
33
+ origin,
34
+ coreStep,
35
+ coreStepId,
36
+ coreStepName,
37
+ configPath,
38
+ buildDir,
39
+ repositoryRoot,
40
+ nodePath,
41
+ childEnv,
42
+ context,
43
+ branch,
44
+ envChanges,
45
+ constants: constantsA,
46
+ steps,
47
+ buildbotServerSocket,
48
+ events,
49
+ error,
50
+ logs,
51
+ debug,
52
+ systemLog,
53
+ verbose,
54
+ saveConfig,
55
+ timers,
56
+ errorParams,
57
+ configOpts,
58
+ netlifyConfig,
59
+ configMutations,
60
+ headersPath,
61
+ redirectsPath,
62
+ featureFlags,
63
+ });
64
+ const newValues = await getStepReturn({
65
+ event,
66
+ packageName,
67
+ newError,
68
+ newEnvChanges,
69
+ newStatus,
70
+ coreStep,
71
+ coreStepName,
72
+ childEnv,
73
+ mode,
74
+ api,
75
+ errorMonitor,
76
+ deployId,
77
+ netlifyConfig: netlifyConfigA,
78
+ configMutations: configMutationsA,
79
+ headersPath: headersPathA,
80
+ redirectsPath: redirectsPathA,
81
+ logs,
82
+ debug,
83
+ timers: timersA,
84
+ durationNs,
85
+ testOpts,
86
+ });
87
+ return { ...newValues, newIndex: index + 1 };
88
+ };
89
+ // A plugin fails _without making the build fail_ when either:
90
+ // - using `utils.build.failPlugin()`
91
+ // - the failure happens after deploy. This means: inside any `onError`,
92
+ // `onSuccess` or `onEnd` event handler.
93
+ //
94
+ // When that happens, no other events for that specific plugin is run.
95
+ // Not even `onError` and `onEnd`.
96
+ // Plugins should use `try`/`catch`/`finally` blocks to handle exceptions,
97
+ // not `onError` nor `onEnd`.
98
+ //
99
+ // Otherwise, most failures will make the build fail. This includes:
100
+ // - the build command failed
101
+ // - Functions or Edge Functions bundling failed
102
+ // - the deploy failed (deploying files to our CDN)
103
+ // - a plugin `onPreBuild`, `onBuild` or `onPostBuild` event handler failed.
104
+ // This includes uncaught exceptions and using `utils.build.failBuild()`
105
+ // or `utils.build.cancelBuild()`.
106
+ //
107
+ // `onError` is triggered when the build failed.
108
+ // It means "on build failure" not "on plugin failure".
109
+ // `onSuccess` is the opposite. It is triggered after the build succeeded.
110
+ // `onEnd` is triggered after the build either failed or succeeded.
111
+ // It is useful for resources cleanup.
112
+ //
113
+ // Finally, some plugins (only core plugins for the moment) might be enabled or
114
+ // not depending on whether a specific action is happening during the build,
115
+ // such as creating a file. For example, the Functions and Edge Functions core
116
+ // plugins are disabled if no Functions or Edge Functions directory is specified
117
+ // or available. However, one might be created by a build plugin, in which case,
118
+ // those core plugins should be triggered. We use a dynamic `condition()` to
119
+ // model this behavior.
120
+ const shouldRunStep = async function ({ event, packageName, error, failedPlugins, netlifyConfig, condition, constants, buildbotServerSocket, buildDir, }) {
121
+ if (failedPlugins.includes(packageName) ||
122
+ (condition !== undefined && !(await condition({ buildDir, constants, buildbotServerSocket, netlifyConfig })))) {
123
+ return false;
124
+ }
125
+ if (error !== undefined) {
126
+ return runsAlsoOnBuildFailure(event);
127
+ }
128
+ return !runsOnlyOnBuildFailure(event);
129
+ };
130
+ // Wrap step function to measure its time
131
+ const getFireStep = function (packageName, coreStepId, event) {
132
+ if (coreStepId !== undefined) {
133
+ return measureDuration(tFireStep, coreStepId);
134
+ }
135
+ const parentTag = normalizeTagName(packageName);
136
+ return measureDuration(tFireStep, event, { parentTag, category: 'pluginEvent' });
137
+ };
138
+ const tFireStep = function ({ event, childProcess, packageName, pluginPackageJson, loadedFrom, origin, coreStep, coreStepId, coreStepName, configPath, buildDir, repositoryRoot, nodePath, childEnv, context, branch, envChanges, constants, steps, buildbotServerSocket, events, error, logs, debug, systemLog, verbose, saveConfig, errorParams, configOpts, netlifyConfig, configMutations, headersPath, redirectsPath, featureFlags, }) {
139
+ if (coreStep !== undefined) {
140
+ return fireCoreStep({
141
+ coreStep,
142
+ coreStepId,
143
+ coreStepName,
144
+ configPath,
145
+ buildDir,
146
+ repositoryRoot,
147
+ constants,
148
+ buildbotServerSocket,
149
+ events,
150
+ logs,
151
+ nodePath,
152
+ childEnv,
153
+ context,
154
+ branch,
155
+ envChanges,
156
+ errorParams,
157
+ configOpts,
158
+ netlifyConfig,
159
+ configMutations,
160
+ headersPath,
161
+ redirectsPath,
162
+ featureFlags,
163
+ debug,
164
+ systemLog,
165
+ saveConfig,
166
+ });
167
+ }
168
+ return firePluginStep({
169
+ event,
170
+ childProcess,
171
+ packageName,
172
+ pluginPackageJson,
173
+ loadedFrom,
174
+ origin,
175
+ envChanges,
176
+ errorParams,
177
+ configOpts,
178
+ netlifyConfig,
179
+ configMutations,
180
+ headersPath,
181
+ redirectsPath,
182
+ constants,
183
+ steps,
184
+ error,
185
+ logs,
186
+ debug,
187
+ verbose,
188
+ });
189
+ };
@@ -0,0 +1,96 @@
1
+ import pReduce from 'p-reduce';
2
+ import { addErrorInfo } from '../error/info.js';
3
+ import { addStatus } from '../status/add.js';
4
+ import { runStep } from './run_step.js';
5
+ // Run all steps.
6
+ // Each step can change some state: last `error`, environment variables changes,
7
+ // list of `failedPlugins` (that ran `utils.build.failPlugin()`).
8
+ // If an error arises, runs `onError` events.
9
+ // Runs `onEnd` events at the end, whether an error was thrown or not.
10
+ export const runSteps = async function ({ steps, buildbotServerSocket, events, configPath, headersPath, redirectsPath, buildDir, repositoryRoot, nodePath, childEnv, context, branch, constants, mode, api, errorMonitor, deployId, errorParams, netlifyConfig, configOpts, logs, debug, systemLog, verbose, saveConfig, timers, testOpts, featureFlags, }) {
11
+ const { index: stepsCount, error: errorA, netlifyConfig: netlifyConfigC, statuses: statusesB, failedPlugins: failedPluginsA, timers: timersC, configMutations: configMutationsB, } = await pReduce(steps, async ({ index, error, failedPlugins, envChanges, netlifyConfig: netlifyConfigA, configMutations, headersPath: headersPathA, redirectsPath: redirectsPathA, statuses, timers: timersA, }, { event, childProcess, packageName, coreStep, coreStepId, coreStepName, coreStepDescription, pluginPackageJson, loadedFrom, origin, condition, }) => {
12
+ const { newIndex = index, newError = error, failedPlugin = [], newEnvChanges = {}, netlifyConfig: netlifyConfigB = netlifyConfigA, configMutations: configMutationsA = configMutations, headersPath: headersPathB = headersPathA, redirectsPath: redirectsPathB = redirectsPathA, newStatus, timers: timersB = timersA, } = await runStep({
13
+ event,
14
+ childProcess,
15
+ packageName,
16
+ coreStep,
17
+ coreStepId,
18
+ coreStepName,
19
+ coreStepDescription,
20
+ pluginPackageJson,
21
+ loadedFrom,
22
+ origin,
23
+ condition,
24
+ configPath,
25
+ buildDir,
26
+ repositoryRoot,
27
+ nodePath,
28
+ index,
29
+ childEnv,
30
+ context,
31
+ branch,
32
+ envChanges,
33
+ constants,
34
+ steps,
35
+ buildbotServerSocket,
36
+ events,
37
+ mode,
38
+ api,
39
+ errorMonitor,
40
+ deployId,
41
+ errorParams,
42
+ error,
43
+ failedPlugins,
44
+ configOpts,
45
+ netlifyConfig: netlifyConfigA,
46
+ configMutations,
47
+ headersPath: headersPathA,
48
+ redirectsPath: redirectsPathA,
49
+ logs,
50
+ debug,
51
+ systemLog,
52
+ verbose,
53
+ saveConfig,
54
+ timers: timersA,
55
+ testOpts,
56
+ featureFlags,
57
+ });
58
+ const statusesA = addStatus({ newStatus, statuses, event, packageName, pluginPackageJson });
59
+ return {
60
+ index: newIndex,
61
+ error: newError,
62
+ failedPlugins: [...failedPlugins, ...failedPlugin],
63
+ envChanges: { ...envChanges, ...newEnvChanges },
64
+ netlifyConfig: netlifyConfigB,
65
+ configMutations: configMutationsA,
66
+ headersPath: headersPathB,
67
+ redirectsPath: redirectsPathB,
68
+ statuses: statusesA,
69
+ timers: timersB,
70
+ };
71
+ }, {
72
+ index: 0,
73
+ failedPlugins: [],
74
+ envChanges: {},
75
+ netlifyConfig,
76
+ configMutations: [],
77
+ headersPath,
78
+ redirectsPath,
79
+ statuses: [],
80
+ timers,
81
+ });
82
+ // Instead of throwing any build failure right away, we wait for `onError`,
83
+ // etc. to complete. This is why we are throwing only now.
84
+ if (errorA !== undefined) {
85
+ addErrorInfo(errorA, { statuses: statusesB });
86
+ throw errorA;
87
+ }
88
+ return {
89
+ stepsCount,
90
+ netlifyConfig: netlifyConfigC,
91
+ statuses: statusesB,
92
+ failedPlugins: failedPluginsA,
93
+ timers: timersC,
94
+ configMutations: configMutationsB,
95
+ };
96
+ };
@@ -0,0 +1,66 @@
1
+ import { isDeepStrictEqual } from 'util';
2
+ import pFilter from 'p-filter';
3
+ import { pathExists } from 'path-exists';
4
+ import { resolveUpdatedConfig } from '../core/config.js';
5
+ import { addErrorInfo } from '../error/info.js';
6
+ import { logConfigOnUpdate } from '../log/messages/config.js';
7
+ import { logConfigMutations } from '../log/messages/mutations.js';
8
+ // If `netlifyConfig` was updated or `_redirects` was created, the configuration
9
+ // is updated by calling `@netlify/config` again.
10
+ export const updateNetlifyConfig = async function ({ configOpts, netlifyConfig, headersPath, redirectsPath, configMutations, newConfigMutations, configSideFiles, errorParams, logs, debug, }) {
11
+ if (!(await shouldUpdateConfig({ newConfigMutations, configSideFiles, headersPath, redirectsPath }))) {
12
+ return { netlifyConfig, configMutations };
13
+ }
14
+ validateConfigMutations(newConfigMutations);
15
+ logConfigMutations(logs, newConfigMutations, debug);
16
+ const configMutationsA = [...configMutations, ...newConfigMutations];
17
+ const { config: netlifyConfigA, headersPath: headersPathA, redirectsPath: redirectsPathA, } = await resolveUpdatedConfig(configOpts, configMutationsA);
18
+ logConfigOnUpdate({ logs, netlifyConfig: netlifyConfigA, debug });
19
+ errorParams.netlifyConfig = netlifyConfigA;
20
+ return {
21
+ netlifyConfig: netlifyConfigA,
22
+ configMutations: configMutationsA,
23
+ headersPath: headersPathA,
24
+ redirectsPath: redirectsPathA,
25
+ };
26
+ };
27
+ const shouldUpdateConfig = async function ({ newConfigMutations, configSideFiles, headersPath, redirectsPath }) {
28
+ return (newConfigMutations.length !== 0 || (await haveConfigSideFilesChanged(configSideFiles, headersPath, redirectsPath)));
29
+ };
30
+ // The configuration mostly depends on `netlify.toml` and UI build settings.
31
+ // However, it also uses some additional optional side files like `_redirects`.
32
+ // Those are often created by the build command. When those are created, we need
33
+ // to update the configuration. We detect this by checking for file existence
34
+ // before and after running plugins and the build command.
35
+ const haveConfigSideFilesChanged = async function (configSideFiles, headersPath, redirectsPath) {
36
+ const newSideFiles = await listConfigSideFiles([headersPath, redirectsPath]);
37
+ return !isDeepStrictEqual(newSideFiles, configSideFiles);
38
+ };
39
+ // List all the files used for configuration besides `netlify.toml`.
40
+ // This is useful when applying configuration mutations since those files
41
+ // sometimes have higher priority and should therefore be deleted in order to
42
+ // apply any configuration update on `netlify.toml`.
43
+ export const listConfigSideFiles = async function (sideFiles) {
44
+ const configSideFiles = await pFilter(sideFiles, pathExists);
45
+ return configSideFiles.sort();
46
+ };
47
+ // Validate each new configuration change
48
+ const validateConfigMutations = function (newConfigMutations) {
49
+ try {
50
+ newConfigMutations.forEach(validateConfigMutation);
51
+ }
52
+ catch (error) {
53
+ addErrorInfo(error, { type: 'pluginValidation' });
54
+ throw error;
55
+ }
56
+ };
57
+ // Triggered when calling `netlifyConfig.{key} = undefined | null`
58
+ // We do not allow this because the back-end only receives mutations as a
59
+ // `netlify.toml`, i.e. cannot apply property deletions since `undefined` is
60
+ // not serializable in TOML.
61
+ const validateConfigMutation = function ({ value, keysString }) {
62
+ if (value === undefined || value === null) {
63
+ throw new Error(`Setting "netlifyConfig.${keysString}" to ${value} is not allowed.
64
+ Please set this property to a specific value instead.`);
65
+ }
66
+ };
@@ -0,0 +1,97 @@
1
+ import { platform } from 'process';
2
+ import got from 'got';
3
+ import osName from 'os-name';
4
+ import { addErrorInfo } from '../error/info.js';
5
+ import { roundTimerToMillisecs } from '../time/measure.js';
6
+ import { ROOT_PACKAGE_JSON } from '../utils/json.js';
7
+ const DEFAULT_TELEMETRY_TIMEOUT = 1200;
8
+ const DEFAULT_TELEMETRY_CONFIG = {
9
+ origin: 'https://api.segment.io/v1',
10
+ writeKey: 'dWhlM1lYSlpNd1k5Uk9rcjFra2JSOEoybnRjZjl0YTI6',
11
+ timeout: DEFAULT_TELEMETRY_TIMEOUT,
12
+ };
13
+ // Send telemetry request when build completes
14
+ export const trackBuildComplete = async function ({ deployId, buildId, status, stepsCount, pluginsOptions, durationNs, siteInfo, telemetry, userNodeVersion, framework, testOpts: { telemetryOrigin = DEFAULT_TELEMETRY_CONFIG.origin, telemetryTimeout = DEFAULT_TELEMETRY_CONFIG.timeout }, }) {
15
+ if (!telemetry) {
16
+ return;
17
+ }
18
+ try {
19
+ const payload = getPayload({
20
+ deployId,
21
+ buildId,
22
+ status,
23
+ stepsCount,
24
+ pluginsOptions,
25
+ durationNs,
26
+ siteInfo,
27
+ userNodeVersion,
28
+ framework,
29
+ });
30
+ await track({
31
+ payload,
32
+ config: { ...DEFAULT_TELEMETRY_CONFIG, origin: telemetryOrigin, timeout: telemetryTimeout },
33
+ });
34
+ }
35
+ catch (error) {
36
+ addErrorInfo(error, { type: 'telemetry' });
37
+ throw error;
38
+ }
39
+ };
40
+ // Send track HTTP request to telemetry.
41
+ const track = async function ({ payload, config: { origin, writeKey, timeout } }) {
42
+ const url = `${origin}/track`;
43
+ await got.post(url, {
44
+ json: payload,
45
+ timeout,
46
+ retry: 0,
47
+ headers: { Authorization: `Basic ${writeKey}` },
48
+ });
49
+ };
50
+ // Retrieve telemetry information
51
+ // siteInfo can be empty if the build fails during the get config step
52
+ const getPayload = function ({ deployId, buildId, status, stepsCount, pluginsOptions, durationNs, userNodeVersion, siteInfo = {}, framework, }) {
53
+ return {
54
+ userId: 'buildbot_user',
55
+ event: 'build:ci_build_process_completed',
56
+ timestamp: Date.now(),
57
+ properties: {
58
+ deployId,
59
+ buildId,
60
+ status,
61
+ steps: stepsCount,
62
+ buildVersion: ROOT_PACKAGE_JSON.version,
63
+ // We're passing the node version set by the buildbot/user which will run the `build.command` and
64
+ // the `package.json`/locally defined plugins
65
+ nodeVersion: userNodeVersion,
66
+ osPlatform: OS_TYPES[platform],
67
+ osName: osName(),
68
+ framework,
69
+ siteId: siteInfo.id,
70
+ ...(pluginsOptions !== undefined && {
71
+ plugins: pluginsOptions.map(getPlugin),
72
+ pluginCount: pluginsOptions.length,
73
+ }),
74
+ ...(durationNs !== undefined && { duration: roundTimerToMillisecs(durationNs) }),
75
+ },
76
+ };
77
+ };
78
+ const OS_TYPES = {
79
+ linux: 'Linux',
80
+ darwin: 'MacOS',
81
+ win32: 'Windows',
82
+ android: 'Android',
83
+ sunos: 'SunOS',
84
+ aix: 'AIX',
85
+ freebsd: 'FreeBSD',
86
+ openbsd: 'OpenBSD',
87
+ };
88
+ const getPlugin = function ({ packageName, origin, loadedFrom, nodeVersion, pinnedVersion, pluginPackageJson: { version } = {}, }) {
89
+ const installType = getInstallType(origin, loadedFrom);
90
+ return { name: packageName, installType, nodeVersion, pinnedVersion, version };
91
+ };
92
+ const getInstallType = function (origin, loadedFrom) {
93
+ if (loadedFrom === 'auto_install') {
94
+ return origin === 'ui' ? 'ui' : 'netlify_toml';
95
+ }
96
+ return loadedFrom;
97
+ };