@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 { 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
- }
@@ -1,152 +0,0 @@
1
- import { addErrorInfo } from '../error/info.js'
2
- import { installMissingPlugins } from '../install/missing.js'
3
- import { resolvePath, tryResolvePath } from '../utils/resolve.js'
4
-
5
- import { addExpectedVersions } from './expected_version.js'
6
- import { addPluginsNodeVersion } from './node_version.js'
7
- import { addPinnedVersions } from './pinned_version.js'
8
-
9
- // Try to find plugins in four places, by priority order:
10
- // - already loaded (core plugins)
11
- // - local plugin
12
- // - external plugin already installed in `node_modules`, most likely through `package.json`
13
- // - automatically installed by us, to `.netlify/plugins/`
14
- export const resolvePluginsPath = async function ({
15
- pluginsOptions,
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 autoPluginsDir = getAutoPluginsDir(buildDir)
30
- const pluginsOptionsA = await Promise.all(
31
- pluginsOptions.map((pluginOptions) => resolvePluginPath({ pluginOptions, buildDir, autoPluginsDir })),
32
- )
33
- const pluginsOptionsB = addPluginsNodeVersion({
34
- pluginsOptions: pluginsOptionsA,
35
- nodePath,
36
- userNodeVersion,
37
- logs,
38
- })
39
- const pluginsOptionsC = await addPinnedVersions({ pluginsOptions: pluginsOptionsB, api, siteInfo, sendStatus })
40
- const pluginsOptionsD = await addExpectedVersions({
41
- pluginsOptions: pluginsOptionsC,
42
- autoPluginsDir,
43
- packageJson,
44
- debug,
45
- logs,
46
- buildDir,
47
- testOpts,
48
- featureFlags,
49
- })
50
- const pluginsOptionsE = await handleMissingPlugins({
51
- pluginsOptions: pluginsOptionsD,
52
- autoPluginsDir,
53
- mode,
54
- logs,
55
- })
56
- return pluginsOptionsE
57
- }
58
-
59
- // Find the path to the directory used to install plugins automatically.
60
- // It is a subdirectory of `buildDir`, so that the plugin can require the
61
- // project's dependencies (peer dependencies).
62
- const getAutoPluginsDir = function (buildDir) {
63
- return `${buildDir}/${AUTO_PLUGINS_DIR}`
64
- }
65
-
66
- const AUTO_PLUGINS_DIR = '.netlify/plugins/'
67
-
68
- const resolvePluginPath = async function ({
69
- pluginOptions,
70
- pluginOptions: { packageName, loadedFrom },
71
- buildDir,
72
- autoPluginsDir,
73
- }) {
74
- // Core plugins
75
- if (loadedFrom !== undefined) {
76
- return pluginOptions
77
- }
78
-
79
- const localPackageName = normalizeLocalPackageName(packageName)
80
-
81
- // Local plugins
82
- if (localPackageName.startsWith('.')) {
83
- const { path: localPath, error } = await tryResolvePath(localPackageName, buildDir)
84
- validateLocalPluginPath(error, localPackageName)
85
- return { ...pluginOptions, pluginPath: localPath, loadedFrom: 'local' }
86
- }
87
-
88
- // Plugin added to `package.json`
89
- const { path: manualPath } = await tryResolvePath(packageName, buildDir)
90
- if (manualPath !== undefined) {
91
- return { ...pluginOptions, pluginPath: manualPath, loadedFrom: 'package.json' }
92
- }
93
-
94
- // Previously automatically installed
95
- const { path: automaticPath } = await tryResolvePath(packageName, autoPluginsDir)
96
- if (automaticPath !== undefined) {
97
- return { ...pluginOptions, pluginPath: automaticPath, loadedFrom: 'auto_install' }
98
- }
99
-
100
- // Happens if the plugin:
101
- // - name is mispelled
102
- // - is not in our official list
103
- // - is in our official list but has not been installed by this site yet
104
- return { ...pluginOptions, loadedFrom: 'auto_install' }
105
- }
106
-
107
- // `packageName` starting with `/` are relative to the build directory
108
- const normalizeLocalPackageName = function (packageName) {
109
- if (packageName.startsWith('/')) {
110
- return `.${packageName}`
111
- }
112
-
113
- return packageName
114
- }
115
-
116
- // When requiring a local plugin with an invalid file path
117
- const validateLocalPluginPath = function (error, localPackageName) {
118
- if (error !== undefined) {
119
- error.message = `Plugin could not be found using local path: ${localPackageName}\n${error.message}`
120
- addErrorInfo(error, { type: 'resolveConfig' })
121
- throw error
122
- }
123
- }
124
-
125
- // Install plugins from the official list that have not been previously installed.
126
- // Print a warning if they have not been installed through the UI.
127
- const handleMissingPlugins = async function ({ pluginsOptions, autoPluginsDir, mode, logs }) {
128
- const missingPlugins = pluginsOptions.filter(isMissingPlugin)
129
-
130
- if (missingPlugins.length === 0) {
131
- return pluginsOptions
132
- }
133
-
134
- await installMissingPlugins({ missingPlugins, autoPluginsDir, mode, logs })
135
- return await Promise.all(
136
- pluginsOptions.map((pluginOptions) => resolveMissingPluginPath({ pluginOptions, autoPluginsDir })),
137
- )
138
- }
139
-
140
- // Resolve the plugins that just got automatically installed
141
- const resolveMissingPluginPath = async function ({ pluginOptions, pluginOptions: { packageName }, autoPluginsDir }) {
142
- if (!isMissingPlugin(pluginOptions)) {
143
- return pluginOptions
144
- }
145
-
146
- const pluginPath = await resolvePath(packageName, autoPluginsDir)
147
- return { ...pluginOptions, pluginPath }
148
- }
149
-
150
- const isMissingPlugin = function ({ isMissing }) {
151
- return isMissing
152
- }
@@ -1,66 +0,0 @@
1
- import { fileURLToPath } from 'url'
2
-
3
- import { execaNode } from 'execa'
4
-
5
- import { addErrorInfo } from '../error/info.js'
6
- import { logLoadingPlugins, logOutdatedPlugins, logIncompatiblePlugins } from '../log/messages/compatibility.js'
7
- import { measureDuration } from '../time/main.js'
8
-
9
- import { getEventFromChild } from './ipc.js'
10
- import { getSpawnInfo } from './options.js'
11
-
12
- const CHILD_MAIN_FILE = fileURLToPath(new URL('child/main.js', import.meta.url))
13
-
14
- // Start child processes used by all plugins
15
- // We fire plugins through child processes so that:
16
- // - each plugin is sandboxed, e.g. cannot access/modify its parent `process`
17
- // (for both security and safety reasons)
18
- // - logs can be buffered which allows manipulating them for log shipping,
19
- // transforming and parallel plugins
20
- const tStartPlugins = async function ({ pluginsOptions, buildDir, childEnv, logs, debug }) {
21
- logLoadingPlugins(logs, pluginsOptions, debug)
22
- logOutdatedPlugins(logs, pluginsOptions)
23
- logIncompatiblePlugins(logs, pluginsOptions)
24
-
25
- const childProcesses = await Promise.all(
26
- pluginsOptions.map(({ pluginDir, nodePath }) => startPlugin({ pluginDir, nodePath, buildDir, childEnv })),
27
- )
28
- return { childProcesses }
29
- }
30
-
31
- export const startPlugins = measureDuration(tStartPlugins, 'start_plugins')
32
-
33
- const startPlugin = async function ({ pluginDir, nodePath, buildDir, childEnv }) {
34
- const childProcess = execaNode(CHILD_MAIN_FILE, {
35
- cwd: buildDir,
36
- preferLocal: true,
37
- localDir: pluginDir,
38
- nodePath,
39
- execPath: nodePath,
40
- env: childEnv,
41
- extendEnv: false,
42
- serialization: 'advanced',
43
- })
44
-
45
- try {
46
- await getEventFromChild(childProcess, 'ready')
47
- return { childProcess }
48
- } catch (error) {
49
- const spawnInfo = getSpawnInfo()
50
- addErrorInfo(error, spawnInfo)
51
- throw error
52
- }
53
- }
54
-
55
- // Stop all plugins child processes
56
- export const stopPlugins = function (childProcesses) {
57
- childProcesses.forEach(stopPlugin)
58
- }
59
-
60
- const stopPlugin = function ({ childProcess }) {
61
- if (childProcess.connected) {
62
- childProcess.disconnect()
63
- }
64
-
65
- childProcess.kill()
66
- }