@netlify/build 29.0.1-rc → 29.0.2

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 (266) hide show
  1. package/bin.js +5 -0
  2. package/lib/core/bin.js +66 -0
  3. package/lib/core/build.js +356 -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 +21 -0
  9. package/lib/core/flags.js +201 -0
  10. package/lib/core/lingering.js +68 -0
  11. package/lib/core/main.js +110 -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 +177 -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/lib/log/colors.js +28 -0
  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 +146 -0
  52. package/lib/log/messages/config.js +91 -0
  53. package/lib/log/messages/core.js +51 -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 +27 -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 +19 -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 +35 -0
  91. package/lib/plugins/options.js +70 -0
  92. package/lib/plugins/pinned_version.js +83 -0
  93. package/lib/plugins/resolve.js +110 -0
  94. package/lib/plugins/spawn.js +58 -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 +76 -0
  101. package/{src → lib}/plugins_core/edge_functions/lib/error.js +13 -17
  102. package/lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +21 -0
  103. package/lib/plugins_core/functions/error.js +123 -0
  104. package/lib/plugins_core/functions/feature_flags.js +6 -0
  105. package/lib/plugins_core/functions/index.js +114 -0
  106. package/lib/plugins_core/functions/utils.js +45 -0
  107. package/lib/plugins_core/functions/zisi.js +39 -0
  108. package/{src → lib}/plugins_core/functions_install/index.js +8 -11
  109. package/{src → lib}/plugins_core/functions_install/manifest.yml +0 -0
  110. package/lib/plugins_core/list.js +20 -0
  111. package/lib/report/statsd.js +31 -0
  112. package/lib/status/add.js +30 -0
  113. package/lib/status/colors.js +18 -0
  114. package/lib/status/load_error.js +10 -0
  115. package/lib/status/report.js +83 -0
  116. package/lib/status/success.js +14 -0
  117. package/lib/steps/core_step.js +59 -0
  118. package/lib/steps/error.js +65 -0
  119. package/lib/steps/get.js +43 -0
  120. package/lib/steps/plugin.js +55 -0
  121. package/lib/steps/return.js +25 -0
  122. package/lib/steps/run_core_steps.js +117 -0
  123. package/lib/steps/run_step.js +190 -0
  124. package/lib/steps/run_steps.js +96 -0
  125. package/lib/steps/update_config.js +66 -0
  126. package/lib/telemetry/main.js +97 -0
  127. package/lib/time/aggregate.js +109 -0
  128. package/lib/time/main.js +31 -0
  129. package/lib/time/measure.js +16 -0
  130. package/lib/time/report.js +24 -0
  131. package/lib/utils/errors.js +13 -0
  132. package/lib/utils/json.js +15 -0
  133. package/lib/utils/omit.js +3 -0
  134. package/lib/utils/package.js +24 -0
  135. package/lib/utils/remove_falsy.js +8 -0
  136. package/lib/utils/resolve.js +41 -0
  137. package/lib/utils/runtime.js +5 -0
  138. package/lib/utils/semver.js +28 -0
  139. package/package.json +41 -24
  140. package/types/config/netlify_config.d.ts +4 -4
  141. package/types/netlify_plugin_constants.d.ts +8 -8
  142. package/src/core/bin.js +0 -83
  143. package/src/core/build.js +0 -554
  144. package/src/core/config.js +0 -186
  145. package/src/core/constants.js +0 -156
  146. package/src/core/dev.js +0 -31
  147. package/src/core/dry.js +0 -39
  148. package/src/core/feature_flags.js +0 -22
  149. package/src/core/flags.js +0 -204
  150. package/src/core/lingering.js +0 -85
  151. package/src/core/main.js +0 -165
  152. package/src/core/missing_side_file.js +0 -29
  153. package/src/core/normalize_flags.js +0 -70
  154. package/src/core/severity.js +0 -22
  155. package/src/core/user_node_version.js +0 -41
  156. package/src/env/changes.js +0 -52
  157. package/src/env/main.js +0 -19
  158. package/src/env/metadata.js +0 -81
  159. package/src/error/api.js +0 -46
  160. package/src/error/build.js +0 -50
  161. package/src/error/colors.js +0 -11
  162. package/src/error/handle.js +0 -57
  163. package/src/error/info.js +0 -46
  164. package/src/error/monitor/location.js +0 -21
  165. package/src/error/monitor/normalize.js +0 -96
  166. package/src/error/monitor/print.js +0 -42
  167. package/src/error/monitor/report.js +0 -138
  168. package/src/error/monitor/start.js +0 -69
  169. package/src/error/parse/clean_stack.js +0 -87
  170. package/src/error/parse/location.js +0 -62
  171. package/src/error/parse/normalize.js +0 -29
  172. package/src/error/parse/parse.js +0 -97
  173. package/src/error/parse/plugin.js +0 -70
  174. package/src/error/parse/properties.js +0 -23
  175. package/src/error/parse/serialize_log.js +0 -42
  176. package/src/error/parse/serialize_status.js +0 -23
  177. package/src/error/parse/stack.js +0 -43
  178. package/src/error/type.js +0 -189
  179. package/src/install/functions.js +0 -28
  180. package/src/install/local.js +0 -62
  181. package/src/install/main.js +0 -81
  182. package/src/install/missing.js +0 -67
  183. package/src/log/colors.js +0 -34
  184. package/src/log/description.js +0 -26
  185. package/src/log/header.js +0 -16
  186. package/src/log/header_func.js +0 -17
  187. package/src/log/logger.js +0 -161
  188. package/src/log/messages/compatibility.js +0 -164
  189. package/src/log/messages/config.js +0 -107
  190. package/src/log/messages/core.js +0 -70
  191. package/src/log/messages/core_steps.js +0 -104
  192. package/src/log/messages/dry.js +0 -63
  193. package/src/log/messages/install.js +0 -20
  194. package/src/log/messages/ipc.js +0 -38
  195. package/src/log/messages/mutations.js +0 -82
  196. package/src/log/messages/status.js +0 -16
  197. package/src/log/messages/steps.js +0 -22
  198. package/src/log/old_version.js +0 -41
  199. package/src/log/serialize.js +0 -13
  200. package/src/log/stream.js +0 -85
  201. package/src/log/theme.js +0 -26
  202. package/src/plugins/child/diff.js +0 -55
  203. package/src/plugins/child/error.js +0 -32
  204. package/src/plugins/child/lazy.js +0 -18
  205. package/src/plugins/child/load.js +0 -29
  206. package/src/plugins/child/logic.js +0 -57
  207. package/src/plugins/child/main.js +0 -51
  208. package/src/plugins/child/run.js +0 -28
  209. package/src/plugins/child/status.js +0 -74
  210. package/src/plugins/child/typescript.js +0 -45
  211. package/src/plugins/child/utils.js +0 -56
  212. package/src/plugins/child/validate.js +0 -34
  213. package/src/plugins/compatibility.js +0 -128
  214. package/src/plugins/expected_version.js +0 -119
  215. package/src/plugins/ipc.js +0 -145
  216. package/src/plugins/list.js +0 -86
  217. package/src/plugins/load.js +0 -70
  218. package/src/plugins/manifest/check.js +0 -106
  219. package/src/plugins/manifest/load.js +0 -41
  220. package/src/plugins/manifest/main.js +0 -22
  221. package/src/plugins/manifest/path.js +0 -31
  222. package/src/plugins/manifest/validate.js +0 -108
  223. package/src/plugins/node_version.js +0 -50
  224. package/src/plugins/options.js +0 -88
  225. package/src/plugins/pinned_version.js +0 -131
  226. package/src/plugins/resolve.js +0 -152
  227. package/src/plugins/spawn.js +0 -66
  228. package/src/plugins_core/add.js +0 -49
  229. package/src/plugins_core/build_command.js +0 -75
  230. package/src/plugins_core/deploy/buildbot_client.js +0 -102
  231. package/src/plugins_core/deploy/index.js +0 -73
  232. package/src/plugins_core/edge_functions/index.js +0 -123
  233. package/src/plugins_core/edge_functions/lib/internal_manifest.js +0 -54
  234. package/src/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +0 -89
  235. package/src/plugins_core/functions/error.js +0 -163
  236. package/src/plugins_core/functions/feature_flags.js +0 -6
  237. package/src/plugins_core/functions/index.js +0 -160
  238. package/src/plugins_core/functions/utils.js +0 -66
  239. package/src/plugins_core/functions/zisi.js +0 -53
  240. package/src/plugins_core/list.js +0 -27
  241. package/src/status/add.js +0 -36
  242. package/src/status/colors.js +0 -23
  243. package/src/status/load_error.js +0 -11
  244. package/src/status/report.js +0 -137
  245. package/src/status/success.js +0 -18
  246. package/src/steps/core_step.js +0 -92
  247. package/src/steps/error.js +0 -102
  248. package/src/steps/get.js +0 -51
  249. package/src/steps/plugin.js +0 -85
  250. package/src/steps/return.js +0 -52
  251. package/src/steps/run_core_steps.js +0 -200
  252. package/src/steps/run_step.js +0 -304
  253. package/src/steps/run_steps.js +0 -179
  254. package/src/steps/update_config.js +0 -93
  255. package/src/telemetry/main.js +0 -136
  256. package/src/time/aggregate.js +0 -146
  257. package/src/time/main.js +0 -48
  258. package/src/time/measure.js +0 -22
  259. package/src/time/report.js +0 -59
  260. package/src/utils/errors.js +0 -12
  261. package/src/utils/json.js +0 -19
  262. package/src/utils/omit.js +0 -6
  263. package/src/utils/package.js +0 -23
  264. package/src/utils/remove_falsy.js +0 -10
  265. package/src/utils/resolve.js +0 -46
  266. 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, systemLog, }) {
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, systemLog);
24
+ return { newEnvChanges, netlifyConfig, configMutations, headersPath, redirectsPath, newStatus, timers };
25
+ };
@@ -0,0 +1,117 @@
1
+ import { startBuild } from '../core/build.js';
2
+ import { getConfigOpts, loadConfig } from '../core/config.js';
3
+ import { getConstants } from '../core/constants.js';
4
+ import { getSeverity } from '../core/severity.js';
5
+ import { handleBuildError } from '../error/handle.js';
6
+ import { getErrorInfo } from '../error/info.js';
7
+ import { getSystemLogger } from '../log/logger.js';
8
+ import { reportStatuses } from '../status/report.js';
9
+ import { getSteps } from './get.js';
10
+ import { runSteps } from './run_steps.js';
11
+ /**
12
+ * Runs specific core steps for a build and returns whether it succeeded or not.
13
+ */
14
+ export const runCoreSteps = async (buildSteps, flags = {}) => {
15
+ const { errorMonitor, mode, logs, debug, ...flagsA } = startBuild(flags);
16
+ const errorParams = { errorMonitor, mode, logs, debug };
17
+ const systemLog = getSystemLogger(logs, debug);
18
+ try {
19
+ const { netlifyConfig: netlifyConfigA, configMutations } = await executeBuildStep({
20
+ ...flagsA,
21
+ errorMonitor,
22
+ mode,
23
+ logs,
24
+ debug,
25
+ errorParams,
26
+ buildSteps,
27
+ systemLog,
28
+ });
29
+ const { success, severityCode } = getSeverity('success');
30
+ return { success, severityCode, netlifyConfig: netlifyConfigA, configMutations, logs };
31
+ }
32
+ catch (error) {
33
+ const { severity } = await handleBuildError(error, errorParams);
34
+ const { success, severityCode } = getSeverity(severity);
35
+ return { success, severityCode, logs };
36
+ }
37
+ };
38
+ const getBuildSteps = function (buildSteps) {
39
+ const allSteps = getSteps([]).steps.filter(({ coreStepId }) => buildSteps.includes(coreStepId));
40
+ return allSteps;
41
+ };
42
+ const executeBuildStep = async function ({ config, defaultConfig, cachedConfig, debug, nodePath, functionsDistDir, edgeFunctionsDistDir, errorMonitor, mode, logs, errorParams, featureFlags, buildSteps, repositoryRoot, systemLog, }) {
43
+ const configOpts = getConfigOpts({
44
+ config,
45
+ defaultConfig,
46
+ featureFlags,
47
+ mode,
48
+ repositoryRoot,
49
+ });
50
+ const { netlifyConfig, buildDir, siteInfo, childEnv, userNodeVersion, repositoryRoot: repositoryRootA, } = await loadConfig({
51
+ configOpts,
52
+ cachedConfig,
53
+ debug,
54
+ logs,
55
+ nodePath,
56
+ timers: [],
57
+ });
58
+ const constants = await getConstants({
59
+ buildDir,
60
+ functionsDistDir,
61
+ edgeFunctionsDistDir,
62
+ netlifyConfig,
63
+ siteInfo,
64
+ mode,
65
+ });
66
+ Object.assign(errorParams, { netlifyConfig, siteInfo, childEnv, userNodeVersion });
67
+ try {
68
+ const { netlifyConfig: netlifyConfigA, configMutations } = await runBuildStep({
69
+ netlifyConfig,
70
+ buildDir,
71
+ nodePath,
72
+ logs,
73
+ debug,
74
+ constants,
75
+ featureFlags,
76
+ childEnv,
77
+ buildSteps,
78
+ repositoryRoot: repositoryRootA,
79
+ systemLog,
80
+ });
81
+ return {
82
+ netlifyConfig: netlifyConfigA,
83
+ configMutations,
84
+ };
85
+ }
86
+ catch (error) {
87
+ const [{ statuses }] = getErrorInfo(error);
88
+ await reportStatuses({
89
+ statuses,
90
+ childEnv,
91
+ mode,
92
+ netlifyConfig,
93
+ errorMonitor,
94
+ logs,
95
+ debug,
96
+ pluginsOptions: [],
97
+ });
98
+ throw error;
99
+ }
100
+ };
101
+ const runBuildStep = async function ({ netlifyConfig, buildDir, nodePath, constants, logs, debug, featureFlags, childEnv, buildSteps, repositoryRoot, systemLog, }) {
102
+ const { netlifyConfig: netlifyConfigA, configMutations } = await runSteps({
103
+ steps: getBuildSteps(buildSteps),
104
+ buildDir,
105
+ nodePath,
106
+ constants,
107
+ netlifyConfig,
108
+ logs,
109
+ debug,
110
+ timers: [],
111
+ featureFlags,
112
+ childEnv,
113
+ repositoryRoot,
114
+ systemLog,
115
+ });
116
+ return { netlifyConfig: netlifyConfigA, configMutations };
117
+ };
@@ -0,0 +1,190 @@
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
+ systemLog,
87
+ });
88
+ return { ...newValues, newIndex: index + 1 };
89
+ };
90
+ // A plugin fails _without making the build fail_ when either:
91
+ // - using `utils.build.failPlugin()`
92
+ // - the failure happens after deploy. This means: inside any `onError`,
93
+ // `onSuccess` or `onEnd` event handler.
94
+ //
95
+ // When that happens, no other events for that specific plugin is run.
96
+ // Not even `onError` and `onEnd`.
97
+ // Plugins should use `try`/`catch`/`finally` blocks to handle exceptions,
98
+ // not `onError` nor `onEnd`.
99
+ //
100
+ // Otherwise, most failures will make the build fail. This includes:
101
+ // - the build command failed
102
+ // - Functions or Edge Functions bundling failed
103
+ // - the deploy failed (deploying files to our CDN)
104
+ // - a plugin `onPreBuild`, `onBuild` or `onPostBuild` event handler failed.
105
+ // This includes uncaught exceptions and using `utils.build.failBuild()`
106
+ // or `utils.build.cancelBuild()`.
107
+ //
108
+ // `onError` is triggered when the build failed.
109
+ // It means "on build failure" not "on plugin failure".
110
+ // `onSuccess` is the opposite. It is triggered after the build succeeded.
111
+ // `onEnd` is triggered after the build either failed or succeeded.
112
+ // It is useful for resources cleanup.
113
+ //
114
+ // Finally, some plugins (only core plugins for the moment) might be enabled or
115
+ // not depending on whether a specific action is happening during the build,
116
+ // such as creating a file. For example, the Functions and Edge Functions core
117
+ // plugins are disabled if no Functions or Edge Functions directory is specified
118
+ // or available. However, one might be created by a build plugin, in which case,
119
+ // those core plugins should be triggered. We use a dynamic `condition()` to
120
+ // model this behavior.
121
+ const shouldRunStep = async function ({ event, packageName, error, failedPlugins, netlifyConfig, condition, constants, buildbotServerSocket, buildDir, }) {
122
+ if (failedPlugins.includes(packageName) ||
123
+ (condition !== undefined && !(await condition({ buildDir, constants, buildbotServerSocket, netlifyConfig })))) {
124
+ return false;
125
+ }
126
+ if (error !== undefined) {
127
+ return runsAlsoOnBuildFailure(event);
128
+ }
129
+ return !runsOnlyOnBuildFailure(event);
130
+ };
131
+ // Wrap step function to measure its time
132
+ const getFireStep = function (packageName, coreStepId, event) {
133
+ if (coreStepId !== undefined) {
134
+ return measureDuration(tFireStep, coreStepId);
135
+ }
136
+ const parentTag = normalizeTagName(packageName);
137
+ return measureDuration(tFireStep, event, { parentTag, category: 'pluginEvent' });
138
+ };
139
+ 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, }) {
140
+ if (coreStep !== undefined) {
141
+ return fireCoreStep({
142
+ coreStep,
143
+ coreStepId,
144
+ coreStepName,
145
+ configPath,
146
+ buildDir,
147
+ repositoryRoot,
148
+ constants,
149
+ buildbotServerSocket,
150
+ events,
151
+ logs,
152
+ nodePath,
153
+ childEnv,
154
+ context,
155
+ branch,
156
+ envChanges,
157
+ errorParams,
158
+ configOpts,
159
+ netlifyConfig,
160
+ configMutations,
161
+ headersPath,
162
+ redirectsPath,
163
+ featureFlags,
164
+ debug,
165
+ systemLog,
166
+ saveConfig,
167
+ });
168
+ }
169
+ return firePluginStep({
170
+ event,
171
+ childProcess,
172
+ packageName,
173
+ pluginPackageJson,
174
+ loadedFrom,
175
+ origin,
176
+ envChanges,
177
+ errorParams,
178
+ configOpts,
179
+ netlifyConfig,
180
+ configMutations,
181
+ headersPath,
182
+ redirectsPath,
183
+ constants,
184
+ steps,
185
+ error,
186
+ logs,
187
+ debug,
188
+ verbose,
189
+ });
190
+ };
@@ -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
+ };