@netlify/build 0.4.48 → 1.0.0-dl-test

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (243) hide show
  1. package/bin.js +5 -0
  2. package/lib/core/bin.js +66 -0
  3. package/lib/core/build.js +392 -0
  4. package/lib/core/config.js +124 -0
  5. package/lib/core/constants.js +116 -0
  6. package/lib/core/dev.js +27 -0
  7. package/lib/core/dry.js +21 -0
  8. package/lib/core/feature_flags.js +17 -0
  9. package/lib/core/flags.js +206 -0
  10. package/lib/core/lingering.js +68 -0
  11. package/lib/core/main.js +114 -0
  12. package/lib/core/missing_side_file.js +17 -0
  13. package/lib/core/normalize_flags.js +62 -0
  14. package/lib/core/report_metrics.js +17 -0
  15. package/lib/core/severity.js +21 -0
  16. package/lib/core/types.js +8 -0
  17. package/lib/core/user_node_version.js +32 -0
  18. package/lib/env/changes.js +43 -0
  19. package/lib/env/main.js +14 -0
  20. package/lib/env/metadata.js +68 -0
  21. package/lib/error/api.js +37 -0
  22. package/lib/error/build.js +36 -0
  23. package/lib/error/cancel.js +7 -0
  24. package/lib/error/colors.js +9 -0
  25. package/lib/error/handle.js +44 -0
  26. package/lib/error/info.js +37 -0
  27. package/lib/error/monitor/location.js +16 -0
  28. package/lib/error/monitor/normalize.js +86 -0
  29. package/lib/error/monitor/print.js +20 -0
  30. package/lib/error/monitor/report.js +120 -0
  31. package/lib/error/monitor/start.js +61 -0
  32. package/lib/error/parse/clean_stack.js +70 -0
  33. package/lib/error/parse/location.js +50 -0
  34. package/lib/error/parse/normalize.js +24 -0
  35. package/lib/error/parse/parse.js +67 -0
  36. package/lib/error/parse/plugin.js +55 -0
  37. package/lib/error/parse/properties.js +16 -0
  38. package/lib/error/parse/serialize_log.js +34 -0
  39. package/lib/error/parse/serialize_status.js +18 -0
  40. package/lib/error/parse/stack.js +34 -0
  41. package/lib/error/report.js +29 -0
  42. package/lib/error/type.js +177 -0
  43. package/lib/install/functions.js +20 -0
  44. package/lib/install/local.js +45 -0
  45. package/lib/install/main.js +67 -0
  46. package/lib/install/missing.js +54 -0
  47. package/lib/log/colors.js +28 -0
  48. package/lib/log/description.js +21 -0
  49. package/lib/log/header.js +12 -0
  50. package/lib/log/header_func.js +13 -0
  51. package/lib/log/logger.js +140 -0
  52. package/lib/log/messages/compatibility.js +120 -0
  53. package/lib/log/messages/config.js +91 -0
  54. package/lib/log/messages/core.js +49 -0
  55. package/lib/log/messages/core_steps.js +75 -0
  56. package/lib/log/messages/dry.js +41 -0
  57. package/lib/log/messages/install.js +25 -0
  58. package/lib/log/messages/ipc.js +29 -0
  59. package/lib/log/messages/mutations.js +62 -0
  60. package/lib/log/messages/plugins.js +25 -0
  61. package/lib/log/messages/status.js +14 -0
  62. package/lib/log/messages/steps.js +18 -0
  63. package/lib/log/serialize.js +10 -0
  64. package/lib/log/stream.js +68 -0
  65. package/lib/log/theme.js +27 -0
  66. package/lib/plugins/child/diff.js +46 -0
  67. package/lib/plugins/child/error.js +26 -0
  68. package/lib/plugins/child/lazy.js +15 -0
  69. package/lib/plugins/child/load.js +22 -0
  70. package/lib/plugins/child/logic.js +57 -0
  71. package/lib/plugins/child/main.js +37 -0
  72. package/lib/plugins/child/run.js +19 -0
  73. package/lib/plugins/child/status.js +63 -0
  74. package/lib/plugins/child/typescript.js +28 -0
  75. package/lib/plugins/child/utils.js +42 -0
  76. package/lib/plugins/child/validate.js +31 -0
  77. package/lib/plugins/compatibility.js +104 -0
  78. package/lib/plugins/error.js +46 -0
  79. package/lib/plugins/events.js +12 -0
  80. package/lib/plugins/expected_version.js +81 -0
  81. package/lib/plugins/internal.js +10 -0
  82. package/lib/plugins/ipc.js +120 -0
  83. package/lib/plugins/list.js +73 -0
  84. package/lib/plugins/load.js +50 -0
  85. package/lib/plugins/manifest/check.js +85 -0
  86. package/lib/plugins/manifest/load.js +38 -0
  87. package/lib/plugins/manifest/main.js +19 -0
  88. package/lib/plugins/manifest/path.js +24 -0
  89. package/lib/plugins/manifest/validate.js +91 -0
  90. package/lib/plugins/node_version.js +35 -0
  91. package/lib/plugins/options.js +70 -0
  92. package/lib/plugins/pinned_version.js +83 -0
  93. package/lib/plugins/resolve.js +110 -0
  94. package/lib/plugins/spawn.js +55 -0
  95. package/lib/plugins_core/add.js +35 -0
  96. package/lib/plugins_core/build_command.js +50 -0
  97. package/lib/plugins_core/deploy/buildbot_client.js +87 -0
  98. package/lib/plugins_core/deploy/index.js +49 -0
  99. package/lib/plugins_core/deploy/manifest.yml +1 -0
  100. package/lib/plugins_core/edge_functions/index.js +106 -0
  101. package/lib/plugins_core/edge_functions/lib/error.js +17 -0
  102. package/lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +14 -0
  103. package/lib/plugins_core/functions/error.js +123 -0
  104. package/lib/plugins_core/functions/feature_flags.js +5 -0
  105. package/lib/plugins_core/functions/index.js +137 -0
  106. package/lib/plugins_core/functions/utils.js +45 -0
  107. package/lib/plugins_core/functions/zisi.js +64 -0
  108. package/lib/plugins_core/functions_install/index.js +10 -0
  109. package/lib/plugins_core/list.js +20 -0
  110. package/lib/plugins_core/save_artifacts/index.js +33 -0
  111. package/lib/report/statsd.js +56 -0
  112. package/lib/status/add.js +30 -0
  113. package/lib/status/colors.js +18 -0
  114. package/lib/status/load_error.js +10 -0
  115. package/lib/status/report.js +83 -0
  116. package/lib/status/success.js +14 -0
  117. package/lib/steps/core_step.js +62 -0
  118. package/lib/steps/error.js +65 -0
  119. package/lib/steps/get.js +44 -0
  120. package/lib/steps/plugin.js +55 -0
  121. package/lib/steps/return.js +27 -0
  122. package/lib/steps/run_core_steps.js +117 -0
  123. package/lib/steps/run_step.js +200 -0
  124. package/lib/steps/run_steps.js +102 -0
  125. package/lib/steps/update_config.js +66 -0
  126. package/lib/telemetry/main.js +94 -0
  127. package/lib/time/aggregate.js +109 -0
  128. package/lib/time/main.js +31 -0
  129. package/lib/time/measure.js +16 -0
  130. package/lib/time/report.js +30 -0
  131. package/lib/utils/errors.js +13 -0
  132. package/lib/utils/json.js +10 -0
  133. package/lib/utils/omit.js +3 -0
  134. package/lib/utils/package.js +24 -0
  135. package/lib/utils/remove_falsy.js +8 -0
  136. package/lib/utils/resolve.js +41 -0
  137. package/lib/utils/runtime.js +5 -0
  138. package/lib/utils/semver.js +28 -0
  139. package/package.json +119 -56
  140. package/types/config/build.d.ts +52 -0
  141. package/types/config/functions.d.ts +36 -0
  142. package/types/config/inputs.d.ts +7 -0
  143. package/types/config/netlify_config.d.ts +58 -0
  144. package/types/index.d.ts +7 -0
  145. package/types/netlify_event_handler.d.ts +29 -0
  146. package/types/netlify_plugin.d.ts +29 -0
  147. package/types/netlify_plugin_constants.d.ts +51 -0
  148. package/types/netlify_plugin_options.d.ts +23 -0
  149. package/types/options/index.d.ts +1 -0
  150. package/types/options/netlify_plugin_build_util.d.ts +7 -0
  151. package/types/options/netlify_plugin_cache_util.d.ts +39 -0
  152. package/types/options/netlify_plugin_functions_util.d.ts +32 -0
  153. package/types/options/netlify_plugin_git_util.d.ts +41 -0
  154. package/types/options/netlify_plugin_run_util.d.ts +24 -0
  155. package/types/options/netlify_plugin_status_util.d.ts +24 -0
  156. package/types/options/netlify_plugin_utils.d.ts +15 -0
  157. package/types/utils/json_value.d.ts +1 -0
  158. package/types/utils/many.d.ts +6 -0
  159. package/README.md +0 -3
  160. package/src/core/bin.js +0 -139
  161. package/src/core/commands.js +0 -304
  162. package/src/core/config.js +0 -130
  163. package/src/core/constants.js +0 -88
  164. package/src/core/dry.js +0 -23
  165. package/src/core/main.js +0 -196
  166. package/src/env/changes.js +0 -49
  167. package/src/env/git.js +0 -27
  168. package/src/env/main.js +0 -97
  169. package/src/env/metadata.js +0 -81
  170. package/src/error/api.js +0 -32
  171. package/src/error/build.js +0 -32
  172. package/src/error/cancel.js +0 -22
  173. package/src/error/colors.js +0 -13
  174. package/src/error/info.js +0 -12
  175. package/src/error/monitor/normalize.js +0 -50
  176. package/src/error/monitor/print.js +0 -43
  177. package/src/error/monitor/report.js +0 -140
  178. package/src/error/monitor/start.js +0 -50
  179. package/src/error/parse/clean_stack.js +0 -86
  180. package/src/error/parse/location.js +0 -50
  181. package/src/error/parse/parse.js +0 -87
  182. package/src/error/parse/plugin.js +0 -68
  183. package/src/error/parse/properties.js +0 -20
  184. package/src/error/parse/serialize_log.js +0 -46
  185. package/src/error/parse/serialize_status.js +0 -28
  186. package/src/error/parse/stack.js +0 -45
  187. package/src/error/process.js +0 -13
  188. package/src/error/type.js +0 -143
  189. package/src/install/functions.js +0 -52
  190. package/src/install/local.js +0 -65
  191. package/src/install/main.js +0 -103
  192. package/src/install/missing.js +0 -86
  193. package/src/log/colors.js +0 -59
  194. package/src/log/description.js +0 -38
  195. package/src/log/header.js +0 -19
  196. package/src/log/logger.js +0 -55
  197. package/src/log/main.js +0 -348
  198. package/src/log/old_version.js +0 -45
  199. package/src/log/serialize.js +0 -15
  200. package/src/log/stream.js +0 -15
  201. package/src/log/theme.js +0 -32
  202. package/src/log/timer.js +0 -28
  203. package/src/plugins/child/api.js +0 -59
  204. package/src/plugins/child/error.js +0 -39
  205. package/src/plugins/child/load.js +0 -40
  206. package/src/plugins/child/logic.js +0 -31
  207. package/src/plugins/child/main.js +0 -48
  208. package/src/plugins/child/normalize.js +0 -20
  209. package/src/plugins/child/run.js +0 -34
  210. package/src/plugins/child/status.js +0 -53
  211. package/src/plugins/child/utils.js +0 -43
  212. package/src/plugins/child/validate.js +0 -46
  213. package/src/plugins/error.js +0 -44
  214. package/src/plugins/events.js +0 -77
  215. package/src/plugins/ipc.js +0 -136
  216. package/src/plugins/load.js +0 -66
  217. package/src/plugins/manifest/check.js +0 -80
  218. package/src/plugins/manifest/load.js +0 -47
  219. package/src/plugins/manifest/main.js +0 -28
  220. package/src/plugins/manifest/path.js +0 -12
  221. package/src/plugins/manifest/validate.js +0 -136
  222. package/src/plugins/node_version.js +0 -74
  223. package/src/plugins/options.js +0 -78
  224. package/src/plugins/package.js +0 -17
  225. package/src/plugins/resolve.js +0 -159
  226. package/src/plugins/spawn.js +0 -82
  227. package/src/plugins_core/cache/manifest.yml +0 -1
  228. package/src/plugins_core/cache/plugin.js +0 -75
  229. package/src/plugins_core/functions/manifest.yml +0 -1
  230. package/src/plugins_core/functions/plugin.js +0 -37
  231. package/src/plugins_core/functions_install/plugin.js +0 -14
  232. package/src/plugins_core/main.js +0 -38
  233. package/src/status/add.js +0 -56
  234. package/src/status/colors.js +0 -25
  235. package/src/status/report.js +0 -57
  236. package/src/telemetry/complete.js +0 -49
  237. package/src/telemetry/request.js +0 -28
  238. package/src/telemetry/track.js +0 -33
  239. package/src/utils/omit.js +0 -8
  240. package/src/utils/polyfills.js +0 -3
  241. package/src/utils/remove_falsy.js +0 -12
  242. package/src/utils/resolve.js +0 -39
  243. /package/{src → lib}/plugins_core/functions_install/manifest.yml +0 -0
@@ -1,47 +0,0 @@
1
- const { readFile } = require('fs')
2
- const { promisify } = require('util')
3
-
4
- const { load: loadYaml, JSON_SCHEMA } = require('js-yaml')
5
-
6
- const { addErrorInfo } = require('../../error/info')
7
-
8
- const { validateManifest } = require('./validate')
9
-
10
- const pReadFile = promisify(readFile)
11
-
12
- // Load "manifest.yml" using its file path
13
- const loadManifest = async function({ manifestPath, package, packageJson, loadedFrom, origin }) {
14
- try {
15
- const rawManifest = await loadRawManifest(manifestPath)
16
- const manifest = await parseManifest(rawManifest)
17
- validateManifest(manifest, rawManifest)
18
- return manifest
19
- } catch (error) {
20
- addErrorInfo(error, {
21
- type: 'pluginValidation',
22
- plugin: { package, packageJson },
23
- location: { event: 'load', package, loadedFrom, origin },
24
- })
25
- throw error
26
- }
27
- }
28
-
29
- const loadRawManifest = async function(manifestPath) {
30
- try {
31
- return await pReadFile(manifestPath, 'utf8')
32
- } catch (error) {
33
- error.message = `Could not load plugin's "manifest.yml"\n${error.message}`
34
- throw error
35
- }
36
- }
37
-
38
- const parseManifest = async function(rawManifest) {
39
- try {
40
- return await loadYaml(rawManifest, { schema: JSON_SCHEMA, json: true })
41
- } catch (error) {
42
- error.message = `Could not parse plugin's "manifest.yml"\n${error.message}`
43
- throw error
44
- }
45
- }
46
-
47
- module.exports = { loadManifest }
@@ -1,28 +0,0 @@
1
- const { reportPluginLoadError } = require('../../status/report')
2
-
3
- const { checkInputs } = require('./check')
4
- const { loadManifest } = require('./load')
5
- const { getManifestPath } = require('./path')
6
-
7
- // Load plugin's `manifest.yml`
8
- const useManifest = async function(
9
- { package, loadedFrom, origin, inputs },
10
- { pluginDir, packageDir, packageJson, packageJson: { version }, mode, api },
11
- ) {
12
- const manifestPath = await getManifestPath(pluginDir, packageDir)
13
-
14
- if (manifestPath === undefined) {
15
- return { manifest: {}, inputs }
16
- }
17
-
18
- try {
19
- const manifest = await loadManifest({ manifestPath, package, packageJson, loadedFrom, origin })
20
- const inputsA = checkInputs({ inputs, manifest, package, packageJson, loadedFrom, origin })
21
- return { manifest, inputs: inputsA }
22
- } catch (error) {
23
- await reportPluginLoadError({ error, api, mode, event: 'load', package, version })
24
- throw error
25
- }
26
- }
27
-
28
- module.exports = { useManifest }
@@ -1,12 +0,0 @@
1
- const locatePath = require('locate-path')
2
-
3
- // Retrieve "manifest.yml" path for a specific plugin
4
- const getManifestPath = async function(pluginDir, packageDir) {
5
- const dirs = [pluginDir, packageDir].filter(Boolean).map(dir => `${dir}/${MANIFEST_FILENAME}`)
6
- const manifestPath = await locatePath(dirs)
7
- return manifestPath
8
- }
9
-
10
- const MANIFEST_FILENAME = 'manifest.yml'
11
-
12
- module.exports = { getManifestPath }
@@ -1,136 +0,0 @@
1
- const isPlainObj = require('is-plain-obj')
2
-
3
- const { serializeArray } = require('../../log/serialize')
4
- const { THEME } = require('../../log/theme')
5
- const { API_METHODS } = require('../child/api')
6
-
7
- // Validate `manifest.yml` syntax
8
- const validateManifest = function(manifest, rawManifest) {
9
- try {
10
- validateBasic(manifest)
11
- validateUnknownProps(manifest)
12
- validateName(manifest)
13
- validateScopes(manifest)
14
- validateInputs(manifest)
15
- } catch (error) {
16
- error.message = `Plugin's "manifest.yml" ${error.message}
17
-
18
- ${THEME.errorSubHeader('manifest.yml')}
19
- ${rawManifest.trim()}`
20
- throw error
21
- }
22
- }
23
-
24
- const validateBasic = function(manifest) {
25
- if (!isPlainObj(manifest)) {
26
- throw new Error('must be a plain object')
27
- }
28
- }
29
-
30
- const validateUnknownProps = function(manifest) {
31
- const unknownProp = Object.keys(manifest).find(key => !VALID_PROPS.includes(key))
32
- if (unknownProp !== undefined) {
33
- throw new Error(`unknown property "${unknownProp}"`)
34
- }
35
- }
36
-
37
- const VALID_PROPS = ['name', 'inputs', 'scopes']
38
-
39
- const validateName = function({ name }) {
40
- if (name === undefined) {
41
- throw new Error('must contain a "name" property')
42
- }
43
-
44
- if (typeof name !== 'string') {
45
- throw new Error('"name" property must be a string')
46
- }
47
- }
48
-
49
- const validateScopes = function({ scopes }) {
50
- if (scopes === undefined) {
51
- return
52
- }
53
-
54
- if (!Array.isArray(scopes)) {
55
- throw new Error('"scopes" property must be an array')
56
- }
57
-
58
- const wrongScope = scopes.find(scope => !isValidScope(scope))
59
- if (wrongScope !== undefined) {
60
- throw new Error(`scope "${wrongScope}" is invalid
61
- Please use a valid scope. One of:
62
- ${serializeArray(ALLOWED_SCOPES)}`)
63
- }
64
- }
65
-
66
- const isValidScope = function(scope) {
67
- return ALLOWED_SCOPES.includes(scope)
68
- }
69
-
70
- const ALLOWED_SCOPES = ['*', ...API_METHODS]
71
-
72
- const validateInputs = function({ inputs }) {
73
- if (inputs === undefined) {
74
- return
75
- }
76
-
77
- if (!isArrayOfObjects(inputs)) {
78
- throw new Error('"inputs" property must be an array of objects')
79
- }
80
-
81
- inputs.forEach(validateInput)
82
- }
83
-
84
- const isArrayOfObjects = function(objects) {
85
- return Array.isArray(objects) && objects.every(isPlainObj)
86
- }
87
-
88
- const validateInput = function(input, index) {
89
- try {
90
- validateUnknownInputProps(input)
91
- validateInputName(input)
92
- validateInputDescription(input)
93
- validateInputRequired(input)
94
- } catch (error) {
95
- error.message = `"inputs" property is invalid.
96
- Input at position ${index} ${error.message}.`
97
- throw error
98
- }
99
- }
100
-
101
- const validateUnknownInputProps = function(input) {
102
- const unknownProp = Object.keys(input).find(key => !VALID_INPUT_PROPS.includes(key))
103
- if (unknownProp !== undefined) {
104
- throw new Error(`has an unknown property "${unknownProp}"`)
105
- }
106
- }
107
-
108
- const VALID_INPUT_PROPS = ['name', 'description', 'required', 'default']
109
-
110
- const validateInputName = function({ name }) {
111
- if (name === undefined) {
112
- throw new Error('must contain a "name" property')
113
- }
114
-
115
- if (typeof name !== 'string') {
116
- throw new Error('"name" property must be a string')
117
- }
118
- }
119
-
120
- const validateInputDescription = function({ description }) {
121
- if (description === undefined) {
122
- return
123
- }
124
-
125
- if (typeof description !== 'string') {
126
- throw new Error('"description" property must be a string')
127
- }
128
- }
129
-
130
- const validateInputRequired = function({ required }) {
131
- if (required !== undefined && typeof required !== 'boolean') {
132
- throw new Error('"required" property must be a boolean')
133
- }
134
- }
135
-
136
- module.exports = { validateManifest }
@@ -1,74 +0,0 @@
1
- const { version: currentVersion, execPath } = require('process')
2
-
3
- const execa = require('execa')
4
- const { satisfies, clean: cleanVersion } = require('semver')
5
-
6
- const {
7
- engines: { node: coreNodeVersionRange },
8
- } = require('../../package.json')
9
- const { addErrorInfo } = require('../error/info')
10
-
11
- // Retrieve Node.js version from `--node-path`
12
- const getUserNodeVersion = async function(nodePath) {
13
- // No `--node-path` CLI flag
14
- if (nodePath === execPath) {
15
- return getCurrentNodeVersion()
16
- }
17
-
18
- const result = NVM_NODE_VERSION_REGEXP.exec(nodePath)
19
- if (result !== null) {
20
- return result[1]
21
- }
22
-
23
- const { stdout } = await execa(nodePath, ['--version'], { reject: false })
24
- const version = cleanVersion(stdout)
25
- if (version === null) {
26
- throwUserError(`Invalid --node-path CLI flag: ${nodePath}`)
27
- }
28
-
29
- return version
30
- }
31
-
32
- // Retrieve Node.js version if the Node.js path is using nvm.
33
- // `node.exe` on Windows, `bin/node` on Unix.
34
- const NVM_NODE_VERSION_REGEXP = /[/\\]v(\d+\.\d+\.\d+)[/\\](bin[/\\]node|node.exe)$/
35
-
36
- // Retrieve Node.js version from current process
37
- const getCurrentNodeVersion = function() {
38
- return cleanVersion(currentVersion)
39
- }
40
-
41
- // Ensure Node.js version is recent enough to run this plugin
42
- const checkNodeVersion = async function({
43
- childNodeVersion,
44
- package,
45
- packageJson: { engines: { node: pluginNodeVersionRange } = {} } = {},
46
- }) {
47
- // Build plugins are instrumented with a wrapper code which has a minimal
48
- // allowed Node.js version.
49
- // A mismatch can only happen in the conditions described below since:
50
- // - production builds use a pinned version, except for local plugins and
51
- // plugins added to `package.json`
52
- // - Netlify CLI has the same minimal allowed Node.js version as
53
- // `@netlify/build`, so if users can run Netlify CLI, everything is good
54
- if (!satisfies(childNodeVersion, coreNodeVersionRange)) {
55
- throwUserError(`The Node.js version is ${childNodeVersion} but it should be ${coreNodeVersionRange} when using build plugins either:
56
- - from the same repository (as opposed to npm modules)
57
- - or added to "package.json"`)
58
- }
59
-
60
- // Plugins can also set a minimal version using `engines.node`
61
- if (pluginNodeVersionRange && !satisfies(childNodeVersion, pluginNodeVersionRange)) {
62
- throwUserError(
63
- `The Node.js version is ${childNodeVersion} but the plugin "${package}" requires ${pluginNodeVersionRange}`,
64
- )
65
- }
66
- }
67
-
68
- const throwUserError = function(message) {
69
- const error = new Error(message)
70
- addErrorInfo(error, { type: 'resolveConfig' })
71
- throw error
72
- }
73
-
74
- module.exports = { getUserNodeVersion, getCurrentNodeVersion, checkNodeVersion }
@@ -1,78 +0,0 @@
1
- const { dirname } = require('path')
2
-
3
- const corePackageJson = require('../../package.json')
4
- const { checkDeprecatedFunctionsInstall } = require('../install/functions')
5
- const { installLocalPluginsDependencies } = require('../install/local')
6
- const { getCorePlugins, CORE_PLUGINS, EARLY_CORE_PLUGINS } = require('../plugins_core/main')
7
-
8
- const { useManifest } = require('./manifest/main')
9
- const { getPackageJson } = require('./package')
10
- const { resolvePluginsPath } = require('./resolve')
11
-
12
- // Load plugin options (specified by user in `config.plugins`)
13
- // Do not allow user override of core plugins
14
- const getPluginsOptions = async function({
15
- netlifyConfig: { plugins },
16
- buildDir,
17
- constants: { FUNCTIONS_SRC },
18
- mode,
19
- api,
20
- }) {
21
- const corePlugins = getCorePlugins(FUNCTIONS_SRC).map(addCoreProperties)
22
- const allCorePlugins = corePlugins.filter(corePlugin => !isOptionalCore(corePlugin, plugins))
23
- const userPlugins = plugins.filter(isUserPlugin)
24
- const pluginsOptions = [...allCorePlugins, ...userPlugins].map(normalizePluginOptions)
25
- const pluginsOptionsA = await resolvePluginsPath({ pluginsOptions, buildDir, mode })
26
- const pluginsOptionsB = await Promise.all(
27
- pluginsOptionsA.map(pluginOptions => loadPluginFiles({ pluginOptions, mode, api })),
28
- )
29
- await Promise.all([
30
- checkDeprecatedFunctionsInstall(plugins, FUNCTIONS_SRC, buildDir),
31
- installLocalPluginsDependencies({ plugins, pluginsOptions: pluginsOptionsB, buildDir, mode }),
32
- ])
33
- return pluginsOptionsB
34
- }
35
-
36
- const addCoreProperties = function(corePlugin) {
37
- return { ...corePlugin, loadedFrom: 'core', origin: 'core' }
38
- }
39
-
40
- // Optional core plugins requires user opt-in
41
- const isOptionalCore = function({ package, optional }, plugins) {
42
- return optional && plugins.every(plugin => plugin.package !== package)
43
- }
44
-
45
- const isUserPlugin = function({ package }) {
46
- return !CORE_PLUGINS.includes(package) && !EARLY_CORE_PLUGINS.includes(package)
47
- }
48
-
49
- const normalizePluginOptions = function({ package, pluginPath, loadedFrom, origin, inputs = {} }) {
50
- return { package, pluginPath, loadedFrom, origin, inputs }
51
- }
52
-
53
- // Retrieve plugin's main file path.
54
- // Then load plugin's `package.json` and `manifest.yml`.
55
- const loadPluginFiles = async function({ pluginOptions: { pluginPath, ...pluginOptions }, mode, api }) {
56
- const pluginDir = dirname(pluginPath)
57
- const { packageDir, packageJson } = await getPackageJson(pluginDir)
58
- const { manifest, inputs: inputsA } = await useManifest(pluginOptions, {
59
- pluginDir,
60
- packageDir,
61
- packageJson,
62
- mode,
63
- api,
64
- })
65
- return { ...pluginOptions, pluginPath, packageDir, packageJson, manifest, inputs: inputsA }
66
- }
67
-
68
- // Retrieve information about @netlify/build when an error happens there and not
69
- // in a plugin
70
- const getSpawnInfo = function() {
71
- const { name } = corePackageJson
72
- return {
73
- plugin: { package: name, packageJson: corePackageJson },
74
- location: { event: 'load', package: name, loadedFrom: 'core', origin: 'core' },
75
- }
76
- }
77
-
78
- module.exports = { getPluginsOptions, getSpawnInfo }
@@ -1,17 +0,0 @@
1
- const { dirname } = require('path')
2
-
3
- const readPkgUp = require('read-pkg-up')
4
-
5
- // Retrieve plugin's `package.json`
6
- const getPackageJson = async function(pluginDir) {
7
- const packageObj = await readPkgUp({ cwd: pluginDir })
8
- if (packageObj === undefined) {
9
- return { packageJson: {} }
10
- }
11
-
12
- const { path, packageJson } = packageObj
13
- const packageDir = dirname(path)
14
- return { packageDir, packageJson }
15
- }
16
-
17
- module.exports = { getPackageJson }
@@ -1,159 +0,0 @@
1
- const { resolve } = require('path')
2
- const { env } = require('process')
3
-
4
- const pathExists = require('path-exists')
5
-
6
- const { installMissingPlugins, getAutoPluginsDirPath } = require('../install/missing')
7
- // const { logMissingPluginsWarning } = require('../log/main')
8
- const { resolvePath } = require('../utils/resolve')
9
-
10
- // Try to find plugins in four places, by priority order:
11
- // - already loaded (core plugins)
12
- // - local plugin
13
- // - external plugin already installed in `node_modules`, most likely through `package.json`
14
- // - cached in the build image
15
- // - automatically installed by us (fallback)
16
- const resolvePluginsPath = async function({ pluginsOptions, buildDir, mode }) {
17
- const autoPluginsDir = getAutoPluginsDirPath(buildDir)
18
- const pluginsOptionsA = await Promise.all(
19
- pluginsOptions.map(pluginOptions => resolvePluginPath({ pluginOptions, buildDir, autoPluginsDir, mode })),
20
- )
21
- await installMissingPlugins({ pluginsOptions: pluginsOptionsA, autoPluginsDir, mode })
22
- const pluginsOptionsB = await Promise.all(
23
- pluginsOptionsA.map(pluginOptions => resolveMissingPluginPath({ pluginOptions, autoPluginsDir })),
24
- )
25
- warnOnMissingPlugins(pluginsOptionsB, mode)
26
- return pluginsOptionsB
27
- }
28
-
29
- const resolvePluginPath = async function({
30
- pluginOptions,
31
- pluginOptions: { package, loadedFrom },
32
- buildDir,
33
- autoPluginsDir,
34
- mode,
35
- }) {
36
- // Core plugins
37
- if (loadedFrom !== undefined) {
38
- return pluginOptions
39
- }
40
-
41
- // Local plugins
42
- if (package.startsWith('.') || package.startsWith('/')) {
43
- const localPath = resolve(buildDir, package)
44
- return { ...pluginOptions, pluginPath: localPath, loadedFrom: 'local' }
45
- }
46
-
47
- // Plugin already installed in the project, most likely either local plugins,
48
- // or external plugins added to `package.json`
49
- const manualPath = await tryResolvePath(package, buildDir)
50
- if (manualPath !== undefined) {
51
- return { ...pluginOptions, pluginPath: manualPath, loadedFrom: 'package.json' }
52
- }
53
-
54
- // Cached in the build image
55
- const buildImagePath = await tryBuildImagePath(package, mode, buildDir)
56
- if (buildImagePath !== undefined) {
57
- return { ...pluginOptions, pluginPath: buildImagePath, loadedFrom: 'image_cache' }
58
- }
59
-
60
- // Plugin previously automatically installed
61
- const automaticPath = await tryAutomaticPath(package, autoPluginsDir)
62
- if (automaticPath !== undefined) {
63
- return { ...pluginOptions, pluginPath: automaticPath, loadedFrom: 'auto_install' }
64
- }
65
-
66
- // Otherwise, it must be automatically installed, as a fallback
67
- return pluginOptions
68
- }
69
-
70
- // In production, we pre-install most Build plugins to that directory, for
71
- // performance reasons
72
- const tryBuildImagePath = async function(package, mode, buildDir) {
73
- if (mode !== 'buildbot') {
74
- return
75
- }
76
-
77
- const pluginsDir = getBuildImagePluginsDir()
78
- const buildImagePath = `${pluginsDir}/${package}`
79
- if (!(await pathExists(buildImagePath))) {
80
- return
81
- }
82
-
83
- return resolvePath(buildImagePath, buildDir)
84
- }
85
-
86
- const getBuildImagePluginsDir = function() {
87
- if (env.TEST_BUILD_IMAGE_PLUGINS_DIR) {
88
- return env.TEST_BUILD_IMAGE_PLUGINS_DIR
89
- }
90
-
91
- return BUILD_IMAGE_PLUGINS_DIR
92
- }
93
-
94
- const BUILD_IMAGE_PLUGINS_DIR = '/opt/buildhome/.netlify-build-plugins/node_modules'
95
-
96
- // Try to find plugin previously automatically installed
97
- const tryAutomaticPath = async function(package, autoPluginsDir) {
98
- if (!(await pathExists(autoPluginsDir))) {
99
- return
100
- }
101
-
102
- return tryResolvePath(package, autoPluginsDir)
103
- }
104
-
105
- // Try to `resolve()` the plugin from the build directory
106
- const tryResolvePath = async function(package, baseDir) {
107
- try {
108
- return await resolvePath(package, baseDir)
109
- } catch (error) {
110
- return
111
- }
112
- }
113
-
114
- // Resolve the plugins that just got automatically installed
115
- const resolveMissingPluginPath = async function({
116
- pluginOptions,
117
- pluginOptions: { package, pluginPath },
118
- autoPluginsDir,
119
- }) {
120
- if (pluginPath !== undefined) {
121
- return pluginOptions
122
- }
123
-
124
- const automaticPath = await resolvePath(package, autoPluginsDir)
125
- return { ...pluginOptions, pluginPath: automaticPath, loadedFrom: 'auto_install' }
126
- }
127
-
128
- // Warns when plugins have been automatically installed. This feature is a
129
- // fallback that should not be relied upon because:
130
- // - it is much slower
131
- // - npm can be unreliable
132
- // Warns both when installing the plugin, and when re-using it in a future build
133
- // Not done for local builds, since they cannot use the alternative
134
- // (build-image cached plugins).
135
- const warnOnMissingPlugins = function(pluginsOptions, mode) {
136
- if (mode !== 'buildbot') {
137
- return
138
- }
139
-
140
- const packages = pluginsOptions.filter(isAutomaticallyInstalled).map(getPackage)
141
- if (packages.length === 0) {
142
- return
143
- }
144
-
145
- // TODO: re-enable warning after the following are available:
146
- // - UI installs
147
- // - build-image pre-installed plugins
148
- // logMissingPluginsWarning(packages)
149
- }
150
-
151
- const isAutomaticallyInstalled = function({ loadedFrom }) {
152
- return loadedFrom === 'auto_install'
153
- }
154
-
155
- const getPackage = function({ package }) {
156
- return package
157
- }
158
-
159
- module.exports = { resolvePluginsPath }
@@ -1,82 +0,0 @@
1
- const { execPath } = require('process')
2
-
3
- const execa = require('execa')
4
-
5
- const { logLoadingPlugins } = require('../log/main')
6
-
7
- const { getEventFromChild } = require('./ipc')
8
- const { getUserNodeVersion, getCurrentNodeVersion, checkNodeVersion } = require('./node_version')
9
- const { getSpawnInfo } = require('./options')
10
-
11
- const CHILD_MAIN_FILE = `${__dirname}/child/main.js`
12
-
13
- // Start child processes used by all plugins
14
- // We fire plugins through child processes so that:
15
- // - each plugin is sandboxed, e.g. cannot access/modify its parent `process`
16
- // (for both security and safety reasons)
17
- // - logs can be buffered which allows manipulating them for log shipping,
18
- // transforming and parallel plugins
19
- const startPlugins = async function({ pluginsOptions, buildDir, nodePath, childEnv, mode }) {
20
- logLoadingPlugins(pluginsOptions)
21
-
22
- const spawnInfo = getSpawnInfo()
23
- const userNodeVersion = await getUserNodeVersion(nodePath)
24
- return Promise.all(
25
- pluginsOptions.map(({ package, packageJson, loadedFrom }) =>
26
- startPlugin({ buildDir, nodePath, childEnv, package, packageJson, loadedFrom, mode, spawnInfo, userNodeVersion }),
27
- ),
28
- )
29
- }
30
-
31
- const startPlugin = async function({
32
- buildDir,
33
- nodePath,
34
- childEnv,
35
- package,
36
- packageJson,
37
- loadedFrom,
38
- mode,
39
- spawnInfo,
40
- userNodeVersion,
41
- }) {
42
- const { childNodePath, childNodeVersion } = getChildNodePath({ loadedFrom, nodePath, userNodeVersion, mode })
43
-
44
- await checkNodeVersion({ childNodeVersion, package, packageJson })
45
-
46
- const childProcess = execa.node(CHILD_MAIN_FILE, {
47
- cwd: buildDir,
48
- preferLocal: true,
49
- nodePath: childNodePath,
50
- execPath: childNodePath,
51
- env: childEnv,
52
- extendEnv: false,
53
- })
54
- await getEventFromChild(childProcess, 'ready', spawnInfo)
55
- return { childProcess }
56
- }
57
-
58
- // Local plugins, `package.json`-installed plugins and local builds use user's
59
- // preferred Node.js version.
60
- // Other plugins use `@netlify/build` Node.js version.
61
- const getChildNodePath = function({ loadedFrom, nodePath, userNodeVersion, mode }) {
62
- if (loadedFrom === 'local' || loadedFrom === 'package.json' || (loadedFrom !== 'core' && mode !== 'buildbot')) {
63
- return { childNodePath: nodePath, childNodeVersion: userNodeVersion }
64
- }
65
-
66
- return { childNodePath: execPath, childNodeVersion: getCurrentNodeVersion() }
67
- }
68
-
69
- // Stop all plugins child processes
70
- const stopPlugins = async function(childProcesses) {
71
- await Promise.all(childProcesses.map(stopPlugin))
72
- }
73
-
74
- const stopPlugin = async function({ childProcess }) {
75
- if (childProcess.connected) {
76
- childProcess.disconnect()
77
- }
78
-
79
- childProcess.kill()
80
- }
81
-
82
- module.exports = { startPlugins, stopPlugins }
@@ -1 +0,0 @@
1
- name: '@netlify/plugin-cache-core'