@netlify/build 28.0.1-beta → 28.1.0-framework-version-detection

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 (259) hide show
  1. package/bin.js +5 -0
  2. package/lib/core/bin.js +66 -0
  3. package/lib/core/build.js +355 -0
  4. package/lib/core/config.js +125 -0
  5. package/lib/core/constants.js +116 -0
  6. package/lib/core/dev.js +27 -0
  7. package/lib/core/dry.js +21 -0
  8. package/lib/core/feature_flags.js +19 -0
  9. package/lib/core/flags.js +201 -0
  10. package/lib/core/lingering.js +68 -0
  11. package/lib/core/main.js +105 -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/type.js +171 -0
  41. package/lib/install/functions.js +20 -0
  42. package/lib/install/local.js +45 -0
  43. package/lib/install/main.js +67 -0
  44. package/lib/install/missing.js +54 -0
  45. package/{src → lib}/log/colors.js +15 -22
  46. package/lib/log/description.js +21 -0
  47. package/lib/log/header.js +14 -0
  48. package/lib/log/header_func.js +13 -0
  49. package/lib/log/logger.js +140 -0
  50. package/lib/log/messages/compatibility.js +120 -0
  51. package/lib/log/messages/config.js +98 -0
  52. package/lib/log/messages/core.js +50 -0
  53. package/lib/log/messages/core_steps.js +75 -0
  54. package/lib/log/messages/dry.js +41 -0
  55. package/lib/log/messages/install.js +25 -0
  56. package/lib/log/messages/ipc.js +29 -0
  57. package/lib/log/messages/mutations.js +62 -0
  58. package/{src → lib}/log/messages/plugins.js +18 -32
  59. package/lib/log/messages/status.js +14 -0
  60. package/lib/log/messages/steps.js +18 -0
  61. package/lib/log/old_version.js +32 -0
  62. package/lib/log/serialize.js +10 -0
  63. package/lib/log/stream.js +68 -0
  64. package/lib/log/theme.js +25 -0
  65. package/lib/plugins/child/diff.js +46 -0
  66. package/lib/plugins/child/error.js +26 -0
  67. package/lib/plugins/child/lazy.js +15 -0
  68. package/lib/plugins/child/load.js +22 -0
  69. package/lib/plugins/child/logic.js +57 -0
  70. package/lib/plugins/child/main.js +37 -0
  71. package/lib/plugins/child/run.js +19 -0
  72. package/lib/plugins/child/status.js +63 -0
  73. package/lib/plugins/child/typescript.js +28 -0
  74. package/lib/plugins/child/utils.js +42 -0
  75. package/lib/plugins/child/validate.js +31 -0
  76. package/lib/plugins/compatibility.js +104 -0
  77. package/{src → lib}/plugins/error.js +31 -35
  78. package/{src → lib}/plugins/events.js +7 -12
  79. package/lib/plugins/expected_version.js +81 -0
  80. package/lib/plugins/ipc.js +120 -0
  81. package/lib/plugins/list.js +73 -0
  82. package/lib/plugins/load.js +50 -0
  83. package/lib/plugins/manifest/check.js +85 -0
  84. package/lib/plugins/manifest/load.js +38 -0
  85. package/lib/plugins/manifest/main.js +17 -0
  86. package/lib/plugins/manifest/path.js +24 -0
  87. package/lib/plugins/manifest/validate.js +91 -0
  88. package/lib/plugins/node_version.js +30 -0
  89. package/lib/plugins/options.js +55 -0
  90. package/lib/plugins/pinned_version.js +83 -0
  91. package/lib/plugins/resolve.js +110 -0
  92. package/lib/plugins/spawn.js +54 -0
  93. package/lib/plugins_core/add.js +35 -0
  94. package/lib/plugins_core/build_command.js +50 -0
  95. package/lib/plugins_core/deploy/buildbot_client.js +87 -0
  96. package/lib/plugins_core/deploy/index.js +49 -0
  97. package/{src → lib}/plugins_core/deploy/manifest.yml +0 -0
  98. package/lib/plugins_core/edge_functions/index.js +79 -0
  99. package/lib/plugins_core/edge_functions/lib/error.js +17 -0
  100. package/lib/plugins_core/edge_functions/lib/internal_manifest.js +50 -0
  101. package/lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +75 -0
  102. package/lib/plugins_core/functions/error.js +123 -0
  103. package/lib/plugins_core/functions/feature_flags.js +6 -0
  104. package/lib/plugins_core/functions/index.js +114 -0
  105. package/lib/plugins_core/functions/utils.js +45 -0
  106. package/lib/plugins_core/functions/zisi.js +39 -0
  107. package/{src → lib}/plugins_core/functions_install/index.js +8 -11
  108. package/{src → lib}/plugins_core/functions_install/manifest.yml +0 -0
  109. package/lib/plugins_core/list.js +20 -0
  110. package/lib/status/add.js +30 -0
  111. package/lib/status/colors.js +18 -0
  112. package/lib/status/load_error.js +10 -0
  113. package/lib/status/report.js +83 -0
  114. package/lib/status/success.js +14 -0
  115. package/lib/steps/core_step.js +57 -0
  116. package/lib/steps/error.js +65 -0
  117. package/lib/steps/get.js +43 -0
  118. package/lib/steps/plugin.js +55 -0
  119. package/lib/steps/return.js +25 -0
  120. package/lib/steps/run_core_steps.js +126 -0
  121. package/lib/steps/run_step.js +188 -0
  122. package/lib/steps/run_steps.js +96 -0
  123. package/lib/steps/update_config.js +66 -0
  124. package/lib/telemetry/main.js +97 -0
  125. package/lib/time/aggregate.js +120 -0
  126. package/lib/time/main.js +37 -0
  127. package/lib/time/measure.js +18 -0
  128. package/lib/time/report.js +47 -0
  129. package/lib/utils/errors.js +13 -0
  130. package/lib/utils/json.js +15 -0
  131. package/{src → lib}/utils/omit.js +3 -4
  132. package/lib/utils/package.js +22 -0
  133. package/lib/utils/remove_falsy.js +8 -0
  134. package/lib/utils/resolve.js +41 -0
  135. package/lib/utils/runtime.js +5 -0
  136. package/lib/utils/semver.js +28 -0
  137. package/package.json +39 -19
  138. package/types/config/netlify_config.d.ts +4 -4
  139. package/types/netlify_plugin_constants.d.ts +8 -8
  140. package/src/core/bin.js +0 -83
  141. package/src/core/config.js +0 -186
  142. package/src/core/constants.js +0 -156
  143. package/src/core/dry.js +0 -39
  144. package/src/core/feature_flags.js +0 -21
  145. package/src/core/flags.js +0 -194
  146. package/src/core/lingering.js +0 -85
  147. package/src/core/main.js +0 -692
  148. package/src/core/missing_side_file.js +0 -29
  149. package/src/core/normalize_flags.js +0 -69
  150. package/src/core/severity.js +0 -22
  151. package/src/core/user_node_version.js +0 -41
  152. package/src/env/changes.js +0 -52
  153. package/src/env/main.js +0 -19
  154. package/src/env/metadata.js +0 -81
  155. package/src/error/api.js +0 -46
  156. package/src/error/build.js +0 -50
  157. package/src/error/colors.js +0 -11
  158. package/src/error/handle.js +0 -57
  159. package/src/error/info.js +0 -46
  160. package/src/error/monitor/location.js +0 -21
  161. package/src/error/monitor/normalize.js +0 -77
  162. package/src/error/monitor/print.js +0 -42
  163. package/src/error/monitor/report.js +0 -133
  164. package/src/error/monitor/start.js +0 -69
  165. package/src/error/parse/clean_stack.js +0 -87
  166. package/src/error/parse/location.js +0 -58
  167. package/src/error/parse/normalize.js +0 -29
  168. package/src/error/parse/parse.js +0 -97
  169. package/src/error/parse/plugin.js +0 -70
  170. package/src/error/parse/properties.js +0 -23
  171. package/src/error/parse/serialize_log.js +0 -42
  172. package/src/error/parse/serialize_status.js +0 -23
  173. package/src/error/parse/stack.js +0 -43
  174. package/src/error/type.js +0 -182
  175. package/src/install/functions.js +0 -28
  176. package/src/install/local.js +0 -62
  177. package/src/install/main.js +0 -81
  178. package/src/install/missing.js +0 -67
  179. package/src/log/description.js +0 -26
  180. package/src/log/header.js +0 -16
  181. package/src/log/header_func.js +0 -17
  182. package/src/log/logger.js +0 -107
  183. package/src/log/messages/compatibility.js +0 -164
  184. package/src/log/messages/config.js +0 -105
  185. package/src/log/messages/core.js +0 -70
  186. package/src/log/messages/core_steps.js +0 -104
  187. package/src/log/messages/dry.js +0 -63
  188. package/src/log/messages/install.js +0 -20
  189. package/src/log/messages/ipc.js +0 -38
  190. package/src/log/messages/mutations.js +0 -82
  191. package/src/log/messages/status.js +0 -16
  192. package/src/log/messages/steps.js +0 -22
  193. package/src/log/old_version.js +0 -41
  194. package/src/log/serialize.js +0 -13
  195. package/src/log/stream.js +0 -85
  196. package/src/log/theme.js +0 -26
  197. package/src/plugins/child/diff.js +0 -55
  198. package/src/plugins/child/error.js +0 -32
  199. package/src/plugins/child/lazy.js +0 -18
  200. package/src/plugins/child/load.js +0 -29
  201. package/src/plugins/child/logic.js +0 -57
  202. package/src/plugins/child/main.js +0 -51
  203. package/src/plugins/child/run.js +0 -28
  204. package/src/plugins/child/status.js +0 -67
  205. package/src/plugins/child/typescript.js +0 -45
  206. package/src/plugins/child/utils.js +0 -56
  207. package/src/plugins/child/validate.js +0 -34
  208. package/src/plugins/compatibility.js +0 -128
  209. package/src/plugins/expected_version.js +0 -119
  210. package/src/plugins/ipc.js +0 -145
  211. package/src/plugins/list.js +0 -86
  212. package/src/plugins/load.js +0 -70
  213. package/src/plugins/manifest/check.js +0 -106
  214. package/src/plugins/manifest/load.js +0 -41
  215. package/src/plugins/manifest/main.js +0 -22
  216. package/src/plugins/manifest/path.js +0 -31
  217. package/src/plugins/manifest/validate.js +0 -108
  218. package/src/plugins/node_version.js +0 -50
  219. package/src/plugins/options.js +0 -88
  220. package/src/plugins/pinned_version.js +0 -131
  221. package/src/plugins/resolve.js +0 -152
  222. package/src/plugins/spawn.js +0 -66
  223. package/src/plugins_core/add.js +0 -49
  224. package/src/plugins_core/build_command.js +0 -75
  225. package/src/plugins_core/deploy/buildbot_client.js +0 -102
  226. package/src/plugins_core/deploy/index.js +0 -73
  227. package/src/plugins_core/edge_functions/index.js +0 -107
  228. package/src/plugins_core/edge_functions/lib/internal_manifest.js +0 -54
  229. package/src/plugins_core/functions/error.js +0 -163
  230. package/src/plugins_core/functions/feature_flags.js +0 -6
  231. package/src/plugins_core/functions/index.js +0 -160
  232. package/src/plugins_core/functions/utils.js +0 -66
  233. package/src/plugins_core/functions/zisi.js +0 -53
  234. package/src/plugins_core/list.js +0 -27
  235. package/src/status/add.js +0 -36
  236. package/src/status/colors.js +0 -23
  237. package/src/status/load_error.js +0 -11
  238. package/src/status/report.js +0 -128
  239. package/src/status/success.js +0 -18
  240. package/src/steps/core_step.js +0 -90
  241. package/src/steps/error.js +0 -102
  242. package/src/steps/get.js +0 -32
  243. package/src/steps/plugin.js +0 -85
  244. package/src/steps/return.js +0 -52
  245. package/src/steps/run_core_steps.js +0 -194
  246. package/src/steps/run_step.js +0 -300
  247. package/src/steps/run_steps.js +0 -179
  248. package/src/steps/update_config.js +0 -93
  249. package/src/telemetry/main.js +0 -136
  250. package/src/time/aggregate.js +0 -146
  251. package/src/time/main.js +0 -48
  252. package/src/time/measure.js +0 -22
  253. package/src/time/report.js +0 -59
  254. package/src/utils/errors.js +0 -12
  255. package/src/utils/json.js +0 -19
  256. package/src/utils/package.js +0 -23
  257. package/src/utils/remove_falsy.js +0 -10
  258. package/src/utils/resolve.js +0 -46
  259. package/src/utils/semver.js +0 -34
@@ -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,67 +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 } = removeEmptyStrings(showArgs)
10
- runState.status = { state: 'success', title, summary, text }
11
- }
12
-
13
- // Validate arguments of `utils.status.show()`
14
- const validateShowArgs = function (showArgs) {
15
- try {
16
- validateShowArgsObject(showArgs)
17
- const { title, summary, text, ...otherArgs } = showArgs
18
- validateShowArgsKeys(otherArgs)
19
- Object.entries({ title, summary, text }).forEach(validateStringArg)
20
- validateShowArgsSummary(summary)
21
- } catch (error) {
22
- error.message = `utils.status.show() ${error.message}`
23
- addErrorInfo(error, { type: 'pluginValidation' })
24
- throw error
25
- }
26
- }
27
-
28
- const validateShowArgsObject = function (showArgs) {
29
- if (showArgs === undefined) {
30
- throw new Error('requires an argument')
31
- }
32
-
33
- if (!isPlainObj(showArgs)) {
34
- throw new Error('argument must be a plain object')
35
- }
36
- }
37
-
38
- const validateShowArgsKeys = function (otherArgs) {
39
- const otherKeys = Object.keys(otherArgs).map((arg) => `"${arg}"`)
40
- if (otherKeys.length !== 0) {
41
- throw new Error(`must only contain "title", "summary" or "text" properties, not ${otherKeys.join(', ')}`)
42
- }
43
- }
44
-
45
- const validateStringArg = function ([key, value]) {
46
- if (value !== undefined && typeof value !== 'string') {
47
- throw new Error(`"${key}" property must be a string`)
48
- }
49
- }
50
-
51
- const validateShowArgsSummary = function (summary) {
52
- if (summary === undefined || summary.trim() === '') {
53
- throw new Error('requires specifying a "summary" property')
54
- }
55
- }
56
-
57
- const removeEmptyStrings = function (showArgs) {
58
- return mapObj(showArgs, removeEmptyString)
59
- }
60
-
61
- const removeEmptyString = function (key, value) {
62
- if (typeof value === 'string' && value.trim() === '') {
63
- return [key]
64
- }
65
-
66
- return [key, value]
67
- }
@@ -1,45 +0,0 @@
1
- import { extname } from 'path'
2
-
3
- import { register } from 'ts-node'
4
-
5
- import { addErrorInfo } from '../../error/info.js'
6
-
7
- // Allow local plugins to be written with TypeScript.
8
- // Local plugins cannot be transpiled by the build command since they can be run
9
- // before it. Therefore, we type-check and transpile them automatically using
10
- // `ts-node`.
11
- export const registerTypeScript = function (pluginPath) {
12
- if (!isTypeScriptPlugin(pluginPath)) {
13
- return
14
- }
15
-
16
- return register()
17
- }
18
-
19
- // On TypeScript errors, adds information about the `ts-node` configuration,
20
- // which includes the resolved `tsconfig.json`.
21
- export const addTsErrorInfo = function (error, tsNodeService) {
22
- if (tsNodeService === undefined) {
23
- return
24
- }
25
-
26
- const {
27
- config: {
28
- raw: { compilerOptions },
29
- },
30
- options: realTsNodeOptions,
31
- } = tsNodeService
32
-
33
- // filter out functions as they cannot be serialized
34
- const tsNodeOptions = Object.fromEntries(
35
- Object.entries(realTsNodeOptions).filter(([, val]) => typeof val !== 'function'),
36
- )
37
-
38
- addErrorInfo(error, { tsConfig: { compilerOptions, tsNodeOptions } })
39
- }
40
-
41
- const isTypeScriptPlugin = function (pluginPath) {
42
- return TYPESCRIPT_EXTENSIONS.has(extname(pluginPath))
43
- }
44
-
45
- const TYPESCRIPT_EXTENSIONS = new Set(['.ts', '.tsx', '.mts', '.cts'])
@@ -1,56 +0,0 @@
1
- import { bindOpts as cacheBindOpts } from '@netlify/cache-utils'
2
- import { add as functionsAdd, list as functionsList, listAll as functionsListAll } from '@netlify/functions-utils'
3
- import { getGitUtils } from '@netlify/git-utils'
4
- import { run, runCommand } from '@netlify/run-utils'
5
-
6
- import { failBuild, failPlugin, cancelBuild, failPluginWithWarning } from '../error.js'
7
- import { isSoftFailEvent } from '../events.js'
8
-
9
- import { addLazyProp } from './lazy.js'
10
- import { show } from './status.js'
11
-
12
- // Retrieve the `utils` argument.
13
- export const getUtils = function ({
14
- event,
15
- constants: { FUNCTIONS_SRC, INTERNAL_FUNCTIONS_SRC, CACHE_DIR },
16
- runState,
17
- }) {
18
- // eslint-disable-next-line fp/no-mutation
19
- run.command = runCommand
20
-
21
- const build = getBuildUtils(event)
22
- const cache = getCacheUtils(CACHE_DIR)
23
- const functions = getFunctionsUtils(FUNCTIONS_SRC, INTERNAL_FUNCTIONS_SRC)
24
- const status = getStatusUtils(runState)
25
- const utils = { build, cache, run, functions, status }
26
- addLazyProp(utils, 'git', () => getGitUtils())
27
- return utils
28
- }
29
-
30
- const getBuildUtils = function (event) {
31
- if (isSoftFailEvent(event)) {
32
- return {
33
- failPlugin,
34
- failBuild: failPluginWithWarning.bind(null, 'failBuild', event),
35
- cancelBuild: failPluginWithWarning.bind(null, 'cancelBuild', event),
36
- }
37
- }
38
-
39
- return { failBuild, failPlugin, cancelBuild }
40
- }
41
-
42
- const getCacheUtils = function (CACHE_DIR) {
43
- return cacheBindOpts({ cacheDir: CACHE_DIR })
44
- }
45
-
46
- const getFunctionsUtils = function (FUNCTIONS_SRC, INTERNAL_FUNCTIONS_SRC) {
47
- const functionsDirectories = [INTERNAL_FUNCTIONS_SRC, FUNCTIONS_SRC].filter(Boolean)
48
- const add = (src) => functionsAdd(src, INTERNAL_FUNCTIONS_SRC, { fail: failBuild })
49
- const list = functionsList.bind(null, functionsDirectories, { fail: failBuild })
50
- const listAll = functionsListAll.bind(null, functionsDirectories, { fail: failBuild })
51
- return { add, list, listAll }
52
- }
53
-
54
- const getStatusUtils = function (runState) {
55
- return { show: show.bind(undefined, runState) }
56
- }
@@ -1,34 +0,0 @@
1
- import { addErrorInfo } from '../../error/info.js'
2
- import { serializeArray } from '../../log/serialize.js'
3
- import { EVENTS } from '../events.js'
4
-
5
- // Validate the shape of a plugin return value
6
- export const validatePlugin = function (logic) {
7
- try {
8
- // This validation must work with the return value of `import()` which has
9
- // a `Module` prototype, not `Object`
10
- if (typeof logic !== 'object' || logic === null) {
11
- throw new Error('Plugin must be an object or a function')
12
- }
13
-
14
- Object.entries(logic).forEach(([propName, value]) => {
15
- validateEventHandler(value, propName)
16
- })
17
- } catch (error) {
18
- addErrorInfo(error, { type: 'pluginValidation' })
19
- throw error
20
- }
21
- }
22
-
23
- // All other properties are event handlers
24
- const validateEventHandler = function (value, propName) {
25
- if (!EVENTS.includes(propName)) {
26
- throw new Error(`Invalid event '${propName}'.
27
- Please use a valid event name. One of:
28
- ${serializeArray(EVENTS)}`)
29
- }
30
-
31
- if (typeof value !== 'function') {
32
- throw new TypeError(`Invalid event handler '${propName}': must be a function`)
33
- }
34
- }