@netlify/build 27.20.3 → 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 +15 -8
@@ -1,31 +1,22 @@
1
- import process from 'process'
2
- import { promisify } from 'util'
3
-
4
- import { pEvent } from 'p-event'
5
- import { v4 as uuidv4 } from 'uuid'
6
-
7
- import { jsonToError, errorToJson } from '../error/build.js'
8
- import { addErrorInfo } from '../error/info.js'
9
- import {
10
- logSendingEventToChild,
11
- logSentEventToChild,
12
- logReceivedEventFromChild,
13
- logSendingEventToParent,
14
- } from '../log/messages/ipc.js'
15
-
1
+ import process from 'process';
2
+ import { promisify } from 'util';
3
+ import { pEvent } from 'p-event';
4
+ import { v4 as uuidv4 } from 'uuid';
5
+ import { jsonToError, errorToJson } from '../error/build.js';
6
+ import { addErrorInfo } from '../error/info.js';
7
+ import { logSendingEventToChild, logSentEventToChild, logReceivedEventFromChild, logSendingEventToParent, } from '../log/messages/ipc.js';
16
8
  // Send event from child to parent process then wait for response
17
9
  // We need to fire them in parallel because `process.send()` can be slow
18
10
  // to await, i.e. child might send response before parent start listening for it
19
11
  export const callChild = async function ({ childProcess, eventName, payload, logs, verbose }) {
20
- const callId = uuidv4()
21
- const [response] = await Promise.all([
22
- getEventFromChild(childProcess, callId),
23
- sendEventToChild({ childProcess, callId, eventName, payload, logs, verbose }),
24
- ])
25
- logReceivedEventFromChild(logs, verbose)
26
- return response
27
- }
28
-
12
+ const callId = uuidv4();
13
+ const [response] = await Promise.all([
14
+ getEventFromChild(childProcess, callId),
15
+ sendEventToChild({ childProcess, callId, eventName, payload, logs, verbose }),
16
+ ]);
17
+ logReceivedEventFromChild(logs, verbose);
18
+ return response;
19
+ };
29
20
  // Receive event from child to parent process
30
21
  // Wait for either:
31
22
  // - `message` event with a specific `callId`
@@ -35,41 +26,36 @@ export const callChild = async function ({ childProcess, eventName, payload, log
35
26
  // In the later two cases, we propagate the error.
36
27
  // We need to make `p-event` listeners are properly cleaned up too.
37
28
  export const getEventFromChild = async function (childProcess, callId) {
38
- if (childProcessHasExited(childProcess)) {
39
- throw getChildExitError('Could not receive event from child process because it already exited.')
40
- }
41
-
42
- const messagePromise = pEvent(childProcess, 'message', { filter: ([actualCallId]) => actualCallId === callId })
43
- const errorPromise = pEvent(childProcess, 'message', { filter: ([actualCallId]) => actualCallId === 'error' })
44
- const exitPromise = pEvent(childProcess, 'exit', { multiArgs: true })
45
- try {
46
- return await Promise.race([getMessage(messagePromise), getError(errorPromise), getExit(exitPromise)])
47
- } finally {
48
- messagePromise.cancel()
49
- errorPromise.cancel()
50
- exitPromise.cancel()
51
- }
52
- }
53
-
29
+ if (childProcessHasExited(childProcess)) {
30
+ throw getChildExitError('Could not receive event from child process because it already exited.');
31
+ }
32
+ const messagePromise = pEvent(childProcess, 'message', { filter: ([actualCallId]) => actualCallId === callId });
33
+ const errorPromise = pEvent(childProcess, 'message', { filter: ([actualCallId]) => actualCallId === 'error' });
34
+ const exitPromise = pEvent(childProcess, 'exit', { multiArgs: true });
35
+ try {
36
+ return await Promise.race([getMessage(messagePromise), getError(errorPromise), getExit(exitPromise)]);
37
+ }
38
+ finally {
39
+ messagePromise.cancel();
40
+ errorPromise.cancel();
41
+ exitPromise.cancel();
42
+ }
43
+ };
54
44
  const childProcessHasExited = function (childProcess) {
55
- return !childProcess.connected || childProcess.signalCode !== null || childProcess.exitCode !== null
56
- }
57
-
45
+ return !childProcess.connected || childProcess.signalCode !== null || childProcess.exitCode !== null;
46
+ };
58
47
  const getMessage = async function (messagePromise) {
59
- const [, response] = await messagePromise
60
- return response
61
- }
62
-
48
+ const [, response] = await messagePromise;
49
+ return response;
50
+ };
63
51
  const getError = async function (errorPromise) {
64
- const [, error] = await errorPromise
65
- throw jsonToError(error)
66
- }
67
-
52
+ const [, error] = await errorPromise;
53
+ throw jsonToError(error);
54
+ };
68
55
  const getExit = async function (exitPromise) {
69
- const [exitCode, signal] = await exitPromise
70
- throw getChildExitError(`Plugin exited with exit code ${exitCode} and signal ${signal}.`)
71
- }
72
-
56
+ const [exitCode, signal] = await exitPromise;
57
+ throw getChildExitError(`Plugin exited with exit code ${exitCode} and signal ${signal}.`);
58
+ };
73
59
  // Plugins should not terminate processes explicitly:
74
60
  // - It prevents specifying error messages to the end users
75
61
  // - It makes it impossible to distinguish between bugs (such as infinite loops) and user errors
@@ -77,67 +63,58 @@ const getExit = async function (exitPromise) {
77
63
  // of a previous event handler is still running, it would be aborted if another
78
64
  // is terminating the process.
79
65
  const getChildExitError = function (message) {
80
- const error = new Error(`${message}\n${EXIT_WARNING}`)
81
- addErrorInfo(error, { type: 'ipc' })
82
- return error
83
- }
84
-
66
+ const error = new Error(`${message}\n${EXIT_WARNING}`);
67
+ addErrorInfo(error, { type: 'ipc' });
68
+ return error;
69
+ };
85
70
  const EXIT_WARNING = `The plugin might have exited due to a bug terminating the process, such as an infinite loop.
86
71
  The plugin might also have explicitly terminated the process, for example with process.exit().
87
72
  Plugin methods should instead:
88
73
  - on success: return
89
- - on failure: call utils.build.failPlugin() or utils.build.failBuild()`
90
-
74
+ - on failure: call utils.build.failPlugin() or utils.build.failBuild()`;
91
75
  // Send event from parent to child process
92
76
  const sendEventToChild = async function ({ childProcess, callId, eventName, payload, logs, verbose }) {
93
- logSendingEventToChild(logs, verbose)
94
-
95
- const payloadA = serializePayload(payload)
96
- await promisify(childProcess.send.bind(childProcess))([callId, eventName, payloadA])
97
-
98
- logSentEventToChild(logs, verbose)
99
- }
100
-
77
+ logSendingEventToChild(logs, verbose);
78
+ const payloadA = serializePayload(payload);
79
+ await promisify(childProcess.send.bind(childProcess))([callId, eventName, payloadA]);
80
+ logSentEventToChild(logs, verbose);
81
+ };
101
82
  // Respond to events from parent to child process.
102
83
  // This runs forever until `childProcess.kill()` is called.
103
84
  // We need to use `new Promise()` and callbacks because this runs forever.
104
85
  export const getEventsFromParent = function (callback) {
105
- return new Promise((resolve, reject) => {
106
- process.on('message', async (message) => {
107
- try {
108
- const [callId, eventName, payload] = message
109
- const payloadA = parsePayload(payload)
110
- return await callback(callId, eventName, payloadA)
111
- } catch (error) {
112
- reject(error)
113
- }
114
- })
115
- })
116
- }
117
-
86
+ return new Promise((resolve, reject) => {
87
+ process.on('message', async (message) => {
88
+ try {
89
+ const [callId, eventName, payload] = message;
90
+ const payloadA = parsePayload(payload);
91
+ return await callback(callId, eventName, payloadA);
92
+ }
93
+ catch (error) {
94
+ reject(error);
95
+ }
96
+ });
97
+ });
98
+ };
118
99
  // Send event from child to parent process
119
100
  export const sendEventToParent = async function (callId, payload, verbose, error) {
120
- logSendingEventToParent(verbose, error)
121
- await promisify(process.send.bind(process))([callId, payload])
122
- }
123
-
101
+ logSendingEventToParent(verbose, error);
102
+ await promisify(process.send.bind(process))([callId, payload]);
103
+ };
124
104
  // Error static properties are not serializable through `child_process`
125
105
  // (which uses `v8.serialize()` under the hood) so we need to convert from/to
126
106
  // plain objects.
127
107
  const serializePayload = function ({ error = {}, error: { name } = {}, ...payload }) {
128
- if (name === undefined) {
129
- return payload
130
- }
131
-
132
- const errorA = errorToJson(error)
133
- return { ...payload, error: errorA }
134
- }
135
-
108
+ if (name === undefined) {
109
+ return payload;
110
+ }
111
+ const errorA = errorToJson(error);
112
+ return { ...payload, error: errorA };
113
+ };
136
114
  const parsePayload = function ({ error = {}, error: { name } = {}, ...payload }) {
137
- if (name === undefined) {
138
- return payload
139
- }
140
-
141
- const errorA = jsonToError(error)
142
- return { ...payload, error: errorA }
143
- }
115
+ if (name === undefined) {
116
+ return payload;
117
+ }
118
+ const errorA = jsonToError(error);
119
+ return { ...payload, error: errorA };
120
+ };
@@ -1,11 +1,8 @@
1
- import { pluginsUrl, pluginsList as oldPluginsList } from '@netlify/plugins-list'
2
- import got from 'got'
3
- import isPlainObj from 'is-plain-obj'
4
-
5
- import { logPluginsList, logPluginsFetchError } from '../log/messages/plugins.js'
6
-
7
- import { CONDITIONS } from './compatibility.js'
8
-
1
+ import { pluginsUrl, pluginsList as oldPluginsList } from '@netlify/plugins-list';
2
+ import got from 'got';
3
+ import isPlainObj from 'is-plain-obj';
4
+ import { logPluginsList, logPluginsFetchError } from '../log/messages/plugins.js';
5
+ import { CONDITIONS } from './compatibility.js';
9
6
  // Retrieve the list of plugins officially vetted by us and displayed in our
10
7
  // plugins directory UI.
11
8
  // We fetch this list during each build (no caching) because we want new
@@ -14,51 +11,44 @@ import { CONDITIONS } from './compatibility.js'
14
11
  // We only fetch this plugins list when needed, i.e. we defer it as much as
15
12
  // possible.
16
13
  export const getPluginsList = async function ({ debug, logs, testOpts: { pluginsListUrl } }) {
17
- // We try not to mock in integration tests. However, sending a request for
18
- // each test would be too slow and make tests unreliable.
19
- if (pluginsListUrl === 'test') {
20
- return []
21
- }
22
-
23
- const pluginsListUrlA = pluginsListUrl === undefined ? pluginsUrl : pluginsListUrl
24
- const pluginsList = await fetchPluginsList({ logs, pluginsListUrl: pluginsListUrlA })
25
- const pluginsListA = normalizePluginsList(pluginsList)
26
- logPluginsList({ pluginsList: pluginsListA, debug, logs })
27
- return pluginsListA
28
- }
29
-
14
+ // We try not to mock in integration tests. However, sending a request for
15
+ // each test would be too slow and make tests unreliable.
16
+ if (pluginsListUrl === 'test') {
17
+ return [];
18
+ }
19
+ const pluginsListUrlA = pluginsListUrl === undefined ? pluginsUrl : pluginsListUrl;
20
+ const pluginsList = await fetchPluginsList({ logs, pluginsListUrl: pluginsListUrlA });
21
+ const pluginsListA = normalizePluginsList(pluginsList);
22
+ logPluginsList({ pluginsList: pluginsListA, debug, logs });
23
+ return pluginsListA;
24
+ };
30
25
  const fetchPluginsList = async function ({ logs, pluginsListUrl }) {
31
- try {
32
- const { body } = await got(pluginsListUrl, { responseType: 'json', timeout: PLUGINS_LIST_TIMEOUT })
33
-
34
- if (!isValidPluginsList(body)) {
35
- throw new Error(`Request succeeded but with an invalid response:\n${JSON.stringify(body, null, 2)}`)
26
+ try {
27
+ const { body } = await got(pluginsListUrl, { responseType: 'json', timeout: PLUGINS_LIST_TIMEOUT });
28
+ if (!isValidPluginsList(body)) {
29
+ throw new Error(`Request succeeded but with an invalid response:\n${JSON.stringify(body, null, 2)}`);
30
+ }
31
+ return body;
32
+ // The Netlify Site should be up. This is a fallback.
33
+ // `oldPluginsList` might not contain the latest plugins versions:
34
+ // - We should do `npm publish` as soon as a PR is merged in
35
+ // `netlify/plugins` but it is possible we don't.
36
+ // - Releasing it requires a @netlify/buld release, which requires itself a
37
+ // buildbot release.
38
+ }
39
+ catch (error) {
40
+ logPluginsFetchError(logs, error.message);
41
+ return oldPluginsList;
36
42
  }
37
-
38
- return body
39
- // The Netlify Site should be up. This is a fallback.
40
- // `oldPluginsList` might not contain the latest plugins versions:
41
- // - We should do `npm publish` as soon as a PR is merged in
42
- // `netlify/plugins` but it is possible we don't.
43
- // - Releasing it requires a @netlify/buld release, which requires itself a
44
- // buildbot release.
45
- } catch (error) {
46
- logPluginsFetchError(logs, error.message)
47
- return oldPluginsList
48
- }
49
- }
50
-
43
+ };
51
44
  // 1 minute HTTP request timeout
52
- const PLUGINS_LIST_TIMEOUT = 6e4
53
-
45
+ const PLUGINS_LIST_TIMEOUT = 6e4;
54
46
  const isValidPluginsList = function (pluginsList) {
55
- return Array.isArray(pluginsList) && pluginsList.every(isPlainObj)
56
- }
57
-
47
+ return Array.isArray(pluginsList) && pluginsList.every(isPlainObj);
48
+ };
58
49
  const normalizePluginsList = function (pluginsList) {
59
- return Object.fromEntries(pluginsList.map(normalizePluginItem))
60
- }
61
-
50
+ return Object.fromEntries(pluginsList.map(normalizePluginItem));
51
+ };
62
52
  // `version` in `plugins.json` is the latest version.
63
53
  // A `compatibility` array of objects can be added to specify conditions to
64
54
  // apply different versions.
@@ -67,20 +57,17 @@ const normalizePluginsList = function (pluginsList) {
67
57
  // - Is sorted from the highest to lowest version.
68
58
  // - Does not include the latest `version`.
69
59
  const normalizePluginItem = function ({ package: packageName, version, compatibility = [] }) {
70
- const versions = compatibility.length === 0 ? [{ version }] : compatibility
71
- const versionsA = versions.map(normalizeCompatVersion)
72
- return [packageName, versionsA]
73
- }
74
-
60
+ const versions = compatibility.length === 0 ? [{ version }] : compatibility;
61
+ const versionsA = versions.map(normalizeCompatVersion);
62
+ return [packageName, versionsA];
63
+ };
75
64
  const normalizeCompatVersion = function ({ version, migrationGuide, featureFlag, ...otherProperties }) {
76
- const conditions = Object.entries(otherProperties).filter(isCondition).map(normalizeCondition)
77
- return { version, migrationGuide, featureFlag, conditions }
78
- }
79
-
65
+ const conditions = Object.entries(otherProperties).filter(isCondition).map(normalizeCondition);
66
+ return { version, migrationGuide, featureFlag, conditions };
67
+ };
80
68
  const isCondition = function ([type]) {
81
- return type in CONDITIONS
82
- }
83
-
69
+ return type in CONDITIONS;
70
+ };
84
71
  const normalizeCondition = function ([type, condition]) {
85
- return { type, condition }
86
- }
72
+ return { type, condition };
73
+ };
@@ -1,70 +1,50 @@
1
- import { addErrorInfo } from '../error/info.js'
2
- import { addPluginLoadErrorStatus } from '../status/load_error.js'
3
- import { measureDuration } from '../time/main.js'
4
-
5
- import { callChild } from './ipc.js'
6
-
1
+ import { addErrorInfo } from '../error/info.js';
2
+ import { addPluginLoadErrorStatus } from '../status/load_error.js';
3
+ import { measureDuration } from '../time/main.js';
4
+ import { callChild } from './ipc.js';
7
5
  // Retrieve all plugins steps
8
6
  // Can use either a module name or a file path to the plugin.
9
- export const loadPlugins = async function ({
10
- pluginsOptions,
11
- childProcesses,
12
- packageJson,
13
- timers,
14
- logs,
15
- debug,
16
- verbose,
17
- }) {
18
- return pluginsOptions.length === 0
19
- ? { pluginsSteps: [], timers }
20
- : await loadAllPlugins({ pluginsOptions, childProcesses, packageJson, timers, logs, debug, verbose })
21
- }
22
-
7
+ export const loadPlugins = async function ({ pluginsOptions, childProcesses, packageJson, timers, logs, debug, verbose, }) {
8
+ return pluginsOptions.length === 0
9
+ ? { pluginsSteps: [], timers }
10
+ : await loadAllPlugins({ pluginsOptions, childProcesses, packageJson, timers, logs, debug, verbose });
11
+ };
23
12
  const tLoadAllPlugins = async function ({ pluginsOptions, childProcesses, packageJson, logs, debug, verbose }) {
24
- const pluginsSteps = await Promise.all(
25
- pluginsOptions.map((pluginOptions, index) =>
26
- loadPlugin(pluginOptions, { childProcesses, index, packageJson, logs, debug, verbose }),
27
- ),
28
- )
29
- const pluginsStepsA = pluginsSteps.flat()
30
- return { pluginsSteps: pluginsStepsA }
31
- }
32
-
13
+ const pluginsSteps = await Promise.all(pluginsOptions.map((pluginOptions, index) => loadPlugin(pluginOptions, { childProcesses, index, packageJson, logs, debug, verbose })));
14
+ const pluginsStepsA = pluginsSteps.flat();
15
+ return { pluginsSteps: pluginsStepsA };
16
+ };
33
17
  // Only performed if there are some plugins
34
- const loadAllPlugins = measureDuration(tLoadAllPlugins, 'load_plugins')
35
-
18
+ const loadAllPlugins = measureDuration(tLoadAllPlugins, 'load_plugins');
36
19
  // Retrieve plugin steps for one plugin.
37
20
  // Do it by executing the plugin `load` event handler.
38
- const loadPlugin = async function (
39
- { packageName, pluginPackageJson, pluginPackageJson: { version } = {}, pluginPath, inputs, loadedFrom, origin },
40
- { childProcesses, index, packageJson, logs, debug, verbose },
41
- ) {
42
- const { childProcess } = childProcesses[index]
43
- const loadEvent = 'load'
44
-
45
- try {
46
- const { events } = await callChild({
47
- childProcess,
48
- eventName: 'load',
49
- payload: { pluginPath, inputs, packageJson, verbose },
50
- logs,
51
- verbose: false,
52
- })
53
- const pluginSteps = events.map((event) => ({
54
- event,
55
- packageName,
56
- loadedFrom,
57
- origin,
58
- pluginPackageJson,
59
- childProcess,
60
- }))
61
- return pluginSteps
62
- } catch (error) {
63
- addErrorInfo(error, {
64
- plugin: { packageName, pluginPackageJson },
65
- location: { event: loadEvent, packageName, loadedFrom, origin },
66
- })
67
- addPluginLoadErrorStatus({ error, packageName, version, debug })
68
- throw error
69
- }
70
- }
21
+ const loadPlugin = async function ({ packageName, pluginPackageJson, pluginPackageJson: { version } = {}, pluginPath, inputs, loadedFrom, origin }, { childProcesses, index, packageJson, logs, debug, verbose }) {
22
+ const { childProcess } = childProcesses[index];
23
+ const loadEvent = 'load';
24
+ try {
25
+ const { events } = await callChild({
26
+ childProcess,
27
+ eventName: 'load',
28
+ payload: { pluginPath, inputs, packageJson, verbose },
29
+ logs,
30
+ verbose: false,
31
+ });
32
+ const pluginSteps = events.map((event) => ({
33
+ event,
34
+ packageName,
35
+ loadedFrom,
36
+ origin,
37
+ pluginPackageJson,
38
+ childProcess,
39
+ }));
40
+ return pluginSteps;
41
+ }
42
+ catch (error) {
43
+ addErrorInfo(error, {
44
+ plugin: { packageName, pluginPackageJson },
45
+ location: { event: loadEvent, packageName, loadedFrom, origin },
46
+ });
47
+ addPluginLoadErrorStatus({ error, packageName, version, debug });
48
+ throw error;
49
+ }
50
+ };
@@ -1,106 +1,85 @@
1
- import { addErrorInfo } from '../../error/info.js'
2
- import { serializeObject } from '../../log/serialize.js'
3
- import { THEME } from '../../log/theme.js'
4
-
1
+ import { addErrorInfo } from '../../error/info.js';
2
+ import { serializeObject } from '../../log/serialize.js';
3
+ import { THEME } from '../../log/theme.js';
5
4
  // Check that plugin inputs match the validation specified in "manifest.yml"
6
5
  // Also assign default values
7
- export const checkInputs = function ({
8
- inputs,
9
- manifest: { inputs: rules = [] },
10
- packageName,
11
- pluginPackageJson,
12
- loadedFrom,
13
- origin,
14
- }) {
15
- try {
16
- const inputsA = addDefaults(inputs, rules)
17
- checkRequiredInputs({ inputs: inputsA, rules, packageName, pluginPackageJson, loadedFrom, origin })
18
- checkUnknownInputs({ inputs: inputsA, rules, packageName, pluginPackageJson, loadedFrom, origin })
19
- return inputsA
20
- } catch (error) {
21
- error.message = `${error.message}
6
+ export const checkInputs = function ({ inputs, manifest: { inputs: rules = [] }, packageName, pluginPackageJson, loadedFrom, origin, }) {
7
+ try {
8
+ const inputsA = addDefaults(inputs, rules);
9
+ checkRequiredInputs({ inputs: inputsA, rules, packageName, pluginPackageJson, loadedFrom, origin });
10
+ checkUnknownInputs({ inputs: inputsA, rules, packageName, pluginPackageJson, loadedFrom, origin });
11
+ return inputsA;
12
+ }
13
+ catch (error) {
14
+ error.message = `${error.message}
22
15
 
23
16
  ${THEME.errorSubHeader('Plugin inputs')}
24
- ${serializeObject(inputs)}`
25
- throw error
26
- }
27
- }
28
-
17
+ ${serializeObject(inputs)}`;
18
+ throw error;
19
+ }
20
+ };
29
21
  // Add "inputs[*].default"
30
22
  const addDefaults = function (inputs, rules) {
31
- const defaults = rules.filter(hasDefault).map(getDefault)
32
- return Object.assign({}, ...defaults, inputs)
33
- }
34
-
23
+ const defaults = rules.filter(hasDefault).map(getDefault);
24
+ return Object.assign({}, ...defaults, inputs);
25
+ };
35
26
  const hasDefault = function (rule) {
36
- return rule.default !== undefined
37
- }
38
-
27
+ return rule.default !== undefined;
28
+ };
39
29
  const getDefault = function ({ name, default: defaultValue }) {
40
- return { [name]: defaultValue }
41
- }
42
-
30
+ return { [name]: defaultValue };
31
+ };
43
32
  // Check "inputs[*].required"
44
33
  const checkRequiredInputs = function ({ inputs, rules, packageName, pluginPackageJson, loadedFrom, origin }) {
45
- const missingInputs = rules.filter((rule) => isMissingRequired(inputs, rule))
46
- if (missingInputs.length === 0) {
47
- return
48
- }
49
-
50
- const names = missingInputs.map(getName)
51
- const error = new Error(`Required inputs for plugin "${packageName}": ${names.join(', ')}`)
52
- addInputError({ error, name: names[0], packageName, pluginPackageJson, loadedFrom, origin })
53
- throw error
54
- }
55
-
34
+ const missingInputs = rules.filter((rule) => isMissingRequired(inputs, rule));
35
+ if (missingInputs.length === 0) {
36
+ return;
37
+ }
38
+ const names = missingInputs.map(getName);
39
+ const error = new Error(`Required inputs for plugin "${packageName}": ${names.join(', ')}`);
40
+ addInputError({ error, name: names[0], packageName, pluginPackageJson, loadedFrom, origin });
41
+ throw error;
42
+ };
56
43
  const isMissingRequired = function (inputs, { name, required }) {
57
- return required && inputs[name] === undefined
58
- }
59
-
44
+ return required && inputs[name] === undefined;
45
+ };
60
46
  const getName = function ({ name }) {
61
- return name
62
- }
63
-
47
+ return name;
48
+ };
64
49
  // Check each "inputs[*].*" property for a specific input
65
50
  const checkUnknownInputs = function ({ inputs, rules, packageName, pluginPackageJson, loadedFrom, origin }) {
66
- const knownInputs = rules.map(getName)
67
- const unknownInputs = Object.keys(inputs).filter((name) => !knownInputs.includes(name))
68
- if (unknownInputs.length === 0) {
69
- return
70
- }
71
-
72
- const unknownInputsMessage = getUnknownInputsMessage({ packageName, knownInputs, unknownInputs })
73
- const error = new Error(`${unknownInputsMessage}
51
+ const knownInputs = rules.map(getName);
52
+ const unknownInputs = Object.keys(inputs).filter((name) => !knownInputs.includes(name));
53
+ if (unknownInputs.length === 0) {
54
+ return;
55
+ }
56
+ const unknownInputsMessage = getUnknownInputsMessage({ packageName, knownInputs, unknownInputs });
57
+ const error = new Error(`${unknownInputsMessage}
74
58
  Check your plugin configuration to be sure that:
75
59
  - the input name is spelled correctly
76
60
  - the input is included in the plugin's available configuration options
77
- - the plugin's input requirements have not changed`)
78
- const [name] = unknownInputs
79
- addInputError({ error, name, packageName, pluginPackageJson, loadedFrom, origin })
80
- throw error
81
- }
82
-
61
+ - the plugin's input requirements have not changed`);
62
+ const [name] = unknownInputs;
63
+ addInputError({ error, name, packageName, pluginPackageJson, loadedFrom, origin });
64
+ throw error;
65
+ };
83
66
  const getUnknownInputsMessage = function ({ packageName, knownInputs, unknownInputs }) {
84
- const unknownInputsStr = unknownInputs.map(quoteWord).join(', ')
85
-
86
- if (knownInputs.length === 0) {
87
- return `Plugin "${packageName}" does not accept any inputs but you specified: ${unknownInputsStr}`
88
- }
89
-
90
- const knownInputsStr = knownInputs.map(quoteWord).join(', ')
91
- return `Unknown inputs for plugin "${packageName}": ${unknownInputsStr}
92
- Plugin inputs should be one of: ${knownInputsStr}`
93
- }
94
-
67
+ const unknownInputsStr = unknownInputs.map(quoteWord).join(', ');
68
+ if (knownInputs.length === 0) {
69
+ return `Plugin "${packageName}" does not accept any inputs but you specified: ${unknownInputsStr}`;
70
+ }
71
+ const knownInputsStr = knownInputs.map(quoteWord).join(', ');
72
+ return `Unknown inputs for plugin "${packageName}": ${unknownInputsStr}
73
+ Plugin inputs should be one of: ${knownInputsStr}`;
74
+ };
95
75
  const quoteWord = function (word) {
96
- return `"${word}"`
97
- }
98
-
76
+ return `"${word}"`;
77
+ };
99
78
  // Add error information
100
79
  const addInputError = function ({ error, name, packageName, pluginPackageJson, loadedFrom, origin }) {
101
- addErrorInfo(error, {
102
- type: 'pluginInput',
103
- plugin: { packageName, pluginPackageJson },
104
- location: { event: 'load', packageName, input: name, loadedFrom, origin },
105
- })
106
- }
80
+ addErrorInfo(error, {
81
+ type: 'pluginInput',
82
+ plugin: { packageName, pluginPackageJson },
83
+ location: { event: 'load', packageName, input: name, loadedFrom, origin },
84
+ });
85
+ };