@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.
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 +14 -7
@@ -1,41 +1,32 @@
1
- import { stdout } from 'process'
2
-
3
- import UpdateNotifier from 'update-notifier'
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
- if (mode !== 'cli') {
14
- return
15
- }
16
-
17
- const corePackageJson = getCorePackageJson(testOpts)
18
- UpdateNotifier({ pkg: corePackageJson, updateCheckInterval: 1 }).notify({
19
- message: OLD_VERSION_MESSAGE,
20
- shouldNotifyInNpmScript: true,
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
- // TODO: Find a way to test this without injecting code in the `src/`
26
- if (testOpts.oldCliLogs) {
27
- // `update-notifier` does not do anything if not in a TTY.
28
- // In tests, we need to monkey patch this
29
- // Mutation is required due to how `stdout.isTTY` works
30
-
31
- stdout.isTTY = true
32
-
33
- return { ...ROOT_PACKAGE_JSON, version: '0.0.1' }
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.`;
@@ -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
- return dump(object, { noRefs: true, sortKeys: true, lineWidth: Number.POSITIVE_INFINITY }).trimEnd()
5
- }
6
-
3
+ return dump(object, { noRefs: true, sortKeys: true, lineWidth: Number.POSITIVE_INFINITY }).trimEnd();
4
+ };
7
5
  export const serializeArray = function (array) {
8
- return array.map(addDash).join('\n')
9
- }
10
-
6
+ return array.map(addDash).join('\n');
7
+ };
11
8
  const addDash = function (string) {
12
- return ` - ${string}`
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
- if (logs !== undefined) {
13
- return 'pipe'
14
- }
15
-
16
- return 'inherit'
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
- if (logs === undefined) {
22
- return
23
- }
24
-
25
- pushBuildCommandOutput(commandStdout, logs.stdout)
26
- pushBuildCommandOutput(commandStderr, logs.stderr)
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
- if (output === '') {
31
- return
32
- }
33
-
34
- logsArray.push(output)
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
- if (logs === undefined) {
40
- return streamOutput(childProcess)
41
- }
42
-
43
- return pushOutputToLogs(childProcess, logs)
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
- // Let `childProcess` `stdout` and `stderr` flush before stopping redirecting
49
- await pSetTimeout(0)
50
-
51
- if (logs === undefined) {
52
- return unstreamOutput(childProcess)
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
- childProcess.stdout.pipe(stdout)
61
- childProcess.stderr.pipe(stderr)
62
- }
63
-
47
+ childProcess.stdout.pipe(stdout);
48
+ childProcess.stderr.pipe(stderr);
49
+ };
64
50
  const unstreamOutput = function (childProcess) {
65
- childProcess.stdout.unpipe(stdout)
66
- childProcess.stderr.unpipe(stderr)
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
- const stdoutListener = logsListener.bind(null, logs.stdout)
72
- const stderrListener = logsListener.bind(null, logs.stderr)
73
- childProcess.stdout.on('data', stdoutListener)
74
- childProcess.stderr.on('data', stderrListener)
75
- return { stdoutListener, stderrListener }
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
- logs.push(chunk.toString().trimEnd())
80
- }
81
-
63
+ logs.push(chunk.toString().trimEnd());
64
+ };
82
65
  const unpushOutputToLogs = function (childProcess, logs, { stdoutListener, stderrListener }) {
83
- childProcess.stdout.removeListener('data', stdoutListener)
84
- childProcess.stderr.removeListener('data', stderrListener)
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
- // Main headers
7
- header: chalk.cyanBright.bold,
8
- // Single lines used as subheaders
9
- subHeader: chalk.cyan.bold,
10
- // One of several words that should be highlighted inside a line
11
- highlightWords: chalk.cyan,
12
- // Same for errors
13
- errorHeader: chalk.redBright.bold,
14
- errorSubHeader: chalk.red.bold,
15
- errorLine: chalk.redBright,
16
- errorHighlightWords: chalk.redBright.bold,
17
- // Same for warnings
18
- warningHeader: chalk.yellowBright.bold,
19
- warningSubHeader: chalk.yellow.bold,
20
- warningLine: chalk.yellowBright,
21
- warningHighlightWords: chalk.yellowBright.bold,
22
- // One of several words that should be dimmed inside a line
23
- dimWords: chalk.gray,
24
- // No colors
25
- none: (string) => string,
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 isPlainObj from 'is-plain-obj'
4
- import rfdc from 'rfdc'
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
- return clone(netlifyConfig)
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
- const configMutations = diffObjects(netlifyConfig, netlifyConfigCopy, [])
23
- return configMutations.map((configMutation) => getConfigMutation(configMutation, event))
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
- const allKeys = [...new Set([...Object.keys(objA), ...Object.keys(objB)])]
30
- return allKeys.flatMap((key) => {
31
- const valueA = objA[key]
32
- const valueB = objB[key]
33
- const keys = [...parentKeys, key]
34
-
35
- if (isPlainObj(valueA) && isPlainObj(valueB)) {
36
- return diffObjects(valueA, valueB, keys)
37
- }
38
-
39
- if (isDeepStrictEqual(valueA, valueB)) {
40
- return []
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
- const serializedKeys = keys.map(String)
49
- return {
50
- keys: serializedKeys,
51
- keysString: serializedKeys.join('.'),
52
- value,
53
- event,
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 { errorToJson } from '../../error/build.js'
4
- import { addDefaultErrorInfo, isBuildError } from '../../error/info.js'
5
- import { normalizeError } from '../../error/parse/normalize.js'
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
- const errorA = normalizeError(error)
11
- addDefaultErrorInfo(errorA, { type: 'pluginInternal' })
12
- const errorPayload = errorToJson(errorA)
13
- await sendEventToParent('error', errorPayload, verbose, errorA)
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
- logProcessErrors({ log: handleProcessError, exitOn: [] })
20
- }
21
-
16
+ logProcessErrors({ log: handleProcessError, exitOn: [] });
17
+ };
22
18
  const handleProcessError = async function (error, level, originalError) {
23
- if (level !== 'error') {
24
- console[level](error)
25
- return
26
- }
27
-
28
- // Do not use log-process-errors prettification with errors thrown by `utils.build.*`
29
- const errorA = isBuildError(originalError) ? originalError : error
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
- const mGetFunc = memoizeOne(getFunc, returnTrue)
7
- // Mutation is required due to the usage of `Object.defineProperty()`
8
-
9
- Object.defineProperty(object, propName, {
10
- get: mGetFunc,
11
- enumerable: true,
12
- configurable: true,
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
- return true
18
- }
14
+ return true;
15
+ };
@@ -1,29 +1,22 @@
1
- import filterObj from 'filter-obj'
2
-
3
- import { getLogic } from './logic.js'
4
- import { registerTypeScript } from './typescript.js'
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
- const tsNodeService = registerTypeScript(pluginPath)
14
- const logic = await getLogic({ pluginPath, inputs, tsNodeService })
15
-
16
- validatePlugin(logic)
17
-
18
- const methods = filterObj(logic, isEventHandler)
19
- const events = Object.keys(methods)
20
-
21
- // Context passed to every event handler
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
- return typeof value === 'function'
29
- }
21
+ return typeof value === 'function';
22
+ };
@@ -1,64 +1,57 @@
1
- import { createRequire } from 'module'
2
- import { pathToFileURL } from 'url'
3
-
4
- import { ROOT_PACKAGE_JSON } from '../../utils/json.js'
5
- import { DEV_EVENTS, EVENTS } from '../events.js'
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
- const logic = await importLogic(pluginPath, tsNodeService)
15
- const logicA = loadLogic({ logic, inputs })
16
- return logicA
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
- try {
21
- // `ts-node` is not available programmatically for pure ES modules yet,
22
- // which is currently making it impossible for local plugins to use both
23
- // pure ES modules and TypeScript.
24
- if (tsNodeService !== undefined) {
25
- return require(pluginPath)
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
- // `pluginPath` is an absolute file path but `import()` needs URLs.
29
- // Converting those with `pathToFileURL()` is needed especially on Windows
30
- // where the drive letter would not work with `import()`.
31
- const returnValue = await import(pathToFileURL(pluginPath))
32
- // Plugins should use named exports, but we still support default exports
33
- // for backward compatibility with CommonJS
34
- return returnValue.default === undefined ? returnValue : returnValue.default
35
- } catch (error) {
36
- addTsErrorInfo(error, tsNodeService)
37
- // We must change `error.stack` instead of `error.message` because some
38
- // errors thrown from `import()` access `error.stack` before throwing.
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
- if (typeof logic !== 'function') {
50
- return logic
51
- }
52
-
53
- const metadata = {
54
- events: new Set([...DEV_EVENTS, ...EVENTS]),
55
- version: ROOT_PACKAGE_JSON.version,
56
- }
57
-
58
- try {
59
- return logic(inputs, metadata)
60
- } catch (error) {
61
- error.message = `Could not load plugin:\n${error.message}`
62
- throw error
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
+ };