@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
@@ -1,179 +1,96 @@
1
- import pReduce from 'p-reduce'
2
-
3
- import { addErrorInfo } from '../error/info.js'
4
- import { addStatus } from '../status/add.js'
5
-
6
- import { runStep } from './run_step.js'
7
-
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';
8
5
  // Run all steps.
9
6
  // Each step can change some state: last `error`, environment variables changes,
10
7
  // list of `failedPlugins` (that ran `utils.build.failPlugin()`).
11
8
  // If an error arises, runs `onError` events.
12
9
  // Runs `onEnd` events at the end, whether an error was thrown or not.
13
- export const runSteps = async function ({
14
- steps,
15
- buildbotServerSocket,
16
- events,
17
- configPath,
18
- headersPath,
19
- redirectsPath,
20
- buildDir,
21
- repositoryRoot,
22
- nodePath,
23
- childEnv,
24
- context,
25
- branch,
26
- constants,
27
- mode,
28
- api,
29
- errorMonitor,
30
- deployId,
31
- errorParams,
32
- netlifyConfig,
33
- configOpts,
34
- logs,
35
- debug,
36
- systemLog,
37
- verbose,
38
- saveConfig,
39
- timers,
40
- testOpts,
41
- featureFlags,
42
- }) {
43
- const {
44
- index: stepsCount,
45
- error: errorA,
46
- netlifyConfig: netlifyConfigC,
47
- statuses: statusesB,
48
- failedPlugins: failedPluginsA,
49
- timers: timersC,
50
- configMutations: configMutationsB,
51
- } = await pReduce(
52
- steps,
53
- async (
54
- {
55
- index,
56
- error,
57
- failedPlugins,
58
- envChanges,
59
- netlifyConfig: netlifyConfigA,
60
- configMutations,
61
- headersPath: headersPathA,
62
- redirectsPath: redirectsPathA,
63
- statuses,
64
- timers: timersA,
65
- },
66
- {
67
- event,
68
- childProcess,
69
- packageName,
70
- coreStep,
71
- coreStepId,
72
- coreStepName,
73
- coreStepDescription,
74
- pluginPackageJson,
75
- loadedFrom,
76
- origin,
77
- condition,
78
- },
79
- ) => {
80
- const {
81
- newIndex = index,
82
- newError = error,
83
- failedPlugin = [],
84
- newEnvChanges = {},
85
- netlifyConfig: netlifyConfigB = netlifyConfigA,
86
- configMutations: configMutationsA = configMutations,
87
- headersPath: headersPathB = headersPathA,
88
- redirectsPath: redirectsPathB = redirectsPathA,
89
- newStatus,
90
- timers: timersB = timersA,
91
- } = await runStep({
92
- event,
93
- childProcess,
94
- packageName,
95
- coreStep,
96
- coreStepId,
97
- coreStepName,
98
- coreStepDescription,
99
- pluginPackageJson,
100
- loadedFrom,
101
- origin,
102
- condition,
103
- configPath,
104
- buildDir,
105
- repositoryRoot,
106
- nodePath,
107
- index,
108
- childEnv,
109
- context,
110
- branch,
111
- envChanges,
112
- constants,
113
- steps,
114
- buildbotServerSocket,
115
- events,
116
- mode,
117
- api,
118
- errorMonitor,
119
- deployId,
120
- errorParams,
121
- error,
122
- failedPlugins,
123
- configOpts,
124
- netlifyConfig: netlifyConfigA,
125
- configMutations,
126
- headersPath: headersPathA,
127
- redirectsPath: redirectsPathA,
128
- logs,
129
- debug,
130
- systemLog,
131
- verbose,
132
- saveConfig,
133
- timers: timersA,
134
- testOpts,
135
- featureFlags,
136
- })
137
- const statusesA = addStatus({ newStatus, statuses, event, packageName, pluginPackageJson })
138
- return {
139
- index: newIndex,
140
- error: newError,
141
- failedPlugins: [...failedPlugins, ...failedPlugin],
142
- envChanges: { ...envChanges, ...newEnvChanges },
143
- netlifyConfig: netlifyConfigB,
144
- configMutations: configMutationsA,
145
- headersPath: headersPathB,
146
- redirectsPath: redirectsPathB,
147
- statuses: statusesA,
148
- timers: timersB,
149
- }
150
- },
151
- {
152
- index: 0,
153
- failedPlugins: [],
154
- envChanges: {},
155
- netlifyConfig,
156
- configMutations: [],
157
- headersPath,
158
- redirectsPath,
159
- statuses: [],
160
- timers,
161
- },
162
- )
163
-
164
- // Instead of throwing any build failure right away, we wait for `onError`,
165
- // etc. to complete. This is why we are throwing only now.
166
- if (errorA !== undefined) {
167
- addErrorInfo(errorA, { statuses: statusesB })
168
- throw errorA
169
- }
170
-
171
- return {
172
- stepsCount,
173
- netlifyConfig: netlifyConfigC,
174
- statuses: statusesB,
175
- failedPlugins: failedPluginsA,
176
- timers: timersC,
177
- configMutations: configMutationsB,
178
- }
179
- }
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
+ };
@@ -1,93 +1,66 @@
1
- import { isDeepStrictEqual } from 'util'
2
-
3
- import pFilter from 'p-filter'
4
- import { pathExists } from 'path-exists'
5
-
6
- import { resolveUpdatedConfig } from '../core/config.js'
7
- import { addErrorInfo } from '../error/info.js'
8
- import { logConfigOnUpdate } from '../log/messages/config.js'
9
- import { logConfigMutations } from '../log/messages/mutations.js'
10
-
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';
11
8
  // If `netlifyConfig` was updated or `_redirects` was created, the configuration
12
9
  // is updated by calling `@netlify/config` again.
13
- export const updateNetlifyConfig = async function ({
14
- configOpts,
15
- netlifyConfig,
16
- headersPath,
17
- redirectsPath,
18
- configMutations,
19
- newConfigMutations,
20
- configSideFiles,
21
- errorParams,
22
- logs,
23
- debug,
24
- }) {
25
- if (!(await shouldUpdateConfig({ newConfigMutations, configSideFiles, headersPath, redirectsPath }))) {
26
- return { netlifyConfig, configMutations }
27
- }
28
-
29
- validateConfigMutations(newConfigMutations)
30
- logConfigMutations(logs, newConfigMutations, debug)
31
- const configMutationsA = [...configMutations, ...newConfigMutations]
32
- const {
33
- config: netlifyConfigA,
34
- headersPath: headersPathA,
35
- redirectsPath: redirectsPathA,
36
- } = await resolveUpdatedConfig(configOpts, configMutationsA)
37
- logConfigOnUpdate({ logs, netlifyConfig: netlifyConfigA, debug })
38
-
39
- errorParams.netlifyConfig = netlifyConfigA
40
- return {
41
- netlifyConfig: netlifyConfigA,
42
- configMutations: configMutationsA,
43
- headersPath: headersPathA,
44
- redirectsPath: redirectsPathA,
45
- }
46
- }
47
-
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
+ };
48
27
  const shouldUpdateConfig = async function ({ newConfigMutations, configSideFiles, headersPath, redirectsPath }) {
49
- return (
50
- newConfigMutations.length !== 0 || (await haveConfigSideFilesChanged(configSideFiles, headersPath, redirectsPath))
51
- )
52
- }
53
-
28
+ return (newConfigMutations.length !== 0 || (await haveConfigSideFilesChanged(configSideFiles, headersPath, redirectsPath)));
29
+ };
54
30
  // The configuration mostly depends on `netlify.toml` and UI build settings.
55
31
  // However, it also uses some additional optional side files like `_redirects`.
56
32
  // Those are often created by the build command. When those are created, we need
57
33
  // to update the configuration. We detect this by checking for file existence
58
34
  // before and after running plugins and the build command.
59
35
  const haveConfigSideFilesChanged = async function (configSideFiles, headersPath, redirectsPath) {
60
- const newSideFiles = await listConfigSideFiles([headersPath, redirectsPath])
61
- return !isDeepStrictEqual(newSideFiles, configSideFiles)
62
- }
63
-
36
+ const newSideFiles = await listConfigSideFiles([headersPath, redirectsPath]);
37
+ return !isDeepStrictEqual(newSideFiles, configSideFiles);
38
+ };
64
39
  // List all the files used for configuration besides `netlify.toml`.
65
40
  // This is useful when applying configuration mutations since those files
66
41
  // sometimes have higher priority and should therefore be deleted in order to
67
42
  // apply any configuration update on `netlify.toml`.
68
43
  export const listConfigSideFiles = async function (sideFiles) {
69
- const configSideFiles = await pFilter(sideFiles, pathExists)
70
-
71
- return configSideFiles.sort()
72
- }
73
-
44
+ const configSideFiles = await pFilter(sideFiles, pathExists);
45
+ return configSideFiles.sort();
46
+ };
74
47
  // Validate each new configuration change
75
48
  const validateConfigMutations = function (newConfigMutations) {
76
- try {
77
- newConfigMutations.forEach(validateConfigMutation)
78
- } catch (error) {
79
- addErrorInfo(error, { type: 'pluginValidation' })
80
- throw error
81
- }
82
- }
83
-
49
+ try {
50
+ newConfigMutations.forEach(validateConfigMutation);
51
+ }
52
+ catch (error) {
53
+ addErrorInfo(error, { type: 'pluginValidation' });
54
+ throw error;
55
+ }
56
+ };
84
57
  // Triggered when calling `netlifyConfig.{key} = undefined | null`
85
58
  // We do not allow this because the back-end only receives mutations as a
86
59
  // `netlify.toml`, i.e. cannot apply property deletions since `undefined` is
87
60
  // not serializable in TOML.
88
61
  const validateConfigMutation = function ({ value, keysString }) {
89
- if (value === undefined || value === null) {
90
- throw new Error(`Setting "netlifyConfig.${keysString}" to ${value} is not allowed.
91
- Please set this property to a specific value instead.`)
92
- }
93
- }
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
+ };
@@ -1,136 +1,97 @@
1
- import { platform } from 'process'
2
-
3
- import got from 'got'
4
- import osName from 'os-name'
5
-
6
- import { addErrorInfo } from '../error/info.js'
7
- import { roundTimerToMillisecs } from '../time/measure.js'
8
- import { ROOT_PACKAGE_JSON } from '../utils/json.js'
9
-
10
- const DEFAULT_TELEMETRY_TIMEOUT = 1200
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;
11
8
  const DEFAULT_TELEMETRY_CONFIG = {
12
- origin: 'https://api.segment.io/v1',
13
- writeKey: 'dWhlM1lYSlpNd1k5Uk9rcjFra2JSOEoybnRjZjl0YTI6',
14
- timeout: DEFAULT_TELEMETRY_TIMEOUT,
15
- }
16
-
9
+ origin: 'https://api.segment.io/v1',
10
+ writeKey: 'dWhlM1lYSlpNd1k5Uk9rcjFra2JSOEoybnRjZjl0YTI6',
11
+ timeout: DEFAULT_TELEMETRY_TIMEOUT,
12
+ };
17
13
  // Send telemetry request when build completes
18
- export const trackBuildComplete = async function ({
19
- deployId,
20
- buildId,
21
- status,
22
- stepsCount,
23
- pluginsOptions,
24
- durationNs,
25
- siteInfo,
26
- telemetry,
27
- userNodeVersion,
28
- framework,
29
- testOpts: { telemetryOrigin = DEFAULT_TELEMETRY_CONFIG.origin, telemetryTimeout = DEFAULT_TELEMETRY_CONFIG.timeout },
30
- }) {
31
- if (!telemetry) {
32
- return
33
- }
34
-
35
- try {
36
- const payload = getPayload({
37
- deployId,
38
- buildId,
39
- status,
40
- stepsCount,
41
- pluginsOptions,
42
- durationNs,
43
- siteInfo,
44
- userNodeVersion,
45
- framework,
46
- })
47
- await track({
48
- payload,
49
- config: { ...DEFAULT_TELEMETRY_CONFIG, origin: telemetryOrigin, timeout: telemetryTimeout },
50
- })
51
- } catch (error) {
52
- addErrorInfo(error, { type: 'telemetry' })
53
- throw error
54
- }
55
- }
56
-
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
+ };
57
40
  // Send track HTTP request to telemetry.
58
41
  const track = async function ({ payload, config: { origin, writeKey, timeout } }) {
59
- const url = `${origin}/track`
60
- await got.post(url, {
61
- json: payload,
62
- timeout,
63
- retry: 0,
64
- headers: { Authorization: `Basic ${writeKey}` },
65
- })
66
- }
67
-
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
+ };
68
50
  // Retrieve telemetry information
69
51
  // siteInfo can be empty if the build fails during the get config step
70
- const getPayload = function ({
71
- deployId,
72
- buildId,
73
- status,
74
- stepsCount,
75
- pluginsOptions,
76
- durationNs,
77
- userNodeVersion,
78
- siteInfo = {},
79
- framework,
80
- }) {
81
- return {
82
- userId: 'buildbot_user',
83
- event: 'build:ci_build_process_completed',
84
- timestamp: Date.now(),
85
- properties: {
86
- deployId,
87
- buildId,
88
- status,
89
- steps: stepsCount,
90
- buildVersion: ROOT_PACKAGE_JSON.version,
91
- // We're passing the node version set by the buildbot/user which will run the `build.command` and
92
- // the `package.json`/locally defined plugins
93
- nodeVersion: userNodeVersion,
94
- osPlatform: OS_TYPES[platform],
95
- osName: osName(),
96
- framework,
97
- siteId: siteInfo.id,
98
- ...(pluginsOptions !== undefined && {
99
- plugins: pluginsOptions.map(getPlugin),
100
- pluginCount: pluginsOptions.length,
101
- }),
102
- ...(durationNs !== undefined && { duration: roundTimerToMillisecs(durationNs) }),
103
- },
104
- }
105
- }
106
-
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
+ };
107
78
  const OS_TYPES = {
108
- linux: 'Linux',
109
- darwin: 'MacOS',
110
- win32: 'Windows',
111
- android: 'Android',
112
- sunos: 'SunOS',
113
- aix: 'AIX',
114
- freebsd: 'FreeBSD',
115
- openbsd: 'OpenBSD',
116
- }
117
-
118
- const getPlugin = function ({
119
- packageName,
120
- origin,
121
- loadedFrom,
122
- nodeVersion,
123
- pinnedVersion,
124
- pluginPackageJson: { version } = {},
125
- }) {
126
- const installType = getInstallType(origin, loadedFrom)
127
- return { name: packageName, installType, nodeVersion, pinnedVersion, version }
128
- }
129
-
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
+ };
130
92
  const getInstallType = function (origin, loadedFrom) {
131
- if (loadedFrom === 'auto_install') {
132
- return origin === 'ui' ? 'ui' : 'netlify_toml'
133
- }
134
-
135
- return loadedFrom
136
- }
93
+ if (loadedFrom === 'auto_install') {
94
+ return origin === 'ui' ? 'ui' : 'netlify_toml';
95
+ }
96
+ return loadedFrom;
97
+ };