@netlify/build 28.0.0-beta → 28.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (258) hide show
  1. package/bin.js +5 -0
  2. package/lib/core/bin.js +66 -0
  3. package/lib/core/build.js +355 -0
  4. package/lib/core/config.js +121 -0
  5. package/lib/core/constants.js +116 -0
  6. package/lib/core/dev.js +27 -0
  7. package/lib/core/dry.js +21 -0
  8. package/lib/core/feature_flags.js +19 -0
  9. package/lib/core/flags.js +201 -0
  10. package/lib/core/lingering.js +68 -0
  11. package/lib/core/main.js +123 -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 +20 -0
  15. package/lib/core/user_node_version.js +32 -0
  16. package/lib/env/changes.js +43 -0
  17. package/lib/env/main.js +14 -0
  18. package/lib/env/metadata.js +68 -0
  19. package/lib/error/api.js +37 -0
  20. package/lib/error/build.js +36 -0
  21. package/{src → lib}/error/cancel.js +5 -6
  22. package/lib/error/colors.js +9 -0
  23. package/lib/error/handle.js +46 -0
  24. package/lib/error/info.js +37 -0
  25. package/lib/error/monitor/location.js +16 -0
  26. package/lib/error/monitor/normalize.js +86 -0
  27. package/lib/error/monitor/print.js +20 -0
  28. package/lib/error/monitor/report.js +120 -0
  29. package/lib/error/monitor/start.js +58 -0
  30. package/lib/error/parse/clean_stack.js +70 -0
  31. package/lib/error/parse/location.js +50 -0
  32. package/lib/error/parse/normalize.js +24 -0
  33. package/lib/error/parse/parse.js +67 -0
  34. package/lib/error/parse/plugin.js +55 -0
  35. package/lib/error/parse/properties.js +16 -0
  36. package/lib/error/parse/serialize_log.js +34 -0
  37. package/lib/error/parse/serialize_status.js +18 -0
  38. package/lib/error/parse/stack.js +34 -0
  39. package/lib/error/type.js +171 -0
  40. package/lib/install/functions.js +20 -0
  41. package/lib/install/local.js +45 -0
  42. package/lib/install/main.js +67 -0
  43. package/lib/install/missing.js +54 -0
  44. package/{src → lib}/log/colors.js +15 -22
  45. package/lib/log/description.js +21 -0
  46. package/lib/log/header.js +14 -0
  47. package/lib/log/header_func.js +13 -0
  48. package/lib/log/logger.js +130 -0
  49. package/lib/log/messages/compatibility.js +120 -0
  50. package/lib/log/messages/config.js +91 -0
  51. package/lib/log/messages/core.js +50 -0
  52. package/lib/log/messages/core_steps.js +75 -0
  53. package/lib/log/messages/dry.js +41 -0
  54. package/lib/log/messages/install.js +25 -0
  55. package/lib/log/messages/ipc.js +29 -0
  56. package/lib/log/messages/mutations.js +62 -0
  57. package/{src → lib}/log/messages/plugins.js +18 -32
  58. package/lib/log/messages/status.js +14 -0
  59. package/lib/log/messages/steps.js +18 -0
  60. package/lib/log/old_version.js +32 -0
  61. package/lib/log/serialize.js +10 -0
  62. package/lib/log/stream.js +68 -0
  63. package/lib/log/theme.js +25 -0
  64. package/lib/plugins/child/diff.js +46 -0
  65. package/lib/plugins/child/error.js +26 -0
  66. package/lib/plugins/child/lazy.js +15 -0
  67. package/lib/plugins/child/load.js +22 -0
  68. package/lib/plugins/child/logic.js +57 -0
  69. package/lib/plugins/child/main.js +37 -0
  70. package/lib/plugins/child/run.js +19 -0
  71. package/lib/plugins/child/status.js +63 -0
  72. package/lib/plugins/child/typescript.js +28 -0
  73. package/lib/plugins/child/utils.js +42 -0
  74. package/lib/plugins/child/validate.js +31 -0
  75. package/lib/plugins/compatibility.js +104 -0
  76. package/{src → lib}/plugins/error.js +31 -35
  77. package/{src → lib}/plugins/events.js +7 -12
  78. package/lib/plugins/expected_version.js +81 -0
  79. package/lib/plugins/ipc.js +120 -0
  80. package/lib/plugins/list.js +73 -0
  81. package/lib/plugins/load.js +50 -0
  82. package/lib/plugins/manifest/check.js +85 -0
  83. package/lib/plugins/manifest/load.js +38 -0
  84. package/lib/plugins/manifest/main.js +17 -0
  85. package/lib/plugins/manifest/path.js +24 -0
  86. package/lib/plugins/manifest/validate.js +91 -0
  87. package/lib/plugins/node_version.js +30 -0
  88. package/lib/plugins/options.js +55 -0
  89. package/lib/plugins/pinned_version.js +83 -0
  90. package/lib/plugins/resolve.js +110 -0
  91. package/lib/plugins/spawn.js +54 -0
  92. package/lib/plugins_core/add.js +35 -0
  93. package/lib/plugins_core/build_command.js +50 -0
  94. package/lib/plugins_core/deploy/buildbot_client.js +87 -0
  95. package/lib/plugins_core/deploy/index.js +49 -0
  96. package/{src → lib}/plugins_core/deploy/manifest.yml +0 -0
  97. package/lib/plugins_core/edge_functions/index.js +79 -0
  98. package/lib/plugins_core/edge_functions/lib/error.js +17 -0
  99. package/lib/plugins_core/edge_functions/lib/internal_manifest.js +50 -0
  100. package/lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +75 -0
  101. package/lib/plugins_core/functions/error.js +123 -0
  102. package/lib/plugins_core/functions/feature_flags.js +6 -0
  103. package/lib/plugins_core/functions/index.js +114 -0
  104. package/lib/plugins_core/functions/utils.js +45 -0
  105. package/lib/plugins_core/functions/zisi.js +39 -0
  106. package/{src → lib}/plugins_core/functions_install/index.js +8 -11
  107. package/{src → lib}/plugins_core/functions_install/manifest.yml +0 -0
  108. package/lib/plugins_core/list.js +20 -0
  109. package/lib/status/add.js +30 -0
  110. package/lib/status/colors.js +18 -0
  111. package/lib/status/load_error.js +10 -0
  112. package/lib/status/report.js +83 -0
  113. package/lib/status/success.js +14 -0
  114. package/lib/steps/core_step.js +57 -0
  115. package/lib/steps/error.js +65 -0
  116. package/lib/steps/get.js +43 -0
  117. package/lib/steps/plugin.js +55 -0
  118. package/lib/steps/return.js +25 -0
  119. package/lib/steps/run_core_steps.js +147 -0
  120. package/lib/steps/run_step.js +188 -0
  121. package/lib/steps/run_steps.js +96 -0
  122. package/lib/steps/update_config.js +66 -0
  123. package/lib/telemetry/main.js +97 -0
  124. package/lib/time/aggregate.js +120 -0
  125. package/lib/time/main.js +37 -0
  126. package/lib/time/measure.js +18 -0
  127. package/lib/time/report.js +47 -0
  128. package/lib/utils/errors.js +13 -0
  129. package/lib/utils/json.js +15 -0
  130. package/{src → lib}/utils/omit.js +3 -4
  131. package/lib/utils/package.js +22 -0
  132. package/lib/utils/remove_falsy.js +8 -0
  133. package/lib/utils/resolve.js +41 -0
  134. package/lib/utils/runtime.js +5 -0
  135. package/lib/utils/semver.js +28 -0
  136. package/package.json +39 -20
  137. package/types/config/netlify_config.d.ts +4 -4
  138. package/types/netlify_plugin_constants.d.ts +8 -8
  139. package/src/core/bin.js +0 -83
  140. package/src/core/config.js +0 -186
  141. package/src/core/constants.js +0 -156
  142. package/src/core/dry.js +0 -39
  143. package/src/core/feature_flags.js +0 -21
  144. package/src/core/flags.js +0 -194
  145. package/src/core/lingering.js +0 -85
  146. package/src/core/main.js +0 -692
  147. package/src/core/missing_side_file.js +0 -29
  148. package/src/core/normalize_flags.js +0 -69
  149. package/src/core/severity.js +0 -22
  150. package/src/core/user_node_version.js +0 -41
  151. package/src/env/changes.js +0 -52
  152. package/src/env/main.js +0 -19
  153. package/src/env/metadata.js +0 -81
  154. package/src/error/api.js +0 -46
  155. package/src/error/build.js +0 -50
  156. package/src/error/colors.js +0 -11
  157. package/src/error/handle.js +0 -57
  158. package/src/error/info.js +0 -46
  159. package/src/error/monitor/location.js +0 -21
  160. package/src/error/monitor/normalize.js +0 -77
  161. package/src/error/monitor/print.js +0 -42
  162. package/src/error/monitor/report.js +0 -133
  163. package/src/error/monitor/start.js +0 -69
  164. package/src/error/parse/clean_stack.js +0 -87
  165. package/src/error/parse/location.js +0 -58
  166. package/src/error/parse/normalize.js +0 -29
  167. package/src/error/parse/parse.js +0 -97
  168. package/src/error/parse/plugin.js +0 -70
  169. package/src/error/parse/properties.js +0 -23
  170. package/src/error/parse/serialize_log.js +0 -42
  171. package/src/error/parse/serialize_status.js +0 -23
  172. package/src/error/parse/stack.js +0 -43
  173. package/src/error/type.js +0 -182
  174. package/src/install/functions.js +0 -28
  175. package/src/install/local.js +0 -62
  176. package/src/install/main.js +0 -81
  177. package/src/install/missing.js +0 -67
  178. package/src/log/description.js +0 -26
  179. package/src/log/header.js +0 -16
  180. package/src/log/header_func.js +0 -17
  181. package/src/log/logger.js +0 -107
  182. package/src/log/messages/compatibility.js +0 -164
  183. package/src/log/messages/config.js +0 -105
  184. package/src/log/messages/core.js +0 -70
  185. package/src/log/messages/core_steps.js +0 -104
  186. package/src/log/messages/dry.js +0 -63
  187. package/src/log/messages/install.js +0 -20
  188. package/src/log/messages/ipc.js +0 -38
  189. package/src/log/messages/mutations.js +0 -82
  190. package/src/log/messages/status.js +0 -16
  191. package/src/log/messages/steps.js +0 -22
  192. package/src/log/old_version.js +0 -41
  193. package/src/log/serialize.js +0 -13
  194. package/src/log/stream.js +0 -85
  195. package/src/log/theme.js +0 -26
  196. package/src/plugins/child/diff.js +0 -55
  197. package/src/plugins/child/error.js +0 -32
  198. package/src/plugins/child/lazy.js +0 -18
  199. package/src/plugins/child/load.js +0 -29
  200. package/src/plugins/child/logic.js +0 -57
  201. package/src/plugins/child/main.js +0 -51
  202. package/src/plugins/child/run.js +0 -28
  203. package/src/plugins/child/status.js +0 -67
  204. package/src/plugins/child/typescript.js +0 -45
  205. package/src/plugins/child/utils.js +0 -56
  206. package/src/plugins/child/validate.js +0 -34
  207. package/src/plugins/compatibility.js +0 -128
  208. package/src/plugins/expected_version.js +0 -119
  209. package/src/plugins/ipc.js +0 -145
  210. package/src/plugins/list.js +0 -86
  211. package/src/plugins/load.js +0 -70
  212. package/src/plugins/manifest/check.js +0 -106
  213. package/src/plugins/manifest/load.js +0 -41
  214. package/src/plugins/manifest/main.js +0 -22
  215. package/src/plugins/manifest/path.js +0 -31
  216. package/src/plugins/manifest/validate.js +0 -108
  217. package/src/plugins/node_version.js +0 -50
  218. package/src/plugins/options.js +0 -88
  219. package/src/plugins/pinned_version.js +0 -131
  220. package/src/plugins/resolve.js +0 -152
  221. package/src/plugins/spawn.js +0 -66
  222. package/src/plugins_core/add.js +0 -49
  223. package/src/plugins_core/build_command.js +0 -75
  224. package/src/plugins_core/deploy/buildbot_client.js +0 -102
  225. package/src/plugins_core/deploy/index.js +0 -73
  226. package/src/plugins_core/edge_functions/index.js +0 -107
  227. package/src/plugins_core/edge_functions/lib/internal_manifest.js +0 -54
  228. package/src/plugins_core/functions/error.js +0 -163
  229. package/src/plugins_core/functions/feature_flags.js +0 -6
  230. package/src/plugins_core/functions/index.js +0 -160
  231. package/src/plugins_core/functions/utils.js +0 -66
  232. package/src/plugins_core/functions/zisi.js +0 -53
  233. package/src/plugins_core/list.js +0 -27
  234. package/src/status/add.js +0 -36
  235. package/src/status/colors.js +0 -23
  236. package/src/status/load_error.js +0 -11
  237. package/src/status/report.js +0 -128
  238. package/src/status/success.js +0 -18
  239. package/src/steps/core_step.js +0 -90
  240. package/src/steps/error.js +0 -102
  241. package/src/steps/get.js +0 -32
  242. package/src/steps/plugin.js +0 -85
  243. package/src/steps/return.js +0 -52
  244. package/src/steps/run_core_steps.js +0 -194
  245. package/src/steps/run_step.js +0 -300
  246. package/src/steps/run_steps.js +0 -179
  247. package/src/steps/update_config.js +0 -93
  248. package/src/telemetry/main.js +0 -136
  249. package/src/time/aggregate.js +0 -146
  250. package/src/time/main.js +0 -48
  251. package/src/time/measure.js +0 -22
  252. package/src/time/report.js +0 -59
  253. package/src/utils/errors.js +0 -12
  254. package/src/utils/json.js +0 -19
  255. package/src/utils/package.js +0 -23
  256. package/src/utils/remove_falsy.js +0 -10
  257. package/src/utils/resolve.js +0 -46
  258. package/src/utils/semver.js +0 -34
@@ -1,69 +0,0 @@
1
- import { env, execPath } from 'process'
2
-
3
- import { logFlags } from '../log/messages/config.js'
4
- import { removeFalsy } from '../utils/remove_falsy.js'
5
-
6
- import { DEFAULT_FEATURE_FLAGS } from './feature_flags.js'
7
-
8
- // Normalize CLI flags
9
- export const normalizeFlags = function (flags, logs) {
10
- const rawFlags = removeFalsy(flags)
11
-
12
- // Combine the flags object env with the process.env
13
- const combinedEnv = { ...env, ...rawFlags.env }
14
- const defaultFlags = getDefaultFlags(rawFlags, combinedEnv)
15
-
16
- // The telemetry flag requires specific logic to compute
17
- const telemetryFlag = computeTelemetry(rawFlags, combinedEnv)
18
-
19
- const mergedFlags = {
20
- ...defaultFlags,
21
- ...rawFlags,
22
- ...telemetryFlag,
23
- statsdOpts: { ...defaultFlags.statsd, ...rawFlags.statsd },
24
- featureFlags: { ...defaultFlags.featureFlags, ...rawFlags.featureFlags },
25
- }
26
- const normalizedFlags = removeFalsy(mergedFlags)
27
-
28
- logFlags(logs, rawFlags, normalizedFlags)
29
-
30
- return normalizedFlags
31
- }
32
-
33
- // Default values of CLI flags
34
- const getDefaultFlags = function ({ env: envOpt = {} }, combinedEnv) {
35
- return {
36
- env: envOpt,
37
- nodePath: execPath,
38
- token: combinedEnv.NETLIFY_AUTH_TOKEN,
39
- mode: REQUIRE_MODE,
40
- offline: false,
41
- telemetry: false,
42
- verbose: Boolean(combinedEnv.NETLIFY_BUILD_DEBUG),
43
- functionsDistDir: DEFAULT_FUNCTIONS_DIST,
44
- edgeFunctionsDistDir: DEFAULT_EDGE_FUNCTIONS_DIST,
45
- cacheDir: DEFAULT_CACHE_DIR,
46
- deployId: combinedEnv.DEPLOY_ID,
47
- buildId: combinedEnv.BUILD_ID,
48
- debug: Boolean(combinedEnv.NETLIFY_BUILD_DEBUG),
49
- bugsnagKey: combinedEnv.BUGSNAG_KEY,
50
- sendStatus: false,
51
- saveConfig: false,
52
- apiHost: 'api.netlify.com',
53
- testOpts: {},
54
- featureFlags: DEFAULT_FEATURE_FLAGS,
55
- statsd: { port: DEFAULT_STATSD_PORT },
56
- }
57
- }
58
-
59
- // Compute the telemetry flag, it's disabled by default and we want to always disable it
60
- // if BUILD_TELEMETRY_DISABLED is passed.
61
- const computeTelemetry = function (flags, envOpts) {
62
- return envOpts.BUILD_TELEMETRY_DISABLED ? { telemetry: false } : { telemetry: flags.telemetry }
63
- }
64
-
65
- const REQUIRE_MODE = 'require'
66
- const DEFAULT_EDGE_FUNCTIONS_DIST = '.netlify/edge-functions-dist/'
67
- const DEFAULT_FUNCTIONS_DIST = '.netlify/functions/'
68
- const DEFAULT_CACHE_DIR = '.netlify/cache/'
69
- const DEFAULT_STATSD_PORT = 8125
@@ -1,22 +0,0 @@
1
- // Used to extract exit codes and respective status strings
2
- // 1|2|3 indicate whether this was a user|plugin|system error.
3
- export const getSeverity = function (severity = FALLBACK_SEVERITY) {
4
- const severityEntry = severity in SEVERITY_MAP ? SEVERITY_MAP[severity] : FALLBACK_SEVERITY_ENTRY
5
- const success = severity === SUCCESS_SEVERITY
6
- return { success, ...severityEntry }
7
- }
8
-
9
- // Map error severities to exit codes and status (used for telemetry purposes)
10
- /* eslint-disable no-magic-numbers */
11
- const SEVERITY_MAP = {
12
- success: { severityCode: 0, status: 'success' },
13
- none: { severityCode: 1, status: 'cancelled' },
14
- info: { severityCode: 2, status: 'user-error' },
15
- warning: { severityCode: 3, status: 'plugin-error' },
16
- error: { severityCode: 4, status: 'system-error' },
17
- }
18
- /* eslint-enable no-magic-numbers */
19
- const SUCCESS_SEVERITY = 'success'
20
- // Indicates a bug in our codebase
21
- const FALLBACK_SEVERITY = 'error'
22
- export const FALLBACK_SEVERITY_ENTRY = SEVERITY_MAP[FALLBACK_SEVERITY]
@@ -1,41 +0,0 @@
1
- import { version as currentVersion, execPath } from 'process'
2
-
3
- import { execa } from 'execa'
4
- import semver from 'semver'
5
-
6
- import { addErrorInfo } from '../error/info.js'
7
-
8
- // Retrieve Node.js version if the Node.js path is using nvm.
9
- // `node.exe` on Windows, `bin/node` on Unix.
10
- const NVM_NODE_VERSION_REGEXP = /[/\\]v(\d+\.\d+\.\d+)[/\\](bin[/\\]node|node.exe)$/
11
-
12
- // Retrieve Node.js version from current process
13
- const getCurrentNodeVersion = function () {
14
- return semver.clean(currentVersion)
15
- }
16
-
17
- // Retrieve Node.js version from `--node-path` or fallback to extracting the current Node.js process version
18
- export const getUserNodeVersion = async function (nodePath) {
19
- // No `--node-path` CLI flag, use the current node process version
20
- if (nodePath === execPath) {
21
- return getCurrentNodeVersion()
22
- }
23
-
24
- // Extract version from path
25
- const result = NVM_NODE_VERSION_REGEXP.exec(nodePath)
26
- if (result !== null) {
27
- return result[1]
28
- }
29
-
30
- // Fallback to actually running `node --version` with the given nodePath
31
- const { stdout } = await execa(nodePath, ['--version'], { reject: false })
32
- const version = semver.clean(stdout)
33
-
34
- if (version === null) {
35
- const error = new Error(`Invalid --node-path CLI flag: ${nodePath}`)
36
- addErrorInfo(error, { type: 'resolveConfig' })
37
- throw error
38
- }
39
-
40
- return version
41
- }
@@ -1,52 +0,0 @@
1
- import { env } from 'process'
2
-
3
- import filterObj from 'filter-obj'
4
- import mapObj from '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
- export const getNewEnvChanges = function (envBefore, netlifyConfig, netlifyConfigCopy) {
10
- const processEnvChanges = diffEnv(envBefore, env)
11
- const netlifyConfigEnvChanges = diffEnv(netlifyConfig.build.environment, netlifyConfigCopy.build.environment)
12
- return { ...processEnvChanges, ...netlifyConfigEnvChanges }
13
- }
14
-
15
- const diffEnv = function (envBefore, envAfter) {
16
- const envChanges = filterObj(envAfter, (name, value) => value !== envBefore[name])
17
- const deletedEnv = filterObj(envBefore, (name) => envAfter[name] === undefined)
18
- const deletedEnvA = mapObj(deletedEnv, setToNull)
19
- return { ...envChanges, ...deletedEnvA }
20
- }
21
-
22
- // `undefined` is not JSON-serializable (which is used in process IPC), so we
23
- // convert it to `null`
24
- // Note: `process.env[name] = undefined` actually does
25
- // `process.env[name] = 'undefined'` in Node.js.
26
- const setToNull = function (name) {
27
- return [name, null]
28
- }
29
-
30
- // Set `process.env` changes from a previous different plugin.
31
- // Can also merge with a `currentEnv` plain object instead of `process.env`.
32
- export const setEnvChanges = function (envChanges, currentEnv = env) {
33
- Object.entries(envChanges).forEach(([name, value]) => {
34
- setEnvChange(name, value, currentEnv)
35
- })
36
- return { ...currentEnv }
37
- }
38
-
39
- const setEnvChange = function (name, value, currentEnv) {
40
- if (currentEnv[name] === value) {
41
- return
42
- }
43
-
44
- if (value === null) {
45
- // `currentEnv` is a mutable variable
46
- // eslint-disable-next-line fp/no-delete
47
- delete currentEnv[name]
48
- return
49
- }
50
-
51
- currentEnv[name] = value
52
- }
package/src/env/main.js DELETED
@@ -1,19 +0,0 @@
1
- import { env } from 'process'
2
-
3
- import filterObj from 'filter-obj'
4
-
5
- import { getParentColorEnv } from '../log/colors.js'
6
-
7
- // Retrieve the environment variables passed to plugins and `build.command`
8
- // When run locally, this tries to emulate the production environment.
9
- export const getChildEnv = function ({ envOpt, env: allConfigEnv }) {
10
- const parentColorEnv = getParentColorEnv()
11
- const parentEnv = { ...env, ...allConfigEnv, ...envOpt, ...parentColorEnv }
12
- return filterObj(parentEnv, shouldKeepEnv)
13
- }
14
-
15
- const shouldKeepEnv = function (key) {
16
- return !REMOVED_PARENT_ENV.has(key.toLowerCase())
17
- }
18
-
19
- const REMOVED_PARENT_ENV = new Set(['bugsnag_key'])
@@ -1,81 +0,0 @@
1
- import { env } from 'process'
2
-
3
- import filterObj from 'filter-obj'
4
-
5
- // Retrieve enviroment variables used in error monitoring
6
- export const getEnvMetadata = function (childEnv = env) {
7
- return filterObj(childEnv, isEnvMetadata)
8
- }
9
-
10
- const isEnvMetadata = function (name) {
11
- return ENVIRONMENT_VARIABLES.has(name)
12
- }
13
-
14
- // This is sorted by most useful in debugging to least
15
- const ENVIRONMENT_VARIABLES = new Set([
16
- // URL and IDs
17
- 'BUILD_ID',
18
- 'DEPLOY_ID',
19
- 'SITE_NAME',
20
- 'SITE_ID',
21
- 'REPOSITORY_URL',
22
- 'URL',
23
- 'DEPLOY_URL',
24
- 'DEPLOY_PRIME_URL',
25
-
26
- // Git
27
- 'HEAD',
28
- 'COMMIT_REF',
29
- 'CACHED_COMMIT_REF',
30
- 'BRANCH',
31
- 'CONTEXT',
32
- 'PULL_REQUEST',
33
- 'REVIEW_ID',
34
-
35
- // Node
36
- 'NODE_VERSION',
37
- 'AWS_LAMBDA_JS_RUNTIME',
38
- 'NPM_VERSION',
39
- 'YARN_VERSION',
40
- 'NPM_FLAGS',
41
- 'YARN_FLAGS',
42
- 'NVM_FLAGS',
43
- 'NODE_ENV',
44
-
45
- // Go
46
- 'GO_VERSION',
47
- 'GO_IMPORT_PATH',
48
- 'GOCACHE',
49
- 'GOPATH',
50
- 'GOROOT',
51
-
52
- // Ruby
53
- 'RUBY_VERSION',
54
- 'GEM_HOME',
55
- 'GEM_PATH',
56
- 'GIMME_GCO_ENABLED',
57
- 'GIMME_ENV_PREFIX',
58
- 'GIMME_GO_PREFIX',
59
- 'GIMME_NO_ENV_ALIAS',
60
- 'GIMME_TYPE',
61
- 'IRBRC',
62
- 'MY_RUBY_HOME',
63
-
64
- // Hugo
65
- 'HUGO_VERSION',
66
-
67
- // Java
68
- 'JAVA_VERSION',
69
-
70
- // PHP
71
- 'PHP_VERSION',
72
-
73
- // Python
74
- 'PIPENV_DEFAULT_PYTHON_VERSION',
75
- 'PIPENV_RUNTIME',
76
- 'PIPENV_VENV_IN_PROJECT',
77
-
78
- // Git LFS
79
- 'GIT_LFS_ENABLED',
80
- 'GIT_LFS_FETCH_INCLUDE',
81
- ])
package/src/error/api.js DELETED
@@ -1,46 +0,0 @@
1
- import isPlainObj from 'is-plain-obj'
2
- import mapObj from 'map-obj'
3
-
4
- import { addErrorInfo } from './info.js'
5
-
6
- // Wrap `api.*` methods so that they add more error information
7
- export const addApiErrorHandlers = function (api) {
8
- if (api === undefined) {
9
- return
10
- }
11
-
12
- return mapObj(api, addErrorHandler)
13
- }
14
-
15
- const addErrorHandler = function (key, value) {
16
- if (typeof value !== 'function') {
17
- return [key, value]
18
- }
19
-
20
- const valueA = apiMethodHandler.bind(null, key, value)
21
- return [key, valueA]
22
- }
23
-
24
- const apiMethodHandler = async function (endpoint, method, parameters, ...args) {
25
- try {
26
- return await method(parameters, ...args)
27
- } catch (error) {
28
- redactError(error)
29
- addErrorInfo(error, { type: 'api', location: { endpoint, parameters } })
30
- throw error
31
- }
32
- }
33
-
34
- // Redact API token from the build logs
35
- const redactError = function (error) {
36
- if (
37
- error instanceof Error &&
38
- isPlainObj(error.data) &&
39
- isPlainObj(error.data.headers) &&
40
- typeof error.data.headers.Authorization === 'string'
41
- ) {
42
- error.data.headers.Authorization = error.data.headers.Authorization.replace(HEX_REGEXP, 'HEX')
43
- }
44
- }
45
-
46
- const HEX_REGEXP = /[\da-f]{6,}/g
@@ -1,50 +0,0 @@
1
- import safeJsonStringify from 'safe-json-stringify'
2
-
3
- import { CUSTOM_ERROR_KEY } from './info.js'
4
-
5
- // Retrieve error information from child process and re-build it in current
6
- // process. We need this since errors static properties are not kept by
7
- // `v8.serialize()`.
8
- export const jsonToError = function ({ name, message, stack, ...errorProps }) {
9
- // eslint-disable-next-line unicorn/error-message
10
- const error = new Error('')
11
-
12
- assignErrorProps(error, { name, message, stack })
13
- // Assign static error properties (if any)
14
- // We need to mutate the `error` directly to preserve its `name`, `stack`, etc.
15
- // eslint-disable-next-line fp/no-mutating-assign
16
- Object.assign(error, errorProps)
17
-
18
- return error
19
- }
20
-
21
- // Make sure `name`, `message` and `stack` are not enumerable
22
- const assignErrorProps = function (error, values) {
23
- ERROR_PROPS.forEach((name) => {
24
- assignErrorProp(error, name, values[name])
25
- })
26
- }
27
-
28
- const ERROR_PROPS = ['name', 'message', 'stack']
29
-
30
- const assignErrorProp = function (error, name, value) {
31
- // `Object.defineProperty()` requires direct mutation
32
- // eslint-disable-next-line fp/no-mutating-methods
33
- Object.defineProperty(error, name, { value, enumerable: false, writable: true, configurable: true })
34
- }
35
-
36
- // Inverse of `jsonToError()`.
37
- export const errorToJson = function (error) {
38
- const { name, message, stack, [CUSTOM_ERROR_KEY]: customError, ...errorProps } = error
39
-
40
- // diagnosticText is not enumerable in TSError so we need to grab it manually. destructuring won't work.
41
- if (error.diagnosticText) {
42
- // eslint-disable-next-line fp/no-mutation
43
- errorProps.diagnosticText = error.diagnosticText
44
- }
45
-
46
- return {
47
- ...safeJsonStringify.ensureProperties(errorProps),
48
- ...safeJsonStringify.ensureProperties({ name, message, stack, [CUSTOM_ERROR_KEY]: customError }),
49
- }
50
- }
@@ -1,11 +0,0 @@
1
- import stripAnsi from 'strip-ansi'
2
-
3
- // Remove ANSI sequences from `error.message`
4
- export 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
- }
@@ -1,57 +0,0 @@
1
- import { cwd as getCwd } from 'process'
2
-
3
- import { pathExists } from 'path-exists'
4
-
5
- import { logBuildError } from '../log/messages/core.js'
6
- import { logOldCliVersionError } from '../log/old_version.js'
7
-
8
- import { removeErrorColors } from './colors.js'
9
- import { getErrorInfo } from './info.js'
10
- import { reportBuildError } from './monitor/report.js'
11
- import { parseErrorInfo } from './parse/parse.js'
12
-
13
- // Logs and reports a build failure
14
- export const handleBuildError = async function (
15
- error,
16
- { errorMonitor, netlifyConfig, childEnv, mode, logs, debug, testOpts },
17
- ) {
18
- const basicErrorInfo = parseErrorInfo(error)
19
-
20
- if (await isCancelCrash(error)) {
21
- return basicErrorInfo
22
- }
23
-
24
- removeErrorColors(error)
25
- // Some errors, such as telemetry ones, should not be logged
26
- if (basicErrorInfo.showInBuildLog) {
27
- logBuildError({ error, netlifyConfig, mode, logs, debug, testOpts })
28
- }
29
- logOldCliVersionError({ mode, testOpts })
30
- await reportBuildError({ error, errorMonitor, childEnv, logs, testOpts })
31
-
32
- return basicErrorInfo
33
- }
34
-
35
- // When builds are canceled, the whole filesystem is being deleted.
36
- // However, the process (and build) keeps going. Because no files exist anymore,
37
- // the build eventually crashes with a randomly odd error. Those should not be
38
- // logged nor reported.
39
- // However builds canceled with `utils.build.cancelBuild()` should still show
40
- // "Build canceled by ..."
41
- const isCancelCrash = async function (error) {
42
- const [{ type }] = getErrorInfo(error)
43
- if (type === 'cancelBuild') {
44
- return false
45
- }
46
-
47
- try {
48
- // TODO: find a better way to detect that the build is being cancelled.
49
- // Otherwise bugs due to (for example) the build command removing
50
- // `process.cwd` are currently not logged/reported.
51
- const cwd = getCwd()
52
- return !(await pathExists(cwd))
53
- // `process.cwd()` fails when the current directory does not exist
54
- } catch {
55
- return true
56
- }
57
- }
package/src/error/info.js DELETED
@@ -1,46 +0,0 @@
1
- // Add information related to an error without colliding with existing properties
2
- export const addDefaultErrorInfo = function (error, info) {
3
- if (!canHaveErrorInfo(error)) {
4
- return
5
- }
6
-
7
- error[CUSTOM_ERROR_KEY] = { ...info, ...error[CUSTOM_ERROR_KEY] }
8
- }
9
-
10
- // Retrieve error information added by our system
11
- export const addErrorInfo = function (error, info) {
12
- if (!canHaveErrorInfo(error)) {
13
- return
14
- }
15
-
16
- error[CUSTOM_ERROR_KEY] = { ...error[CUSTOM_ERROR_KEY], ...info }
17
- }
18
-
19
- export const getErrorInfo = function (error) {
20
- if (!isBuildError(error)) {
21
- return [{}, error]
22
- }
23
-
24
- const { [CUSTOM_ERROR_KEY]: errorInfo, ...errorA } = error
25
- return [errorInfo, errorA]
26
- }
27
-
28
- // Change error type from one to another
29
- export const changeErrorType = function (error, oldType, newType) {
30
- const [{ type }] = getErrorInfo(error)
31
- if (type === oldType) {
32
- addErrorInfo(error, { type: newType })
33
- }
34
- }
35
-
36
- export const isBuildError = function (error) {
37
- return canHaveErrorInfo(error) && error[CUSTOM_ERROR_KEY] !== undefined
38
- }
39
-
40
- // Exceptions that are not objects (including `Error` instances) cannot have an
41
- // `CUSTOM_ERROR_KEY` property
42
- const canHaveErrorInfo = function (error) {
43
- return error != null
44
- }
45
-
46
- export const CUSTOM_ERROR_KEY = 'customErrorInfo'
@@ -1,21 +0,0 @@
1
- // Retrieve plugin's location and build logs
2
- export const getLocationMetadata = function (location, envMetadata) {
3
- const buildLogs = getBuildLogs(envMetadata)
4
-
5
- if (buildLogs === undefined && location === undefined) {
6
- return
7
- }
8
-
9
- return { buildLogs, ...location }
10
- }
11
-
12
- // Retrieve the URL to the build logs
13
- const getBuildLogs = function ({ SITE_NAME, DEPLOY_ID }) {
14
- if (SITE_NAME === undefined || DEPLOY_ID === undefined) {
15
- return
16
- }
17
-
18
- return `${NETLIFY_ORIGIN}/sites/${SITE_NAME}/deploys/${DEPLOY_ID}`
19
- }
20
-
21
- const NETLIFY_ORIGIN = 'https://app.netlify.com'
@@ -1,77 +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
- export 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.split('\n').filter(isErrorLine).join('\n')
16
- }
17
-
18
- const isErrorLine = function (line) {
19
- return ERROR_LINES.some((errorLine) => line.startsWith(errorLine))
20
- }
21
-
22
- const ERROR_LINES = [
23
- // Prefix for npm
24
- 'npm ERR!',
25
- // Prefix for Yarn
26
- 'error',
27
- ]
28
-
29
- const normalizeMessage = function (message, [regExp, replacement]) {
30
- return message.replace(regExp, replacement)
31
- }
32
-
33
- const NORMALIZE_REGEXPS = [
34
- // Base64 URL
35
- [/(data:[^;]+;base64),[\w+/-]+/g, 'dataURI'],
36
- // File paths
37
- [/(["'`, ]|^)([^"'`, \n]*[/\\][^"'`, \n]*)(["'`, ]|$)/gm, '$1/file/path$3'],
38
- // Semantic versions
39
- [/\d+\.\d+\.\d+(-\d+)?/g, '1.0.0'],
40
- [/version "[^"]+"/g, 'version "1.0.0"'],
41
- // Cypress plugin prints the user's platform
42
- [/^Platform: .*/gm, ''],
43
- // URLs
44
- [/https?:[\w.+~!$&'()*,;=:@/?#]+/g, 'https://domain.com'],
45
- // Numbers, e.g. number of issues/problems
46
- [/\d+/g, '0'],
47
- // Hexadecimal strings
48
- [/[\da-fA-F]{6,}/g, 'hex'],
49
- // On unknown inputs, we print the inputs
50
- [/(does not accept any inputs but you specified: ).*/, '$1'],
51
- [/(Unknown inputs for plugin).*/, '$1'],
52
- [/(Plugin inputs should be one of: ).*/, '$1'],
53
- // On required inputs, we print the inputs
54
- [/^Plugin inputs[^]*/gm, ''],
55
- [/(Required inputs for plugin).*/gm, '$1'],
56
- // Netlify Functions validation check
57
- [/(should target a directory, not a regular file):.*/, '$1'],
58
- // zip-it-and-ship-it error when there is an `import()` but dependencies
59
- // were not installed
60
- [/(Cannot find module) '([^']+)'/g, "$1 'moduleName'"],
61
- [/(A Netlify Function is using) "[^"]+"/g, '$1 "moduleName"'],
62
- // Deploy upload errors include the filename
63
- [/(Upload cancelled).*/g, '$1'],
64
- [/(aborting upload of file).*/g, '$1'],
65
- // netlify-plugin-inline-critical-css errors prints a list of file paths
66
- [/Searched in: .*/g, ''],
67
- // netlify-plugin-subfont prints font name in errors
68
- [/(is not supported yet): .*/, '$1'],
69
- // netlify-plugin-subfont prints generic information in every error that
70
- // is highly build-specific
71
- [/^(vers?ions|Plugin configuration|Subfont called with): {[^}]+}/gm, ''],
72
- [/^Resolved entry points: \[[^\]]+]/gm, ''],
73
- // netlify-plugin-minify-html parse error
74
- [/(Parse Error):[^]*/, '$1'],
75
- // Multiple empty lines
76
- [/^\s*$/gm, ''],
77
- ]
@@ -1,42 +0,0 @@
1
- import { log } from '../../log/logger.js'
2
-
3
- // Print event payload instead of sending actual request during tests
4
- export const printEventForTest = function (
5
- { name: errorClass, message: errorMessage },
6
- {
7
- context,
8
- groupingHash,
9
- severity,
10
- unhandled,
11
- _metadata: {
12
- location,
13
- plugin: { packageName, homepage } = {},
14
- pluginPackageJson,
15
- tsConfig,
16
- env: { BUILD_ID } = {},
17
- other,
18
- },
19
- },
20
- logs,
21
- ) {
22
- const eventString = JSON.stringify(
23
- {
24
- errorClass,
25
- errorMessage,
26
- context,
27
- groupingHash,
28
- severity,
29
- unhandled,
30
- location,
31
- packageName,
32
- pluginPackageJson: pluginPackageJson !== undefined,
33
- homepage,
34
- tsConfig,
35
- BUILD_ID,
36
- other,
37
- },
38
- null,
39
- 2,
40
- )
41
- log(logs, `\nError monitoring payload:\n${eventString}`)
42
- }