@netlify/build 0.4.48 → 1.0.0-dl-test

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 (243) hide show
  1. package/bin.js +5 -0
  2. package/lib/core/bin.js +66 -0
  3. package/lib/core/build.js +392 -0
  4. package/lib/core/config.js +124 -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 +17 -0
  9. package/lib/core/flags.js +206 -0
  10. package/lib/core/lingering.js +68 -0
  11. package/lib/core/main.js +114 -0
  12. package/lib/core/missing_side_file.js +17 -0
  13. package/lib/core/normalize_flags.js +62 -0
  14. package/lib/core/report_metrics.js +17 -0
  15. package/lib/core/severity.js +21 -0
  16. package/lib/core/types.js +8 -0
  17. package/lib/core/user_node_version.js +32 -0
  18. package/lib/env/changes.js +43 -0
  19. package/lib/env/main.js +14 -0
  20. package/lib/env/metadata.js +68 -0
  21. package/lib/error/api.js +37 -0
  22. package/lib/error/build.js +36 -0
  23. package/lib/error/cancel.js +7 -0
  24. package/lib/error/colors.js +9 -0
  25. package/lib/error/handle.js +44 -0
  26. package/lib/error/info.js +37 -0
  27. package/lib/error/monitor/location.js +16 -0
  28. package/lib/error/monitor/normalize.js +86 -0
  29. package/lib/error/monitor/print.js +20 -0
  30. package/lib/error/monitor/report.js +120 -0
  31. package/lib/error/monitor/start.js +61 -0
  32. package/lib/error/parse/clean_stack.js +70 -0
  33. package/lib/error/parse/location.js +50 -0
  34. package/lib/error/parse/normalize.js +24 -0
  35. package/lib/error/parse/parse.js +67 -0
  36. package/lib/error/parse/plugin.js +55 -0
  37. package/lib/error/parse/properties.js +16 -0
  38. package/lib/error/parse/serialize_log.js +34 -0
  39. package/lib/error/parse/serialize_status.js +18 -0
  40. package/lib/error/parse/stack.js +34 -0
  41. package/lib/error/report.js +29 -0
  42. package/lib/error/type.js +177 -0
  43. package/lib/install/functions.js +20 -0
  44. package/lib/install/local.js +45 -0
  45. package/lib/install/main.js +67 -0
  46. package/lib/install/missing.js +54 -0
  47. package/lib/log/colors.js +28 -0
  48. package/lib/log/description.js +21 -0
  49. package/lib/log/header.js +12 -0
  50. package/lib/log/header_func.js +13 -0
  51. package/lib/log/logger.js +140 -0
  52. package/lib/log/messages/compatibility.js +120 -0
  53. package/lib/log/messages/config.js +91 -0
  54. package/lib/log/messages/core.js +49 -0
  55. package/lib/log/messages/core_steps.js +75 -0
  56. package/lib/log/messages/dry.js +41 -0
  57. package/lib/log/messages/install.js +25 -0
  58. package/lib/log/messages/ipc.js +29 -0
  59. package/lib/log/messages/mutations.js +62 -0
  60. package/lib/log/messages/plugins.js +25 -0
  61. package/lib/log/messages/status.js +14 -0
  62. package/lib/log/messages/steps.js +18 -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/lib/plugins/error.js +46 -0
  79. package/lib/plugins/events.js +12 -0
  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 +55 -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/lib/plugins_core/deploy/manifest.yml +1 -0
  100. package/lib/plugins_core/edge_functions/index.js +106 -0
  101. package/lib/plugins_core/edge_functions/lib/error.js +17 -0
  102. package/lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +14 -0
  103. package/lib/plugins_core/functions/error.js +123 -0
  104. package/lib/plugins_core/functions/feature_flags.js +5 -0
  105. package/lib/plugins_core/functions/index.js +137 -0
  106. package/lib/plugins_core/functions/utils.js +45 -0
  107. package/lib/plugins_core/functions/zisi.js +64 -0
  108. package/lib/plugins_core/functions_install/index.js +10 -0
  109. package/lib/plugins_core/list.js +20 -0
  110. package/lib/plugins_core/save_artifacts/index.js +33 -0
  111. package/lib/report/statsd.js +56 -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 +62 -0
  118. package/lib/steps/error.js +65 -0
  119. package/lib/steps/get.js +44 -0
  120. package/lib/steps/plugin.js +55 -0
  121. package/lib/steps/return.js +27 -0
  122. package/lib/steps/run_core_steps.js +117 -0
  123. package/lib/steps/run_step.js +200 -0
  124. package/lib/steps/run_steps.js +102 -0
  125. package/lib/steps/update_config.js +66 -0
  126. package/lib/telemetry/main.js +94 -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 +30 -0
  131. package/lib/utils/errors.js +13 -0
  132. package/lib/utils/json.js +10 -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 +119 -56
  140. package/types/config/build.d.ts +52 -0
  141. package/types/config/functions.d.ts +36 -0
  142. package/types/config/inputs.d.ts +7 -0
  143. package/types/config/netlify_config.d.ts +58 -0
  144. package/types/index.d.ts +7 -0
  145. package/types/netlify_event_handler.d.ts +29 -0
  146. package/types/netlify_plugin.d.ts +29 -0
  147. package/types/netlify_plugin_constants.d.ts +51 -0
  148. package/types/netlify_plugin_options.d.ts +23 -0
  149. package/types/options/index.d.ts +1 -0
  150. package/types/options/netlify_plugin_build_util.d.ts +7 -0
  151. package/types/options/netlify_plugin_cache_util.d.ts +39 -0
  152. package/types/options/netlify_plugin_functions_util.d.ts +32 -0
  153. package/types/options/netlify_plugin_git_util.d.ts +41 -0
  154. package/types/options/netlify_plugin_run_util.d.ts +24 -0
  155. package/types/options/netlify_plugin_status_util.d.ts +24 -0
  156. package/types/options/netlify_plugin_utils.d.ts +15 -0
  157. package/types/utils/json_value.d.ts +1 -0
  158. package/types/utils/many.d.ts +6 -0
  159. package/README.md +0 -3
  160. package/src/core/bin.js +0 -139
  161. package/src/core/commands.js +0 -304
  162. package/src/core/config.js +0 -130
  163. package/src/core/constants.js +0 -88
  164. package/src/core/dry.js +0 -23
  165. package/src/core/main.js +0 -196
  166. package/src/env/changes.js +0 -49
  167. package/src/env/git.js +0 -27
  168. package/src/env/main.js +0 -97
  169. package/src/env/metadata.js +0 -81
  170. package/src/error/api.js +0 -32
  171. package/src/error/build.js +0 -32
  172. package/src/error/cancel.js +0 -22
  173. package/src/error/colors.js +0 -13
  174. package/src/error/info.js +0 -12
  175. package/src/error/monitor/normalize.js +0 -50
  176. package/src/error/monitor/print.js +0 -43
  177. package/src/error/monitor/report.js +0 -140
  178. package/src/error/monitor/start.js +0 -50
  179. package/src/error/parse/clean_stack.js +0 -86
  180. package/src/error/parse/location.js +0 -50
  181. package/src/error/parse/parse.js +0 -87
  182. package/src/error/parse/plugin.js +0 -68
  183. package/src/error/parse/properties.js +0 -20
  184. package/src/error/parse/serialize_log.js +0 -46
  185. package/src/error/parse/serialize_status.js +0 -28
  186. package/src/error/parse/stack.js +0 -45
  187. package/src/error/process.js +0 -13
  188. package/src/error/type.js +0 -143
  189. package/src/install/functions.js +0 -52
  190. package/src/install/local.js +0 -65
  191. package/src/install/main.js +0 -103
  192. package/src/install/missing.js +0 -86
  193. package/src/log/colors.js +0 -59
  194. package/src/log/description.js +0 -38
  195. package/src/log/header.js +0 -19
  196. package/src/log/logger.js +0 -55
  197. package/src/log/main.js +0 -348
  198. package/src/log/old_version.js +0 -45
  199. package/src/log/serialize.js +0 -15
  200. package/src/log/stream.js +0 -15
  201. package/src/log/theme.js +0 -32
  202. package/src/log/timer.js +0 -28
  203. package/src/plugins/child/api.js +0 -59
  204. package/src/plugins/child/error.js +0 -39
  205. package/src/plugins/child/load.js +0 -40
  206. package/src/plugins/child/logic.js +0 -31
  207. package/src/plugins/child/main.js +0 -48
  208. package/src/plugins/child/normalize.js +0 -20
  209. package/src/plugins/child/run.js +0 -34
  210. package/src/plugins/child/status.js +0 -53
  211. package/src/plugins/child/utils.js +0 -43
  212. package/src/plugins/child/validate.js +0 -46
  213. package/src/plugins/error.js +0 -44
  214. package/src/plugins/events.js +0 -77
  215. package/src/plugins/ipc.js +0 -136
  216. package/src/plugins/load.js +0 -66
  217. package/src/plugins/manifest/check.js +0 -80
  218. package/src/plugins/manifest/load.js +0 -47
  219. package/src/plugins/manifest/main.js +0 -28
  220. package/src/plugins/manifest/path.js +0 -12
  221. package/src/plugins/manifest/validate.js +0 -136
  222. package/src/plugins/node_version.js +0 -74
  223. package/src/plugins/options.js +0 -78
  224. package/src/plugins/package.js +0 -17
  225. package/src/plugins/resolve.js +0 -159
  226. package/src/plugins/spawn.js +0 -82
  227. package/src/plugins_core/cache/manifest.yml +0 -1
  228. package/src/plugins_core/cache/plugin.js +0 -75
  229. package/src/plugins_core/functions/manifest.yml +0 -1
  230. package/src/plugins_core/functions/plugin.js +0 -37
  231. package/src/plugins_core/functions_install/plugin.js +0 -14
  232. package/src/plugins_core/main.js +0 -38
  233. package/src/status/add.js +0 -56
  234. package/src/status/colors.js +0 -25
  235. package/src/status/report.js +0 -57
  236. package/src/telemetry/complete.js +0 -49
  237. package/src/telemetry/request.js +0 -28
  238. package/src/telemetry/track.js +0 -33
  239. package/src/utils/omit.js +0 -8
  240. package/src/utils/polyfills.js +0 -3
  241. package/src/utils/remove_falsy.js +0 -12
  242. package/src/utils/resolve.js +0 -39
  243. /package/{src → lib}/plugins_core/functions_install/manifest.yml +0 -0
package/src/core/main.js DELETED
@@ -1,196 +0,0 @@
1
- require('../utils/polyfills')
2
-
3
- // This needs to be done before `chalk` is loaded.
4
- // Note: `chalk` is also required by some of our dependencies.
5
- // eslint-disable-next-line import/order
6
- const { setColorLevel } = require('../log/colors')
7
- setColorLevel()
8
-
9
- require('../error/process')
10
-
11
- const { getChildEnv } = require('../env/main')
12
- const { maybeCancelBuild } = require('../error/cancel')
13
- const { removeErrorColors } = require('../error/colors')
14
- const { reportBuildError } = require('../error/monitor/report')
15
- const { startErrorMonitor } = require('../error/monitor/start')
16
- const { logBuildStart, logBuildError, logBuildSuccess } = require('../log/main')
17
- const { logOldCliVersionError } = require('../log/old_version')
18
- const { startTimer, endTimer } = require('../log/timer')
19
- const { startUtils } = require('../plugins/child/utils')
20
- const { loadPlugins } = require('../plugins/load')
21
- const { getPluginsOptions } = require('../plugins/options')
22
- const { startPlugins, stopPlugins } = require('../plugins/spawn')
23
- const { reportStatuses } = require('../status/report')
24
- const { trackBuildComplete } = require('../telemetry/complete')
25
-
26
- const { getCommands, runCommands } = require('./commands')
27
- const { normalizeFlags, loadConfig } = require('./config')
28
- const { doDryRun } = require('./dry')
29
-
30
- /**
31
- * Netlify Build
32
- * @param {object} flags - build configuration CLI flags
33
- * @param {string} [flags.config] - Netlify config file path
34
- * @param {string} [flags.cwd] - Current directory
35
- * @param {string} [flags.token] - Netlify API token for authentication
36
- * @param {string} [flags.siteId] - Netlify Site ID
37
- * @param {string} [flags.context] - Build context
38
- * @param {boolean} [flags.dry] - printing commands without executing them
39
- */
40
- const build = async function(flags) {
41
- const buildTimer = startTimer()
42
-
43
- logBuildStart()
44
-
45
- const flagsA = normalizeFlags(flags)
46
- const errorMonitor = startErrorMonitor(flagsA)
47
-
48
- try {
49
- const {
50
- netlifyConfig,
51
- configPath,
52
- buildDir,
53
- nodePath,
54
- token,
55
- api,
56
- dry,
57
- siteInfo,
58
- constants,
59
- context,
60
- branch,
61
- mode,
62
- } = await loadConfig(flagsA)
63
- const childEnv = await getChildEnv({ netlifyConfig, buildDir, context, branch, siteInfo, mode })
64
-
65
- try {
66
- const pluginsOptions = await getPluginsOptions({ netlifyConfig, buildDir, constants, mode, api })
67
-
68
- const { commandsCount, error, statuses } = await buildRun({
69
- pluginsOptions,
70
- netlifyConfig,
71
- configPath,
72
- buildDir,
73
- nodePath,
74
- childEnv,
75
- token,
76
- dry,
77
- constants,
78
- mode,
79
- api,
80
- errorMonitor,
81
- })
82
-
83
- if (dry) {
84
- return true
85
- }
86
-
87
- await reportStatuses(statuses, api, mode)
88
-
89
- if (error !== undefined) {
90
- throw error
91
- }
92
-
93
- logBuildSuccess()
94
- const duration = endTimer(buildTimer, 'Netlify Build')
95
- await trackBuildComplete({ commandsCount, netlifyConfig, duration, siteInfo, mode })
96
- return true
97
- } catch (error) {
98
- await maybeCancelBuild(error, api)
99
- await logOldCliVersionError(mode)
100
- error.netlifyConfig = netlifyConfig
101
- error.childEnv = childEnv
102
- throw error
103
- }
104
- } catch (error) {
105
- removeErrorColors(error)
106
- await reportBuildError(error, errorMonitor)
107
- logBuildError(error)
108
- return false
109
- }
110
- }
111
-
112
- const buildRun = async function({
113
- pluginsOptions,
114
- netlifyConfig,
115
- configPath,
116
- buildDir,
117
- nodePath,
118
- childEnv,
119
- token,
120
- dry,
121
- constants,
122
- mode,
123
- api,
124
- errorMonitor,
125
- }) {
126
- const utilsData = await startUtils(buildDir)
127
- const childProcesses = await startPlugins({ pluginsOptions, buildDir, nodePath, childEnv, mode })
128
-
129
- try {
130
- return await executeCommands({
131
- pluginsOptions,
132
- childProcesses,
133
- netlifyConfig,
134
- utilsData,
135
- configPath,
136
- buildDir,
137
- nodePath,
138
- childEnv,
139
- token,
140
- dry,
141
- constants,
142
- mode,
143
- api,
144
- errorMonitor,
145
- })
146
- } finally {
147
- await stopPlugins(childProcesses)
148
- }
149
- }
150
-
151
- const executeCommands = async function({
152
- pluginsOptions,
153
- childProcesses,
154
- netlifyConfig,
155
- utilsData,
156
- configPath,
157
- buildDir,
158
- nodePath,
159
- childEnv,
160
- token,
161
- dry,
162
- constants,
163
- mode,
164
- api,
165
- errorMonitor,
166
- }) {
167
- const pluginsCommands = await loadPlugins({
168
- pluginsOptions,
169
- childProcesses,
170
- netlifyConfig,
171
- utilsData,
172
- token,
173
- constants,
174
- mode,
175
- api,
176
- })
177
-
178
- const { commands, commandsCount } = getCommands(pluginsCommands, netlifyConfig)
179
-
180
- if (dry) {
181
- doDryRun({ commands, commandsCount, configPath })
182
- return {}
183
- }
184
-
185
- return runCommands({
186
- commands,
187
- configPath,
188
- buildDir,
189
- nodePath,
190
- childEnv,
191
- errorMonitor,
192
- netlifyConfig,
193
- })
194
- }
195
-
196
- module.exports = build
@@ -1,49 +0,0 @@
1
- const process = require('process')
2
-
3
- const filterObj = require('filter-obj')
4
- const mapObj = require('map-obj')
5
-
6
- // If plugins modify `process.env`, this is propagated in other plugins and in
7
- // `build.command`. Since those are different processes, we figure out when they
8
- // do this and communicate the new `process.env` to other processes.
9
- const getNewEnvChanges = function(envBefore) {
10
- const currentEnv = getCurrentEnv()
11
- const envChanges = filterObj(currentEnv, (name, value) => value !== envBefore[name])
12
- const deletedEnv = filterObj(envBefore, name => currentEnv[name] === undefined)
13
- const deletedEnvA = mapObj(deletedEnv, setToNull)
14
- return { ...envChanges, ...deletedEnvA }
15
- }
16
-
17
- // `undefined` is not JSON-serializable (which is used in process IPC), so we
18
- // convert it to `null`
19
- // Note: `process.env[name] = undefined` actually does
20
- // `process.env[name] = 'undefined'` in Node.js.
21
- const setToNull = function(name) {
22
- return [name, null]
23
- }
24
-
25
- // Set `process.env` changes from a previous different plugin.
26
- // Can also merge with a `currentEnv` plain object instead of `process.env`.
27
- const setEnvChanges = function(envChanges, currentEnv = getCurrentEnv()) {
28
- Object.entries(envChanges).forEach(([name, value]) => setEnvChange(name, value, currentEnv))
29
- return { ...currentEnv }
30
- }
31
-
32
- const setEnvChange = function(name, value, currentEnv) {
33
- if (currentEnv[name] === value) {
34
- return
35
- }
36
-
37
- if (value === null) {
38
- delete currentEnv[name]
39
- return
40
- }
41
-
42
- currentEnv[name] = value
43
- }
44
-
45
- const getCurrentEnv = function() {
46
- return process.env
47
- }
48
-
49
- module.exports = { getNewEnvChanges, setEnvChanges }
package/src/env/git.js DELETED
@@ -1,27 +0,0 @@
1
- const execa = require('execa')
2
-
3
- const { removeFalsy } = require('../utils/remove_falsy')
4
-
5
- // Retrieve git-related information for use in environment variables.
6
- // git is optional and there might be not git repository.
7
- // We purposely keep this decoupled from the git utility.
8
- const getGitEnv = async function(buildDir, branch) {
9
- const [COMMIT_REF, CACHED_COMMIT_REF] = await Promise.all([
10
- git(['rev-parse', 'HEAD'], buildDir),
11
- git(['rev-parse', 'HEAD^'], buildDir),
12
- ])
13
- const gitEnv = { BRANCH: branch, HEAD: branch, COMMIT_REF, CACHED_COMMIT_REF, PULL_REQUEST: 'false' }
14
- const gitEnvA = removeFalsy(gitEnv)
15
- return gitEnvA
16
- }
17
-
18
- const git = async function(args, cwd) {
19
- try {
20
- const { stdout } = await execa('git', args, { cwd })
21
- return stdout
22
- } catch (error) {
23
- return
24
- }
25
- }
26
-
27
- module.exports = { getGitEnv }
package/src/env/main.js DELETED
@@ -1,97 +0,0 @@
1
- const { omit } = require('../utils/omit')
2
- const { removeFalsy } = require('../utils/remove_falsy')
3
-
4
- const { getGitEnv } = require('./git')
5
-
6
- // Retrieve the environment variables passed to plugins and `build.command`
7
- // When run locally, this tries to emulate the production environment.
8
- const getChildEnv = async function({ netlifyConfig, buildDir, branch, context, siteInfo, mode }) {
9
- if (mode === 'buildbot') {
10
- return process.env
11
- }
12
-
13
- const defaultEnv = getDefaultEnv()
14
- const configurableEnv = getConfigurableEnv()
15
- const configEnv = getConfigEnv(netlifyConfig)
16
- const forcedEnv = await getForcedEnv({ buildDir, branch, context, siteInfo })
17
- return {
18
- ...removeFalsy(defaultEnv),
19
- ...process.env,
20
- ...removeFalsy(configurableEnv),
21
- ...removeFalsy(configEnv),
22
- ...removeFalsy(forcedEnv),
23
- }
24
- }
25
-
26
- // Environment variables that can be unset by local ones or configuration ones
27
- const getDefaultEnv = function() {
28
- return {}
29
- }
30
-
31
- // Environment variables that can be unset by configuration ones but not local
32
- const getConfigurableEnv = function() {
33
- return {
34
- // Localization
35
- LANG: 'en_US.UTF-8',
36
- LANGUAGE: 'en_US:en',
37
- LC_ALL: 'en_US.UTF-8',
38
- // Disable telemetry of some tools
39
- GATSBY_TELEMETRY_DISABLED: '1',
40
- NEXT_TELEMETRY_DISABLED: '1',
41
- }
42
- }
43
-
44
- // Environment variables specified in UI settings or in `build.environment`
45
- const getConfigEnv = function({ build: { environment } }) {
46
- return omit(environment, READONLY_ENV)
47
- }
48
-
49
- // Those environment variables cannot be overriden by configuration
50
- const READONLY_ENV = [
51
- // Set in local builds
52
- 'BRANCH',
53
- 'CACHED_COMMIT_REF',
54
- 'COMMIT_REF',
55
- 'CONTEXT',
56
- 'HEAD',
57
- 'REPOSITORY_URL',
58
- 'URL',
59
-
60
- // Purposely left unset in local builds
61
- 'NETLIFY',
62
-
63
- // Not set in local builds because there is CI build/deploy, incoming hooks nor PR
64
- 'BUILD_ID',
65
- 'DEPLOY_ID',
66
- 'DEPLOY_PRIME_URL',
67
- 'DEPLOY_URL',
68
- 'INCOMING_HOOK_BODY',
69
- 'INCOMING_HOOK_TITLE',
70
- 'INCOMING_HOOK_URL',
71
- 'NETLIFY_BUILD_BASE',
72
- 'NETLIFY_BUILD_LIFECYCLE_TRIAL',
73
- 'NETLIFY_IMAGES_CDN_DOMAIN',
74
- 'PULL_REQUEST',
75
- 'REVIEW_ID',
76
- ]
77
-
78
- // Environment variables that can be unset by neither local nor configuration
79
- const getForcedEnv = async function({
80
- buildDir,
81
- branch,
82
- context,
83
- siteInfo: { url, build_settings: { repo_url } = {} },
84
- }) {
85
- const gitEnv = await getGitEnv(buildDir, branch)
86
- return {
87
- // Netlify Site information
88
- URL: url,
89
- REPOSITORY_URL: repo_url,
90
- // Configuration file context
91
- CONTEXT: context,
92
- // Git-related environment variables
93
- ...gitEnv,
94
- }
95
- }
96
-
97
- module.exports = { getChildEnv }
@@ -1,81 +0,0 @@
1
- const { env } = require('process')
2
-
3
- const filterObj = require('filter-obj')
4
-
5
- // Retrieve enviroment variables used in error monitoring
6
- const getEnvMetadata = function(childEnv = env) {
7
- return filterObj(childEnv, isEnvMetadata)
8
- }
9
-
10
- const isEnvMetadata = function(name) {
11
- return ENVIRONMENT_VARIABLES.includes(name)
12
- }
13
-
14
- // This is sorted by most useful in debugging to least
15
- const ENVIRONMENT_VARIABLES = [
16
- // URL and IDs
17
- 'BUILD_ID',
18
- 'DEPLOY_ID',
19
- 'REPOSITORY_URL',
20
- 'URL',
21
- 'DEPLOY_URL',
22
- 'DEPLOY_PRIME_URL',
23
-
24
- // Git
25
- 'HEAD',
26
- 'COMMIT_REF',
27
- 'CACHED_COMMIT_REF',
28
- 'BRANCH',
29
- 'CONTEXT',
30
- 'PULL_REQUEST',
31
- 'REVIEW_ID',
32
-
33
- // Node
34
- 'NODE_VERSION',
35
- 'AWS_LAMBDA_JS_RUNTIME',
36
- 'NPM_VERSION',
37
- 'YARN_VERSION',
38
- 'NPM_FLAGS',
39
- 'YARN_FLAGS',
40
- 'NVM_FLAGS',
41
- 'NODE_ENV',
42
-
43
- // Go
44
- 'GO_VERSION',
45
- 'GO_IMPORT_PATH',
46
- 'GOCACHE',
47
- 'GOPATH',
48
- 'GOROOT',
49
-
50
- // Ruby
51
- 'RUBY_VERSION',
52
- 'GEM_HOME',
53
- 'GEM_PATH',
54
- 'GIMME_GCO_ENABLED',
55
- 'GIMME_ENV_PREFIX',
56
- 'GIMME_GO_PREFIX',
57
- 'GIMME_NO_ENV_ALIAS',
58
- 'GIMME_TYPE',
59
- 'IRBRC',
60
- 'MY_RUBY_HOME',
61
-
62
- // Hugo
63
- 'HUGO_VERSION',
64
-
65
- // Java
66
- 'JAVA_VERSION',
67
-
68
- // PHP
69
- 'PHP_VERSION',
70
-
71
- // Python
72
- 'PIPENV_DEFAULT_PYTHON_VERSION',
73
- 'PIPENV_RUNTIME',
74
- 'PIPENV_VENV_IN_PROJECT',
75
-
76
- // Git LFS
77
- 'GIT_LFS_ENABLED',
78
- 'GIT_LFS_FETCH_INCLUDE',
79
- ]
80
-
81
- module.exports = { getEnvMetadata }
package/src/error/api.js DELETED
@@ -1,32 +0,0 @@
1
- const mapObj = require('map-obj')
2
-
3
- const { addErrorInfo } = require('./info')
4
-
5
- // Wrap `api.*` methods so that they add more error information
6
- const addApiErrorHandlers = function(api) {
7
- if (api === undefined) {
8
- return
9
- }
10
-
11
- return mapObj(api, addErrorHandler)
12
- }
13
-
14
- const addErrorHandler = function(key, value) {
15
- if (typeof value !== 'function') {
16
- return [key, value]
17
- }
18
-
19
- const valueA = apiMethodHandler.bind(null, key, value)
20
- return [key, valueA]
21
- }
22
-
23
- const apiMethodHandler = async function(endpoint, method, parameters, ...args) {
24
- try {
25
- return await method(parameters, ...args)
26
- } catch (error) {
27
- addErrorInfo(error, { type: 'api', location: { endpoint, parameters } })
28
- throw error
29
- }
30
- }
31
-
32
- module.exports = { addApiErrorHandlers }
@@ -1,32 +0,0 @@
1
- const { addErrorInfo } = require('./info')
2
-
3
- // Retrieve error information from child process and re-build it in current
4
- // process. We need this since errors are not JSON-serializable.
5
- const buildError = function({ type, plugin, location, name, message, stack, ...errorProps }) {
6
- const error = new Error('')
7
-
8
- assignErrorProps(error, { name, message, stack })
9
- // Assign static error properties (if any)
10
- Object.assign(error, errorProps)
11
-
12
- // Distinguish between utils.build.*() errors and uncaught exceptions / bugs
13
- if (type !== undefined) {
14
- addErrorInfo(error, { type, plugin, location })
15
- }
16
- return error
17
- }
18
-
19
- // Make sure `name`, `message` and `stack` are not enumerable
20
- const assignErrorProps = function(error, values) {
21
- ERROR_PROPS.forEach(name => {
22
- assignErrorProp(error, name, values[name])
23
- })
24
- }
25
-
26
- const ERROR_PROPS = ['name', 'message', 'stack']
27
-
28
- const assignErrorProp = function(error, name, value) {
29
- Object.defineProperty(error, name, { value, enumerable: false, writable: true, configurable: true })
30
- }
31
-
32
- module.exports = { buildError }
@@ -1,22 +0,0 @@
1
- const {
2
- env: { DEPLOY_ID },
3
- } = require('process')
4
-
5
- const { getErrorInfo } = require('./info')
6
-
7
- // Cancel builds, for example when a plugin uses `utils.build.cancelBuild()`
8
- const maybeCancelBuild = async function(error, api) {
9
- if (api === undefined || !DEPLOY_ID) {
10
- return
11
- }
12
-
13
- const { type } = getErrorInfo(error)
14
-
15
- if (type !== 'cancelBuild') {
16
- return
17
- }
18
-
19
- await api.cancelSiteDeploy({ deploy_id: DEPLOY_ID })
20
- }
21
-
22
- module.exports = { maybeCancelBuild }
@@ -1,13 +0,0 @@
1
- const stripAnsi = require('strip-ansi')
2
-
3
- // Remove ANSI sequences from `error.message`
4
- const removeErrorColors = function(error) {
5
- if (!(error instanceof Error)) {
6
- return
7
- }
8
-
9
- error.message = stripAnsi(error.message)
10
- error.stack = stripAnsi(error.stack)
11
- }
12
-
13
- module.exports = { removeErrorColors }
package/src/error/info.js DELETED
@@ -1,12 +0,0 @@
1
- // Add information related to an error without colliding with existing properties
2
- const addErrorInfo = function(error, info) {
3
- error[INFO_SYM] = { ...error[INFO_SYM], ...info }
4
- }
5
-
6
- const getErrorInfo = function(error) {
7
- return error[INFO_SYM] || {}
8
- }
9
-
10
- const INFO_SYM = Symbol('info')
11
-
12
- module.exports = { addErrorInfo, getErrorInfo, INFO_SYM }
@@ -1,50 +0,0 @@
1
- // We group errors by `error.message`. However some `error.message` contain
2
- // unique IDs, etc. which defeats that grouping. So we normalize those to make
3
- // them consistent
4
- const normalizeGroupingMessage = function(message, type) {
5
- const messageA = removeDependenciesLogs(message, type)
6
- return NORMALIZE_REGEXPS.reduce(normalizeMessage, messageA)
7
- }
8
-
9
- // Discard debug/info installation information
10
- const removeDependenciesLogs = function(message, type) {
11
- if (type !== 'dependencies') {
12
- return message
13
- }
14
-
15
- return message
16
- .split('\n')
17
- .filter(isErrorLine)
18
- .join('\n')
19
- }
20
-
21
- const isErrorLine = function(line) {
22
- return ERROR_LINES.some(errorLine => line.startsWith(errorLine))
23
- }
24
-
25
- const ERROR_LINES = [
26
- // Prefix for npm
27
- 'npm ERR!',
28
- // Prefix for Yarn
29
- 'error',
30
- ]
31
-
32
- const normalizeMessage = function(message, [regExp, replacement]) {
33
- return message.replace(regExp, replacement)
34
- }
35
-
36
- const NORMALIZE_REGEXPS = [
37
- // File paths
38
- [/(["'` ]|^)([^"'` ]*[/\\][^"'` ]*)(["'` ]|$)/gm, '$1/file/path$3'],
39
- // Semantic versions
40
- [/\d+\.\d+\.\d+(-\d+)?/g, '1.0.0'],
41
- [/version "[^"]+"/g, 'version "1.0.0"'],
42
- // Cypress plugin prints the user's platform
43
- [/^Platform: .*/gm, ''],
44
- // URLs
45
- [/https?:[\w.+_~!$&'()*,;=:@/?#]+/g, 'https://domain.com'],
46
- // Numbers, e.g. number of issues/problems
47
- [/\d+/g, '0'],
48
- ]
49
-
50
- module.exports = { normalizeGroupingMessage }
@@ -1,43 +0,0 @@
1
- const { log } = require('../../log/logger.js')
2
-
3
- // Print event payload instead of sending actual request during tests
4
- const printEventForTest = function({
5
- errors: [{ errorClass, errorMessage }],
6
- context,
7
- groupingHash,
8
- severity,
9
- unhandled,
10
- app: { releaseStage, version, type },
11
- device: {
12
- runtimeVersions: { node },
13
- },
14
- _metadata: { location, plugin: { package, homepage } = {}, packageJson, env: { BUILD_ID } = {}, other },
15
- }) {
16
- const eventString = JSON.stringify(
17
- {
18
- errorClass,
19
- errorMessage,
20
- context,
21
- groupingHash,
22
- severity,
23
- unhandled,
24
- releaseStage,
25
- version,
26
- type,
27
- node,
28
- location,
29
- package,
30
- packageJson: packageJson !== undefined,
31
- homepage,
32
- BUILD_ID,
33
- other,
34
- },
35
- null,
36
- 2,
37
- )
38
- log(`\nError monitoring payload:\n${eventString}`)
39
- }
40
-
41
- module.exports = {
42
- printEventForTest,
43
- }