@netlify/build 25.0.3 → 26.1.0

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 (125) hide show
  1. package/package.json +5 -3
  2. package/src/core/bin.js +7 -8
  3. package/src/core/config.js +18 -35
  4. package/src/core/constants.js +7 -13
  5. package/src/core/dry.js +4 -8
  6. package/src/core/feature_flags.js +2 -7
  7. package/src/core/flags.js +2 -6
  8. package/src/core/lingering.js +7 -7
  9. package/src/core/main.js +25 -29
  10. package/src/core/missing_side_file.js +4 -8
  11. package/src/core/normalize_flags.js +5 -9
  12. package/src/core/severity.js +2 -6
  13. package/src/core/user_node_version.js +7 -11
  14. package/src/env/changes.js +5 -9
  15. package/src/env/main.js +4 -8
  16. package/src/env/metadata.js +3 -7
  17. package/src/error/api.js +4 -8
  18. package/src/error/build.js +4 -8
  19. package/src/error/cancel.js +1 -5
  20. package/src/error/colors.js +2 -6
  21. package/src/error/handle.js +10 -14
  22. package/src/error/info.js +6 -10
  23. package/src/error/monitor/location.js +1 -5
  24. package/src/error/monitor/normalize.js +2 -6
  25. package/src/error/monitor/print.js +2 -8
  26. package/src/error/monitor/report.js +11 -15
  27. package/src/error/monitor/start.js +7 -9
  28. package/src/error/parse/clean_stack.js +4 -8
  29. package/src/error/parse/location.js +2 -6
  30. package/src/error/parse/normalize.js +1 -5
  31. package/src/error/parse/parse.js +10 -14
  32. package/src/error/parse/plugin.js +2 -6
  33. package/src/error/parse/properties.js +3 -7
  34. package/src/error/parse/serialize_log.js +2 -6
  35. package/src/error/parse/serialize_status.js +1 -5
  36. package/src/error/parse/stack.js +2 -6
  37. package/src/error/type.js +1 -5
  38. package/src/install/functions.js +5 -9
  39. package/src/install/local.js +5 -9
  40. package/src/install/main.js +6 -10
  41. package/src/install/missing.js +9 -13
  42. package/src/log/colors.js +5 -11
  43. package/src/log/description.js +2 -6
  44. package/src/log/header.js +2 -6
  45. package/src/log/header_func.js +3 -7
  46. package/src/log/logger.js +20 -40
  47. package/src/log/messages/compatibility.js +9 -18
  48. package/src/log/messages/config.js +12 -27
  49. package/src/log/messages/core.js +19 -30
  50. package/src/log/messages/core_steps.js +7 -15
  51. package/src/log/messages/dry.js +7 -15
  52. package/src/log/messages/install.js +4 -12
  53. package/src/log/messages/ipc.js +8 -20
  54. package/src/log/messages/mutations.js +8 -17
  55. package/src/log/messages/plugins.js +5 -14
  56. package/src/log/messages/status.js +3 -9
  57. package/src/log/messages/steps.js +6 -14
  58. package/src/log/old_version.js +4 -8
  59. package/src/log/serialize.js +3 -7
  60. package/src/log/stream.js +6 -15
  61. package/src/log/theme.js +14 -29
  62. package/src/plugins/child/diff.js +5 -9
  63. package/src/plugins/child/error.js +7 -11
  64. package/src/plugins/child/lazy.js +2 -6
  65. package/src/plugins/child/load.js +6 -10
  66. package/src/plugins/child/logic.js +6 -7
  67. package/src/plugins/child/main.js +5 -7
  68. package/src/plugins/child/run.js +6 -10
  69. package/src/plugins/child/status.js +4 -8
  70. package/src/plugins/child/typescript.js +5 -9
  71. package/src/plugins/child/utils.js +21 -27
  72. package/src/plugins/child/validate.js +6 -11
  73. package/src/plugins/compatibility.js +12 -15
  74. package/src/plugins/error.js +6 -15
  75. package/src/plugins/events.js +5 -20
  76. package/src/plugins/expected_version.js +8 -12
  77. package/src/plugins/ipc.js +12 -21
  78. package/src/plugins/list.js +6 -15
  79. package/src/plugins/load.js +13 -9
  80. package/src/plugins/manifest/check.js +4 -8
  81. package/src/plugins/manifest/load.js +6 -10
  82. package/src/plugins/manifest/main.js +5 -9
  83. package/src/plugins/manifest/path.js +3 -7
  84. package/src/plugins/manifest/validate.js +3 -7
  85. package/src/plugins/node_version.js +9 -13
  86. package/src/plugins/options.js +10 -14
  87. package/src/plugins/pinned_version.js +4 -8
  88. package/src/plugins/resolve.js +7 -11
  89. package/src/plugins/spawn.js +10 -12
  90. package/src/plugins_core/add.js +2 -6
  91. package/src/plugins_core/build_command.js +7 -11
  92. package/src/plugins_core/deploy/buildbot_client.js +11 -20
  93. package/src/plugins_core/deploy/index.js +5 -9
  94. package/src/plugins_core/functions/error.js +4 -8
  95. package/src/plugins_core/functions/feature_flags.js +1 -5
  96. package/src/plugins_core/functions/index.js +22 -16
  97. package/src/plugins_core/functions/utils.js +9 -13
  98. package/src/plugins_core/functions_install/index.js +3 -7
  99. package/src/plugins_core/list.js +10 -7
  100. package/src/status/add.js +1 -5
  101. package/src/status/colors.js +2 -6
  102. package/src/status/load_error.js +4 -8
  103. package/src/status/report.js +4 -8
  104. package/src/status/success.js +2 -6
  105. package/src/steps/core_step.js +4 -8
  106. package/src/steps/error.js +7 -11
  107. package/src/steps/get.js +7 -12
  108. package/src/steps/plugin.js +8 -12
  109. package/src/steps/return.js +4 -8
  110. package/src/steps/run_step.js +8 -12
  111. package/src/steps/run_steps.js +5 -9
  112. package/src/steps/update_config.js +10 -14
  113. package/src/telemetry/main.js +7 -11
  114. package/src/time/aggregate.js +2 -6
  115. package/src/time/main.js +8 -12
  116. package/src/time/measure.js +4 -8
  117. package/src/time/report.js +5 -9
  118. package/src/utils/errors.js +1 -5
  119. package/src/utils/json.js +5 -8
  120. package/src/utils/omit.js +2 -6
  121. package/src/utils/package.js +3 -7
  122. package/src/utils/remove_falsy.js +2 -6
  123. package/src/utils/resolve.js +8 -6
  124. package/src/utils/semver.js +9 -13
  125. package/types/config/functions.d.ts +1 -1
@@ -1,30 +1,26 @@
1
- 'use strict'
1
+ import { bindOpts as cacheBindOpts } from '@netlify/cache-utils'
2
+ import { add as functionsAdd, list as functionsList, listAll as functionsListAll } from '@netlify/functions-utils'
3
+ import { getGitUtils } from '@netlify/git-utils'
4
+ import { run, runCommand } from '@netlify/run-utils'
2
5
 
3
- const { failBuild, failPlugin, cancelBuild, failPluginWithWarning } = require('../error')
4
- const { isSoftFailEvent } = require('../events')
6
+ import { failBuild, failPlugin, cancelBuild, failPluginWithWarning } from '../error.js'
7
+ import { isSoftFailEvent } from '../events.js'
5
8
 
6
- const { addLazyProp } = require('./lazy')
7
- const { show } = require('./status')
8
-
9
- const cacheUtilsPromise = import('@netlify/cache-utils')
10
- const functionsUtilsPromise = import('@netlify/functions-utils')
11
- const gitUtilsPromise = import('@netlify/git-utils')
12
- const runUtilsPromise = import('@netlify/run-utils')
9
+ import { addLazyProp } from './lazy.js'
10
+ import { show } from './status.js'
13
11
 
14
12
  // Retrieve the `utils` argument.
15
- const getUtils = async function ({ event, constants: { FUNCTIONS_SRC, INTERNAL_FUNCTIONS_SRC, CACHE_DIR }, runState }) {
16
- const [cacheUtils, functionsUtils, { getGitUtils }, { run, runCommand }] = await Promise.all([
17
- cacheUtilsPromise,
18
- functionsUtilsPromise,
19
- gitUtilsPromise,
20
- runUtilsPromise,
21
- ])
13
+ export const getUtils = function ({
14
+ event,
15
+ constants: { FUNCTIONS_SRC, INTERNAL_FUNCTIONS_SRC, CACHE_DIR },
16
+ runState,
17
+ }) {
22
18
  // eslint-disable-next-line fp/no-mutation
23
19
  run.command = runCommand
24
20
 
25
21
  const build = getBuildUtils(event)
26
- const cache = getCacheUtils(cacheUtils, CACHE_DIR)
27
- const functions = getFunctionsUtils(functionsUtils, FUNCTIONS_SRC, INTERNAL_FUNCTIONS_SRC)
22
+ const cache = getCacheUtils(CACHE_DIR)
23
+ const functions = getFunctionsUtils(FUNCTIONS_SRC, INTERNAL_FUNCTIONS_SRC)
28
24
  const status = getStatusUtils(runState)
29
25
  const utils = { build, cache, run, functions, status }
30
26
  addLazyProp(utils, 'git', () => getGitUtils())
@@ -43,20 +39,18 @@ const getBuildUtils = function (event) {
43
39
  return { failBuild, failPlugin, cancelBuild }
44
40
  }
45
41
 
46
- const getCacheUtils = function (cacheUtils, CACHE_DIR) {
47
- return cacheUtils.bindOpts({ cacheDir: CACHE_DIR })
42
+ const getCacheUtils = function (CACHE_DIR) {
43
+ return cacheBindOpts({ cacheDir: CACHE_DIR })
48
44
  }
49
45
 
50
- const getFunctionsUtils = function (functionsUtils, FUNCTIONS_SRC, INTERNAL_FUNCTIONS_SRC) {
46
+ const getFunctionsUtils = function (FUNCTIONS_SRC, INTERNAL_FUNCTIONS_SRC) {
51
47
  const functionsDirectories = [INTERNAL_FUNCTIONS_SRC, FUNCTIONS_SRC].filter(Boolean)
52
- const add = (src) => functionsUtils.add(src, INTERNAL_FUNCTIONS_SRC, { fail: failBuild })
53
- const list = functionsUtils.list.bind(null, functionsDirectories, { fail: failBuild })
54
- const listAll = functionsUtils.listAll.bind(null, functionsDirectories, { fail: failBuild })
48
+ const add = (src) => functionsAdd(src, INTERNAL_FUNCTIONS_SRC, { fail: failBuild })
49
+ const list = functionsList.bind(null, functionsDirectories, { fail: failBuild })
50
+ const listAll = functionsListAll.bind(null, functionsDirectories, { fail: failBuild })
55
51
  return { add, list, listAll }
56
52
  }
57
53
 
58
54
  const getStatusUtils = function (runState) {
59
55
  return { show: show.bind(undefined, runState) }
60
56
  }
61
-
62
- module.exports = { getUtils }
@@ -1,11 +1,9 @@
1
- 'use strict'
2
-
3
- const { addErrorInfo } = require('../../error/info')
4
- const { serializeArray } = require('../../log/serialize')
5
- const { listEvents } = require('../events')
1
+ import { addErrorInfo } from '../../error/info.js'
2
+ import { serializeArray } from '../../log/serialize.js'
3
+ import { EVENTS } from '../events.js'
6
4
 
7
5
  // Validate the shape of a plugin return value
8
- const validatePlugin = async function (logic) {
6
+ export const validatePlugin = function (logic) {
9
7
  try {
10
8
  // This validation must work with the return value of `import()` which has
11
9
  // a `Module` prototype, not `Object`
@@ -13,9 +11,8 @@ const validatePlugin = async function (logic) {
13
11
  throw new Error('Plugin must be an object or a function')
14
12
  }
15
13
 
16
- const EVENTS = await listEvents()
17
14
  Object.entries(logic).forEach(([propName, value]) => {
18
- validateEventHandler(value, propName, EVENTS)
15
+ validateEventHandler(value, propName)
19
16
  })
20
17
  } catch (error) {
21
18
  addErrorInfo(error, { type: 'pluginValidation' })
@@ -24,7 +21,7 @@ const validatePlugin = async function (logic) {
24
21
  }
25
22
 
26
23
  // All other properties are event handlers
27
- const validateEventHandler = function (value, propName, EVENTS) {
24
+ const validateEventHandler = function (value, propName) {
28
25
  if (!EVENTS.includes(propName)) {
29
26
  throw new Error(`Invalid event '${propName}'.
30
27
  Please use a valid event name. One of:
@@ -35,5 +32,3 @@ ${serializeArray(EVENTS)}`)
35
32
  throw new TypeError(`Invalid event handler '${propName}': must be a function`)
36
33
  }
37
34
  }
38
-
39
- module.exports = { validatePlugin }
@@ -1,10 +1,9 @@
1
- 'use strict'
2
- const pEvery = require('p-every')
3
- const pLocate = require('p-locate')
4
- const { satisfies, clean: cleanVersion } = require('semver')
1
+ import pEvery from 'p-every'
2
+ import pLocate from 'p-locate'
3
+ import semver from 'semver'
5
4
 
6
- const { importJsonFile } = require('../utils/json')
7
- const { resolvePath } = require('../utils/resolve')
5
+ import { importJsonFile } from '../utils/json.js'
6
+ import { resolvePath } from '../utils/resolve.js'
8
7
 
9
8
  // Retrieve the `expectedVersion` of a plugin:
10
9
  // - This is the version which should be run
@@ -15,7 +14,7 @@ const { resolvePath } = require('../utils/resolve')
15
14
  // - This is the same logic except it does not use version pinning
16
15
  // - This is only used to print a warning message when the `compatibleVersion`
17
16
  // is older than the currently used version.
18
- const getExpectedVersion = async function ({ versions, nodeVersion, packageJson, buildDir, pinnedVersion }) {
17
+ export const getExpectedVersion = async function ({ versions, nodeVersion, packageJson, buildDir, pinnedVersion }) {
19
18
  const { version, conditions } = await getCompatibleEntry({
20
19
  versions,
21
20
  nodeVersion,
@@ -43,7 +42,7 @@ const getExpectedVersion = async function ({ versions, nodeVersion, packageJson,
43
42
  // - Otherwise, use `latestVersion`
44
43
  const getCompatibleEntry = async function ({ versions, nodeVersion, packageJson, buildDir, pinnedVersion }) {
45
44
  if (pinnedVersion !== undefined) {
46
- return versions.find(({ version }) => satisfies(version, pinnedVersion)) || { version: pinnedVersion }
45
+ return versions.find(({ version }) => semver.satisfies(version, pinnedVersion)) || { version: pinnedVersion }
47
46
  }
48
47
 
49
48
  const versionsWithConditions = versions.filter(hasConditions)
@@ -77,7 +76,7 @@ const getConditionWarning = function ({ type, condition }) {
77
76
  // Plugins can use `compatibility.{version}.nodeVersion: 'allowedNodeVersion'`
78
77
  // to deliver different plugin versions based on the Node.js version
79
78
  const nodeVersionTest = function (allowedNodeVersion, { nodeVersion }) {
80
- return satisfies(nodeVersion, allowedNodeVersion)
79
+ return semver.satisfies(nodeVersion, allowedNodeVersion)
81
80
  }
82
81
 
83
82
  const nodeVersionWarning = function (allowedNodeVersion) {
@@ -101,15 +100,15 @@ const siteDependencyTest = async function ({ dependencyName, allowedVersion, sit
101
100
  }
102
101
 
103
102
  // if this is a valid version we can apply the rule directly
104
- if (cleanVersion(siteDependency) !== null) {
105
- return satisfies(siteDependency, allowedVersion)
103
+ if (semver.clean(siteDependency) !== null) {
104
+ return semver.satisfies(siteDependency, allowedVersion)
106
105
  }
107
106
 
108
107
  try {
109
108
  // if this is a range we need to get the exact version
110
109
  const packageJsonPath = await resolvePath(`${dependencyName}/package.json`, buildDir)
111
110
  const { version } = await importJsonFile(packageJsonPath)
112
- return satisfies(version, allowedVersion)
111
+ return semver.satisfies(version, allowedVersion)
113
112
  } catch (error) {
114
113
  return false
115
114
  }
@@ -123,9 +122,7 @@ const siteDependencyWarning = function ([dependencyName, allowedVersion]) {
123
122
  return `${dependencyName}@${allowedVersion}`
124
123
  }
125
124
 
126
- const CONDITIONS = {
125
+ export const CONDITIONS = {
127
126
  nodeVersion: { test: nodeVersionTest, warning: nodeVersionWarning },
128
127
  siteDependencies: { test: siteDependenciesTest, warning: siteDependenciesWarning },
129
128
  }
130
-
131
- module.exports = { getExpectedVersion, CONDITIONS }
@@ -1,29 +1,27 @@
1
- 'use strict'
2
-
3
- const { addErrorInfo } = require('../error/info')
4
- const { logFailPluginWarning } = require('../log/messages/plugins')
1
+ import { addErrorInfo } from '../error/info.js'
2
+ import { logFailPluginWarning } from '../log/messages/plugins.js'
5
3
 
6
4
  // Stop build.
7
5
  // As opposed to throwing an error directly or to uncaught exceptions, this is
8
6
  // displayed as a user error, not an implementation error.
9
- const failBuild = function (message, opts) {
7
+ export const failBuild = function (message, opts) {
10
8
  throw normalizeError('failBuild', failBuild, message, opts)
11
9
  }
12
10
 
13
11
  // Stop plugin. Same as `failBuild` but only stops plugin not whole build
14
- const failPlugin = function (message, opts) {
12
+ export const failPlugin = function (message, opts) {
15
13
  throw normalizeError('failPlugin', failPlugin, message, opts)
16
14
  }
17
15
 
18
16
  // Cancel build. Same as `failBuild` except it marks the build as "canceled".
19
- const cancelBuild = function (message, opts) {
17
+ export const cancelBuild = function (message, opts) {
20
18
  throw normalizeError('cancelBuild', cancelBuild, message, opts)
21
19
  }
22
20
 
23
21
  // `onSuccess`, `onEnd` and `onError` cannot cancel the build since they are run
24
22
  // or might be run after deployment. When calling `failBuild()` or
25
23
  // `cancelBuild()`, `failPlugin()` is run instead and a warning is printed.
26
- const failPluginWithWarning = function (methodName, event, message, opts) {
24
+ export const failPluginWithWarning = function (methodName, event, message, opts) {
27
25
  logFailPluginWarning(methodName, event)
28
26
  failPlugin(message, opts)
29
27
  }
@@ -47,10 +45,3 @@ const getError = function (error, message, func) {
47
45
  Error.captureStackTrace(errorA, func)
48
46
  return errorA
49
47
  }
50
-
51
- module.exports = {
52
- failBuild,
53
- failPlugin,
54
- failPluginWithWarning,
55
- cancelBuild,
56
- }
@@ -1,32 +1,17 @@
1
- 'use strict'
2
-
3
- const netlifyConfigPromise = import('@netlify/config')
4
-
5
- const listEvents = async function () {
6
- const { EVENTS } = await netlifyConfigPromise
7
- return EVENTS
8
- }
1
+ export { EVENTS } from '@netlify/config'
9
2
 
10
3
  const isAmongEvents = function (events, event) {
11
4
  return events.includes(event)
12
5
  }
13
6
 
14
7
  // Check if failure of the event should not make the build fail
15
- const isSoftFailEvent = isAmongEvents.bind(null, ['onSuccess', 'onError', 'onEnd'])
8
+ export const isSoftFailEvent = isAmongEvents.bind(null, ['onSuccess', 'onError', 'onEnd'])
16
9
 
17
10
  // Check if the event is triggered even when the build fails
18
- const runsAlsoOnBuildFailure = isAmongEvents.bind(null, ['onError', 'onEnd'])
11
+ export const runsAlsoOnBuildFailure = isAmongEvents.bind(null, ['onError', 'onEnd'])
19
12
 
20
13
  // Check if the event is only triggered when the build fails
21
- const runsOnlyOnBuildFailure = isAmongEvents.bind(null, ['onError'])
14
+ export const runsOnlyOnBuildFailure = isAmongEvents.bind(null, ['onError'])
22
15
 
23
16
  // Check if the event is happening after deploy
24
- const runsAfterDeploy = isAmongEvents.bind(null, ['onSuccess', 'onEnd'])
25
-
26
- module.exports = {
27
- listEvents,
28
- isSoftFailEvent,
29
- runsAlsoOnBuildFailure,
30
- runsOnlyOnBuildFailure,
31
- runsAfterDeploy,
32
- }
17
+ export const runsAfterDeploy = isAmongEvents.bind(null, ['onSuccess', 'onEnd'])
@@ -1,18 +1,16 @@
1
- 'use strict'
1
+ import semver from 'semver'
2
2
 
3
- const { satisfies } = require('semver')
3
+ import { addErrorInfo } from '../error/info.js'
4
+ import { importJsonFile } from '../utils/json.js'
5
+ import { resolvePath } from '../utils/resolve.js'
4
6
 
5
- const { addErrorInfo } = require('../error/info')
6
- const { importJsonFile } = require('../utils/json')
7
- const { resolvePath } = require('../utils/resolve')
8
-
9
- const { getExpectedVersion } = require('./compatibility')
10
- const { getPluginsList } = require('./list')
7
+ import { getExpectedVersion } from './compatibility.js'
8
+ import { getPluginsList } from './list.js'
11
9
 
12
10
  // When using plugins in our official list, those are installed in .netlify/plugins/
13
11
  // We ensure that the last version that's been approved is always the one being used.
14
12
  // We also ensure that the plugin is our official list.
15
- const addExpectedVersions = async function ({
13
+ export const addExpectedVersions = async function ({
16
14
  pluginsOptions,
17
15
  autoPluginsDir,
18
16
  packageJson,
@@ -90,7 +88,7 @@ const isMissingVersion = async function ({ autoPluginsDir, packageName, pluginPa
90
88
  // Plugin was not previously installed
91
89
  (pluginPath === undefined ||
92
90
  // Plugin was previously installed but a different version should be used
93
- !satisfies(await getAutoPluginVersion(packageName, autoPluginsDir), expectedVersion))
91
+ !semver.satisfies(await getAutoPluginVersion(packageName, autoPluginsDir), expectedVersion))
94
92
  )
95
93
  }
96
94
 
@@ -119,5 +117,3 @@ Please run "npm install -D ${packageName}" or "yarn add -D ${packageName}".`,
119
117
  addErrorInfo(error, { type: 'resolveConfig' })
120
118
  throw error
121
119
  }
122
-
123
- module.exports = { addExpectedVersions }
@@ -1,24 +1,22 @@
1
- 'use strict'
1
+ import process from 'process'
2
+ import { promisify } from 'util'
2
3
 
3
- const process = require('process')
4
- const { promisify } = require('util')
4
+ import pEvent from 'p-event'
5
+ import { v4 as uuidv4 } from 'uuid'
5
6
 
6
- const pEvent = require('p-event')
7
- const { v4: uuidv4 } = require('uuid')
8
-
9
- const { jsonToError, errorToJson } = require('../error/build')
10
- const { addErrorInfo } = require('../error/info')
11
- const {
7
+ import { jsonToError, errorToJson } from '../error/build.js'
8
+ import { addErrorInfo } from '../error/info.js'
9
+ import {
12
10
  logSendingEventToChild,
13
11
  logSentEventToChild,
14
12
  logReceivedEventFromChild,
15
13
  logSendingEventToParent,
16
- } = require('../log/messages/ipc')
14
+ } from '../log/messages/ipc.js'
17
15
 
18
16
  // Send event from child to parent process then wait for response
19
17
  // We need to fire them in parallel because `process.send()` can be slow
20
18
  // to await, i.e. child might send response before parent start listening for it
21
- const callChild = async function ({ childProcess, eventName, payload, logs, verbose }) {
19
+ export const callChild = async function ({ childProcess, eventName, payload, logs, verbose }) {
22
20
  const callId = uuidv4()
23
21
  const [response] = await Promise.all([
24
22
  getEventFromChild(childProcess, callId),
@@ -36,7 +34,7 @@ const callChild = async function ({ childProcess, eventName, payload, logs, verb
36
34
  // - child process `exit`
37
35
  // In the later two cases, we propagate the error.
38
36
  // We need to make `p-event` listeners are properly cleaned up too.
39
- const getEventFromChild = async function (childProcess, callId) {
37
+ export const getEventFromChild = async function (childProcess, callId) {
40
38
  if (childProcessHasExited(childProcess)) {
41
39
  throw getChildExitError('Could not receive event from child process because it already exited.')
42
40
  }
@@ -104,7 +102,7 @@ const sendEventToChild = async function ({ childProcess, callId, eventName, payl
104
102
  // This runs forever until `childProcess.kill()` is called.
105
103
  // We need to use `new Promise()` and callbacks because this runs forever.
106
104
  // eslint-disable-next-line promise/prefer-await-to-callbacks
107
- const getEventsFromParent = function (callback) {
105
+ export const getEventsFromParent = function (callback) {
108
106
  return new Promise((resolve, reject) => {
109
107
  process.on('message', async (message) => {
110
108
  try {
@@ -120,7 +118,7 @@ const getEventsFromParent = function (callback) {
120
118
  }
121
119
 
122
120
  // Send event from child to parent process
123
- const sendEventToParent = async function (callId, payload, verbose, error) {
121
+ export const sendEventToParent = async function (callId, payload, verbose, error) {
124
122
  logSendingEventToParent(verbose, error)
125
123
  await promisify(process.send.bind(process))([callId, payload])
126
124
  }
@@ -145,10 +143,3 @@ const parsePayload = function ({ error = {}, error: { name } = {}, ...payload })
145
143
  const errorA = jsonToError(error)
146
144
  return { ...payload, error: errorA }
147
145
  }
148
-
149
- module.exports = {
150
- callChild,
151
- getEventFromChild,
152
- getEventsFromParent,
153
- sendEventToParent,
154
- }
@@ -1,15 +1,10 @@
1
- 'use strict'
1
+ import { pluginsUrl, pluginsList as oldPluginsList } from '@netlify/plugins-list'
2
+ import got from 'got'
3
+ import isPlainObj from 'is-plain-obj'
2
4
 
3
- const got = require('got')
4
- const isPlainObj = require('is-plain-obj')
5
+ import { logPluginsList, logPluginsFetchError } from '../log/messages/plugins.js'
5
6
 
6
- // TODO: use static `import` after migrating this repository to pure ES modules
7
- const netlifyPluginsList = import('@netlify/plugins-list')
8
-
9
- const { logPluginsList } = require('../log/messages/plugins')
10
- const { logPluginsFetchError } = require('../log/messages/plugins')
11
-
12
- const { CONDITIONS } = require('./compatibility')
7
+ import { CONDITIONS } from './compatibility.js'
13
8
 
14
9
  // Retrieve the list of plugins officially vetted by us and displayed in our
15
10
  // plugins directory UI.
@@ -18,14 +13,13 @@ const { CONDITIONS } = require('./compatibility')
18
13
  // make this request is somewhat ok (in the 100ms range).
19
14
  // We only fetch this plugins list when needed, i.e. we defer it as much as
20
15
  // possible.
21
- const getPluginsList = async function ({ debug, logs, testOpts: { pluginsListUrl } }) {
16
+ export const getPluginsList = async function ({ debug, logs, testOpts: { pluginsListUrl } }) {
22
17
  // We try not to mock in integration tests. However, sending a request for
23
18
  // each test would be too slow and make tests unreliable.
24
19
  if (pluginsListUrl === 'test') {
25
20
  return []
26
21
  }
27
22
 
28
- const { pluginsUrl } = await netlifyPluginsList
29
23
  const pluginsListUrlA = pluginsListUrl === undefined ? pluginsUrl : pluginsListUrl
30
24
  const pluginsList = await fetchPluginsList({ logs, pluginsListUrl: pluginsListUrlA })
31
25
  const pluginsListA = normalizePluginsList(pluginsList)
@@ -50,7 +44,6 @@ const fetchPluginsList = async function ({ logs, pluginsListUrl }) {
50
44
  // buildbot release.
51
45
  } catch (error) {
52
46
  logPluginsFetchError(logs, error.message)
53
- const { pluginsList: oldPluginsList } = await netlifyPluginsList
54
47
  return oldPluginsList
55
48
  }
56
49
  }
@@ -91,5 +84,3 @@ const isCondition = function ([type]) {
91
84
  const normalizeCondition = function ([type, condition]) {
92
85
  return { type, condition }
93
86
  }
94
-
95
- module.exports = { getPluginsList }
@@ -1,14 +1,20 @@
1
- 'use strict'
1
+ import { addErrorInfo } from '../error/info.js'
2
+ import { addPluginLoadErrorStatus } from '../status/load_error.js'
3
+ import { measureDuration } from '../time/main.js'
2
4
 
3
- const { addErrorInfo } = require('../error/info')
4
- const { addPluginLoadErrorStatus } = require('../status/load_error')
5
- const { measureDuration } = require('../time/main')
6
-
7
- const { callChild } = require('./ipc')
5
+ import { callChild } from './ipc.js'
8
6
 
9
7
  // Retrieve all plugins steps
10
8
  // Can use either a module name or a file path to the plugin.
11
- const loadPlugins = async function ({ pluginsOptions, childProcesses, packageJson, timers, logs, debug, verbose }) {
9
+ export const loadPlugins = async function ({
10
+ pluginsOptions,
11
+ childProcesses,
12
+ packageJson,
13
+ timers,
14
+ logs,
15
+ debug,
16
+ verbose,
17
+ }) {
12
18
  return pluginsOptions.length === 0
13
19
  ? { pluginsSteps: [], timers }
14
20
  : await loadAllPlugins({ pluginsOptions, childProcesses, packageJson, timers, logs, debug, verbose })
@@ -62,5 +68,3 @@ const loadPlugin = async function (
62
68
  throw error
63
69
  }
64
70
  }
65
-
66
- module.exports = { loadPlugins }
@@ -1,12 +1,10 @@
1
- 'use strict'
2
-
3
- const { addErrorInfo } = require('../../error/info')
4
- const { serializeObject } = require('../../log/serialize')
5
- const { THEME } = require('../../log/theme')
1
+ import { addErrorInfo } from '../../error/info.js'
2
+ import { serializeObject } from '../../log/serialize.js'
3
+ import { THEME } from '../../log/theme.js'
6
4
 
7
5
  // Check that plugin inputs match the validation specified in "manifest.yml"
8
6
  // Also assign default values
9
- const checkInputs = function ({
7
+ export const checkInputs = function ({
10
8
  inputs,
11
9
  manifest: { inputs: rules = [] },
12
10
  packageName,
@@ -106,5 +104,3 @@ const addInputError = function ({ error, name, packageName, pluginPackageJson, l
106
104
  location: { event: 'load', packageName, input: name, loadedFrom, origin },
107
105
  })
108
106
  }
109
-
110
- module.exports = { checkInputs }
@@ -1,18 +1,16 @@
1
- 'use strict'
1
+ import { readFile } from 'fs'
2
+ import { promisify } from 'util'
2
3
 
3
- const { readFile } = require('fs')
4
- const { promisify } = require('util')
4
+ import { load as loadYaml, JSON_SCHEMA } from 'js-yaml'
5
5
 
6
- const { load: loadYaml, JSON_SCHEMA } = require('js-yaml')
6
+ import { addErrorInfo } from '../../error/info.js'
7
7
 
8
- const { addErrorInfo } = require('../../error/info')
9
-
10
- const { validateManifest } = require('./validate')
8
+ import { validateManifest } from './validate.js'
11
9
 
12
10
  const pReadFile = promisify(readFile)
13
11
 
14
12
  // Load "manifest.yml" using its file path
15
- const loadManifest = async function ({ manifestPath, packageName, pluginPackageJson, loadedFrom, origin }) {
13
+ export const loadManifest = async function ({ manifestPath, packageName, pluginPackageJson, loadedFrom, origin }) {
16
14
  try {
17
15
  const rawManifest = await loadRawManifest(manifestPath)
18
16
  const manifest = await parseManifest(rawManifest)
@@ -44,5 +42,3 @@ const parseManifest = async function (rawManifest) {
44
42
  throw new Error(`Could not parse plugin's "manifest.yml"\n${error.message}`)
45
43
  }
46
44
  }
47
-
48
- module.exports = { loadManifest }
@@ -1,13 +1,11 @@
1
- 'use strict'
1
+ import { addPluginLoadErrorStatus } from '../../status/load_error.js'
2
2
 
3
- const { addPluginLoadErrorStatus } = require('../../status/load_error')
4
-
5
- const { checkInputs } = require('./check')
6
- const { loadManifest } = require('./load')
7
- const { getManifestPath } = require('./path')
3
+ import { checkInputs } from './check.js'
4
+ import { loadManifest } from './load.js'
5
+ import { getManifestPath } from './path.js'
8
6
 
9
7
  // Load plugin's `manifest.yml`
10
- const useManifest = async function (
8
+ export const useManifest = async function (
11
9
  { packageName, loadedFrom, origin, inputs },
12
10
  { pluginDir, packageDir, pluginPackageJson, pluginPackageJson: { version }, debug },
13
11
  ) {
@@ -22,5 +20,3 @@ const useManifest = async function (
22
20
  throw error
23
21
  }
24
22
  }
25
-
26
- module.exports = { useManifest }
@@ -1,11 +1,9 @@
1
- 'use strict'
1
+ import locatePath from 'locate-path'
2
2
 
3
- const locatePath = require('locate-path')
4
-
5
- const { addErrorInfo } = require('../../error/info')
3
+ import { addErrorInfo } from '../../error/info.js'
6
4
 
7
5
  // Retrieve "manifest.yml" path for a specific plugin
8
- const getManifestPath = async function ({ pluginDir, packageDir, packageName }) {
6
+ export const getManifestPath = async function ({ pluginDir, packageDir, packageName }) {
9
7
  const dirs = [pluginDir, packageDir]
10
8
  .filter(Boolean)
11
9
  .flatMap((dir) => MANIFEST_FILENAMES.map((filename) => `${dir}/${filename}`))
@@ -31,5 +29,3 @@ This might mean:
31
29
  }
32
30
 
33
31
  const MANIFEST_FILENAMES = ['manifest.yml', 'manifest.yaml']
34
-
35
- module.exports = { getManifestPath }
@@ -1,11 +1,9 @@
1
- 'use strict'
1
+ import isPlainObj from 'is-plain-obj'
2
2
 
3
- const isPlainObj = require('is-plain-obj')
4
-
5
- const { THEME } = require('../../log/theme')
3
+ import { THEME } from '../../log/theme.js'
6
4
 
7
5
  // Validate `manifest.yml` syntax
8
- const validateManifest = function (manifest, rawManifest) {
6
+ export const validateManifest = function (manifest, rawManifest) {
9
7
  try {
10
8
  validateBasic(manifest)
11
9
  validateUnknownProps(manifest)
@@ -108,5 +106,3 @@ const validateInputRequired = function ({ required }) {
108
106
  throw new Error('"required" property must be a boolean')
109
107
  }
110
108
  }
111
-
112
- module.exports = { validateManifest }
@@ -1,19 +1,17 @@
1
- 'use strict'
1
+ import { version as currentVersion, execPath } from 'process'
2
2
 
3
- const { version: currentVersion, execPath } = require('process')
3
+ import semver from 'semver'
4
4
 
5
- const { satisfies, clean: cleanVersion } = require('semver')
6
-
7
- const { addErrorInfo } = require('../error/info')
8
- const { ROOT_PACKAGE_JSON } = require('../utils/json')
5
+ import { addErrorInfo } from '../error/info.js'
6
+ import { ROOT_PACKAGE_JSON } from '../utils/json.js'
9
7
 
10
8
  // Local plugins and `package.json`-installed plugins use user's preferred Node.js version if higher than our minimum
11
9
  // supported version. Else default to the system Node version.
12
10
  // Local and programmatic builds use `@netlify/build` Node.js version, which is
13
11
  // usually the system's Node.js version.
14
12
  // If the user Node version does not satisfy our supported engine range use our own system Node version
15
- const addPluginsNodeVersion = function ({ pluginsOptions, nodePath, userNodeVersion }) {
16
- const currentNodeVersion = cleanVersion(currentVersion)
13
+ export const addPluginsNodeVersion = function ({ pluginsOptions, nodePath, userNodeVersion }) {
14
+ const currentNodeVersion = semver.clean(currentVersion)
17
15
  return pluginsOptions.map((pluginOptions) =>
18
16
  addPluginNodeVersion({ pluginOptions, currentNodeVersion, userNodeVersion, nodePath }),
19
17
  )
@@ -27,18 +25,18 @@ const addPluginNodeVersion = function ({
27
25
  nodePath,
28
26
  }) {
29
27
  return (loadedFrom === 'local' || loadedFrom === 'package.json') &&
30
- satisfies(userNodeVersion, ROOT_PACKAGE_JSON.engines.node)
28
+ semver.satisfies(userNodeVersion, ROOT_PACKAGE_JSON.engines.node)
31
29
  ? { ...pluginOptions, nodePath, nodeVersion: userNodeVersion }
32
30
  : { ...pluginOptions, nodePath: execPath, nodeVersion: currentNodeVersion }
33
31
  }
34
32
 
35
33
  // Ensure Node.js version is compatible with plugin's `engines.node`
36
- const checkNodeVersion = function ({
34
+ export const checkNodeVersion = function ({
37
35
  nodeVersion,
38
36
  packageName,
39
37
  pluginPackageJson: { engines: { node: pluginNodeVersionRange } = {} } = {},
40
38
  }) {
41
- if (pluginNodeVersionRange && !satisfies(nodeVersion, pluginNodeVersionRange)) {
39
+ if (pluginNodeVersionRange && !semver.satisfies(nodeVersion, pluginNodeVersionRange)) {
42
40
  throwUserError(
43
41
  `The Node.js version is ${nodeVersion} but the plugin "${packageName}" requires ${pluginNodeVersionRange}`,
44
42
  )
@@ -50,5 +48,3 @@ const throwUserError = function (message) {
50
48
  addErrorInfo(error, { type: 'resolveConfig' })
51
49
  throw error
52
50
  }
53
-
54
- module.exports = { addPluginsNodeVersion, checkNodeVersion }