@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/log/main.js DELETED
@@ -1,348 +0,0 @@
1
- const {
2
- env: { NETLIFY_BUILD_DEBUG },
3
- } = require('process')
4
-
5
- const { arrowDown } = require('figures')
6
- const filterObj = require('filter-obj')
7
- const prettyMs = require('pretty-ms')
8
-
9
- const { name, version } = require('../../package.json')
10
- const { serializeLogError } = require('../error/parse/serialize_log')
11
- const { omit } = require('../utils/omit')
12
- const { removeFalsy } = require('../utils/remove_falsy')
13
-
14
- const { getCommandDescription, getBuildCommandDescription, getPluginOrigin } = require('./description')
15
- const {
16
- log,
17
- logMessage,
18
- logObject,
19
- logArray,
20
- logHeader,
21
- logErrorHeader,
22
- logSubHeader,
23
- logErrorSubHeader,
24
- } = require('./logger')
25
- const { THEME } = require('./theme')
26
-
27
- const logBuildStart = function() {
28
- logHeader('Netlify Build')
29
- logSubHeader('Version')
30
- logMessage(`${name} ${version}`)
31
- }
32
-
33
- const logFlags = function(flags) {
34
- const hiddenFlags = flags.mode === 'buildbot' ? [...HIDDEN_FLAGS, 'nodePath'] : HIDDEN_FLAGS
35
- const flagsA = omit(flags, hiddenFlags)
36
- logSubHeader('Flags')
37
- logObject(flagsA)
38
- }
39
-
40
- const HIDDEN_FLAGS = ['token', 'cachedConfig', 'defaultConfig']
41
-
42
- const logBuildDir = function(buildDir) {
43
- logSubHeader('Current directory')
44
- logMessage(buildDir)
45
- }
46
-
47
- const logConfigPath = function(configPath = NO_CONFIG_MESSAGE) {
48
- logSubHeader('Config file')
49
- logMessage(configPath)
50
- }
51
-
52
- const NO_CONFIG_MESSAGE = 'No config file was defined: using default values.'
53
-
54
- const logConfig = function(netlifyConfig) {
55
- if (!NETLIFY_BUILD_DEBUG) {
56
- return
57
- }
58
-
59
- logSubHeader('Resolved config')
60
- logObject(simplifyConfig(netlifyConfig))
61
- }
62
-
63
- const logConfigOnError = function(netlifyConfig) {
64
- if (netlifyConfig === undefined) {
65
- return
66
- }
67
-
68
- logMessage(THEME.errorSubHeader('Resolved config'))
69
- logObject(simplifyConfig(keepPublicProperties(netlifyConfig)))
70
- }
71
-
72
- // Make sure we are not printing secret values. Use an allow list.
73
- const keepPublicProperties = function({
74
- build: { base, command, functions, ignore, processing, publish },
75
- headers,
76
- plugins,
77
- redirects,
78
- }) {
79
- const pluginsA = plugins.map(keepPluginPublicProperties)
80
- return {
81
- build: { base, command, functions, ignore, processing, publish },
82
- headers,
83
- plugins: pluginsA,
84
- redirects,
85
- }
86
- }
87
-
88
- const keepPluginPublicProperties = function({ package, origin, inputs }) {
89
- if (inputs === undefined) {
90
- return { package, origin }
91
- }
92
-
93
- const inputsA = filterObj(inputs, isPublicInput)
94
- return { package, origin, inputs: inputsA }
95
- }
96
-
97
- const isPublicInput = function(key, input) {
98
- return typeof input === 'boolean'
99
- }
100
-
101
- // The resolved configuration gets assigned some default values (empty objects and arrays)
102
- // to make it more convenient to use without checking for `undefined`.
103
- // However those empty values are not useful to users, so we don't log them.
104
- const simplifyConfig = function({ build: { environment = {}, ...build }, plugins, ...netlifyConfig }) {
105
- const environmentA = omit(environment, BUILDBOT_ENVIRONMENT)
106
- const simplifiedBuild = removeFalsy({
107
- ...build,
108
- ...removeEmptyObject(environmentA, 'environment'),
109
- })
110
- return removeFalsy({
111
- ...netlifyConfig,
112
- ...removeEmptyObject(simplifiedBuild, 'build'),
113
- ...removeEmptyArray(plugins, 'plugins'),
114
- })
115
- }
116
-
117
- // Added by the buildbot. We only want to print environment variables specified
118
- // by the user.
119
- const BUILDBOT_ENVIRONMENT = [
120
- 'BRANCH',
121
- 'CONTEXT',
122
- 'DEPLOY_PRIME_URL',
123
- 'DEPLOY_URL',
124
- 'GO_VERSION',
125
- 'NETLIFY_IMAGES_CDN_DOMAIN',
126
- 'URL',
127
- ]
128
-
129
- const removeEmptyObject = function(object, propName) {
130
- return Object.keys(object).length === 0 ? {} : { [propName]: object }
131
- }
132
-
133
- const removeEmptyArray = function(array, propName) {
134
- return array.length === 0 ? {} : { [propName]: array }
135
- }
136
-
137
- const logContext = function(context) {
138
- if (context === undefined) {
139
- return
140
- }
141
-
142
- logSubHeader('Context')
143
- logMessage(context)
144
- }
145
-
146
- const logInstallMissingPlugins = function(packages) {
147
- logSubHeader('Installing plugins')
148
- logArray(packages)
149
- }
150
-
151
- const logMissingPluginsWarning = function(packages) {
152
- logErrorSubHeader('Missing plugins')
153
- logMessage(
154
- THEME.errorSubHeader(
155
- `The following plugins should be installed either via the Netlify app or as a "dependency" inside your project's "package.json"`,
156
- ),
157
- )
158
- logArray(packages, { color: THEME.errorSubHeader })
159
- }
160
-
161
- const logInstallLocalPluginsDeps = function(localPluginsOptions) {
162
- const packages = localPluginsOptions.map(getPackage)
163
- logSubHeader('Installing local plugins dependencies')
164
- logArray(packages)
165
- }
166
-
167
- const logDeprecatedLocalInstall = function() {
168
- logErrorSubHeader('Missing plugin')
169
- logMessage(
170
- THEME.errorSubHeader(`Please use the plugin "@netlify/plugin-local-install-core" to install dependencies from the "package.json" inside your local plugins.
171
- Example "netlify.toml":
172
-
173
- [[plugins]]
174
- package = "@netlify/plugin-local-install-core"`),
175
- )
176
- }
177
-
178
- const logInstallFunctionDependencies = function() {
179
- log('Installing functions dependencies')
180
- }
181
-
182
- const logDeprecatedFunctionsInstall = function(functionsSrc) {
183
- logErrorSubHeader('Missing plugin')
184
- logMessage(
185
- THEME.errorSubHeader(`Please use the plugin "@netlify/plugin-functions-install-core" to install dependencies from the "package.json" inside your "${functionsSrc}" directory.
186
- Example "netlify.toml":
187
-
188
- [build]
189
- functions = "${functionsSrc}"
190
-
191
- [[plugins]]
192
- package = "@netlify/plugin-functions-install-core"`),
193
- )
194
- }
195
-
196
- const getPackage = function({ package }) {
197
- return package
198
- }
199
-
200
- const logLoadingPlugins = function(pluginsOptions) {
201
- const loadingPlugins = pluginsOptions.map(getPluginDescription)
202
-
203
- if (loadingPlugins.length === 0) {
204
- return
205
- }
206
-
207
- logSubHeader('Loading plugins')
208
- logArray(loadingPlugins)
209
- }
210
-
211
- const getPluginDescription = function({ package, packageJson: { version }, loadedFrom, origin }) {
212
- const versionA = version === undefined ? '' : `@${version}`
213
- const pluginOrigin = getPluginOrigin(loadedFrom, origin)
214
- return `${THEME.highlightWords(package)}${versionA} ${pluginOrigin}`
215
- }
216
-
217
- const logDryRunStart = function(eventWidth, commandsCount) {
218
- const columnWidth = getDryColumnWidth(eventWidth, commandsCount)
219
- const line = '─'.repeat(columnWidth)
220
- const secondLine = '─'.repeat(columnWidth)
221
-
222
- logSubHeader('Netlify Build Commands')
223
- logMessage(`For more information on build events see the docs https://github.com/netlify/build
224
-
225
- Running \`netlify build\` will execute this build flow
226
-
227
- ${THEME.header(`┌─${line}─┬─${secondLine}─┐
228
- │ ${DRY_HEADER_NAMES[0].padEnd(columnWidth)} │ ${DRY_HEADER_NAMES[1].padEnd(columnWidth)} │
229
- └─${line}─┴─${secondLine}─┘`)}`)
230
- }
231
-
232
- const logDryRunCommand = function({ command: { event, package }, index, configPath, eventWidth, commandsCount }) {
233
- const columnWidth = getDryColumnWidth(eventWidth, commandsCount)
234
- const line = '─'.repeat(columnWidth)
235
- const countText = `${index + 1}. `
236
- const downArrow = commandsCount === index + 1 ? ' ' : ` ${arrowDown}`
237
- const eventWidthA = columnWidth - countText.length - downArrow.length
238
- const fullName = getPluginFullName({ package, configPath })
239
-
240
- logMessage(
241
- `${THEME.header(`┌─${line}─┐`)}
242
- ${THEME.header(`│ ${countText}${event.padEnd(eventWidthA)}${downArrow} │`)} ${fullName}
243
- ${THEME.header(`└─${line}─┘ `)}`,
244
- )
245
- }
246
-
247
- const getPluginFullName = function({ package, configPath }) {
248
- if (package === undefined) {
249
- return getBuildCommandDescription(configPath)
250
- }
251
-
252
- return `Plugin ${THEME.highlightWords(package)}`
253
- }
254
-
255
- const getDryColumnWidth = function(eventWidth, commandsCount) {
256
- const symbolsWidth = `${commandsCount}`.length + 4
257
- return Math.max(eventWidth + symbolsWidth, DRY_HEADER_NAMES[1].length)
258
- }
259
-
260
- const DRY_HEADER_NAMES = ['Event', 'Location']
261
-
262
- const logDryRunEnd = function() {
263
- logMessage(`\nIf this looks good to you, run \`netlify build\` to execute the build\n`)
264
- }
265
-
266
- const logCommand = function({ event, package, index, configPath, error }) {
267
- const description = getCommandDescription({ event, package, configPath })
268
- const logHeaderFunc = error ? logErrorHeader : logHeader
269
- logHeaderFunc(`${index + 1}. ${description}`)
270
- logMessage('')
271
- }
272
-
273
- const logBuildCommandStart = function(buildCommand) {
274
- log(THEME.highlightWords(`$ ${buildCommand}`))
275
- }
276
-
277
- const logCommandSuccess = function() {
278
- logMessage('')
279
- }
280
-
281
- const logTimer = function(durationMs, timerName) {
282
- const duration = prettyMs(durationMs)
283
- log(THEME.dimWords(`(${timerName} completed in ${duration})`))
284
- }
285
-
286
- const logStatuses = function(statuses) {
287
- logHeader('Summary')
288
- statuses.forEach(logStatus)
289
- }
290
-
291
- const logStatus = function({ package, title = `Plugin ${package} ran successfully`, summary, text }) {
292
- const titleA = title.includes(package) ? title : `${package}: ${title}`
293
- const body = text === undefined ? summary : `${summary}\n${THEME.dimWords(text)}`
294
- logSubHeader(titleA)
295
- logMessage(body)
296
- }
297
-
298
- const logCacheDir = function(path) {
299
- logMessage(`Caching ${path}`)
300
- }
301
-
302
- const logPluginError = function(error, netlifyConfig) {
303
- const { title, body } = serializeLogError(error)
304
- logErrorHeader(title)
305
- logMessage(`\n${body}\n`)
306
- logConfigOnError(netlifyConfig)
307
- }
308
-
309
- const logBuildError = function(error) {
310
- const { title, body, isSuccess, netlifyConfig } = serializeLogError(error)
311
- const logFunction = isSuccess ? logHeader : logErrorHeader
312
- logFunction(title)
313
- logMessage(`\n${body}\n`)
314
- logConfigOnError(netlifyConfig)
315
- }
316
-
317
- const logBuildSuccess = function() {
318
- logHeader('Netlify Build Complete')
319
- logMessage('')
320
- }
321
-
322
- module.exports = {
323
- logBuildStart,
324
- logFlags,
325
- logBuildDir,
326
- logConfigPath,
327
- logConfig,
328
- logContext,
329
- logInstallMissingPlugins,
330
- logMissingPluginsWarning,
331
- logInstallLocalPluginsDeps,
332
- logDeprecatedLocalInstall,
333
- logInstallFunctionDependencies,
334
- logDeprecatedFunctionsInstall,
335
- logLoadingPlugins,
336
- logDryRunStart,
337
- logDryRunCommand,
338
- logDryRunEnd,
339
- logCommand,
340
- logBuildCommandStart,
341
- logCommandSuccess,
342
- logTimer,
343
- logStatuses,
344
- logCacheDir,
345
- logPluginError,
346
- logBuildError,
347
- logBuildSuccess,
348
- }
@@ -1,45 +0,0 @@
1
- const {
2
- env: { NETLIFY_BUILD_TEST },
3
- stdout,
4
- } = require('process')
5
-
6
- const readPkgUp = require('read-pkg-up')
7
- const UpdateNotifier = require('update-notifier')
8
-
9
- // Many build errors happen in local builds that do not use the latest version
10
- // of `@netlify/build`. We print a warning message on those.
11
- // We only print this when Netlify CLI has been used. Programmatic usage might
12
- // come from a deep dependency calling `@netlify/build` and user might not be
13
- // able to take any upgrade action, making the message noisy.
14
- const logOldCliVersionError = async function(mode) {
15
- if (mode !== 'cli') {
16
- return
17
- }
18
-
19
- const pkg = await getPkg()
20
- UpdateNotifier({ pkg, updateCheckInterval: 1 }).notify({
21
- message: OLD_VERSION_MESSAGE,
22
- shouldNotifyInNpmScript: true,
23
- })
24
- }
25
-
26
- const getPkg = async function() {
27
- const { packageJson } = await readPkgUp({ cwd: __dirname, normalize: false })
28
-
29
- // TODO: Find a way to test this without injecting code in the `src/`
30
- if (NETLIFY_BUILD_TEST) {
31
- // `update-notifier` does not do anything if not in a TTY.
32
- // In tests, we need to monkey patch this
33
- stdout.isTTY = true
34
-
35
- return { ...packageJson, version: '0.0.1' }
36
- }
37
-
38
- return packageJson
39
- }
40
-
41
- const OLD_VERSION_MESSAGE = `Please update netlify-cli to its latest version.
42
- If netlify-cli is already the latest version,
43
- please update your dependencies lock file instead.`
44
-
45
- module.exports = { logOldCliVersionError }
@@ -1,15 +0,0 @@
1
- const { dump, JSON_SCHEMA } = require('js-yaml')
2
-
3
- const serializeObject = function(object) {
4
- return dump(object, { schema: JSON_SCHEMA, noRefs: true, sortKeys: true, lineWidth: Infinity }).trimRight()
5
- }
6
-
7
- const serializeArray = function(array) {
8
- return array.map(addDash).join('\n')
9
- }
10
-
11
- const addDash = function(string) {
12
- return ` - ${string}`
13
- }
14
-
15
- module.exports = { serializeObject, serializeArray }
package/src/log/stream.js DELETED
@@ -1,15 +0,0 @@
1
- const { stdout, stderr } = require('process')
2
-
3
- // Start streaming Bash command or plugin command output
4
- const pipeOutput = function(childProcess) {
5
- childProcess.stdout.pipe(stdout)
6
- childProcess.stderr.pipe(stderr)
7
- }
8
-
9
- // Stop streaming/buffering Bash command or plugin command output
10
- const unpipeOutput = function(childProcess) {
11
- childProcess.stdout.unpipe(stdout)
12
- childProcess.stderr.unpipe(stderr)
13
- }
14
-
15
- module.exports = { pipeOutput, unpipeOutput }
package/src/log/theme.js DELETED
@@ -1,32 +0,0 @@
1
- const {
2
- cyanBright: { bold: cyanBrightBold },
3
- cyan: { bold: cyanBold },
4
- cyan,
5
- redBright: { bold: redBrightBold },
6
- red: { bold: redBold },
7
- red,
8
- gray,
9
- } = require('chalk')
10
-
11
- // Color theme. Please use this instead of requiring chalk directly, to ensure
12
- // consistent colors.
13
- const THEME = {
14
- // Main headers
15
- header: cyanBrightBold,
16
- // Single lines used as subheaders
17
- subHeader: cyanBold,
18
- // Main headers indicating an error
19
- errorHeader: redBrightBold,
20
- // Single lines used as subheaders indicating an error
21
- errorSubHeader: redBold,
22
- // Non-headers indicating an error
23
- errorLine: red,
24
- // One of several words that should be highlighted inside a line
25
- highlightWords: cyan,
26
- // One of several words that should be dimmed inside a line
27
- dimWords: gray,
28
- // No colors
29
- none: string => string,
30
- }
31
-
32
- module.exports = { THEME }
package/src/log/timer.js DELETED
@@ -1,28 +0,0 @@
1
- const { hrtime } = require('process')
2
-
3
- const { logTimer } = require('./main')
4
-
5
- // Starts a timer
6
- const startTimer = function() {
7
- return hrtime()
8
- }
9
-
10
- // Stops a timer
11
- const endTimerDuration = function([startSecs, startNsecs]) {
12
- const [endSecs, endNsecs] = hrtime()
13
- const durationNs = (endSecs - startSecs) * NANOSECS_TO_SECS + endNsecs - startNsecs
14
- const durationMs = Math.ceil(durationNs / NANOSECS_TO_MSECS)
15
- return durationMs
16
- }
17
-
18
- // Ends a timer and prints the result on console
19
- const endTimer = function(hrTime, timerName) {
20
- const durationMs = endTimerDuration(hrTime)
21
- logTimer(durationMs, timerName)
22
- return durationMs
23
- }
24
-
25
- const NANOSECS_TO_SECS = 1e9
26
- const NANOSECS_TO_MSECS = 1e6
27
-
28
- module.exports = { startTimer, endTimer }
@@ -1,59 +0,0 @@
1
- const {
2
- env: { NETLIFY_BUILD_API_CLIENT },
3
- } = require('process')
4
-
5
- const NetlifyAPI = require('netlify')
6
-
7
- const { failBuild } = require('../error')
8
-
9
- // Retrieve Netlify API client, providing a authentication token was provided
10
- const getApiClient = function({ manifest: { scopes = DEFAULT_SCOPES }, token }) {
11
- // This feature is not currently finished due to lack of API support
12
- // See https://github.com/netlify/build/issues/585
13
- if (NETLIFY_BUILD_API_CLIENT !== '1') {
14
- return
15
- }
16
-
17
- if (!token) {
18
- if (scopes.length !== 0) {
19
- failBuild('This plugin requires a Netlify API authentication token')
20
- }
21
-
22
- return
23
- }
24
-
25
- const api = new NetlifyAPI(token)
26
-
27
- disableApiMethods(api, scopes)
28
-
29
- return api
30
- }
31
-
32
- const DEFAULT_SCOPES = []
33
-
34
- // Redact API methods to scopes
35
- const disableApiMethods = function(api, scopes) {
36
- if (scopes.includes('*')) {
37
- return
38
- }
39
-
40
- API_METHODS.filter(method => !scopes.includes(method)).forEach(method => {
41
- api[method] = disabledApiMethod.bind(null, method)
42
- })
43
- }
44
-
45
- const getApiMethods = function() {
46
- return NetlifyAPI.methods.map(getApiMethod)
47
- }
48
-
49
- const getApiMethod = function({ operationId }) {
50
- return operationId
51
- }
52
-
53
- const API_METHODS = getApiMethods()
54
-
55
- const disabledApiMethod = async function(method) {
56
- failBuild(`This plugin is not authorized to use "api.${method}". Please update the plugin scopes.`)
57
- }
58
-
59
- module.exports = { getApiClient, API_METHODS }
@@ -1,39 +0,0 @@
1
- // eslint-disable-next-line import/order
2
- const logProcessErrors = require('log-process-errors')
3
-
4
- const { hasColors } = require('../../log/colors')
5
- const { isBuildError, ERROR_TYPE_SYM } = require('../error')
6
- const { sendEventToParent } = require('../ipc')
7
-
8
- // Handle any top-level error and communicate it back to parent
9
- const handleError = async function({
10
- name,
11
- message,
12
- stack,
13
- [ERROR_TYPE_SYM]: type = DEFAULT_ERROR_TYPE,
14
- ...errorProps
15
- }) {
16
- await sendEventToParent('error', { name, message, stack, type, errorProps })
17
- }
18
-
19
- const DEFAULT_ERROR_TYPE = 'pluginInternal'
20
-
21
- // On uncaught exceptions and unhandled rejections, print the stack trace.
22
- // Also, prevent child processes from crashing on uncaught exceptions.
23
- const handleProcessErrors = function() {
24
- logProcessErrors({ log: handleProcessError, colors: hasColors(), exitOn: [], level: { multipleResolves: 'silent' } })
25
- }
26
-
27
- const handleProcessError = async function(error, level, originalError) {
28
- if (level !== 'error') {
29
- console[level](error)
30
- return
31
- }
32
-
33
- // Do not use log-process-errors prettification with errors thrown by `utils.build.*`
34
- const errorA = isBuildError(originalError) ? originalError : error
35
-
36
- await handleError(errorA)
37
- }
38
-
39
- module.exports = { handleError, handleProcessErrors }
@@ -1,40 +0,0 @@
1
- const { getApiClient } = require('./api')
2
- const { getLogic } = require('./logic')
3
- const { normalizePlugin } = require('./normalize')
4
- const { validatePlugin } = require('./validate')
5
-
6
- // Load context passed to every plugin method.
7
- // This also requires the plugin file and fire its top-level function.
8
- // This also validates the plugin.
9
- // Do it when parent requests it using the `load` event.
10
- // Also figure out the list of plugin commands. This is also passed to the parent.
11
- const load = function(payload) {
12
- const logic = getLogic(payload)
13
-
14
- validatePlugin(logic)
15
-
16
- const logicA = normalizePlugin(logic)
17
-
18
- const pluginCommands = getPluginCommands(logicA)
19
-
20
- const context = getContext(pluginCommands, payload)
21
- return { pluginCommands, context }
22
- }
23
-
24
- const getPluginCommands = function(logic) {
25
- return Object.entries(logic)
26
- .filter(isEventHandler)
27
- .map(([event, method]) => ({ event, method }))
28
- }
29
-
30
- const isEventHandler = function([, value]) {
31
- return typeof value === 'function'
32
- }
33
-
34
- // Retrieve context passed to every event handler
35
- const getContext = function(pluginCommands, { manifest, inputs, netlifyConfig, constants, utilsData, token }) {
36
- const api = getApiClient({ manifest, token })
37
- return { pluginCommands, api, utilsData, constants, inputs, netlifyConfig }
38
- }
39
-
40
- module.exports = { load }
@@ -1,31 +0,0 @@
1
- // Require the plugin file and fire its top-level function.
2
- // The returned object is the `logic` which includes all event handlers.
3
- const getLogic = function({ pluginPath, inputs }) {
4
- const logic = requireLogic(pluginPath)
5
- const logicA = loadLogic({ logic, inputs })
6
- return logicA
7
- }
8
-
9
- const requireLogic = function(pluginPath) {
10
- try {
11
- return require(pluginPath)
12
- } catch (error) {
13
- error.message = `Could not import plugin:\n${error.message}`
14
- throw error
15
- }
16
- }
17
-
18
- const loadLogic = function({ logic, inputs }) {
19
- if (typeof logic !== 'function') {
20
- return logic
21
- }
22
-
23
- try {
24
- return logic(inputs)
25
- } catch (error) {
26
- error.message = `Could not load plugin:\n${error.message}`
27
- throw error
28
- }
29
- }
30
-
31
- module.exports = { getLogic }