@netlify/build 27.18.3 → 27.18.5-rc

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 (135) hide show
  1. package/package.json +10 -9
  2. package/src/core/bin.js +0 -83
  3. package/src/core/build.js +0 -559
  4. package/src/core/config.js +0 -186
  5. package/src/core/constants.js +0 -156
  6. package/src/core/dev.js +0 -31
  7. package/src/core/dry.js +0 -39
  8. package/src/core/feature_flags.js +0 -22
  9. package/src/core/flags.js +0 -204
  10. package/src/core/lingering.js +0 -85
  11. package/src/core/main.js +0 -165
  12. package/src/core/missing_side_file.js +0 -29
  13. package/src/core/normalize_flags.js +0 -70
  14. package/src/core/severity.js +0 -22
  15. package/src/core/user_node_version.js +0 -41
  16. package/src/env/changes.js +0 -52
  17. package/src/env/main.js +0 -19
  18. package/src/env/metadata.js +0 -81
  19. package/src/error/api.js +0 -46
  20. package/src/error/build.js +0 -50
  21. package/src/error/cancel.js +0 -8
  22. package/src/error/colors.js +0 -11
  23. package/src/error/handle.js +0 -57
  24. package/src/error/info.js +0 -46
  25. package/src/error/monitor/location.js +0 -21
  26. package/src/error/monitor/normalize.js +0 -96
  27. package/src/error/monitor/print.js +0 -42
  28. package/src/error/monitor/report.js +0 -138
  29. package/src/error/monitor/start.js +0 -69
  30. package/src/error/parse/clean_stack.js +0 -87
  31. package/src/error/parse/location.js +0 -62
  32. package/src/error/parse/normalize.js +0 -29
  33. package/src/error/parse/parse.js +0 -97
  34. package/src/error/parse/plugin.js +0 -70
  35. package/src/error/parse/properties.js +0 -23
  36. package/src/error/parse/serialize_log.js +0 -42
  37. package/src/error/parse/serialize_status.js +0 -23
  38. package/src/error/parse/stack.js +0 -43
  39. package/src/error/type.js +0 -189
  40. package/src/install/functions.js +0 -28
  41. package/src/install/local.js +0 -62
  42. package/src/install/main.js +0 -81
  43. package/src/install/missing.js +0 -67
  44. package/src/log/colors.js +0 -34
  45. package/src/log/description.js +0 -26
  46. package/src/log/header.js +0 -16
  47. package/src/log/header_func.js +0 -17
  48. package/src/log/logger.js +0 -161
  49. package/src/log/messages/compatibility.js +0 -178
  50. package/src/log/messages/config.js +0 -107
  51. package/src/log/messages/core.js +0 -70
  52. package/src/log/messages/core_steps.js +0 -104
  53. package/src/log/messages/dry.js +0 -63
  54. package/src/log/messages/install.js +0 -32
  55. package/src/log/messages/ipc.js +0 -38
  56. package/src/log/messages/mutations.js +0 -82
  57. package/src/log/messages/plugins.js +0 -39
  58. package/src/log/messages/status.js +0 -16
  59. package/src/log/messages/steps.js +0 -22
  60. package/src/log/old_version.js +0 -41
  61. package/src/log/serialize.js +0 -13
  62. package/src/log/stream.js +0 -85
  63. package/src/log/theme.js +0 -26
  64. package/src/plugins/child/diff.js +0 -55
  65. package/src/plugins/child/error.js +0 -32
  66. package/src/plugins/child/lazy.js +0 -18
  67. package/src/plugins/child/load.js +0 -29
  68. package/src/plugins/child/logic.js +0 -65
  69. package/src/plugins/child/main.js +0 -51
  70. package/src/plugins/child/run.js +0 -28
  71. package/src/plugins/child/status.js +0 -74
  72. package/src/plugins/child/typescript.js +0 -45
  73. package/src/plugins/child/utils.js +0 -56
  74. package/src/plugins/child/validate.js +0 -34
  75. package/src/plugins/compatibility.js +0 -132
  76. package/src/plugins/error.js +0 -50
  77. package/src/plugins/events.js +0 -17
  78. package/src/plugins/expected_version.js +0 -119
  79. package/src/plugins/ipc.js +0 -145
  80. package/src/plugins/list.js +0 -86
  81. package/src/plugins/load.js +0 -70
  82. package/src/plugins/manifest/check.js +0 -106
  83. package/src/plugins/manifest/load.js +0 -41
  84. package/src/plugins/manifest/main.js +0 -22
  85. package/src/plugins/manifest/path.js +0 -31
  86. package/src/plugins/manifest/validate.js +0 -108
  87. package/src/plugins/node_version.js +0 -50
  88. package/src/plugins/options.js +0 -88
  89. package/src/plugins/pinned_version.js +0 -131
  90. package/src/plugins/resolve.js +0 -152
  91. package/src/plugins/spawn.js +0 -72
  92. package/src/plugins_core/add.js +0 -49
  93. package/src/plugins_core/build_command.js +0 -75
  94. package/src/plugins_core/deploy/buildbot_client.js +0 -113
  95. package/src/plugins_core/deploy/index.js +0 -73
  96. package/src/plugins_core/deploy/manifest.yml +0 -1
  97. package/src/plugins_core/edge_functions/index.js +0 -123
  98. package/src/plugins_core/edge_functions/lib/error.js +0 -21
  99. package/src/plugins_core/edge_functions/lib/internal_manifest.js +0 -60
  100. package/src/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +0 -89
  101. package/src/plugins_core/functions/error.js +0 -163
  102. package/src/plugins_core/functions/feature_flags.js +0 -6
  103. package/src/plugins_core/functions/index.js +0 -161
  104. package/src/plugins_core/functions/utils.js +0 -66
  105. package/src/plugins_core/functions/zisi.js +0 -56
  106. package/src/plugins_core/functions_install/index.js +0 -13
  107. package/src/plugins_core/functions_install/manifest.yml +0 -1
  108. package/src/plugins_core/list.js +0 -27
  109. package/src/status/add.js +0 -36
  110. package/src/status/colors.js +0 -23
  111. package/src/status/load_error.js +0 -11
  112. package/src/status/report.js +0 -137
  113. package/src/status/success.js +0 -18
  114. package/src/steps/core_step.js +0 -92
  115. package/src/steps/error.js +0 -102
  116. package/src/steps/get.js +0 -51
  117. package/src/steps/plugin.js +0 -85
  118. package/src/steps/return.js +0 -52
  119. package/src/steps/run_core_steps.js +0 -200
  120. package/src/steps/run_step.js +0 -304
  121. package/src/steps/run_steps.js +0 -179
  122. package/src/steps/update_config.js +0 -93
  123. package/src/telemetry/main.js +0 -136
  124. package/src/time/aggregate.js +0 -146
  125. package/src/time/main.js +0 -48
  126. package/src/time/measure.js +0 -22
  127. package/src/time/report.js +0 -59
  128. package/src/utils/errors.js +0 -12
  129. package/src/utils/json.js +0 -19
  130. package/src/utils/omit.js +0 -6
  131. package/src/utils/package.js +0 -23
  132. package/src/utils/remove_falsy.js +0 -10
  133. package/src/utils/resolve.js +0 -46
  134. package/src/utils/runtime.js +0 -5
  135. package/src/utils/semver.js +0 -34
@@ -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,72 +0,0 @@
1
- import { fileURLToPath } from 'url'
2
-
3
- import { execaNode } from 'execa'
4
-
5
- import { addErrorInfo } from '../error/info.js'
6
- import {
7
- logRuntime,
8
- logLoadingPlugins,
9
- logOutdatedPlugins,
10
- logIncompatiblePlugins,
11
- } from '../log/messages/compatibility.js'
12
- import { measureDuration } from '../time/main.js'
13
-
14
- import { getEventFromChild } from './ipc.js'
15
- import { getSpawnInfo } from './options.js'
16
-
17
- const CHILD_MAIN_FILE = fileURLToPath(new URL('child/main.js', import.meta.url))
18
-
19
- // Start child processes used by all plugins
20
- // We fire plugins through child processes so that:
21
- // - each plugin is sandboxed, e.g. cannot access/modify its parent `process`
22
- // (for both security and safety reasons)
23
- // - logs can be buffered which allows manipulating them for log shipping,
24
- // transforming and parallel plugins
25
- const tStartPlugins = async function ({ pluginsOptions, buildDir, childEnv, logs, debug }) {
26
- logRuntime(logs, pluginsOptions)
27
- logLoadingPlugins(logs, pluginsOptions, debug)
28
- logOutdatedPlugins(logs, pluginsOptions)
29
- logIncompatiblePlugins(logs, pluginsOptions)
30
-
31
- const childProcesses = await Promise.all(
32
- pluginsOptions.map(({ pluginDir, nodePath }) => startPlugin({ pluginDir, nodePath, buildDir, childEnv })),
33
- )
34
- return { childProcesses }
35
- }
36
-
37
- export const startPlugins = measureDuration(tStartPlugins, 'start_plugins')
38
-
39
- const startPlugin = async function ({ pluginDir, nodePath, buildDir, childEnv }) {
40
- const childProcess = execaNode(CHILD_MAIN_FILE, {
41
- cwd: buildDir,
42
- preferLocal: true,
43
- localDir: pluginDir,
44
- nodePath,
45
- execPath: nodePath,
46
- env: childEnv,
47
- extendEnv: false,
48
- serialization: 'advanced',
49
- })
50
-
51
- try {
52
- await getEventFromChild(childProcess, 'ready')
53
- return { childProcess }
54
- } catch (error) {
55
- const spawnInfo = getSpawnInfo()
56
- addErrorInfo(error, spawnInfo)
57
- throw error
58
- }
59
- }
60
-
61
- // Stop all plugins child processes
62
- export const stopPlugins = function (childProcesses) {
63
- childProcesses.forEach(stopPlugin)
64
- }
65
-
66
- const stopPlugin = function ({ childProcess }) {
67
- if (childProcess.connected) {
68
- childProcess.disconnect()
69
- }
70
-
71
- childProcess.kill()
72
- }
@@ -1,49 +0,0 @@
1
- import { listCorePlugins, isCorePlugin } from './list.js'
2
-
3
- // Add core plugins and user plugins together.
4
- // Do not allow user override of core plugins.
5
- export const addCorePlugins = function ({ netlifyConfig: { plugins }, constants }) {
6
- const corePlugins = listCorePlugins(constants)
7
- const allCorePlugins = corePlugins
8
- .map((corePlugin) => addCoreProperties(corePlugin, plugins))
9
- .filter((corePlugin) => !isOptionalCore(corePlugin, plugins))
10
- const userPlugins = plugins.filter(isUserPlugin)
11
- const allPlugins = [...userPlugins, ...allCorePlugins]
12
- const pluginsOptions = allPlugins.map(normalizePluginOptions)
13
- return pluginsOptions
14
- }
15
-
16
- const addCoreProperties = function (corePlugin, plugins) {
17
- const inputs = getCorePluginInputs(corePlugin, plugins)
18
- return { ...corePlugin, inputs, loadedFrom: 'core', origin: 'core' }
19
- }
20
-
21
- // Core plugins can get inputs too
22
- const getCorePluginInputs = function (corePlugin, plugins) {
23
- const configuredCorePlugin = plugins.find((plugin) => plugin.package === corePlugin.package)
24
- if (configuredCorePlugin === undefined) {
25
- return {}
26
- }
27
-
28
- return configuredCorePlugin.inputs
29
- }
30
-
31
- // Optional core plugins requires user opt-in
32
- const isOptionalCore = function (pluginA, plugins) {
33
- return pluginA.optional && plugins.every((pluginB) => pluginB.package !== pluginA.package)
34
- }
35
-
36
- const isUserPlugin = function (plugin) {
37
- return !isCorePlugin(plugin.package)
38
- }
39
-
40
- const normalizePluginOptions = function ({
41
- package: packageName,
42
- pluginPath,
43
- pinned_version: pinnedVersion,
44
- loadedFrom,
45
- origin,
46
- inputs,
47
- }) {
48
- return { packageName, pluginPath, pinnedVersion, loadedFrom, origin, inputs }
49
- }