@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.
- package/lib/core/bin.js +42 -59
- package/lib/core/build.js +333 -536
- package/lib/core/config.js +94 -159
- package/lib/core/constants.js +95 -135
- package/lib/core/dev.js +26 -30
- package/lib/core/dry.js +18 -36
- package/lib/core/feature_flags.js +13 -16
- package/lib/core/flags.js +168 -169
- package/lib/core/lingering.js +44 -61
- package/lib/core/main.js +94 -136
- package/lib/core/missing_side_file.js +12 -24
- package/lib/core/normalize_flags.js +52 -63
- package/lib/core/severity.js +13 -15
- package/lib/core/user_node_version.js +26 -35
- package/lib/env/changes.js +29 -37
- package/lib/env/main.js +10 -15
- package/lib/env/metadata.js +63 -76
- package/lib/error/api.js +31 -40
- package/lib/error/build.js +27 -38
- package/lib/error/cancel.js +5 -6
- package/lib/error/colors.js +7 -9
- package/lib/error/handle.js +38 -49
- package/lib/error/info.js +26 -35
- package/lib/error/monitor/location.js +12 -17
- package/lib/error/monitor/normalize.js +75 -85
- package/lib/error/monitor/print.js +19 -41
- package/lib/error/monitor/report.js +102 -121
- package/lib/error/monitor/start.js +43 -56
- package/lib/error/parse/clean_stack.js +52 -69
- package/lib/error/parse/location.js +40 -52
- package/lib/error/parse/normalize.js +18 -23
- package/lib/error/parse/parse.js +59 -93
- package/lib/error/parse/plugin.js +42 -57
- package/lib/error/parse/properties.js +13 -20
- package/lib/error/parse/serialize_log.js +29 -37
- package/lib/error/parse/serialize_status.js +15 -23
- package/lib/error/parse/stack.js +29 -38
- package/lib/error/type.js +132 -150
- package/lib/install/functions.js +16 -24
- package/lib/install/local.js +31 -48
- package/lib/install/main.js +52 -66
- package/lib/install/missing.js +40 -53
- package/lib/log/colors.js +15 -22
- package/lib/log/description.js +16 -21
- package/lib/log/header.js +11 -13
- package/lib/log/header_func.js +11 -15
- package/lib/log/logger.js +88 -119
- package/lib/log/messages/compatibility.js +100 -158
- package/lib/log/messages/config.js +76 -92
- package/lib/log/messages/core.js +40 -60
- package/lib/log/messages/core_steps.js +63 -92
- package/lib/log/messages/dry.js +31 -53
- package/lib/log/messages/install.js +21 -28
- package/lib/log/messages/ipc.js +21 -30
- package/lib/log/messages/mutations.js +51 -71
- package/lib/log/messages/plugins.js +18 -31
- package/lib/log/messages/status.js +12 -14
- package/lib/log/messages/steps.js +14 -18
- package/lib/log/old_version.js +23 -32
- package/lib/log/serialize.js +7 -10
- package/lib/log/stream.js +48 -65
- package/lib/log/theme.js +22 -23
- package/lib/plugins/child/diff.js +31 -40
- package/lib/plugins/child/error.js +20 -26
- package/lib/plugins/child/lazy.js +11 -14
- package/lib/plugins/child/load.js +15 -22
- package/lib/plugins/child/logic.js +51 -58
- package/lib/plugins/child/main.js +32 -46
- package/lib/plugins/child/run.js +18 -27
- package/lib/plugins/child/status.js +52 -63
- package/lib/plugins/child/typescript.js +19 -36
- package/lib/plugins/child/utils.js +36 -49
- package/lib/plugins/child/validate.js +25 -28
- package/lib/plugins/compatibility.js +64 -92
- package/lib/plugins/error.js +29 -35
- package/lib/plugins/events.js +7 -12
- package/lib/plugins/expected_version.js +61 -99
- package/lib/plugins/ipc.js +79 -102
- package/lib/plugins/list.js +49 -62
- package/lib/plugins/load.js +44 -64
- package/lib/plugins/manifest/check.js +64 -85
- package/lib/plugins/manifest/load.js +34 -37
- package/lib/plugins/manifest/main.js +16 -21
- package/lib/plugins/manifest/path.js +18 -25
- package/lib/plugins/manifest/validate.js +77 -94
- package/lib/plugins/node_version.js +22 -42
- package/lib/plugins/options.js +45 -78
- package/lib/plugins/pinned_version.js +58 -106
- package/lib/plugins/resolve.js +91 -133
- package/lib/plugins/spawn.js +43 -61
- package/lib/plugins_core/add.js +26 -40
- package/lib/plugins_core/build_command.js +47 -72
- package/lib/plugins_core/deploy/buildbot_client.js +61 -87
- package/lib/plugins_core/deploy/index.js +47 -71
- package/lib/plugins_core/edge_functions/index.js +73 -116
- package/lib/plugins_core/edge_functions/lib/error.js +13 -17
- package/lib/plugins_core/edge_functions/lib/internal_manifest.js +45 -55
- package/lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +65 -80
- package/lib/plugins_core/functions/error.js +88 -128
- package/lib/plugins_core/functions/feature_flags.js +5 -5
- package/lib/plugins_core/functions/index.js +98 -145
- package/lib/plugins_core/functions/utils.js +36 -57
- package/lib/plugins_core/functions/zisi.js +35 -52
- package/lib/plugins_core/functions_install/index.js +8 -11
- package/lib/plugins_core/list.js +15 -22
- package/lib/status/add.js +26 -32
- package/lib/status/colors.js +14 -19
- package/lib/status/load_error.js +8 -9
- package/lib/status/report.js +72 -126
- package/lib/status/success.js +10 -14
- package/lib/steps/core_step.js +54 -89
- package/lib/steps/error.js +50 -87
- package/lib/steps/get.js +33 -41
- package/lib/steps/plugin.js +53 -83
- package/lib/steps/return.js +24 -51
- package/lib/steps/run_core_steps.js +119 -171
- package/lib/steps/run_step.js +154 -270
- package/lib/steps/run_steps.js +91 -174
- package/lib/steps/update_config.js +45 -72
- package/lib/telemetry/main.js +89 -128
- package/lib/time/aggregate.js +84 -110
- package/lib/time/main.js +23 -34
- package/lib/time/measure.js +11 -15
- package/lib/time/report.js +32 -44
- package/lib/utils/errors.js +10 -9
- package/lib/utils/json.js +11 -15
- package/lib/utils/omit.js +3 -4
- package/lib/utils/package.js +19 -22
- package/lib/utils/remove_falsy.js +5 -7
- package/lib/utils/resolve.js +30 -34
- package/lib/utils/runtime.js +4 -4
- package/lib/utils/semver.js +19 -25
- package/package.json +15 -8
package/lib/plugins/ipc.js
CHANGED
|
@@ -1,31 +1,22 @@
|
|
|
1
|
-
import process from 'process'
|
|
2
|
-
import { promisify } from 'util'
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import {
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
45
|
+
return !childProcess.connected || childProcess.signalCode !== null || childProcess.exitCode !== null;
|
|
46
|
+
};
|
|
58
47
|
const getMessage = async function (messagePromise) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
48
|
+
const [, response] = await messagePromise;
|
|
49
|
+
return response;
|
|
50
|
+
};
|
|
63
51
|
const getError = async function (errorPromise) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
52
|
+
const [, error] = await errorPromise;
|
|
53
|
+
throw jsonToError(error);
|
|
54
|
+
};
|
|
68
55
|
const getExit = async function (exitPromise) {
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
121
|
-
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
115
|
+
if (name === undefined) {
|
|
116
|
+
return payload;
|
|
117
|
+
}
|
|
118
|
+
const errorA = jsonToError(error);
|
|
119
|
+
return { ...payload, error: errorA };
|
|
120
|
+
};
|
package/lib/plugins/list.js
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
47
|
+
return Array.isArray(pluginsList) && pluginsList.every(isPlainObj);
|
|
48
|
+
};
|
|
58
49
|
const normalizePluginsList = function (pluginsList) {
|
|
59
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
77
|
-
|
|
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
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
69
|
+
return type in CONDITIONS;
|
|
70
|
+
};
|
|
84
71
|
const normalizeCondition = function ([type, condition]) {
|
|
85
|
-
|
|
86
|
-
}
|
|
72
|
+
return { type, condition };
|
|
73
|
+
};
|
package/lib/plugins/load.js
CHANGED
|
@@ -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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
17
|
+
${serializeObject(inputs)}`;
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
29
21
|
// Add "inputs[*].default"
|
|
30
22
|
const addDefaults = function (inputs, rules) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
23
|
+
const defaults = rules.filter(hasDefault).map(getDefault);
|
|
24
|
+
return Object.assign({}, ...defaults, inputs);
|
|
25
|
+
};
|
|
35
26
|
const hasDefault = function (rule) {
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
27
|
+
return rule.default !== undefined;
|
|
28
|
+
};
|
|
39
29
|
const getDefault = function ({ name, default: defaultValue }) {
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
30
|
+
return { [name]: defaultValue };
|
|
31
|
+
};
|
|
43
32
|
// Check "inputs[*].required"
|
|
44
33
|
const checkRequiredInputs = function ({ inputs, rules, packageName, pluginPackageJson, loadedFrom, origin }) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
44
|
+
return required && inputs[name] === undefined;
|
|
45
|
+
};
|
|
60
46
|
const getName = function ({ name }) {
|
|
61
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
76
|
+
return `"${word}"`;
|
|
77
|
+
};
|
|
99
78
|
// Add error information
|
|
100
79
|
const addInputError = function ({ error, name, packageName, pluginPackageJson, loadedFrom, origin }) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
80
|
+
addErrorInfo(error, {
|
|
81
|
+
type: 'pluginInput',
|
|
82
|
+
plugin: { packageName, pluginPackageJson },
|
|
83
|
+
location: { event: 'load', packageName, input: name, loadedFrom, origin },
|
|
84
|
+
});
|
|
85
|
+
};
|