@netlify/build 29.0.1-rc → 29.0.2

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 (266) hide show
  1. package/bin.js +5 -0
  2. package/lib/core/bin.js +66 -0
  3. package/lib/core/build.js +356 -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 +21 -0
  9. package/lib/core/flags.js +201 -0
  10. package/lib/core/lingering.js +68 -0
  11. package/lib/core/main.js +110 -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 +21 -0
  15. package/lib/core/types.js +8 -0
  16. package/lib/core/user_node_version.js +32 -0
  17. package/lib/env/changes.js +43 -0
  18. package/lib/env/main.js +14 -0
  19. package/lib/env/metadata.js +68 -0
  20. package/lib/error/api.js +37 -0
  21. package/lib/error/build.js +36 -0
  22. package/{src → lib}/error/cancel.js +5 -6
  23. package/lib/error/colors.js +9 -0
  24. package/lib/error/handle.js +46 -0
  25. package/lib/error/info.js +37 -0
  26. package/lib/error/monitor/location.js +16 -0
  27. package/lib/error/monitor/normalize.js +86 -0
  28. package/lib/error/monitor/print.js +20 -0
  29. package/lib/error/monitor/report.js +120 -0
  30. package/lib/error/monitor/start.js +61 -0
  31. package/lib/error/parse/clean_stack.js +70 -0
  32. package/lib/error/parse/location.js +50 -0
  33. package/lib/error/parse/normalize.js +24 -0
  34. package/lib/error/parse/parse.js +67 -0
  35. package/lib/error/parse/plugin.js +55 -0
  36. package/lib/error/parse/properties.js +16 -0
  37. package/lib/error/parse/serialize_log.js +34 -0
  38. package/lib/error/parse/serialize_status.js +18 -0
  39. package/lib/error/parse/stack.js +34 -0
  40. package/lib/error/report.js +27 -0
  41. package/lib/error/type.js +177 -0
  42. package/lib/install/functions.js +20 -0
  43. package/lib/install/local.js +45 -0
  44. package/lib/install/main.js +67 -0
  45. package/lib/install/missing.js +54 -0
  46. package/lib/log/colors.js +28 -0
  47. package/lib/log/description.js +21 -0
  48. package/lib/log/header.js +14 -0
  49. package/lib/log/header_func.js +13 -0
  50. package/lib/log/logger.js +140 -0
  51. package/lib/log/messages/compatibility.js +146 -0
  52. package/lib/log/messages/config.js +91 -0
  53. package/lib/log/messages/core.js +51 -0
  54. package/lib/log/messages/core_steps.js +75 -0
  55. package/lib/log/messages/dry.js +41 -0
  56. package/lib/log/messages/install.js +25 -0
  57. package/lib/log/messages/ipc.js +29 -0
  58. package/lib/log/messages/mutations.js +62 -0
  59. package/{src → lib}/log/messages/plugins.js +18 -32
  60. package/lib/log/messages/status.js +14 -0
  61. package/lib/log/messages/steps.js +18 -0
  62. package/lib/log/old_version.js +32 -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/{src → lib}/plugins/error.js +31 -35
  79. package/{src → lib}/plugins/events.js +7 -12
  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 +58 -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/{src → lib}/plugins_core/deploy/manifest.yml +0 -0
  100. package/lib/plugins_core/edge_functions/index.js +76 -0
  101. package/{src → lib}/plugins_core/edge_functions/lib/error.js +13 -17
  102. package/lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +21 -0
  103. package/lib/plugins_core/functions/error.js +123 -0
  104. package/lib/plugins_core/functions/feature_flags.js +6 -0
  105. package/lib/plugins_core/functions/index.js +114 -0
  106. package/lib/plugins_core/functions/utils.js +45 -0
  107. package/lib/plugins_core/functions/zisi.js +39 -0
  108. package/{src → lib}/plugins_core/functions_install/index.js +8 -11
  109. package/{src → lib}/plugins_core/functions_install/manifest.yml +0 -0
  110. package/lib/plugins_core/list.js +20 -0
  111. package/lib/report/statsd.js +31 -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 +59 -0
  118. package/lib/steps/error.js +65 -0
  119. package/lib/steps/get.js +43 -0
  120. package/lib/steps/plugin.js +55 -0
  121. package/lib/steps/return.js +25 -0
  122. package/lib/steps/run_core_steps.js +117 -0
  123. package/lib/steps/run_step.js +190 -0
  124. package/lib/steps/run_steps.js +96 -0
  125. package/lib/steps/update_config.js +66 -0
  126. package/lib/telemetry/main.js +97 -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 +24 -0
  131. package/lib/utils/errors.js +13 -0
  132. package/lib/utils/json.js +15 -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 +41 -24
  140. package/types/config/netlify_config.d.ts +4 -4
  141. package/types/netlify_plugin_constants.d.ts +8 -8
  142. package/src/core/bin.js +0 -83
  143. package/src/core/build.js +0 -554
  144. package/src/core/config.js +0 -186
  145. package/src/core/constants.js +0 -156
  146. package/src/core/dev.js +0 -31
  147. package/src/core/dry.js +0 -39
  148. package/src/core/feature_flags.js +0 -22
  149. package/src/core/flags.js +0 -204
  150. package/src/core/lingering.js +0 -85
  151. package/src/core/main.js +0 -165
  152. package/src/core/missing_side_file.js +0 -29
  153. package/src/core/normalize_flags.js +0 -70
  154. package/src/core/severity.js +0 -22
  155. package/src/core/user_node_version.js +0 -41
  156. package/src/env/changes.js +0 -52
  157. package/src/env/main.js +0 -19
  158. package/src/env/metadata.js +0 -81
  159. package/src/error/api.js +0 -46
  160. package/src/error/build.js +0 -50
  161. package/src/error/colors.js +0 -11
  162. package/src/error/handle.js +0 -57
  163. package/src/error/info.js +0 -46
  164. package/src/error/monitor/location.js +0 -21
  165. package/src/error/monitor/normalize.js +0 -96
  166. package/src/error/monitor/print.js +0 -42
  167. package/src/error/monitor/report.js +0 -138
  168. package/src/error/monitor/start.js +0 -69
  169. package/src/error/parse/clean_stack.js +0 -87
  170. package/src/error/parse/location.js +0 -62
  171. package/src/error/parse/normalize.js +0 -29
  172. package/src/error/parse/parse.js +0 -97
  173. package/src/error/parse/plugin.js +0 -70
  174. package/src/error/parse/properties.js +0 -23
  175. package/src/error/parse/serialize_log.js +0 -42
  176. package/src/error/parse/serialize_status.js +0 -23
  177. package/src/error/parse/stack.js +0 -43
  178. package/src/error/type.js +0 -189
  179. package/src/install/functions.js +0 -28
  180. package/src/install/local.js +0 -62
  181. package/src/install/main.js +0 -81
  182. package/src/install/missing.js +0 -67
  183. package/src/log/colors.js +0 -34
  184. package/src/log/description.js +0 -26
  185. package/src/log/header.js +0 -16
  186. package/src/log/header_func.js +0 -17
  187. package/src/log/logger.js +0 -161
  188. package/src/log/messages/compatibility.js +0 -164
  189. package/src/log/messages/config.js +0 -107
  190. package/src/log/messages/core.js +0 -70
  191. package/src/log/messages/core_steps.js +0 -104
  192. package/src/log/messages/dry.js +0 -63
  193. package/src/log/messages/install.js +0 -20
  194. package/src/log/messages/ipc.js +0 -38
  195. package/src/log/messages/mutations.js +0 -82
  196. package/src/log/messages/status.js +0 -16
  197. package/src/log/messages/steps.js +0 -22
  198. package/src/log/old_version.js +0 -41
  199. package/src/log/serialize.js +0 -13
  200. package/src/log/stream.js +0 -85
  201. package/src/log/theme.js +0 -26
  202. package/src/plugins/child/diff.js +0 -55
  203. package/src/plugins/child/error.js +0 -32
  204. package/src/plugins/child/lazy.js +0 -18
  205. package/src/plugins/child/load.js +0 -29
  206. package/src/plugins/child/logic.js +0 -57
  207. package/src/plugins/child/main.js +0 -51
  208. package/src/plugins/child/run.js +0 -28
  209. package/src/plugins/child/status.js +0 -74
  210. package/src/plugins/child/typescript.js +0 -45
  211. package/src/plugins/child/utils.js +0 -56
  212. package/src/plugins/child/validate.js +0 -34
  213. package/src/plugins/compatibility.js +0 -128
  214. package/src/plugins/expected_version.js +0 -119
  215. package/src/plugins/ipc.js +0 -145
  216. package/src/plugins/list.js +0 -86
  217. package/src/plugins/load.js +0 -70
  218. package/src/plugins/manifest/check.js +0 -106
  219. package/src/plugins/manifest/load.js +0 -41
  220. package/src/plugins/manifest/main.js +0 -22
  221. package/src/plugins/manifest/path.js +0 -31
  222. package/src/plugins/manifest/validate.js +0 -108
  223. package/src/plugins/node_version.js +0 -50
  224. package/src/plugins/options.js +0 -88
  225. package/src/plugins/pinned_version.js +0 -131
  226. package/src/plugins/resolve.js +0 -152
  227. package/src/plugins/spawn.js +0 -66
  228. package/src/plugins_core/add.js +0 -49
  229. package/src/plugins_core/build_command.js +0 -75
  230. package/src/plugins_core/deploy/buildbot_client.js +0 -102
  231. package/src/plugins_core/deploy/index.js +0 -73
  232. package/src/plugins_core/edge_functions/index.js +0 -123
  233. package/src/plugins_core/edge_functions/lib/internal_manifest.js +0 -54
  234. package/src/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +0 -89
  235. package/src/plugins_core/functions/error.js +0 -163
  236. package/src/plugins_core/functions/feature_flags.js +0 -6
  237. package/src/plugins_core/functions/index.js +0 -160
  238. package/src/plugins_core/functions/utils.js +0 -66
  239. package/src/plugins_core/functions/zisi.js +0 -53
  240. package/src/plugins_core/list.js +0 -27
  241. package/src/status/add.js +0 -36
  242. package/src/status/colors.js +0 -23
  243. package/src/status/load_error.js +0 -11
  244. package/src/status/report.js +0 -137
  245. package/src/status/success.js +0 -18
  246. package/src/steps/core_step.js +0 -92
  247. package/src/steps/error.js +0 -102
  248. package/src/steps/get.js +0 -51
  249. package/src/steps/plugin.js +0 -85
  250. package/src/steps/return.js +0 -52
  251. package/src/steps/run_core_steps.js +0 -200
  252. package/src/steps/run_step.js +0 -304
  253. package/src/steps/run_steps.js +0 -179
  254. package/src/steps/update_config.js +0 -93
  255. package/src/telemetry/main.js +0 -136
  256. package/src/time/aggregate.js +0 -146
  257. package/src/time/main.js +0 -48
  258. package/src/time/measure.js +0 -22
  259. package/src/time/report.js +0 -59
  260. package/src/utils/errors.js +0 -12
  261. package/src/utils/json.js +0 -19
  262. package/src/utils/omit.js +0 -6
  263. package/src/utils/package.js +0 -23
  264. package/src/utils/remove_falsy.js +0 -10
  265. package/src/utils/resolve.js +0 -46
  266. package/src/utils/semver.js +0 -34
@@ -1,38 +0,0 @@
1
- import { log } from '../logger.js'
2
-
3
- const logVerbose = function (logs, verbose, message) {
4
- if (!verbose) {
5
- return
6
- }
7
-
8
- log(logs, message)
9
- }
10
-
11
- export const logSendingEventToChild = function (logs, verbose) {
12
- logVerbose(logs, verbose, 'Step starting.')
13
- }
14
-
15
- export const logSentEventToChild = function (logs, verbose) {
16
- logVerbose(logs, verbose, 'Step started.')
17
- }
18
-
19
- export const logPluginMethodStart = function (verbose) {
20
- logVerbose(undefined, verbose, 'Plugin logic started.')
21
- }
22
-
23
- export const logPluginMethodEnd = function (verbose) {
24
- logVerbose(undefined, verbose, 'Plugin logic ended.')
25
- }
26
-
27
- export const logSendingEventToParent = function (verbose, error) {
28
- const message = error instanceof Error ? `Step erroring.\n${error.stack}` : 'Stop closing.'
29
- logVerbose(undefined, verbose, message)
30
- }
31
-
32
- export const logReceivedEventFromChild = function (logs, verbose) {
33
- logVerbose(logs, verbose, 'Step ended.')
34
- }
35
-
36
- export const logStepCompleted = function (logs, verbose) {
37
- logVerbose(logs, verbose, 'Step completed.')
38
- }
@@ -1,82 +0,0 @@
1
- import { promises as fs } from 'fs'
2
- import { inspect } from 'util'
3
-
4
- import { pathExists } from 'path-exists'
5
-
6
- import { log, logMessage, logSubHeader } from '../logger.js'
7
-
8
- export const logConfigMutations = function (logs, newConfigMutations, debug) {
9
- const configMutationsToLog = debug ? newConfigMutations : newConfigMutations.filter(shouldLogConfigMutation)
10
- configMutationsToLog.forEach(({ keysString, value }) => {
11
- logConfigMutation(logs, keysString, value)
12
- })
13
- }
14
-
15
- // Some configuration mutations are only logged in debug mode
16
- const shouldLogConfigMutation = function ({ keysString }) {
17
- return !HIDDEN_PROPS.some((hiddenProp) => keysString.startsWith(hiddenProp))
18
- }
19
-
20
- // `functions` is an object which can have thousands of properties, one per
21
- // function file. This can be very verbose, especially for plugins which create
22
- // many function files like Essential Next.js
23
- const HIDDEN_PROPS = ['functions']
24
-
25
- const logConfigMutation = function (logs, keysString, value) {
26
- const newValue = shouldHideConfigValue(keysString) ? '' : ` to ${inspect(value, { colors: false })}`
27
- log(logs, `Netlify configuration property "${keysString}" value changed${newValue}.`)
28
- }
29
-
30
- const shouldHideConfigValue = function (keysString) {
31
- return SECRET_PROPS.some((secretProp) => keysString.startsWith(secretProp))
32
- }
33
-
34
- const SECRET_PROPS = ['build.environment']
35
-
36
- export const logConfigOnUpload = async function ({ logs, configPath, debug }) {
37
- if (!debug) {
38
- return
39
- }
40
-
41
- logSubHeader(logs, 'Uploaded config')
42
-
43
- if (!(await pathExists(configPath))) {
44
- logMessage(logs, 'No netlify.toml')
45
- return
46
- }
47
-
48
- const configContents = await fs.readFile(configPath, 'utf8')
49
- logMessage(logs, configContents.trim())
50
- }
51
-
52
- export const logHeadersOnUpload = async function ({ logs, headersPath, debug }) {
53
- if (!debug) {
54
- return
55
- }
56
-
57
- logSubHeader(logs, 'Uploaded headers')
58
-
59
- if (!(await pathExists(headersPath))) {
60
- logMessage(logs, 'No headers')
61
- return
62
- }
63
-
64
- const headersContents = await fs.readFile(headersPath, 'utf8')
65
- logMessage(logs, headersContents.trim())
66
- }
67
-
68
- export const logRedirectsOnUpload = async function ({ logs, redirectsPath, debug }) {
69
- if (!debug) {
70
- return
71
- }
72
-
73
- logSubHeader(logs, 'Uploaded redirects')
74
-
75
- if (!(await pathExists(redirectsPath))) {
76
- logMessage(logs, 'No redirects\n')
77
- return
78
- }
79
-
80
- const redirectsContents = await fs.readFile(redirectsPath, 'utf8')
81
- logMessage(logs, `${redirectsContents.trim()}\n`)
82
- }
@@ -1,16 +0,0 @@
1
- import { logMessage, logHeader, logSubHeader } from '../logger.js'
2
- import { THEME } from '../theme.js'
3
-
4
- export const logStatuses = function (logs, statuses) {
5
- logHeader(logs, 'Summary')
6
- statuses.forEach((status) => {
7
- logStatus(logs, status)
8
- })
9
- }
10
-
11
- const logStatus = function (logs, { packageName, title = `Plugin ${packageName} ran successfully`, summary, text }) {
12
- const titleA = title.includes(packageName) ? title : `${packageName}: ${title}`
13
- const body = text === undefined ? summary : `${summary}\n${THEME.dimWords(text)}`
14
- logSubHeader(logs, titleA)
15
- logMessage(logs, body)
16
- }
@@ -1,22 +0,0 @@
1
- import { getLogHeaderFunc } from '../header_func.js'
2
- import { log, logMessage } from '../logger.js'
3
- import { THEME } from '../theme.js'
4
-
5
- export const logStepStart = function ({ logs, event, packageName, coreStepDescription, index, error, netlifyConfig }) {
6
- const description = getDescription({ coreStepDescription, netlifyConfig, packageName, event })
7
- const logHeaderFunc = getLogHeaderFunc(error)
8
- logHeaderFunc(logs, `${index + 1}. ${description}`)
9
- logMessage(logs, '')
10
- }
11
-
12
- const getDescription = function ({ coreStepDescription, netlifyConfig, packageName, event }) {
13
- return coreStepDescription === undefined ? `${packageName} (${event} event)` : coreStepDescription({ netlifyConfig })
14
- }
15
-
16
- export const logBuildCommandStart = function (logs, buildCommand) {
17
- log(logs, THEME.highlightWords(`$ ${buildCommand}`))
18
- }
19
-
20
- export const logStepSuccess = function (logs) {
21
- logMessage(logs, '')
22
- }
@@ -1,41 +0,0 @@
1
- import { stdout } from 'process'
2
-
3
- import UpdateNotifier from 'update-notifier'
4
-
5
- import { ROOT_PACKAGE_JSON } from '../utils/json.js'
6
-
7
- // Many build errors happen in local builds that do not use the latest version
8
- // of `@netlify/build`. We print a warning message on those.
9
- // We only print this when Netlify CLI has been used. Programmatic usage might
10
- // come from a deep dependency calling `@netlify/build` and user might not be
11
- // able to take any upgrade action, making the message noisy.
12
- export const logOldCliVersionError = function ({ mode, testOpts }) {
13
- if (mode !== 'cli') {
14
- return
15
- }
16
-
17
- const corePackageJson = getCorePackageJson(testOpts)
18
- UpdateNotifier({ pkg: corePackageJson, updateCheckInterval: 1 }).notify({
19
- message: OLD_VERSION_MESSAGE,
20
- shouldNotifyInNpmScript: true,
21
- })
22
- }
23
-
24
- const getCorePackageJson = function (testOpts) {
25
- // TODO: Find a way to test this without injecting code in the `src/`
26
- if (testOpts.oldCliLogs) {
27
- // `update-notifier` does not do anything if not in a TTY.
28
- // In tests, we need to monkey patch this
29
- // Mutation is required due to how `stdout.isTTY` works
30
- // eslint-disable-next-line fp/no-mutation
31
- stdout.isTTY = true
32
-
33
- return { ...ROOT_PACKAGE_JSON, version: '0.0.1' }
34
- }
35
-
36
- return ROOT_PACKAGE_JSON
37
- }
38
-
39
- const OLD_VERSION_MESSAGE = `Please update netlify-cli to its latest version.
40
- If netlify-cli is already the latest version,
41
- please update your dependencies lock file instead.`
@@ -1,13 +0,0 @@
1
- import { dump } from 'js-yaml'
2
-
3
- export const serializeObject = function (object) {
4
- return dump(object, { noRefs: true, sortKeys: true, lineWidth: Number.POSITIVE_INFINITY }).trimEnd()
5
- }
6
-
7
- export const serializeArray = function (array) {
8
- return array.map(addDash).join('\n')
9
- }
10
-
11
- const addDash = function (string) {
12
- return ` - ${string}`
13
- }
package/src/log/stream.js DELETED
@@ -1,85 +0,0 @@
1
- import { stdout, stderr } from 'process'
2
- import { promisify } from 'util'
3
-
4
- // TODO: replace with `timers/promises` after dropping Node < 15.0.0
5
- const pSetTimeout = promisify(setTimeout)
6
-
7
- // We try to use `stdio: inherit` because it keeps `stdout/stderr` as `TTY`,
8
- // which solves many problems. However we can only do it in build.command.
9
- // Plugins have several events, so need to be switch on and off instead.
10
- // In buffer mode (`logs` not `undefined`), `pipe` is necessary.
11
- export const getBuildCommandStdio = function (logs) {
12
- if (logs !== undefined) {
13
- return 'pipe'
14
- }
15
-
16
- return 'inherit'
17
- }
18
-
19
- // Add build command output
20
- export const handleBuildCommandOutput = function ({ stdout: commandStdout, stderr: commandStderr }, logs) {
21
- if (logs === undefined) {
22
- return
23
- }
24
-
25
- pushBuildCommandOutput(commandStdout, logs.stdout)
26
- pushBuildCommandOutput(commandStderr, logs.stderr)
27
- }
28
-
29
- const pushBuildCommandOutput = function (output, logsArray) {
30
- if (output === '') {
31
- return
32
- }
33
-
34
- logsArray.push(output)
35
- }
36
-
37
- // Start plugin step output
38
- export const pipePluginOutput = function (childProcess, logs) {
39
- if (logs === undefined) {
40
- return streamOutput(childProcess)
41
- }
42
-
43
- return pushOutputToLogs(childProcess, logs)
44
- }
45
-
46
- // Stop streaming/buffering plugin step output
47
- export const unpipePluginOutput = async function (childProcess, logs, listeners) {
48
- // Let `childProcess` `stdout` and `stderr` flush before stopping redirecting
49
- await pSetTimeout(0)
50
-
51
- if (logs === undefined) {
52
- return unstreamOutput(childProcess)
53
- }
54
-
55
- unpushOutputToLogs(childProcess, logs, listeners)
56
- }
57
-
58
- // Usually, we stream stdout/stderr because it is more efficient
59
- const streamOutput = function (childProcess) {
60
- childProcess.stdout.pipe(stdout)
61
- childProcess.stderr.pipe(stderr)
62
- }
63
-
64
- const unstreamOutput = function (childProcess) {
65
- childProcess.stdout.unpipe(stdout)
66
- childProcess.stderr.unpipe(stderr)
67
- }
68
-
69
- // In tests, we push to the `logs` array instead
70
- const pushOutputToLogs = function (childProcess, logs) {
71
- const stdoutListener = logsListener.bind(null, logs.stdout)
72
- const stderrListener = logsListener.bind(null, logs.stderr)
73
- childProcess.stdout.on('data', stdoutListener)
74
- childProcess.stderr.on('data', stderrListener)
75
- return { stdoutListener, stderrListener }
76
- }
77
-
78
- const logsListener = function (logs, chunk) {
79
- logs.push(chunk.toString().trimEnd())
80
- }
81
-
82
- const unpushOutputToLogs = function (childProcess, logs, { stdoutListener, stderrListener }) {
83
- childProcess.stdout.removeListener('data', stdoutListener)
84
- childProcess.stderr.removeListener('data', stderrListener)
85
- }
package/src/log/theme.js DELETED
@@ -1,26 +0,0 @@
1
- import chalk from 'chalk'
2
-
3
- // Color theme. Please use this instead of requiring chalk directly, to ensure
4
- // consistent colors.
5
- export const THEME = {
6
- // Main headers
7
- header: chalk.cyanBright.bold,
8
- // Single lines used as subheaders
9
- subHeader: chalk.cyan.bold,
10
- // One of several words that should be highlighted inside a line
11
- highlightWords: chalk.cyan,
12
- // Same for errors
13
- errorHeader: chalk.redBright.bold,
14
- errorSubHeader: chalk.red.bold,
15
- errorLine: chalk.redBright,
16
- errorHighlightWords: chalk.redBright.bold,
17
- // Same for warnings
18
- warningHeader: chalk.yellowBright.bold,
19
- warningSubHeader: chalk.yellow.bold,
20
- warningLine: chalk.yellowBright,
21
- warningHighlightWords: chalk.yellowBright.bold,
22
- // One of several words that should be dimmed inside a line
23
- dimWords: chalk.gray,
24
- // No colors
25
- none: (string) => string,
26
- }
@@ -1,55 +0,0 @@
1
- import { isDeepStrictEqual } from 'util'
2
-
3
- import isPlainObj from 'is-plain-obj'
4
- import rfdc from 'rfdc'
5
-
6
- const clone = rfdc()
7
-
8
- // Copy `netlifyConfig` so we can compare before/after mutating it
9
- export const cloneNetlifyConfig = function (netlifyConfig) {
10
- return clone(netlifyConfig)
11
- }
12
-
13
- // Diff `netlifyConfig` before and after mutating it to retrieve an array of
14
- // `configMutations` objects.
15
- // We need to keep track of the changes on `netlifyConfig` so they can be
16
- // processed later to:
17
- // - Warn plugin authors when mutating read-only properties
18
- // - Apply the change to `netlifyConfig` in the parent process so it can
19
- // run `@netlify/config` to normalize and validate the new values
20
- // `configMutations` is passed to parent process as JSON
21
- export const getConfigMutations = function (netlifyConfig, netlifyConfigCopy, event) {
22
- const configMutations = diffObjects(netlifyConfig, netlifyConfigCopy, [])
23
- return configMutations.map((configMutation) => getConfigMutation(configMutation, event))
24
- }
25
-
26
- // We only recurse over plain objects, not arrays. Which means array properties
27
- // can only be modified all at once.
28
- const diffObjects = function (objA, objB, parentKeys) {
29
- const allKeys = [...new Set([...Object.keys(objA), ...Object.keys(objB)])]
30
- return allKeys.flatMap((key) => {
31
- const valueA = objA[key]
32
- const valueB = objB[key]
33
- const keys = [...parentKeys, key]
34
-
35
- if (isPlainObj(valueA) && isPlainObj(valueB)) {
36
- return diffObjects(valueA, valueB, keys)
37
- }
38
-
39
- if (isDeepStrictEqual(valueA, valueB)) {
40
- return []
41
- }
42
-
43
- return [{ keys, value: valueB }]
44
- })
45
- }
46
-
47
- const getConfigMutation = function ({ keys, value }, event) {
48
- const serializedKeys = keys.map(String)
49
- return {
50
- keys: serializedKeys,
51
- keysString: serializedKeys.join('.'),
52
- value,
53
- event,
54
- }
55
- }
@@ -1,32 +0,0 @@
1
- import logProcessErrors from 'log-process-errors'
2
-
3
- import { errorToJson } from '../../error/build.js'
4
- import { addDefaultErrorInfo, isBuildError } from '../../error/info.js'
5
- import { normalizeError } from '../../error/parse/normalize.js'
6
- import { sendEventToParent } from '../ipc.js'
7
-
8
- // Handle any top-level error and communicate it back to parent
9
- export const handleError = async function (error, verbose) {
10
- const errorA = normalizeError(error)
11
- addDefaultErrorInfo(errorA, { type: 'pluginInternal' })
12
- const errorPayload = errorToJson(errorA)
13
- await sendEventToParent('error', errorPayload, verbose, errorA)
14
- }
15
-
16
- // On uncaught exceptions and unhandled rejections, print the stack trace.
17
- // Also, prevent child processes from crashing on uncaught exceptions.
18
- export const handleProcessErrors = function () {
19
- logProcessErrors({ log: handleProcessError, exitOn: [] })
20
- }
21
-
22
- const handleProcessError = async function (error, level, originalError) {
23
- if (level !== 'error') {
24
- console[level](error)
25
- return
26
- }
27
-
28
- // Do not use log-process-errors prettification with errors thrown by `utils.build.*`
29
- const errorA = isBuildError(originalError) ? originalError : error
30
-
31
- await handleError(errorA)
32
- }
@@ -1,18 +0,0 @@
1
- import memoizeOne from 'memoize-one'
2
-
3
- // Add a `object[propName]` whose value is the return value of `getFunc()`, but
4
- // is only retrieved when accessed.
5
- export const addLazyProp = function (object, propName, getFunc) {
6
- const mGetFunc = memoizeOne(getFunc, returnTrue)
7
- // Mutation is required due to the usage of `Object.defineProperty()`
8
- // eslint-disable-next-line fp/no-mutating-methods
9
- Object.defineProperty(object, propName, {
10
- get: mGetFunc,
11
- enumerable: true,
12
- configurable: true,
13
- })
14
- }
15
-
16
- const returnTrue = function () {
17
- return true
18
- }
@@ -1,29 +0,0 @@
1
- import filterObj from 'filter-obj'
2
-
3
- import { getLogic } from './logic.js'
4
- import { registerTypeScript } from './typescript.js'
5
- import { validatePlugin } from './validate.js'
6
-
7
- // Load context passed to every plugin method.
8
- // This also requires the plugin file and fire its top-level function.
9
- // This also validates the plugin.
10
- // Do it when parent requests it using the `load` event.
11
- // Also figure out the list of plugin steps. This is also passed to the parent.
12
- export const load = async function ({ pluginPath, inputs, packageJson, verbose }) {
13
- const tsNodeService = registerTypeScript(pluginPath)
14
- const logic = await getLogic({ pluginPath, inputs, tsNodeService })
15
-
16
- validatePlugin(logic)
17
-
18
- const methods = filterObj(logic, isEventHandler)
19
- const events = Object.keys(methods)
20
-
21
- // Context passed to every event handler
22
- const context = { methods, inputs, packageJson, verbose }
23
-
24
- return { events, context }
25
- }
26
-
27
- const isEventHandler = function (event, value) {
28
- return typeof value === 'function'
29
- }
@@ -1,57 +0,0 @@
1
- import { createRequire } from 'module'
2
- import { pathToFileURL } from 'url'
3
-
4
- import { addTsErrorInfo } from './typescript.js'
5
-
6
- const require = createRequire(import.meta.url)
7
-
8
- // Require the plugin file and fire its top-level function.
9
- // The returned object is the `logic` which includes all event handlers.
10
- export const getLogic = async function ({ pluginPath, inputs, tsNodeService }) {
11
- const logic = await importLogic(pluginPath, tsNodeService)
12
- const logicA = loadLogic({ logic, inputs })
13
- return logicA
14
- }
15
-
16
- const importLogic = async function (pluginPath, tsNodeService) {
17
- try {
18
- // `ts-node` is not available programmatically for pure ES modules yet,
19
- // which is currently making it impossible for local plugins to use both
20
- // pure ES modules and TypeScript.
21
- if (tsNodeService !== undefined) {
22
- // eslint-disable-next-line import/no-dynamic-require
23
- return require(pluginPath)
24
- }
25
-
26
- // `pluginPath` is an absolute file path but `import()` needs URLs.
27
- // Converting those with `pathToFileURL()` is needed especially on Windows
28
- // where the drive letter would not work with `import()`.
29
- const returnValue = await import(pathToFileURL(pluginPath))
30
- // Plugins should use named exports, but we still support default exports
31
- // for backward compatibility with CommonJS
32
- return returnValue.default === undefined ? returnValue : returnValue.default
33
- } catch (error) {
34
- addTsErrorInfo(error, tsNodeService)
35
- // We must change `error.stack` instead of `error.message` because some
36
- // errors thrown from `import()` access `error.stack` before throwing.
37
- // `error.stack` is lazily instantiated by Node.js, so changing
38
- // `error.message` afterwards would not modify `error.stack`. Therefore, the
39
- // resulting stack trace, which is printed in the build logs, would not
40
- // include the additional message prefix.
41
- error.stack = `Could not import plugin:\n${error.stack}`
42
- throw error
43
- }
44
- }
45
-
46
- const loadLogic = function ({ logic, inputs }) {
47
- if (typeof logic !== 'function') {
48
- return logic
49
- }
50
-
51
- try {
52
- return logic(inputs)
53
- } catch (error) {
54
- error.message = `Could not load plugin:\n${error.message}`
55
- throw error
56
- }
57
- }
@@ -1,51 +0,0 @@
1
- import { setInspectColors } from '../../log/colors.js'
2
- import { sendEventToParent, getEventsFromParent } from '../ipc.js'
3
-
4
- import { handleProcessErrors, handleError } from './error.js'
5
- import { load } from './load.js'
6
- import { run } from './run.js'
7
-
8
- // Boot plugin child process.
9
- const bootPlugin = async function () {
10
- const state = { context: { verbose: false } }
11
-
12
- try {
13
- handleProcessErrors()
14
- setInspectColors()
15
-
16
- // We need to fire them in parallel because `process.send()` can be slow
17
- // to await, i.e. parent might send `load` event before child `ready` event
18
- // returns.
19
- await Promise.all([handleEvents(state), sendEventToParent('ready', {}, false)])
20
- } catch (error) {
21
- await handleError(error, state.context.verbose)
22
- }
23
- }
24
-
25
- // Wait for events from parent to perform plugin methods
26
- const handleEvents = async function (state) {
27
- await getEventsFromParent((callId, eventName, payload) => handleEvent({ callId, eventName, payload, state }))
28
- }
29
-
30
- // Each event can pass `context` information to the next event
31
- const handleEvent = async function ({
32
- callId,
33
- eventName,
34
- payload,
35
- state,
36
- state: {
37
- context: { verbose },
38
- },
39
- }) {
40
- try {
41
- const { context, ...response } = await EVENTS[eventName](payload, state.context)
42
- state.context = { ...state.context, ...context }
43
- await sendEventToParent(callId, response, verbose)
44
- } catch (error) {
45
- await handleError(error, verbose)
46
- }
47
- }
48
-
49
- const EVENTS = { load, run }
50
-
51
- bootPlugin()
@@ -1,28 +0,0 @@
1
- import { getNewEnvChanges, setEnvChanges } from '../../env/changes.js'
2
- import { logPluginMethodStart, logPluginMethodEnd } from '../../log/messages/ipc.js'
3
-
4
- import { cloneNetlifyConfig, getConfigMutations } from './diff.js'
5
- import { getUtils } from './utils.js'
6
-
7
- // Run a specific plugin event handler
8
- export const run = async function (
9
- { event, error, constants, envChanges, netlifyConfig },
10
- { methods, inputs, packageJson, verbose },
11
- ) {
12
- const method = methods[event]
13
- const runState = {}
14
- const utils = getUtils({ event, constants, runState })
15
- const netlifyConfigCopy = cloneNetlifyConfig(netlifyConfig)
16
- const runOptions = { utils, constants, inputs, netlifyConfig: netlifyConfigCopy, packageJson, error }
17
-
18
- const envBefore = setEnvChanges(envChanges)
19
-
20
- logPluginMethodStart(verbose)
21
- await method(runOptions)
22
- logPluginMethodEnd(verbose)
23
-
24
- const newEnvChanges = getNewEnvChanges(envBefore, netlifyConfig, netlifyConfigCopy)
25
-
26
- const configMutations = getConfigMutations(netlifyConfig, netlifyConfigCopy, event)
27
- return { ...runState, newEnvChanges, configMutations }
28
- }
@@ -1,74 +0,0 @@
1
- import isPlainObj from 'is-plain-obj'
2
- import mapObj from 'map-obj'
3
-
4
- import { addErrorInfo } from '../../error/info.js'
5
-
6
- // Report status information to the UI
7
- export const show = function (runState, showArgs) {
8
- validateShowArgs(showArgs)
9
- const { title, summary, text, extraData } = removeEmptyStrings(showArgs)
10
- runState.status = { state: 'success', title, summary, text, extraData }
11
- }
12
-
13
- // Validate arguments of `utils.status.show()`
14
- const validateShowArgs = function (showArgs) {
15
- try {
16
- validateShowArgsObject(showArgs)
17
- const { title, summary, text, extraData, ...otherArgs } = showArgs
18
- validateShowArgsKeys(otherArgs)
19
- Object.entries({ title, summary, text }).forEach(validateStringArg)
20
- validateShowArgsSummary(summary)
21
- validateShowArgsExtraData(extraData)
22
- } catch (error) {
23
- error.message = `utils.status.show() ${error.message}`
24
- addErrorInfo(error, { type: 'pluginValidation' })
25
- throw error
26
- }
27
- }
28
-
29
- const validateShowArgsObject = function (showArgs) {
30
- if (showArgs === undefined) {
31
- throw new Error('requires an argument')
32
- }
33
-
34
- if (!isPlainObj(showArgs)) {
35
- throw new Error('argument must be a plain object')
36
- }
37
- }
38
-
39
- const validateShowArgsKeys = function (otherArgs) {
40
- const otherKeys = Object.keys(otherArgs).map((arg) => `"${arg}"`)
41
- if (otherKeys.length !== 0) {
42
- throw new Error(`must only contain "title", "summary" or "text" properties, not ${otherKeys.join(', ')}`)
43
- }
44
- }
45
-
46
- const validateStringArg = function ([key, value]) {
47
- if (value !== undefined && typeof value !== 'string') {
48
- throw new Error(`"${key}" property must be a string`)
49
- }
50
- }
51
-
52
- const validateShowArgsSummary = function (summary) {
53
- if (summary === undefined || summary.trim() === '') {
54
- throw new Error('requires specifying a "summary" property')
55
- }
56
- }
57
-
58
- const validateShowArgsExtraData = function (extraData) {
59
- if (extraData !== undefined && Array.isArray(extraData) === false) {
60
- throw new TypeError('provided extra data must be an array')
61
- }
62
- }
63
-
64
- const removeEmptyStrings = function (showArgs) {
65
- return mapObj(showArgs, removeEmptyString)
66
- }
67
-
68
- const removeEmptyString = function (key, value) {
69
- if (typeof value === 'string' && value.trim() === '') {
70
- return [key]
71
- }
72
-
73
- return [key, value]
74
- }