@netlify/build 27.20.4 → 27.20.6
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 +14 -7
package/lib/log/old_version.js
CHANGED
|
@@ -1,41 +1,32 @@
|
|
|
1
|
-
import { stdout } from 'process'
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import { ROOT_PACKAGE_JSON } from '../utils/json.js'
|
|
6
|
-
|
|
1
|
+
import { stdout } from 'process';
|
|
2
|
+
import UpdateNotifier from 'update-notifier';
|
|
3
|
+
import { ROOT_PACKAGE_JSON } from '../utils/json.js';
|
|
7
4
|
// Many build errors happen in local builds that do not use the latest version
|
|
8
5
|
// of `@netlify/build`. We print a warning message on those.
|
|
9
6
|
// We only print this when Netlify CLI has been used. Programmatic usage might
|
|
10
7
|
// come from a deep dependency calling `@netlify/build` and user might not be
|
|
11
8
|
// able to take any upgrade action, making the message noisy.
|
|
12
9
|
export const logOldCliVersionError = function ({ mode, testOpts }) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
10
|
+
if (mode !== 'cli') {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const corePackageJson = getCorePackageJson(testOpts);
|
|
14
|
+
UpdateNotifier({ pkg: corePackageJson, updateCheckInterval: 1 }).notify({
|
|
15
|
+
message: OLD_VERSION_MESSAGE,
|
|
16
|
+
shouldNotifyInNpmScript: true,
|
|
17
|
+
});
|
|
18
|
+
};
|
|
24
19
|
const getCorePackageJson = function (testOpts) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return ROOT_PACKAGE_JSON
|
|
37
|
-
}
|
|
38
|
-
|
|
20
|
+
// TODO: Find a way to test this without injecting code in the `src/`
|
|
21
|
+
if (testOpts.oldCliLogs) {
|
|
22
|
+
// `update-notifier` does not do anything if not in a TTY.
|
|
23
|
+
// In tests, we need to monkey patch this
|
|
24
|
+
// Mutation is required due to how `stdout.isTTY` works
|
|
25
|
+
stdout.isTTY = true;
|
|
26
|
+
return { ...ROOT_PACKAGE_JSON, version: '0.0.1' };
|
|
27
|
+
}
|
|
28
|
+
return ROOT_PACKAGE_JSON;
|
|
29
|
+
};
|
|
39
30
|
const OLD_VERSION_MESSAGE = `Please update netlify-cli to its latest version.
|
|
40
31
|
If netlify-cli is already the latest version,
|
|
41
|
-
please update your dependencies lock file instead
|
|
32
|
+
please update your dependencies lock file instead.`;
|
package/lib/log/serialize.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import { dump } from 'js-yaml'
|
|
2
|
-
|
|
1
|
+
import { dump } from 'js-yaml';
|
|
3
2
|
export const serializeObject = function (object) {
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
3
|
+
return dump(object, { noRefs: true, sortKeys: true, lineWidth: Number.POSITIVE_INFINITY }).trimEnd();
|
|
4
|
+
};
|
|
7
5
|
export const serializeArray = function (array) {
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
6
|
+
return array.map(addDash).join('\n');
|
|
7
|
+
};
|
|
11
8
|
const addDash = function (string) {
|
|
12
|
-
|
|
13
|
-
}
|
|
9
|
+
return ` - ${string}`;
|
|
10
|
+
};
|
package/lib/log/stream.js
CHANGED
|
@@ -1,85 +1,68 @@
|
|
|
1
|
-
import { stdout, stderr } from 'process'
|
|
2
|
-
import { promisify } from 'util'
|
|
3
|
-
|
|
1
|
+
import { stdout, stderr } from 'process';
|
|
2
|
+
import { promisify } from 'util';
|
|
4
3
|
// TODO: replace with `timers/promises` after dropping Node < 15.0.0
|
|
5
|
-
const pSetTimeout = promisify(setTimeout)
|
|
6
|
-
|
|
4
|
+
const pSetTimeout = promisify(setTimeout);
|
|
7
5
|
// We try to use `stdio: inherit` because it keeps `stdout/stderr` as `TTY`,
|
|
8
6
|
// which solves many problems. However we can only do it in build.command.
|
|
9
7
|
// Plugins have several events, so need to be switch on and off instead.
|
|
10
8
|
// In buffer mode (`logs` not `undefined`), `pipe` is necessary.
|
|
11
9
|
export const getBuildCommandStdio = function (logs) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
10
|
+
if (logs !== undefined) {
|
|
11
|
+
return 'pipe';
|
|
12
|
+
}
|
|
13
|
+
return 'inherit';
|
|
14
|
+
};
|
|
19
15
|
// Add build command output
|
|
20
16
|
export const handleBuildCommandOutput = function ({ stdout: commandStdout, stderr: commandStderr }, logs) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
17
|
+
if (logs === undefined) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
pushBuildCommandOutput(commandStdout, logs.stdout);
|
|
21
|
+
pushBuildCommandOutput(commandStderr, logs.stderr);
|
|
22
|
+
};
|
|
29
23
|
const pushBuildCommandOutput = function (output, logsArray) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
24
|
+
if (output === '') {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
logsArray.push(output);
|
|
28
|
+
};
|
|
37
29
|
// Start plugin step output
|
|
38
30
|
export const pipePluginOutput = function (childProcess, logs) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
31
|
+
if (logs === undefined) {
|
|
32
|
+
return streamOutput(childProcess);
|
|
33
|
+
}
|
|
34
|
+
return pushOutputToLogs(childProcess, logs);
|
|
35
|
+
};
|
|
46
36
|
// Stop streaming/buffering plugin step output
|
|
47
37
|
export const unpipePluginOutput = async function (childProcess, logs, listeners) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
unpushOutputToLogs(childProcess, logs, listeners)
|
|
56
|
-
}
|
|
57
|
-
|
|
38
|
+
// Let `childProcess` `stdout` and `stderr` flush before stopping redirecting
|
|
39
|
+
await pSetTimeout(0);
|
|
40
|
+
if (logs === undefined) {
|
|
41
|
+
return unstreamOutput(childProcess);
|
|
42
|
+
}
|
|
43
|
+
unpushOutputToLogs(childProcess, logs, listeners);
|
|
44
|
+
};
|
|
58
45
|
// Usually, we stream stdout/stderr because it is more efficient
|
|
59
46
|
const streamOutput = function (childProcess) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
47
|
+
childProcess.stdout.pipe(stdout);
|
|
48
|
+
childProcess.stderr.pipe(stderr);
|
|
49
|
+
};
|
|
64
50
|
const unstreamOutput = function (childProcess) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
51
|
+
childProcess.stdout.unpipe(stdout);
|
|
52
|
+
childProcess.stderr.unpipe(stderr);
|
|
53
|
+
};
|
|
69
54
|
// In tests, we push to the `logs` array instead
|
|
70
55
|
const pushOutputToLogs = function (childProcess, logs) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
56
|
+
const stdoutListener = logsListener.bind(null, logs.stdout);
|
|
57
|
+
const stderrListener = logsListener.bind(null, logs.stderr);
|
|
58
|
+
childProcess.stdout.on('data', stdoutListener);
|
|
59
|
+
childProcess.stderr.on('data', stderrListener);
|
|
60
|
+
return { stdoutListener, stderrListener };
|
|
61
|
+
};
|
|
78
62
|
const logsListener = function (logs, chunk) {
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
63
|
+
logs.push(chunk.toString().trimEnd());
|
|
64
|
+
};
|
|
82
65
|
const unpushOutputToLogs = function (childProcess, logs, { stdoutListener, stderrListener }) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
66
|
+
childProcess.stdout.removeListener('data', stdoutListener);
|
|
67
|
+
childProcess.stderr.removeListener('data', stderrListener);
|
|
68
|
+
};
|
package/lib/log/theme.js
CHANGED
|
@@ -1,26 +1,25 @@
|
|
|
1
|
-
import chalk from 'chalk'
|
|
2
|
-
|
|
1
|
+
import chalk from 'chalk';
|
|
3
2
|
// Color theme. Please use this instead of requiring chalk directly, to ensure
|
|
4
3
|
// consistent colors.
|
|
5
4
|
export const THEME = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
5
|
+
// Main headers
|
|
6
|
+
header: chalk.cyanBright.bold,
|
|
7
|
+
// Single lines used as subheaders
|
|
8
|
+
subHeader: chalk.cyan.bold,
|
|
9
|
+
// One of several words that should be highlighted inside a line
|
|
10
|
+
highlightWords: chalk.cyan,
|
|
11
|
+
// Same for errors
|
|
12
|
+
errorHeader: chalk.redBright.bold,
|
|
13
|
+
errorSubHeader: chalk.red.bold,
|
|
14
|
+
errorLine: chalk.redBright,
|
|
15
|
+
errorHighlightWords: chalk.redBright.bold,
|
|
16
|
+
// Same for warnings
|
|
17
|
+
warningHeader: chalk.yellowBright.bold,
|
|
18
|
+
warningSubHeader: chalk.yellow.bold,
|
|
19
|
+
warningLine: chalk.yellowBright,
|
|
20
|
+
warningHighlightWords: chalk.yellowBright.bold,
|
|
21
|
+
// One of several words that should be dimmed inside a line
|
|
22
|
+
dimWords: chalk.gray,
|
|
23
|
+
// No colors
|
|
24
|
+
none: (string) => string,
|
|
25
|
+
};
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import { isDeepStrictEqual } from 'util'
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const clone = rfdc()
|
|
7
|
-
|
|
1
|
+
import { isDeepStrictEqual } from 'util';
|
|
2
|
+
import isPlainObj from 'is-plain-obj';
|
|
3
|
+
import rfdc from 'rfdc';
|
|
4
|
+
const clone = rfdc();
|
|
8
5
|
// Copy `netlifyConfig` so we can compare before/after mutating it
|
|
9
6
|
export const cloneNetlifyConfig = function (netlifyConfig) {
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
7
|
+
return clone(netlifyConfig);
|
|
8
|
+
};
|
|
13
9
|
// Diff `netlifyConfig` before and after mutating it to retrieve an array of
|
|
14
10
|
// `configMutations` objects.
|
|
15
11
|
// We need to keep track of the changes on `netlifyConfig` so they can be
|
|
@@ -19,37 +15,32 @@ export const cloneNetlifyConfig = function (netlifyConfig) {
|
|
|
19
15
|
// run `@netlify/config` to normalize and validate the new values
|
|
20
16
|
// `configMutations` is passed to parent process as JSON
|
|
21
17
|
export const getConfigMutations = function (netlifyConfig, netlifyConfigCopy, event) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
18
|
+
const configMutations = diffObjects(netlifyConfig, netlifyConfigCopy, []);
|
|
19
|
+
return configMutations.map((configMutation) => getConfigMutation(configMutation, event));
|
|
20
|
+
};
|
|
26
21
|
// We only recurse over plain objects, not arrays. Which means array properties
|
|
27
22
|
// can only be modified all at once.
|
|
28
23
|
const diffObjects = function (objA, objB, parentKeys) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return [{ keys, value: valueB }]
|
|
44
|
-
})
|
|
45
|
-
}
|
|
46
|
-
|
|
24
|
+
const allKeys = [...new Set([...Object.keys(objA), ...Object.keys(objB)])];
|
|
25
|
+
return allKeys.flatMap((key) => {
|
|
26
|
+
const valueA = objA[key];
|
|
27
|
+
const valueB = objB[key];
|
|
28
|
+
const keys = [...parentKeys, key];
|
|
29
|
+
if (isPlainObj(valueA) && isPlainObj(valueB)) {
|
|
30
|
+
return diffObjects(valueA, valueB, keys);
|
|
31
|
+
}
|
|
32
|
+
if (isDeepStrictEqual(valueA, valueB)) {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
return [{ keys, value: valueB }];
|
|
36
|
+
});
|
|
37
|
+
};
|
|
47
38
|
const getConfigMutation = function ({ keys, value }, event) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
39
|
+
const serializedKeys = keys.map(String);
|
|
40
|
+
return {
|
|
41
|
+
keys: serializedKeys,
|
|
42
|
+
keysString: serializedKeys.join('.'),
|
|
43
|
+
value,
|
|
44
|
+
event,
|
|
45
|
+
};
|
|
46
|
+
};
|
|
@@ -1,32 +1,26 @@
|
|
|
1
|
-
import logProcessErrors from 'log-process-errors'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { sendEventToParent } from '../ipc.js'
|
|
7
|
-
|
|
1
|
+
import logProcessErrors from 'log-process-errors';
|
|
2
|
+
import { errorToJson } from '../../error/build.js';
|
|
3
|
+
import { addDefaultErrorInfo, isBuildError } from '../../error/info.js';
|
|
4
|
+
import { normalizeError } from '../../error/parse/normalize.js';
|
|
5
|
+
import { sendEventToParent } from '../ipc.js';
|
|
8
6
|
// Handle any top-level error and communicate it back to parent
|
|
9
7
|
export const handleError = async function (error, verbose) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
8
|
+
const errorA = normalizeError(error);
|
|
9
|
+
addDefaultErrorInfo(errorA, { type: 'pluginInternal' });
|
|
10
|
+
const errorPayload = errorToJson(errorA);
|
|
11
|
+
await sendEventToParent('error', errorPayload, verbose, errorA);
|
|
12
|
+
};
|
|
16
13
|
// On uncaught exceptions and unhandled rejections, print the stack trace.
|
|
17
14
|
// Also, prevent child processes from crashing on uncaught exceptions.
|
|
18
15
|
export const handleProcessErrors = function () {
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
16
|
+
logProcessErrors({ log: handleProcessError, exitOn: [] });
|
|
17
|
+
};
|
|
22
18
|
const handleProcessError = async function (error, level, originalError) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
await handleError(errorA)
|
|
32
|
-
}
|
|
19
|
+
if (level !== 'error') {
|
|
20
|
+
console[level](error);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
// Do not use log-process-errors prettification with errors thrown by `utils.build.*`
|
|
24
|
+
const errorA = isBuildError(originalError) ? originalError : error;
|
|
25
|
+
await handleError(errorA);
|
|
26
|
+
};
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import memoizeOne from 'memoize-one'
|
|
2
|
-
|
|
1
|
+
import memoizeOne from 'memoize-one';
|
|
3
2
|
// Add a `object[propName]` whose value is the return value of `getFunc()`, but
|
|
4
3
|
// is only retrieved when accessed.
|
|
5
4
|
export const addLazyProp = function (object, propName, getFunc) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
5
|
+
const mGetFunc = memoizeOne(getFunc, returnTrue);
|
|
6
|
+
// Mutation is required due to the usage of `Object.defineProperty()`
|
|
7
|
+
Object.defineProperty(object, propName, {
|
|
8
|
+
get: mGetFunc,
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
});
|
|
12
|
+
};
|
|
16
13
|
const returnTrue = function () {
|
|
17
|
-
|
|
18
|
-
}
|
|
14
|
+
return true;
|
|
15
|
+
};
|
|
@@ -1,29 +1,22 @@
|
|
|
1
|
-
import filterObj from 'filter-obj'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { validatePlugin } from './validate.js'
|
|
6
|
-
|
|
1
|
+
import filterObj from 'filter-obj';
|
|
2
|
+
import { getLogic } from './logic.js';
|
|
3
|
+
import { registerTypeScript } from './typescript.js';
|
|
4
|
+
import { validatePlugin } from './validate.js';
|
|
7
5
|
// Load context passed to every plugin method.
|
|
8
6
|
// This also requires the plugin file and fire its top-level function.
|
|
9
7
|
// This also validates the plugin.
|
|
10
8
|
// Do it when parent requests it using the `load` event.
|
|
11
9
|
// Also figure out the list of plugin steps. This is also passed to the parent.
|
|
12
10
|
export const load = async function ({ pluginPath, inputs, packageJson, verbose }) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const context = { methods, inputs, packageJson, verbose }
|
|
23
|
-
|
|
24
|
-
return { events, context }
|
|
25
|
-
}
|
|
26
|
-
|
|
11
|
+
const tsNodeService = registerTypeScript(pluginPath);
|
|
12
|
+
const logic = await getLogic({ pluginPath, inputs, tsNodeService });
|
|
13
|
+
validatePlugin(logic);
|
|
14
|
+
const methods = filterObj(logic, isEventHandler);
|
|
15
|
+
const events = Object.keys(methods);
|
|
16
|
+
// Context passed to every event handler
|
|
17
|
+
const context = { methods, inputs, packageJson, verbose };
|
|
18
|
+
return { events, context };
|
|
19
|
+
};
|
|
27
20
|
const isEventHandler = function (event, value) {
|
|
28
|
-
|
|
29
|
-
}
|
|
21
|
+
return typeof value === 'function';
|
|
22
|
+
};
|
|
@@ -1,64 +1,57 @@
|
|
|
1
|
-
import { createRequire } from 'module'
|
|
2
|
-
import { pathToFileURL } from 'url'
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import { addTsErrorInfo } from './typescript.js'
|
|
8
|
-
|
|
9
|
-
const require = createRequire(import.meta.url)
|
|
10
|
-
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
import { pathToFileURL } from 'url';
|
|
3
|
+
import { ROOT_PACKAGE_JSON } from '../../utils/json.js';
|
|
4
|
+
import { DEV_EVENTS, EVENTS } from '../events.js';
|
|
5
|
+
import { addTsErrorInfo } from './typescript.js';
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
11
7
|
// Require the plugin file and fire its top-level function.
|
|
12
8
|
// The returned object is the `logic` which includes all event handlers.
|
|
13
9
|
export const getLogic = async function ({ pluginPath, inputs, tsNodeService }) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
10
|
+
const logic = await importLogic(pluginPath, tsNodeService);
|
|
11
|
+
const logicA = loadLogic({ logic, inputs });
|
|
12
|
+
return logicA;
|
|
13
|
+
};
|
|
19
14
|
const importLogic = async function (pluginPath, tsNodeService) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
try {
|
|
16
|
+
// `ts-node` is not available programmatically for pure ES modules yet,
|
|
17
|
+
// which is currently making it impossible for local plugins to use both
|
|
18
|
+
// pure ES modules and TypeScript.
|
|
19
|
+
if (tsNodeService !== undefined) {
|
|
20
|
+
return require(pluginPath);
|
|
21
|
+
}
|
|
22
|
+
// `pluginPath` is an absolute file path but `import()` needs URLs.
|
|
23
|
+
// Converting those with `pathToFileURL()` is needed especially on Windows
|
|
24
|
+
// where the drive letter would not work with `import()`.
|
|
25
|
+
const returnValue = await import(pathToFileURL(pluginPath));
|
|
26
|
+
// Plugins should use named exports, but we still support default exports
|
|
27
|
+
// for backward compatibility with CommonJS
|
|
28
|
+
return returnValue.default === undefined ? returnValue : returnValue.default;
|
|
26
29
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// `error.stack` is lazily instantiated by Node.js, so changing
|
|
40
|
-
// `error.message` afterwards would not modify `error.stack`. Therefore, the
|
|
41
|
-
// resulting stack trace, which is printed in the build logs, would not
|
|
42
|
-
// include the additional message prefix.
|
|
43
|
-
error.stack = `Could not import plugin:\n${error.stack}`
|
|
44
|
-
throw error
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
30
|
+
catch (error) {
|
|
31
|
+
addTsErrorInfo(error, tsNodeService);
|
|
32
|
+
// We must change `error.stack` instead of `error.message` because some
|
|
33
|
+
// errors thrown from `import()` access `error.stack` before throwing.
|
|
34
|
+
// `error.stack` is lazily instantiated by Node.js, so changing
|
|
35
|
+
// `error.message` afterwards would not modify `error.stack`. Therefore, the
|
|
36
|
+
// resulting stack trace, which is printed in the build logs, would not
|
|
37
|
+
// include the additional message prefix.
|
|
38
|
+
error.stack = `Could not import plugin:\n${error.stack}`;
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
48
42
|
const loadLogic = function ({ logic, inputs }) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
43
|
+
if (typeof logic !== 'function') {
|
|
44
|
+
return logic;
|
|
45
|
+
}
|
|
46
|
+
const metadata = {
|
|
47
|
+
events: new Set([...DEV_EVENTS, ...EVENTS]),
|
|
48
|
+
version: ROOT_PACKAGE_JSON.version,
|
|
49
|
+
};
|
|
50
|
+
try {
|
|
51
|
+
return logic(inputs, metadata);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
error.message = `Could not load plugin:\n${error.message}`;
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
};
|