@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
@@ -1,140 +0,0 @@
1
- const { type, freemem, totalmem } = require('os')
2
- const { env } = require('process')
3
- const { promisify } = require('util')
4
-
5
- const osName = require('os-name')
6
-
7
- const { getEnvMetadata } = require('../../env/metadata')
8
- const { log } = require('../../log/logger.js')
9
- const { getErrorInfo } = require('../info')
10
- const { getHomepage } = require('../parse/plugin')
11
- const { getTypeInfo } = require('../type')
12
-
13
- const { normalizeGroupingMessage } = require('./normalize')
14
- const { printEventForTest } = require('./print')
15
-
16
- // Report a build failure for monitoring purpose
17
- const reportBuildError = async function(error, errorMonitor) {
18
- if (errorMonitor === undefined) {
19
- return
20
- }
21
-
22
- const errorInfo = getErrorInfo(error)
23
- const { type, severity, title, group = title } = getTypeInfo(errorInfo)
24
- const severityA = getSeverity(severity, errorInfo)
25
- const groupA = getGroup(group, errorInfo)
26
- const groupingHash = getGroupingHash(groupA, error, type)
27
- const metadata = getMetadata(errorInfo, groupingHash)
28
- const app = getApp()
29
-
30
- const errorName = updateErrorName(error, type)
31
- try {
32
- await reportError({
33
- errorMonitor,
34
- error,
35
- severity: severityA,
36
- group: groupA,
37
- groupingHash,
38
- metadata,
39
- app,
40
- })
41
- } finally {
42
- error.name = errorName
43
- }
44
- }
45
-
46
- // Plugin authors test their plugins as local plugins. Errors there are more
47
- // like development errors, and should be reported as `info` only.
48
- const getSeverity = function(severity, { location: { loadedFrom } = {} }) {
49
- if (loadedFrom === 'local') {
50
- return 'info'
51
- }
52
-
53
- return severity
54
- }
55
-
56
- const getGroup = function(group, errorInfo) {
57
- if (typeof group !== 'function') {
58
- return group
59
- }
60
-
61
- return group(errorInfo)
62
- }
63
-
64
- const getGroupingHash = function(group, error, type) {
65
- const message = error instanceof Error && typeof error.message === 'string' ? error.message : String(error)
66
- const messageA = normalizeGroupingMessage(message, type)
67
- return `${group}\n${messageA}`
68
- }
69
-
70
- const getMetadata = function({ location, plugin, childEnv }, groupingHash) {
71
- const pluginMetadata = getPluginMetadata(plugin)
72
- const envMetadata = getEnvMetadata(childEnv)
73
- return { location, ...pluginMetadata, env: envMetadata, other: { groupingHash } }
74
- }
75
-
76
- const getPluginMetadata = function(plugin) {
77
- if (plugin === undefined) {
78
- return {}
79
- }
80
-
81
- const { packageJson } = plugin
82
- const homepage = getHomepage(packageJson)
83
- return { plugin: { ...plugin, homepage }, packageJson }
84
- }
85
-
86
- const getApp = function() {
87
- return {
88
- osName: type(),
89
- osVersion: osName(),
90
- freeMemory: freemem(),
91
- totalMemory: totalmem(),
92
- }
93
- }
94
-
95
- // `error.name` is shown proeminently in the Bugsnag UI. We need to update it to
96
- // match error `type` since it is more granular and useful.
97
- // But we change it back after Bugsnag is done reporting.
98
- const updateErrorName = function(error, type) {
99
- const { name } = error
100
- error.name = type
101
- return name
102
- }
103
-
104
- const reportError = async function({ errorMonitor, error, severity, group, groupingHash, metadata, app }) {
105
- try {
106
- await promisify(errorMonitor.notify)(error, event =>
107
- onError({ event, severity, group, groupingHash, metadata, app }),
108
- )
109
- // Failsafe
110
- } catch (error) {
111
- log(`Error monitor could not notify\n${error.stack}`)
112
- return
113
- }
114
- }
115
-
116
- // Add more information to Bugsnag events
117
- const onError = function({ event, severity, group, groupingHash, metadata, app }) {
118
- // `unhandled` is used to calculate Releases "stabiity score", which is
119
- // basically the percentage of unhandled errors. Since we handle all errors,
120
- // we need to implement this according to error types.
121
- const unhandled = event.unhandled || severity === 'error'
122
-
123
- Object.assign(event, {
124
- severity,
125
- context: group,
126
- groupingHash,
127
- _metadata: { ...event._metadata, ...metadata },
128
- app: { ...event.app, ...app },
129
- unhandled,
130
- })
131
-
132
- if (env.NETLIFY_BUILD_TEST === '1') {
133
- printEventForTest(event)
134
- return false
135
- }
136
-
137
- return true
138
- }
139
-
140
- module.exports = { reportBuildError }
@@ -1,50 +0,0 @@
1
- const { env } = require('process')
2
-
3
- const Bugsnag = require('@bugsnag/js')
4
-
5
- const { name, version } = require('../../../package.json')
6
- const { log } = require('../../log/logger.js')
7
-
8
- const projectRoot = `${__dirname}/../../..`
9
-
10
- // Start a client to monitor errors
11
- const startErrorMonitor = function({ mode }) {
12
- const apiKey = env.BUGSNAG_KEY
13
- if (!apiKey) {
14
- return
15
- }
16
-
17
- const releaseStage = getReleaseStage(mode)
18
- try {
19
- const errorMonitor = Bugsnag.start({
20
- apiKey,
21
- appVersion: `${name} ${version}`,
22
- appType: name,
23
- releaseStage,
24
- logger,
25
- projectRoot,
26
- })
27
-
28
- // Allows knowing the percentage of failed builds per release
29
- errorMonitor.startSession()
30
-
31
- return errorMonitor
32
- // Failsafe
33
- } catch (error) {
34
- log(`Error monitor could not start\n${error.stack}`)
35
- return
36
- }
37
- }
38
-
39
- // Based the release stage on the `mode`
40
- const getReleaseStage = function(mode = DEFAULT_RELEASE_STAGE) {
41
- return mode
42
- }
43
-
44
- const DEFAULT_RELEASE_STAGE = 'unknown'
45
-
46
- // We don't want Bugsnag logs except on warnings/errors.
47
- // We also want to use our own `log` utility, unprefixed.
48
- const logger = { debug() {}, info() {}, warn: log, error: log }
49
-
50
- module.exports = { startErrorMonitor }
@@ -1,86 +0,0 @@
1
- const { cwd } = require('process')
2
-
3
- const cleanStack = require('clean-stack')
4
- const stripAnsi = require('strip-ansi')
5
-
6
- // Clean stack traces:
7
- // - remove our internal code, e.g. the logic spawning plugins
8
- // - remove node modules and Node.js internals
9
- // - strip process.cwd()
10
- // - remove colors
11
- // Keep non stack trace lines as is.
12
- // We do not use libraries that patch `Error.prepareStackTrace()` because they
13
- // tend to create issues.
14
- const cleanStacks = function(string, rawStack) {
15
- // Internal errors / bugs keep their full stack trace
16
- if (rawStack || string === undefined) {
17
- return string
18
- }
19
-
20
- return String(string)
21
- .split('\n')
22
- .reduce(cleanStackLine, '')
23
- .replace(INITIAL_NEWLINES, '')
24
- }
25
-
26
- const cleanStackLine = function(lines, line) {
27
- const lineA = line.replace(getCwd(), '')
28
- const lineB = stripAnsi(lineA)
29
-
30
- if (!STACK_LINE_REGEXP.test(lineB)) {
31
- return `${lines}\n${lineA}`
32
- }
33
-
34
- if (isUselessStack(lineB)) {
35
- return lines
36
- }
37
-
38
- if (isInternalStack(lineB)) {
39
- return lines
40
- }
41
-
42
- const lineC = cleanStack(lineB)
43
-
44
- if (lineC === '') {
45
- return lines
46
- }
47
-
48
- return `${lines}\n${lineC}`
49
- }
50
-
51
- // `process.cwd()` can sometimes fail: directory name too long, current
52
- // directory has been removed, access denied.
53
- const getCwd = function() {
54
- try {
55
- return cwd()
56
- } catch (error) {
57
- return ''
58
- }
59
- }
60
-
61
- // Check if a line is part of a stack trace
62
- const STACK_LINE_REGEXP = /^\s+at /
63
-
64
- const isUselessStack = function(line) {
65
- const lineA = line.replace(BACKLASH_REGEXP, '/')
66
- return (
67
- // Anonymous function
68
- lineA.includes('<anonymous>') ||
69
- // nyc internal code
70
- lineA.includes('node_modules/append-transform') ||
71
- lineA.includes('node_modules/signal-exit')
72
- )
73
- }
74
-
75
- const BACKLASH_REGEXP = /\\/g
76
-
77
- const isInternalStack = function(line) {
78
- // This is only needed for local builds
79
- return INTERNAL_STACK_REGEXP.test(line)
80
- }
81
-
82
- const INTERNAL_STACK_REGEXP = /(packages|@netlify)[/\\]build[/\\](src|node_modules)[/\\]/
83
-
84
- const INITIAL_NEWLINES = /^\n+/
85
-
86
- module.exports = { cleanStacks }
@@ -1,50 +0,0 @@
1
- const { getBuildCommandDescription, getPluginOrigin } = require('../../log/description')
2
-
3
- // Retrieve an error's location to print in logs.
4
- // Each error type has its own logic (or none if there's no location to print).
5
- const getLocationInfo = function({ stack, location, locationType }) {
6
- // No location to print
7
- if (locationType === undefined && stack === undefined) {
8
- return
9
- }
10
-
11
- // The location is only the stack trace
12
- if (locationType === undefined) {
13
- return stack
14
- }
15
-
16
- const locationString = LOCATIONS[locationType](location)
17
- return [locationString, stack].filter(Boolean).join('\n')
18
- }
19
-
20
- const getBuildCommandLocation = function({ buildCommand, configPath }) {
21
- const description = getBuildCommandDescription(configPath)
22
- return `In ${description}:
23
- ${buildCommand}`
24
- }
25
-
26
- const getBuildFailLocation = function({ event, package, loadedFrom, origin }) {
27
- const eventMessage = getEventMessage(event)
28
- const pluginOrigin = getPluginOrigin(loadedFrom, origin)
29
- return `${eventMessage} "${package}" ${pluginOrigin}`
30
- }
31
-
32
- const getEventMessage = function(event) {
33
- if (event === 'load') {
34
- return `While loading`
35
- }
36
-
37
- return `In "${event}" event in`
38
- }
39
-
40
- const getApiLocation = function({ endpoint, parameters }) {
41
- return `While calling the Netlify API endpoint '${endpoint}' with:\n${JSON.stringify(parameters, null, 2)}`
42
- }
43
-
44
- const LOCATIONS = {
45
- buildCommand: getBuildCommandLocation,
46
- buildFail: getBuildFailLocation,
47
- api: getApiLocation,
48
- }
49
-
50
- module.exports = { getLocationInfo }
@@ -1,87 +0,0 @@
1
- const { getErrorInfo } = require('../info')
2
- const { getTypeInfo } = require('../type')
3
-
4
- const { getLocationInfo } = require('./location')
5
- const { getPluginInfo } = require('./plugin')
6
- const { getErrorProps } = require('./properties')
7
- const { getStackInfo } = require('./stack')
8
-
9
- // Parse all error information into a normalized sets of properties
10
- const parseError = function({ error, colors }) {
11
- const {
12
- message,
13
- stack,
14
- netlifyConfig,
15
- childEnv,
16
- errorProps,
17
- errorInfo,
18
- errorInfo: { location = {}, plugin = {} },
19
- state,
20
- title,
21
- isSuccess,
22
- stackType,
23
- locationType,
24
- showErrorProps,
25
- rawStack,
26
- } = parseErrorInfo(error)
27
-
28
- const titleA = getTitle(title, errorInfo)
29
-
30
- const { message: messageA, stack: stackA } = getStackInfo({ message, stack, stackType, rawStack, isSuccess })
31
-
32
- const pluginInfo = getPluginInfo(plugin, location)
33
- const locationInfo = getLocationInfo({ stack: stackA, location, locationType })
34
- const errorPropsA = getErrorProps({ errorProps, showErrorProps, colors })
35
- return {
36
- state,
37
- title: titleA,
38
- message: messageA,
39
- pluginInfo,
40
- locationInfo,
41
- netlifyConfig,
42
- childEnv,
43
- errorProps: errorPropsA,
44
- isSuccess,
45
- }
46
- }
47
-
48
- // Parse error instance into all the basic properties containing information
49
- const parseErrorInfo = function(error) {
50
- const { message, stack, netlifyConfig, childEnv, ...errorProps } = normalizeError(error)
51
- const errorInfo = getErrorInfo(errorProps)
52
- const { state, title, isSuccess, stackType, locationType, showErrorProps, rawStack } = getTypeInfo(errorInfo)
53
- return {
54
- message,
55
- stack,
56
- netlifyConfig,
57
- childEnv,
58
- errorProps,
59
- errorInfo,
60
- state,
61
- title,
62
- isSuccess,
63
- stackType,
64
- locationType,
65
- showErrorProps,
66
- rawStack,
67
- }
68
- }
69
-
70
- const normalizeError = function(error) {
71
- if (error instanceof Error) {
72
- return error
73
- }
74
-
75
- return new Error(String(error))
76
- }
77
-
78
- // Retrieve title to print in logs
79
- const getTitle = function(title, errorInfo) {
80
- if (typeof title !== 'function') {
81
- return title
82
- }
83
-
84
- return title(errorInfo)
85
- }
86
-
87
- module.exports = { parseError }
@@ -1,68 +0,0 @@
1
- // Retrieve plugin's package.json details to include in error messages.
2
- // Please note `packageJson` has been normalized by `normalize-package-data`.
3
- const getPluginInfo = function({ packageJson = {} }, { package }) {
4
- if (Object.keys(packageJson).length === 0) {
5
- return
6
- }
7
-
8
- return Object.entries(FIELDS)
9
- .map(([name, getField]) => serializeField({ name, getField, packageJson, package }))
10
- .filter(Boolean)
11
- .join('\n')
12
- }
13
-
14
- // Serialize a single package.json field
15
- const serializeField = function({ name, getField, packageJson, package }) {
16
- const field = getField(packageJson, package)
17
- if (field === undefined) {
18
- return
19
- }
20
-
21
- const nameA = `${name}:`.padEnd(NAME_PADDING)
22
- return `${nameA}${field}`
23
- }
24
-
25
- const NAME_PADDING = 16
26
-
27
- const getPackage = function(packageJson, package) {
28
- return package
29
- }
30
-
31
- const getVersion = function({ version }) {
32
- if (version === '') {
33
- return
34
- }
35
-
36
- return version
37
- }
38
-
39
- const getHomepage = function(packageJson = {}) {
40
- return getRepository(packageJson) || getNpmLink(packageJson) || getIssuesLink(packageJson)
41
- }
42
-
43
- const getRepository = function({ repository: { url } = {} }) {
44
- return url
45
- }
46
-
47
- const getNpmLink = function({ name }) {
48
- if (!name) {
49
- return
50
- }
51
-
52
- return `https://www.npmjs.com/package/${name}`
53
- }
54
-
55
- const getIssuesLink = function({ bugs: { url } = {} }) {
56
- return url
57
- }
58
-
59
- // List of package.json to serialize
60
- const FIELDS = {
61
- Package: getPackage,
62
- Version: getVersion,
63
- Repository: getRepository,
64
- 'npm link': getNpmLink,
65
- 'Report issues': getIssuesLink,
66
- }
67
-
68
- module.exports = { getPluginInfo, getHomepage }
@@ -1,20 +0,0 @@
1
- const { inspect } = require('util')
2
-
3
- const { omit } = require('../../utils/omit')
4
- const { INFO_SYM } = require('../info')
5
-
6
- // In uncaught exceptions, print error static properties
7
- const getErrorProps = function({ errorProps, showErrorProps, colors }) {
8
- const errorPropsA = omit(errorProps, CLEANED_ERROR_PROPS)
9
-
10
- if (!showErrorProps || Object.keys(errorPropsA).length === 0) {
11
- return
12
- }
13
-
14
- return inspect(errorPropsA, { colors, depth: 5 })
15
- }
16
-
17
- // Remove error static properties that should not be logged
18
- const CLEANED_ERROR_PROPS = [INFO_SYM, 'requireStack']
19
-
20
- module.exports = { getErrorProps }
@@ -1,46 +0,0 @@
1
- const { THEME } = require('../../log/theme')
2
-
3
- const { parseError } = require('./parse')
4
-
5
- // Serialize an error object into a title|body string to print in logs
6
- const serializeLogError = function(error) {
7
- const { title, message, pluginInfo, locationInfo, netlifyConfig, errorProps, isSuccess } = parseError({
8
- error,
9
- colors: true,
10
- })
11
- const body = getBody({ message, pluginInfo, locationInfo, errorProps, isSuccess })
12
- return { title, body, isSuccess, netlifyConfig }
13
- }
14
-
15
- const getBody = function({ message, pluginInfo, locationInfo, errorProps, isSuccess }) {
16
- if (isSuccess) {
17
- return message
18
- }
19
-
20
- return Object.entries({
21
- message,
22
- pluginInfo,
23
- locationInfo,
24
- errorProps,
25
- })
26
- .filter(blockHasValue)
27
- .map(serializeBlock)
28
- .join('\n\n')
29
- }
30
-
31
- const blockHasValue = function([, value]) {
32
- return value !== undefined
33
- }
34
-
35
- const serializeBlock = function([key, value]) {
36
- return `${THEME.errorSubHeader(LOG_BLOCK_NAMES[key])}\n${value}`
37
- }
38
-
39
- const LOG_BLOCK_NAMES = {
40
- message: 'Error message',
41
- pluginInfo: 'Plugin details',
42
- locationInfo: 'Error location',
43
- errorProps: 'Error properties',
44
- }
45
-
46
- module.exports = { serializeLogError }
@@ -1,28 +0,0 @@
1
- const { parseError } = require('./parse')
2
-
3
- // Serialize an error object to `statuses` properties
4
- const serializeErrorStatus = function(error) {
5
- const { state, title, message, locationInfo, errorProps } = parseError({ error, colors: false })
6
- const text = getText({ locationInfo, errorProps })
7
- return { state, title, summary: message, text }
8
- }
9
-
10
- const getText = function({ locationInfo, errorProps }) {
11
- const parts = [locationInfo, getErrorProps(errorProps)].filter(Boolean)
12
-
13
- if (parts.length === 0) {
14
- return
15
- }
16
-
17
- return parts.join('\n\n')
18
- }
19
-
20
- const getErrorProps = function(errorProps) {
21
- if (errorProps === undefined) {
22
- return
23
- }
24
-
25
- return `Error properties:\n${errorProps}`
26
- }
27
-
28
- module.exports = { serializeErrorStatus }
@@ -1,45 +0,0 @@
1
- const { cleanStacks } = require('./clean_stack')
2
-
3
- // Retrieve the stack trace
4
- const getStackInfo = function({ message, stack, stackType, rawStack, isSuccess }) {
5
- const { message: messageA, stack: stackA } = splitStackInfo({ message, stack, stackType })
6
- const messageB = isSuccess ? messageA.replace(SUCCESS_ERROR_NAME, '') : messageA
7
- const stackB = cleanStacks(stackA, rawStack)
8
- return { message: messageB, stack: stackB }
9
- }
10
-
11
- const splitStackInfo = function({ message, stack, stackType }) {
12
- // Some errors should not show any stack trace
13
- if (stackType === 'none') {
14
- return { message }
15
- }
16
-
17
- // Some errors have their stack trace inside `error.message` instead of
18
- // `error.stack` due to IPC
19
- if (stackType === 'message') {
20
- return splitStack(message)
21
- }
22
-
23
- return splitStack(stack)
24
- }
25
-
26
- const splitStack = function(string) {
27
- const lines = string.split('\n')
28
- const stackIndex = lines.findIndex(isStackTrace)
29
-
30
- if (stackIndex === -1) {
31
- return { message: string }
32
- }
33
-
34
- const messageA = lines.slice(0, stackIndex).join('\n')
35
- const stackA = lines.slice(stackIndex).join('\n')
36
- return { message: messageA, stack: stackA }
37
- }
38
-
39
- const isStackTrace = function(line) {
40
- return line.trim().startsWith('at ')
41
- }
42
-
43
- const SUCCESS_ERROR_NAME = 'Error: '
44
-
45
- module.exports = { getStackInfo }
@@ -1,13 +0,0 @@
1
- const {
2
- env: { NETLIFY_BUILD_DEBUG_PROCESS_ERRORS },
3
- } = require('process')
4
-
5
- const logProcessErrors = require('log-process-errors')
6
-
7
- const { hasColors } = require('../log/colors')
8
-
9
- // Print stack traces of warnings.
10
- // This is for debugging purpose only, so behind an environment variable.
11
- if (NETLIFY_BUILD_DEBUG_PROCESS_ERRORS === '1') {
12
- logProcessErrors({ colors: hasColors() })
13
- }