@netlify/build 27.20.4 → 27.20.5

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 (133) hide show
  1. package/lib/core/bin.js +42 -59
  2. package/lib/core/build.js +333 -536
  3. package/lib/core/config.js +94 -159
  4. package/lib/core/constants.js +95 -135
  5. package/lib/core/dev.js +26 -30
  6. package/lib/core/dry.js +18 -36
  7. package/lib/core/feature_flags.js +13 -16
  8. package/lib/core/flags.js +168 -169
  9. package/lib/core/lingering.js +44 -61
  10. package/lib/core/main.js +94 -136
  11. package/lib/core/missing_side_file.js +12 -24
  12. package/lib/core/normalize_flags.js +52 -63
  13. package/lib/core/severity.js +13 -15
  14. package/lib/core/user_node_version.js +26 -35
  15. package/lib/env/changes.js +29 -37
  16. package/lib/env/main.js +10 -15
  17. package/lib/env/metadata.js +63 -76
  18. package/lib/error/api.js +31 -40
  19. package/lib/error/build.js +27 -38
  20. package/lib/error/cancel.js +5 -6
  21. package/lib/error/colors.js +7 -9
  22. package/lib/error/handle.js +38 -49
  23. package/lib/error/info.js +26 -35
  24. package/lib/error/monitor/location.js +12 -17
  25. package/lib/error/monitor/normalize.js +75 -85
  26. package/lib/error/monitor/print.js +19 -41
  27. package/lib/error/monitor/report.js +102 -121
  28. package/lib/error/monitor/start.js +43 -56
  29. package/lib/error/parse/clean_stack.js +52 -69
  30. package/lib/error/parse/location.js +40 -52
  31. package/lib/error/parse/normalize.js +18 -23
  32. package/lib/error/parse/parse.js +59 -93
  33. package/lib/error/parse/plugin.js +42 -57
  34. package/lib/error/parse/properties.js +13 -20
  35. package/lib/error/parse/serialize_log.js +29 -37
  36. package/lib/error/parse/serialize_status.js +15 -23
  37. package/lib/error/parse/stack.js +29 -38
  38. package/lib/error/type.js +132 -150
  39. package/lib/install/functions.js +16 -24
  40. package/lib/install/local.js +31 -48
  41. package/lib/install/main.js +52 -66
  42. package/lib/install/missing.js +40 -53
  43. package/lib/log/colors.js +15 -22
  44. package/lib/log/description.js +16 -21
  45. package/lib/log/header.js +11 -13
  46. package/lib/log/header_func.js +11 -15
  47. package/lib/log/logger.js +88 -119
  48. package/lib/log/messages/compatibility.js +100 -158
  49. package/lib/log/messages/config.js +76 -92
  50. package/lib/log/messages/core.js +40 -60
  51. package/lib/log/messages/core_steps.js +63 -92
  52. package/lib/log/messages/dry.js +31 -53
  53. package/lib/log/messages/install.js +21 -28
  54. package/lib/log/messages/ipc.js +21 -30
  55. package/lib/log/messages/mutations.js +51 -71
  56. package/lib/log/messages/plugins.js +18 -31
  57. package/lib/log/messages/status.js +12 -14
  58. package/lib/log/messages/steps.js +14 -18
  59. package/lib/log/old_version.js +23 -32
  60. package/lib/log/serialize.js +7 -10
  61. package/lib/log/stream.js +48 -65
  62. package/lib/log/theme.js +22 -23
  63. package/lib/plugins/child/diff.js +31 -40
  64. package/lib/plugins/child/error.js +20 -26
  65. package/lib/plugins/child/lazy.js +11 -14
  66. package/lib/plugins/child/load.js +15 -22
  67. package/lib/plugins/child/logic.js +51 -58
  68. package/lib/plugins/child/main.js +32 -46
  69. package/lib/plugins/child/run.js +18 -27
  70. package/lib/plugins/child/status.js +52 -63
  71. package/lib/plugins/child/typescript.js +19 -36
  72. package/lib/plugins/child/utils.js +36 -49
  73. package/lib/plugins/child/validate.js +25 -28
  74. package/lib/plugins/compatibility.js +64 -92
  75. package/lib/plugins/error.js +29 -35
  76. package/lib/plugins/events.js +7 -12
  77. package/lib/plugins/expected_version.js +61 -99
  78. package/lib/plugins/ipc.js +79 -102
  79. package/lib/plugins/list.js +49 -62
  80. package/lib/plugins/load.js +44 -64
  81. package/lib/plugins/manifest/check.js +64 -85
  82. package/lib/plugins/manifest/load.js +34 -37
  83. package/lib/plugins/manifest/main.js +16 -21
  84. package/lib/plugins/manifest/path.js +18 -25
  85. package/lib/plugins/manifest/validate.js +77 -94
  86. package/lib/plugins/node_version.js +22 -42
  87. package/lib/plugins/options.js +45 -78
  88. package/lib/plugins/pinned_version.js +58 -106
  89. package/lib/plugins/resolve.js +91 -133
  90. package/lib/plugins/spawn.js +43 -61
  91. package/lib/plugins_core/add.js +26 -40
  92. package/lib/plugins_core/build_command.js +47 -72
  93. package/lib/plugins_core/deploy/buildbot_client.js +61 -87
  94. package/lib/plugins_core/deploy/index.js +47 -71
  95. package/lib/plugins_core/edge_functions/index.js +73 -116
  96. package/lib/plugins_core/edge_functions/lib/error.js +13 -17
  97. package/lib/plugins_core/edge_functions/lib/internal_manifest.js +45 -55
  98. package/lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +65 -80
  99. package/lib/plugins_core/functions/error.js +88 -128
  100. package/lib/plugins_core/functions/feature_flags.js +5 -5
  101. package/lib/plugins_core/functions/index.js +98 -145
  102. package/lib/plugins_core/functions/utils.js +36 -57
  103. package/lib/plugins_core/functions/zisi.js +35 -52
  104. package/lib/plugins_core/functions_install/index.js +8 -11
  105. package/lib/plugins_core/list.js +15 -22
  106. package/lib/status/add.js +26 -32
  107. package/lib/status/colors.js +14 -19
  108. package/lib/status/load_error.js +8 -9
  109. package/lib/status/report.js +72 -126
  110. package/lib/status/success.js +10 -14
  111. package/lib/steps/core_step.js +54 -89
  112. package/lib/steps/error.js +50 -87
  113. package/lib/steps/get.js +33 -41
  114. package/lib/steps/plugin.js +53 -83
  115. package/lib/steps/return.js +24 -51
  116. package/lib/steps/run_core_steps.js +119 -171
  117. package/lib/steps/run_step.js +154 -270
  118. package/lib/steps/run_steps.js +91 -174
  119. package/lib/steps/update_config.js +45 -72
  120. package/lib/telemetry/main.js +89 -128
  121. package/lib/time/aggregate.js +84 -110
  122. package/lib/time/main.js +23 -34
  123. package/lib/time/measure.js +11 -15
  124. package/lib/time/report.js +32 -44
  125. package/lib/utils/errors.js +10 -9
  126. package/lib/utils/json.js +11 -15
  127. package/lib/utils/omit.js +3 -4
  128. package/lib/utils/package.js +19 -22
  129. package/lib/utils/remove_falsy.js +5 -7
  130. package/lib/utils/resolve.js +30 -34
  131. package/lib/utils/runtime.js +4 -4
  132. package/lib/utils/semver.js +19 -25
  133. package/package.json +13 -6
@@ -1,65 +1,41 @@
1
- import { handleBuildError } from '../error/handle.js'
2
- import { getMajorVersion } from '../utils/semver.js'
3
-
1
+ import { handleBuildError } from '../error/handle.js';
2
+ import { getMajorVersion } from '../utils/semver.js';
4
3
  // Retrieve plugin's pinned major versions by fetching the latest `PluginRun`
5
4
  // Only applies to `netlify.toml`-only installed plugins.
6
5
  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
-
6
+ if (!sendStatus || api === undefined || !siteId) {
7
+ return pluginsOptions;
8
+ }
9
+ const packages = pluginsOptions.filter(shouldFetchPinVersion).map(getPackageName);
10
+ if (packages.length === 0) {
11
+ return pluginsOptions;
12
+ }
13
+ const pluginRuns = await api.getLatestPluginRuns({ site_id: siteId, packages, state: 'success' });
14
+ const pluginsOptionsA = pluginsOptions.map((pluginOption) => addPinnedVersion(pluginOption, pluginRuns));
15
+ return pluginsOptionsA;
16
+ };
21
17
  const shouldFetchPinVersion = function ({ pinnedVersion, loadedFrom, origin }) {
22
- return pinnedVersion === undefined && loadedFrom === 'auto_install' && origin === 'config'
23
- }
24
-
18
+ return pinnedVersion === undefined && loadedFrom === 'auto_install' && origin === 'config';
19
+ };
25
20
  const getPackageName = function ({ packageName }) {
26
- return packageName
27
- }
28
-
21
+ return packageName;
22
+ };
29
23
  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
-
24
+ const foundPluginRun = pluginRuns.find((pluginRun) => pluginRun.package === pluginOptions.packageName);
25
+ if (foundPluginRun === undefined) {
26
+ return pluginOptions;
27
+ }
28
+ const pinnedVersion = getMajorVersion(foundPluginRun.version);
29
+ return pinnedVersion === undefined ? pluginOptions : { ...pluginOptions, pinnedVersion };
30
+ };
39
31
  // Send an API request to pin plugins' major versions.
40
32
  // 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({
33
+ export const pinPlugins = async function ({ pluginsOptions, failedPlugins, api, siteInfo: { id: siteId }, childEnv, mode, netlifyConfig, errorMonitor, logs, debug, testOpts, sendStatus, }) {
34
+ if ((mode !== 'buildbot' && !sendStatus) || api === undefined || !siteId) {
35
+ return;
36
+ }
37
+ const pluginsOptionsA = pluginsOptions.filter((pluginOptions) => shouldPinVersion({ pluginOptions, failedPlugins }));
38
+ await Promise.all(pluginsOptionsA.map((pluginOptions) => pinPlugin({
63
39
  pluginOptions,
64
40
  api,
65
41
  childEnv,
@@ -70,62 +46,38 @@ export const pinPlugins = async function ({
70
46
  debug,
71
47
  testOpts,
72
48
  siteId,
73
- }),
74
- ),
75
- )
76
- }
77
-
49
+ })));
50
+ };
78
51
  // Only pin version if:
79
52
  // - the plugin's version has not been pinned yet
80
53
  // - the plugin was installed in the UI
81
54
  // - 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
55
+ const shouldPinVersion = function ({ pluginOptions: { packageName, pinnedVersion, loadedFrom, origin }, failedPlugins, }) {
56
+ return (pinnedVersion === undefined &&
57
+ loadedFrom === 'auto_install' &&
58
+ origin === 'ui' &&
59
+ !failedPlugins.includes(packageName));
60
+ };
61
+ const pinPlugin = async function ({ pluginOptions: { packageName, pluginPackageJson: { version }, }, api, childEnv, mode, netlifyConfig, errorMonitor, logs, debug, testOpts, siteId, }) {
62
+ const pinnedVersion = getMajorVersion(version);
63
+ try {
64
+ await api.updatePlugin({
65
+ package: encodeURIComponent(packageName),
66
+ site_id: siteId,
67
+ body: { pinned_version: pinnedVersion },
68
+ });
69
+ // Bitballoon API randomly fails with 502.
70
+ // Builds should be successful when this API call fails, but we still want
71
+ // to report the error both in logs and in error monitoring.
72
+ }
73
+ catch (error) {
74
+ if (shouldIgnoreError(error)) {
75
+ return;
76
+ }
77
+ await handleBuildError(error, { errorMonitor, netlifyConfig, childEnv, mode, logs, debug, testOpts });
122
78
  }
123
-
124
- await handleBuildError(error, { errorMonitor, netlifyConfig, childEnv, mode, logs, debug, testOpts })
125
- }
126
- }
127
-
79
+ };
128
80
  // Status is 404 if the plugin is uninstalled while the build is ongoing.
129
81
  const shouldIgnoreError = function ({ status }) {
130
- return status === 404
131
- }
82
+ return status === 404;
83
+ };
@@ -1,152 +1,110 @@
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
-
1
+ import { addErrorInfo } from '../error/info.js';
2
+ import { installMissingPlugins } from '../install/missing.js';
3
+ import { resolvePath, tryResolvePath } from '../utils/resolve.js';
4
+ import { addExpectedVersions } from './expected_version.js';
5
+ import { addPluginsNodeVersion } from './node_version.js';
6
+ import { addPinnedVersions } from './pinned_version.js';
9
7
  // Try to find plugins in four places, by priority order:
10
8
  // - already loaded (core plugins)
11
9
  // - local plugin
12
10
  // - external plugin already installed in `node_modules`, most likely through `package.json`
13
11
  // - 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
-
12
+ export const resolvePluginsPath = async function ({ pluginsOptions, siteInfo, buildDir, nodePath, packageJson, userNodeVersion, mode, api, logs, debug, sendStatus, testOpts, featureFlags, }) {
13
+ const autoPluginsDir = getAutoPluginsDir(buildDir);
14
+ const pluginsOptionsA = await Promise.all(pluginsOptions.map((pluginOptions) => resolvePluginPath({ pluginOptions, buildDir, autoPluginsDir })));
15
+ const pluginsOptionsB = addPluginsNodeVersion({
16
+ pluginsOptions: pluginsOptionsA,
17
+ nodePath,
18
+ userNodeVersion,
19
+ logs,
20
+ });
21
+ const pluginsOptionsC = await addPinnedVersions({ pluginsOptions: pluginsOptionsB, api, siteInfo, sendStatus });
22
+ const pluginsOptionsD = await addExpectedVersions({
23
+ pluginsOptions: pluginsOptionsC,
24
+ autoPluginsDir,
25
+ packageJson,
26
+ debug,
27
+ logs,
28
+ buildDir,
29
+ testOpts,
30
+ featureFlags,
31
+ });
32
+ const pluginsOptionsE = await handleMissingPlugins({
33
+ pluginsOptions: pluginsOptionsD,
34
+ autoPluginsDir,
35
+ mode,
36
+ logs,
37
+ });
38
+ return pluginsOptionsE;
39
+ };
59
40
  // Find the path to the directory used to install plugins automatically.
60
41
  // It is a subdirectory of `buildDir`, so that the plugin can require the
61
42
  // project's dependencies (peer dependencies).
62
43
  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
-
44
+ return `${buildDir}/${AUTO_PLUGINS_DIR}`;
45
+ };
46
+ const AUTO_PLUGINS_DIR = '.netlify/plugins/';
47
+ const resolvePluginPath = async function ({ pluginOptions, pluginOptions: { packageName, loadedFrom }, buildDir, autoPluginsDir, }) {
48
+ // Core plugins
49
+ if (loadedFrom !== undefined) {
50
+ return pluginOptions;
51
+ }
52
+ const localPackageName = normalizeLocalPackageName(packageName);
53
+ // Local plugins
54
+ if (localPackageName.startsWith('.')) {
55
+ const { path: localPath, error } = await tryResolvePath(localPackageName, buildDir);
56
+ validateLocalPluginPath(error, localPackageName);
57
+ return { ...pluginOptions, pluginPath: localPath, loadedFrom: 'local' };
58
+ }
59
+ // Plugin added to `package.json`
60
+ const { path: manualPath } = await tryResolvePath(packageName, buildDir);
61
+ if (manualPath !== undefined) {
62
+ return { ...pluginOptions, pluginPath: manualPath, loadedFrom: 'package.json' };
63
+ }
64
+ // Previously automatically installed
65
+ const { path: automaticPath } = await tryResolvePath(packageName, autoPluginsDir);
66
+ if (automaticPath !== undefined) {
67
+ return { ...pluginOptions, pluginPath: automaticPath, loadedFrom: 'auto_install' };
68
+ }
69
+ // Happens if the plugin:
70
+ // - name is mispelled
71
+ // - is not in our official list
72
+ // - is in our official list but has not been installed by this site yet
73
+ return { ...pluginOptions, loadedFrom: 'auto_install' };
74
+ };
107
75
  // `packageName` starting with `/` are relative to the build directory
108
76
  const normalizeLocalPackageName = function (packageName) {
109
- if (packageName.startsWith('/')) {
110
- return `.${packageName}`
111
- }
112
-
113
- return packageName
114
- }
115
-
77
+ if (packageName.startsWith('/')) {
78
+ return `.${packageName}`;
79
+ }
80
+ return packageName;
81
+ };
116
82
  // When requiring a local plugin with an invalid file path
117
83
  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
-
84
+ if (error !== undefined) {
85
+ error.message = `Plugin could not be found using local path: ${localPackageName}\n${error.message}`;
86
+ addErrorInfo(error, { type: 'resolveConfig' });
87
+ throw error;
88
+ }
89
+ };
125
90
  // Install plugins from the official list that have not been previously installed.
126
91
  // Print a warning if they have not been installed through the UI.
127
92
  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
-
93
+ const missingPlugins = pluginsOptions.filter(isMissingPlugin);
94
+ if (missingPlugins.length === 0) {
95
+ return pluginsOptions;
96
+ }
97
+ await installMissingPlugins({ missingPlugins, autoPluginsDir, mode, logs });
98
+ return await Promise.all(pluginsOptions.map((pluginOptions) => resolveMissingPluginPath({ pluginOptions, autoPluginsDir })));
99
+ };
140
100
  // Resolve the plugins that just got automatically installed
141
101
  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
-
102
+ if (!isMissingPlugin(pluginOptions)) {
103
+ return pluginOptions;
104
+ }
105
+ const pluginPath = await resolvePath(packageName, autoPluginsDir);
106
+ return { ...pluginOptions, pluginPath };
107
+ };
150
108
  const isMissingPlugin = function ({ isMissing }) {
151
- return isMissing
152
- }
109
+ return isMissing;
110
+ };
@@ -1,21 +1,11 @@
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
-
1
+ import { fileURLToPath } from 'url';
2
+ import { execaNode } from 'execa';
3
+ import { addErrorInfo } from '../error/info.js';
4
+ import { logRuntime, logLoadingPlugins, logOutdatedPlugins, logIncompatiblePlugins, } from '../log/messages/compatibility.js';
5
+ import { measureDuration } from '../time/main.js';
6
+ import { getEventFromChild } from './ipc.js';
7
+ import { getSpawnInfo } from './options.js';
8
+ const CHILD_MAIN_FILE = fileURLToPath(new URL('child/main.js', import.meta.url));
19
9
  // Start child processes used by all plugins
20
10
  // We fire plugins through child processes so that:
21
11
  // - each plugin is sandboxed, e.g. cannot access/modify its parent `process`
@@ -23,50 +13,42 @@ const CHILD_MAIN_FILE = fileURLToPath(new URL('child/main.js', import.meta.url))
23
13
  // - logs can be buffered which allows manipulating them for log shipping,
24
14
  // transforming and parallel plugins
25
15
  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
-
16
+ logRuntime(logs, pluginsOptions);
17
+ logLoadingPlugins(logs, pluginsOptions, debug);
18
+ logOutdatedPlugins(logs, pluginsOptions);
19
+ logIncompatiblePlugins(logs, pluginsOptions);
20
+ const childProcesses = await Promise.all(pluginsOptions.map(({ pluginDir, nodePath }) => startPlugin({ pluginDir, nodePath, buildDir, childEnv })));
21
+ return { childProcesses };
22
+ };
23
+ export const startPlugins = measureDuration(tStartPlugins, 'start_plugins');
39
24
  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
-
25
+ const childProcess = execaNode(CHILD_MAIN_FILE, {
26
+ cwd: buildDir,
27
+ preferLocal: true,
28
+ localDir: pluginDir,
29
+ nodePath,
30
+ execPath: nodePath,
31
+ env: childEnv,
32
+ extendEnv: false,
33
+ serialization: 'advanced',
34
+ });
35
+ try {
36
+ await getEventFromChild(childProcess, 'ready');
37
+ return { childProcess };
38
+ }
39
+ catch (error) {
40
+ const spawnInfo = getSpawnInfo();
41
+ addErrorInfo(error, spawnInfo);
42
+ throw error;
43
+ }
44
+ };
61
45
  // Stop all plugins child processes
62
46
  export const stopPlugins = function (childProcesses) {
63
- childProcesses.forEach(stopPlugin)
64
- }
65
-
47
+ childProcesses.forEach(stopPlugin);
48
+ };
66
49
  const stopPlugin = function ({ childProcess }) {
67
- if (childProcess.connected) {
68
- childProcess.disconnect()
69
- }
70
-
71
- childProcess.kill()
72
- }
50
+ if (childProcess.connected) {
51
+ childProcess.disconnect();
52
+ }
53
+ childProcess.kill();
54
+ };
@@ -1,49 +1,35 @@
1
- import { listCorePlugins, isCorePlugin } from './list.js'
2
-
1
+ import { listCorePlugins, isCorePlugin } from './list.js';
3
2
  // Add core plugins and user plugins together.
4
3
  // Do not allow user override of core plugins.
5
4
  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
-
5
+ const corePlugins = listCorePlugins(constants);
6
+ const allCorePlugins = corePlugins
7
+ .map((corePlugin) => addCoreProperties(corePlugin, plugins))
8
+ .filter((corePlugin) => !isOptionalCore(corePlugin, plugins));
9
+ const userPlugins = plugins.filter(isUserPlugin);
10
+ const allPlugins = [...userPlugins, ...allCorePlugins];
11
+ const pluginsOptions = allPlugins.map(normalizePluginOptions);
12
+ return pluginsOptions;
13
+ };
16
14
  const addCoreProperties = function (corePlugin, plugins) {
17
- const inputs = getCorePluginInputs(corePlugin, plugins)
18
- return { ...corePlugin, inputs, loadedFrom: 'core', origin: 'core' }
19
- }
20
-
15
+ const inputs = getCorePluginInputs(corePlugin, plugins);
16
+ return { ...corePlugin, inputs, loadedFrom: 'core', origin: 'core' };
17
+ };
21
18
  // Core plugins can get inputs too
22
19
  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
-
20
+ const configuredCorePlugin = plugins.find((plugin) => plugin.package === corePlugin.package);
21
+ if (configuredCorePlugin === undefined) {
22
+ return {};
23
+ }
24
+ return configuredCorePlugin.inputs;
25
+ };
31
26
  // Optional core plugins requires user opt-in
32
27
  const isOptionalCore = function (pluginA, plugins) {
33
- return pluginA.optional && plugins.every((pluginB) => pluginB.package !== pluginA.package)
34
- }
35
-
28
+ return pluginA.optional && plugins.every((pluginB) => pluginB.package !== pluginA.package);
29
+ };
36
30
  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
- }
31
+ return !isCorePlugin(plugin.package);
32
+ };
33
+ const normalizePluginOptions = function ({ package: packageName, pluginPath, pinned_version: pinnedVersion, loadedFrom, origin, inputs, }) {
34
+ return { packageName, pluginPath, pinnedVersion, loadedFrom, origin, inputs };
35
+ };