@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,106 +0,0 @@
1
- import { addErrorInfo } from '../../error/info.js'
2
- import { serializeObject } from '../../log/serialize.js'
3
- import { THEME } from '../../log/theme.js'
4
-
5
- // Check that plugin inputs match the validation specified in "manifest.yml"
6
- // Also assign default values
7
- export const checkInputs = function ({
8
- inputs,
9
- manifest: { inputs: rules = [] },
10
- packageName,
11
- pluginPackageJson,
12
- loadedFrom,
13
- origin,
14
- }) {
15
- try {
16
- const inputsA = addDefaults(inputs, rules)
17
- checkRequiredInputs({ inputs: inputsA, rules, packageName, pluginPackageJson, loadedFrom, origin })
18
- checkUnknownInputs({ inputs: inputsA, rules, packageName, pluginPackageJson, loadedFrom, origin })
19
- return inputsA
20
- } catch (error) {
21
- error.message = `${error.message}
22
-
23
- ${THEME.errorSubHeader('Plugin inputs')}
24
- ${serializeObject(inputs)}`
25
- throw error
26
- }
27
- }
28
-
29
- // Add "inputs[*].default"
30
- const addDefaults = function (inputs, rules) {
31
- const defaults = rules.filter(hasDefault).map(getDefault)
32
- return Object.assign({}, ...defaults, inputs)
33
- }
34
-
35
- const hasDefault = function (rule) {
36
- return rule.default !== undefined
37
- }
38
-
39
- const getDefault = function ({ name, default: defaultValue }) {
40
- return { [name]: defaultValue }
41
- }
42
-
43
- // Check "inputs[*].required"
44
- const checkRequiredInputs = function ({ inputs, rules, packageName, pluginPackageJson, loadedFrom, origin }) {
45
- const missingInputs = rules.filter((rule) => isMissingRequired(inputs, rule))
46
- if (missingInputs.length === 0) {
47
- return
48
- }
49
-
50
- const names = missingInputs.map(getName)
51
- const error = new Error(`Required inputs for plugin "${packageName}": ${names.join(', ')}`)
52
- addInputError({ error, name: names[0], packageName, pluginPackageJson, loadedFrom, origin })
53
- throw error
54
- }
55
-
56
- const isMissingRequired = function (inputs, { name, required }) {
57
- return required && inputs[name] === undefined
58
- }
59
-
60
- const getName = function ({ name }) {
61
- return name
62
- }
63
-
64
- // Check each "inputs[*].*" property for a specific input
65
- const checkUnknownInputs = function ({ inputs, rules, packageName, pluginPackageJson, loadedFrom, origin }) {
66
- const knownInputs = rules.map(getName)
67
- const unknownInputs = Object.keys(inputs).filter((name) => !knownInputs.includes(name))
68
- if (unknownInputs.length === 0) {
69
- return
70
- }
71
-
72
- const unknownInputsMessage = getUnknownInputsMessage({ packageName, knownInputs, unknownInputs })
73
- const error = new Error(`${unknownInputsMessage}
74
- Check your plugin configuration to be sure that:
75
- - the input name is spelled correctly
76
- - the input is included in the plugin's available configuration options
77
- - the plugin's input requirements have not changed`)
78
- const [name] = unknownInputs
79
- addInputError({ error, name, packageName, pluginPackageJson, loadedFrom, origin })
80
- throw error
81
- }
82
-
83
- const getUnknownInputsMessage = function ({ packageName, knownInputs, unknownInputs }) {
84
- const unknownInputsStr = unknownInputs.map(quoteWord).join(', ')
85
-
86
- if (knownInputs.length === 0) {
87
- return `Plugin "${packageName}" does not accept any inputs but you specified: ${unknownInputsStr}`
88
- }
89
-
90
- const knownInputsStr = knownInputs.map(quoteWord).join(', ')
91
- return `Unknown inputs for plugin "${packageName}": ${unknownInputsStr}
92
- Plugin inputs should be one of: ${knownInputsStr}`
93
- }
94
-
95
- const quoteWord = function (word) {
96
- return `"${word}"`
97
- }
98
-
99
- // Add error information
100
- const addInputError = function ({ error, name, packageName, pluginPackageJson, loadedFrom, origin }) {
101
- addErrorInfo(error, {
102
- type: 'pluginInput',
103
- plugin: { packageName, pluginPackageJson },
104
- location: { event: 'load', packageName, input: name, loadedFrom, origin },
105
- })
106
- }
@@ -1,41 +0,0 @@
1
- import { promises as fs } from 'fs'
2
-
3
- import { load as loadYaml, JSON_SCHEMA } from 'js-yaml'
4
-
5
- import { addErrorInfo } from '../../error/info.js'
6
-
7
- import { validateManifest } from './validate.js'
8
-
9
- // Load "manifest.yml" using its file path
10
- export const loadManifest = async function ({ manifestPath, packageName, pluginPackageJson, loadedFrom, origin }) {
11
- try {
12
- const rawManifest = await loadRawManifest(manifestPath)
13
- const manifest = await parseManifest(rawManifest)
14
- validateManifest(manifest, rawManifest)
15
- return manifest
16
- } catch (error) {
17
- addErrorInfo(error, {
18
- type: 'pluginValidation',
19
- plugin: { packageName, pluginPackageJson },
20
- location: { event: 'load', packageName, loadedFrom, origin },
21
- })
22
- throw error
23
- }
24
- }
25
-
26
- const loadRawManifest = async function (manifestPath) {
27
- try {
28
- return await fs.readFile(manifestPath, 'utf8')
29
- } catch (error) {
30
- error.message = `Could not load plugin's "manifest.yml"\n${error.message}`
31
- throw error
32
- }
33
- }
34
-
35
- const parseManifest = async function (rawManifest) {
36
- try {
37
- return await loadYaml(rawManifest, { schema: JSON_SCHEMA, json: true })
38
- } catch (error) {
39
- throw new Error(`Could not parse plugin's "manifest.yml"\n${error.message}`)
40
- }
41
- }
@@ -1,22 +0,0 @@
1
- import { addPluginLoadErrorStatus } from '../../status/load_error.js'
2
-
3
- import { checkInputs } from './check.js'
4
- import { loadManifest } from './load.js'
5
- import { getManifestPath } from './path.js'
6
-
7
- // Load plugin's `manifest.yml`
8
- export const useManifest = async function (
9
- { packageName, loadedFrom, origin, inputs },
10
- { pluginDir, packageDir, pluginPackageJson, pluginPackageJson: { version }, debug },
11
- ) {
12
- const manifestPath = await getManifestPath({ pluginDir, packageDir, packageName })
13
-
14
- try {
15
- const manifest = await loadManifest({ manifestPath, packageName, pluginPackageJson, loadedFrom, origin })
16
- const inputsA = checkInputs({ inputs, manifest, packageName, pluginPackageJson, loadedFrom, origin })
17
- return { manifest, inputs: inputsA }
18
- } catch (error) {
19
- addPluginLoadErrorStatus({ error, packageName, version, debug })
20
- throw error
21
- }
22
- }
@@ -1,31 +0,0 @@
1
- import { locatePath } from 'locate-path'
2
-
3
- import { addErrorInfo } from '../../error/info.js'
4
-
5
- // Retrieve "manifest.yml" path for a specific plugin
6
- export const getManifestPath = async function ({ pluginDir, packageDir, packageName }) {
7
- const dirs = [pluginDir, packageDir]
8
- .filter(Boolean)
9
- .flatMap((dir) => MANIFEST_FILENAMES.map((filename) => `${dir}/${filename}`))
10
- const manifestPath = await locatePath(dirs)
11
- validateManifestExists(manifestPath, packageName)
12
- return manifestPath
13
- }
14
-
15
- const validateManifestExists = function (manifestPath, packageName) {
16
- if (manifestPath !== undefined) {
17
- return
18
- }
19
-
20
- const error = new Error(
21
- `The plugin "${packageName}" is missing a "manifest.yml".
22
- This might mean:
23
- - The plugin "package" name is misspelled
24
- - The plugin "package" points to a Node module that is not a Netlify Build plugin
25
- - If you're developing a plugin, please see the documentation at https://docs.netlify.com/configure-builds/build-plugins/create-plugins/#anatomy-of-a-plugin`,
26
- )
27
- addErrorInfo(error, { type: 'resolveConfig' })
28
- throw error
29
- }
30
-
31
- const MANIFEST_FILENAMES = ['manifest.yml', 'manifest.yaml']
@@ -1,108 +0,0 @@
1
- import isPlainObj from 'is-plain-obj'
2
-
3
- import { THEME } from '../../log/theme.js'
4
-
5
- // Validate `manifest.yml` syntax
6
- export const validateManifest = function (manifest, rawManifest) {
7
- try {
8
- validateBasic(manifest)
9
- validateUnknownProps(manifest)
10
- validateName(manifest)
11
- validateInputs(manifest)
12
- } catch (error) {
13
- error.message = `Plugin's "manifest.yml" ${error.message}
14
-
15
- ${THEME.errorSubHeader('manifest.yml')}
16
- ${rawManifest.trim()}`
17
- throw error
18
- }
19
- }
20
-
21
- const validateBasic = function (manifest) {
22
- if (!isPlainObj(manifest)) {
23
- throw new Error('must be a plain object')
24
- }
25
- }
26
-
27
- const validateUnknownProps = function (manifest) {
28
- const unknownProp = Object.keys(manifest).find((key) => !VALID_PROPS.has(key))
29
- if (unknownProp !== undefined) {
30
- throw new Error(`unknown property "${unknownProp}"`)
31
- }
32
- }
33
-
34
- const VALID_PROPS = new Set(['name', 'inputs'])
35
-
36
- const validateName = function ({ name }) {
37
- if (name === undefined) {
38
- throw new Error('must contain a "name" property')
39
- }
40
-
41
- if (typeof name !== 'string') {
42
- throw new TypeError('"name" property must be a string')
43
- }
44
- }
45
-
46
- const validateInputs = function ({ inputs }) {
47
- if (inputs === undefined) {
48
- return
49
- }
50
-
51
- if (!isArrayOfObjects(inputs)) {
52
- throw new Error('"inputs" property must be an array of objects')
53
- }
54
-
55
- inputs.forEach(validateInput)
56
- }
57
-
58
- const isArrayOfObjects = function (objects) {
59
- return Array.isArray(objects) && objects.every(isPlainObj)
60
- }
61
-
62
- const validateInput = function (input, index) {
63
- try {
64
- validateUnknownInputProps(input)
65
- validateInputName(input)
66
- validateInputDescription(input)
67
- validateInputRequired(input)
68
- } catch (error) {
69
- error.message = `"inputs" property is invalid.
70
- Input at position ${index} ${error.message}.`
71
- throw error
72
- }
73
- }
74
-
75
- const validateUnknownInputProps = function (input) {
76
- const unknownProp = Object.keys(input).find((key) => !VALID_INPUT_PROPS.has(key))
77
- if (unknownProp !== undefined) {
78
- throw new Error(`has an unknown property "${unknownProp}"`)
79
- }
80
- }
81
-
82
- const VALID_INPUT_PROPS = new Set(['name', 'description', 'required', 'default'])
83
-
84
- const validateInputName = function ({ name }) {
85
- if (name === undefined) {
86
- throw new Error('must contain a "name" property')
87
- }
88
-
89
- if (typeof name !== 'string') {
90
- throw new TypeError('"name" property must be a string')
91
- }
92
- }
93
-
94
- const validateInputDescription = function ({ description }) {
95
- if (description === undefined) {
96
- return
97
- }
98
-
99
- if (typeof description !== 'string') {
100
- throw new TypeError('"description" property must be a string')
101
- }
102
- }
103
-
104
- const validateInputRequired = function ({ required }) {
105
- if (required !== undefined && typeof required !== 'boolean') {
106
- throw new Error('"required" property must be a boolean')
107
- }
108
- }
@@ -1,50 +0,0 @@
1
- import { version as currentVersion, execPath } from 'process'
2
-
3
- import semver from 'semver'
4
-
5
- import { addErrorInfo } from '../error/info.js'
6
- import { ROOT_PACKAGE_JSON } from '../utils/json.js'
7
-
8
- // Local plugins and `package.json`-installed plugins use user's preferred Node.js version if higher than our minimum
9
- // supported version. Else default to the system Node version.
10
- // Local and programmatic builds use `@netlify/build` Node.js version, which is
11
- // usually the system's Node.js version.
12
- // If the user Node version does not satisfy our supported engine range use our own system Node version
13
- export const addPluginsNodeVersion = function ({ pluginsOptions, nodePath, userNodeVersion }) {
14
- const currentNodeVersion = semver.clean(currentVersion)
15
- return pluginsOptions.map((pluginOptions) =>
16
- addPluginNodeVersion({ pluginOptions, currentNodeVersion, userNodeVersion, nodePath }),
17
- )
18
- }
19
-
20
- const addPluginNodeVersion = function ({
21
- pluginOptions,
22
- pluginOptions: { loadedFrom },
23
- currentNodeVersion,
24
- userNodeVersion,
25
- nodePath,
26
- }) {
27
- return (loadedFrom === 'local' || loadedFrom === 'package.json') &&
28
- semver.satisfies(userNodeVersion, ROOT_PACKAGE_JSON.engines.node)
29
- ? { ...pluginOptions, nodePath, nodeVersion: userNodeVersion }
30
- : { ...pluginOptions, nodePath: execPath, nodeVersion: currentNodeVersion }
31
- }
32
-
33
- // Ensure Node.js version is compatible with plugin's `engines.node`
34
- export const checkNodeVersion = function ({
35
- nodeVersion,
36
- packageName,
37
- pluginPackageJson: { engines: { node: pluginNodeVersionRange } = {} } = {},
38
- }) {
39
- if (pluginNodeVersionRange && !semver.satisfies(nodeVersion, pluginNodeVersionRange)) {
40
- throwUserError(
41
- `The Node.js version is ${nodeVersion} but the plugin "${packageName}" requires ${pluginNodeVersionRange}`,
42
- )
43
- }
44
- }
45
-
46
- const throwUserError = function (message) {
47
- const error = new Error(message)
48
- addErrorInfo(error, { type: 'resolveConfig' })
49
- throw error
50
- }
@@ -1,88 +0,0 @@
1
- import { dirname } from 'path'
2
-
3
- import { installLocalPluginsDependencies } from '../install/local.js'
4
- import { measureDuration } from '../time/main.js'
5
- import { ROOT_PACKAGE_JSON } from '../utils/json.js'
6
- import { getPackageJson } from '../utils/package.js'
7
-
8
- import { useManifest } from './manifest/main.js'
9
- import { checkNodeVersion } from './node_version.js'
10
- import { resolvePluginsPath } from './resolve.js'
11
-
12
- // Load core plugins and user plugins
13
- const tGetPluginsOptions = async function ({
14
- pluginsOptions,
15
- netlifyConfig: { plugins },
16
- siteInfo,
17
- buildDir,
18
- nodePath,
19
- packageJson,
20
- userNodeVersion,
21
- mode,
22
- api,
23
- logs,
24
- debug,
25
- sendStatus,
26
- testOpts,
27
- featureFlags,
28
- }) {
29
- const pluginsOptionsA = await resolvePluginsPath({
30
- pluginsOptions,
31
- siteInfo,
32
- buildDir,
33
- nodePath,
34
- packageJson,
35
- userNodeVersion,
36
- mode,
37
- api,
38
- logs,
39
- debug,
40
- sendStatus,
41
- testOpts,
42
- featureFlags,
43
- })
44
- const pluginsOptionsB = await Promise.all(
45
- pluginsOptionsA.map((pluginOptions) => loadPluginFiles({ pluginOptions, debug })),
46
- )
47
- const pluginsOptionsC = pluginsOptionsB.filter(isNotRedundantCorePlugin)
48
- await installLocalPluginsDependencies({ plugins, pluginsOptions: pluginsOptionsC, buildDir, mode, logs })
49
- return { pluginsOptions: pluginsOptionsC }
50
- }
51
-
52
- export const getPluginsOptions = measureDuration(tGetPluginsOptions, 'get_plugins_options')
53
-
54
- // Retrieve plugin's main file path.
55
- // Then load plugin's `package.json` and `manifest.yml`.
56
- const loadPluginFiles = async function ({
57
- pluginOptions,
58
- pluginOptions: { pluginPath, nodeVersion, packageName },
59
- debug,
60
- }) {
61
- const pluginDir = dirname(pluginPath)
62
- const { packageDir, packageJson: pluginPackageJson } = await getPackageJson(pluginDir)
63
- checkNodeVersion({ nodeVersion, packageName, pluginPackageJson })
64
- const { manifest, inputs } = await useManifest(pluginOptions, { pluginDir, packageDir, pluginPackageJson, debug })
65
- return { ...pluginOptions, pluginDir, packageDir, pluginPackageJson, manifest, inputs }
66
- }
67
-
68
- // Core plugins can only be included once.
69
- // For example, when testing core plugins, they might be included as local plugins,
70
- // in which case they should not be included twice.
71
- const isNotRedundantCorePlugin = function (pluginOptionsA, index, pluginsOptions) {
72
- return (
73
- pluginOptionsA.loadedFrom !== 'core' ||
74
- pluginsOptions.every(
75
- (pluginOptionsB) =>
76
- pluginOptionsA.manifest.name !== pluginOptionsB.manifest.name || pluginOptionsA === pluginOptionsB,
77
- )
78
- )
79
- }
80
-
81
- // Retrieve information about @netlify/build when an error happens there and not
82
- // in a plugin
83
- export const getSpawnInfo = function () {
84
- return {
85
- plugin: { packageName: ROOT_PACKAGE_JSON.name, pluginPackageJson: ROOT_PACKAGE_JSON },
86
- location: { event: 'load', packageName: ROOT_PACKAGE_JSON.name, loadedFrom: 'core', origin: 'core' },
87
- }
88
- }
@@ -1,131 +0,0 @@
1
- import { handleBuildError } from '../error/handle.js'
2
- import { getMajorVersion } from '../utils/semver.js'
3
-
4
- // Retrieve plugin's pinned major versions by fetching the latest `PluginRun`
5
- // Only applies to `netlify.toml`-only installed plugins.
6
- export const addPinnedVersions = async function ({ pluginsOptions, api, siteInfo: { id: siteId }, sendStatus }) {
7
- if (!sendStatus || api === undefined || !siteId) {
8
- return pluginsOptions
9
- }
10
-
11
- const packages = pluginsOptions.filter(shouldFetchPinVersion).map(getPackageName)
12
- if (packages.length === 0) {
13
- return pluginsOptions
14
- }
15
-
16
- const pluginRuns = await api.getLatestPluginRuns({ site_id: siteId, packages, state: 'success' })
17
- const pluginsOptionsA = pluginsOptions.map((pluginOption) => addPinnedVersion(pluginOption, pluginRuns))
18
- return pluginsOptionsA
19
- }
20
-
21
- const shouldFetchPinVersion = function ({ pinnedVersion, loadedFrom, origin }) {
22
- return pinnedVersion === undefined && loadedFrom === 'auto_install' && origin === 'config'
23
- }
24
-
25
- const getPackageName = function ({ packageName }) {
26
- return packageName
27
- }
28
-
29
- const addPinnedVersion = function (pluginOptions, pluginRuns) {
30
- const foundPluginRun = pluginRuns.find((pluginRun) => pluginRun.package === pluginOptions.packageName)
31
- if (foundPluginRun === undefined) {
32
- return pluginOptions
33
- }
34
-
35
- const pinnedVersion = getMajorVersion(foundPluginRun.version)
36
- return pinnedVersion === undefined ? pluginOptions : { ...pluginOptions, pinnedVersion }
37
- }
38
-
39
- // Send an API request to pin plugins' major versions.
40
- // Only applies to UI-installed plugins.
41
- export const pinPlugins = async function ({
42
- pluginsOptions,
43
- failedPlugins,
44
- api,
45
- siteInfo: { id: siteId },
46
- childEnv,
47
- mode,
48
- netlifyConfig,
49
- errorMonitor,
50
- logs,
51
- debug,
52
- testOpts,
53
- sendStatus,
54
- }) {
55
- if ((mode !== 'buildbot' && !sendStatus) || api === undefined || !siteId) {
56
- return
57
- }
58
-
59
- const pluginsOptionsA = pluginsOptions.filter((pluginOptions) => shouldPinVersion({ pluginOptions, failedPlugins }))
60
- await Promise.all(
61
- pluginsOptionsA.map((pluginOptions) =>
62
- pinPlugin({
63
- pluginOptions,
64
- api,
65
- childEnv,
66
- mode,
67
- netlifyConfig,
68
- errorMonitor,
69
- logs,
70
- debug,
71
- testOpts,
72
- siteId,
73
- }),
74
- ),
75
- )
76
- }
77
-
78
- // Only pin version if:
79
- // - the plugin's version has not been pinned yet
80
- // - the plugin was installed in the UI
81
- // - both the build and the plugin succeeded
82
- const shouldPinVersion = function ({
83
- pluginOptions: { packageName, pinnedVersion, loadedFrom, origin },
84
- failedPlugins,
85
- }) {
86
- return (
87
- pinnedVersion === undefined &&
88
- loadedFrom === 'auto_install' &&
89
- origin === 'ui' &&
90
- !failedPlugins.includes(packageName)
91
- )
92
- }
93
-
94
- const pinPlugin = async function ({
95
- pluginOptions: {
96
- packageName,
97
- pluginPackageJson: { version },
98
- },
99
- api,
100
- childEnv,
101
- mode,
102
- netlifyConfig,
103
- errorMonitor,
104
- logs,
105
- debug,
106
- testOpts,
107
- siteId,
108
- }) {
109
- const pinnedVersion = getMajorVersion(version)
110
- try {
111
- await api.updatePlugin({
112
- package: encodeURIComponent(packageName),
113
- site_id: siteId,
114
- body: { pinned_version: pinnedVersion },
115
- })
116
- // Bitballoon API randomly fails with 502.
117
- // Builds should be successful when this API call fails, but we still want
118
- // to report the error both in logs and in error monitoring.
119
- } catch (error) {
120
- if (shouldIgnoreError(error)) {
121
- return
122
- }
123
-
124
- await handleBuildError(error, { errorMonitor, netlifyConfig, childEnv, mode, logs, debug, testOpts })
125
- }
126
- }
127
-
128
- // Status is 404 if the plugin is uninstalled while the build is ongoing.
129
- const shouldIgnoreError = function ({ status }) {
130
- return status === 404
131
- }