@netlify/build 25.0.0 → 26.0.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 +6 -4
  2. package/src/core/bin.js +7 -8
  3. package/src/core/config.js +18 -35
  4. package/src/core/constants.js +8 -14
  5. package/src/core/dry.js +4 -8
  6. package/src/core/feature_flags.js +2 -6
  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 +9 -11
  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 +20 -31
  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 +6 -10
  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 +13 -16
  74. package/src/plugins/error.js +6 -15
  75. package/src/plugins/events.js +5 -20
  76. package/src/plugins/expected_version.js +9 -13
  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 -15
  86. package/src/plugins/options.js +12 -17
  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 +20 -14
  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 +8 -12
  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 +19 -0
  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,21 +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 {
8
- engines: { node: nodeVersionSupportedRange },
9
- } = require('../../package.json')
10
- const { addErrorInfo } = require('../error/info')
5
+ import { addErrorInfo } from '../error/info.js'
6
+ import { ROOT_PACKAGE_JSON } from '../utils/json.js'
11
7
 
12
8
  // Local plugins and `package.json`-installed plugins use user's preferred Node.js version if higher than our minimum
13
9
  // supported version. Else default to the system Node version.
14
10
  // Local and programmatic builds use `@netlify/build` Node.js version, which is
15
11
  // usually the system's Node.js version.
16
12
  // If the user Node version does not satisfy our supported engine range use our own system Node version
17
- const addPluginsNodeVersion = function ({ pluginsOptions, nodePath, userNodeVersion }) {
18
- const currentNodeVersion = cleanVersion(currentVersion)
13
+ export const addPluginsNodeVersion = function ({ pluginsOptions, nodePath, userNodeVersion }) {
14
+ const currentNodeVersion = semver.clean(currentVersion)
19
15
  return pluginsOptions.map((pluginOptions) =>
20
16
  addPluginNodeVersion({ pluginOptions, currentNodeVersion, userNodeVersion, nodePath }),
21
17
  )
@@ -29,18 +25,18 @@ const addPluginNodeVersion = function ({
29
25
  nodePath,
30
26
  }) {
31
27
  return (loadedFrom === 'local' || loadedFrom === 'package.json') &&
32
- satisfies(userNodeVersion, nodeVersionSupportedRange)
28
+ semver.satisfies(userNodeVersion, ROOT_PACKAGE_JSON.engines.node)
33
29
  ? { ...pluginOptions, nodePath, nodeVersion: userNodeVersion }
34
30
  : { ...pluginOptions, nodePath: execPath, nodeVersion: currentNodeVersion }
35
31
  }
36
32
 
37
33
  // Ensure Node.js version is compatible with plugin's `engines.node`
38
- const checkNodeVersion = function ({
34
+ export const checkNodeVersion = function ({
39
35
  nodeVersion,
40
36
  packageName,
41
37
  pluginPackageJson: { engines: { node: pluginNodeVersionRange } = {} } = {},
42
38
  }) {
43
- if (pluginNodeVersionRange && !satisfies(nodeVersion, pluginNodeVersionRange)) {
39
+ if (pluginNodeVersionRange && !semver.satisfies(nodeVersion, pluginNodeVersionRange)) {
44
40
  throwUserError(
45
41
  `The Node.js version is ${nodeVersion} but the plugin "${packageName}" requires ${pluginNodeVersionRange}`,
46
42
  )
@@ -52,5 +48,3 @@ const throwUserError = function (message) {
52
48
  addErrorInfo(error, { type: 'resolveConfig' })
53
49
  throw error
54
50
  }
55
-
56
- module.exports = { addPluginsNodeVersion, checkNodeVersion }
@@ -1,15 +1,13 @@
1
- 'use strict'
1
+ import { dirname } from 'path'
2
2
 
3
- const { dirname } = require('path')
3
+ import { installLocalPluginsDependencies } from '../install/local.js'
4
+ import { measureDuration } from '../time/main.js'
5
+ import { ROOT_PACKAGE_JSON } from '../utils/json.js'
6
+ import { getPackageJson } from '../utils/package.js'
4
7
 
5
- const corePackageJson = require('../../package.json')
6
- const { installLocalPluginsDependencies } = require('../install/local')
7
- const { measureDuration } = require('../time/main')
8
- const { getPackageJson } = require('../utils/package')
9
-
10
- const { useManifest } = require('./manifest/main')
11
- const { checkNodeVersion } = require('./node_version')
12
- const { resolvePluginsPath } = require('./resolve')
8
+ import { useManifest } from './manifest/main.js'
9
+ import { checkNodeVersion } from './node_version.js'
10
+ import { resolvePluginsPath } from './resolve.js'
13
11
 
14
12
  // Load core plugins and user plugins
15
13
  const tGetPluginsOptions = async function ({
@@ -51,7 +49,7 @@ const tGetPluginsOptions = async function ({
51
49
  return { pluginsOptions: pluginsOptionsC }
52
50
  }
53
51
 
54
- const getPluginsOptions = measureDuration(tGetPluginsOptions, 'get_plugins_options')
52
+ export const getPluginsOptions = measureDuration(tGetPluginsOptions, 'get_plugins_options')
55
53
 
56
54
  // Retrieve plugin's main file path.
57
55
  // Then load plugin's `package.json` and `manifest.yml`.
@@ -82,12 +80,9 @@ const isNotRedundantCorePlugin = function (pluginOptionsA, index, pluginsOptions
82
80
 
83
81
  // Retrieve information about @netlify/build when an error happens there and not
84
82
  // in a plugin
85
- const getSpawnInfo = function () {
86
- const { name } = corePackageJson
83
+ export const getSpawnInfo = function () {
87
84
  return {
88
- plugin: { packageName: name, pluginPackageJson: corePackageJson },
89
- location: { event: 'load', packageName: name, loadedFrom: 'core', origin: 'core' },
85
+ plugin: { packageName: ROOT_PACKAGE_JSON.name, pluginPackageJson: ROOT_PACKAGE_JSON },
86
+ location: { event: 'load', packageName: ROOT_PACKAGE_JSON.name, loadedFrom: 'core', origin: 'core' },
90
87
  }
91
88
  }
92
-
93
- module.exports = { getPluginsOptions, getSpawnInfo }
@@ -1,11 +1,9 @@
1
- 'use strict'
2
-
3
- const { handleBuildError } = require('../error/handle')
4
- const { getMajorVersion } = require('../utils/semver')
1
+ import { handleBuildError } from '../error/handle.js'
2
+ import { getMajorVersion } from '../utils/semver.js'
5
3
 
6
4
  // Retrieve plugin's pinned major versions by fetching the latest `PluginRun`
7
5
  // Only applies to `netlify.toml`-only installed plugins.
8
- const addPinnedVersions = async function ({ pluginsOptions, api, siteInfo: { id: siteId }, sendStatus }) {
6
+ export const addPinnedVersions = async function ({ pluginsOptions, api, siteInfo: { id: siteId }, sendStatus }) {
9
7
  if (!sendStatus || api === undefined || !siteId) {
10
8
  return pluginsOptions
11
9
  }
@@ -40,7 +38,7 @@ const addPinnedVersion = function (pluginOptions, pluginRuns) {
40
38
 
41
39
  // Send an API request to pin plugins' major versions.
42
40
  // Only applies to UI-installed plugins.
43
- const pinPlugins = async function ({
41
+ export const pinPlugins = async function ({
44
42
  pluginsOptions,
45
43
  failedPlugins,
46
44
  api,
@@ -131,5 +129,3 @@ const pinPlugin = async function ({
131
129
  const shouldIgnoreError = function ({ status }) {
132
130
  return status === 404
133
131
  }
134
-
135
- module.exports = { addPinnedVersions, pinPlugins }
@@ -1,19 +1,17 @@
1
- 'use strict'
1
+ import { addErrorInfo } from '../error/info.js'
2
+ import { installMissingPlugins } from '../install/missing.js'
3
+ import { resolvePath, tryResolvePath } from '../utils/resolve.js'
2
4
 
3
- const { addErrorInfo } = require('../error/info')
4
- const { installMissingPlugins } = require('../install/missing')
5
- const { resolvePath, tryResolvePath } = require('../utils/resolve')
6
-
7
- const { addExpectedVersions } = require('./expected_version')
8
- const { addPluginsNodeVersion } = require('./node_version')
9
- const { addPinnedVersions } = require('./pinned_version')
5
+ import { addExpectedVersions } from './expected_version.js'
6
+ import { addPluginsNodeVersion } from './node_version.js'
7
+ import { addPinnedVersions } from './pinned_version.js'
10
8
 
11
9
  // Try to find plugins in four places, by priority order:
12
10
  // - already loaded (core plugins)
13
11
  // - local plugin
14
12
  // - external plugin already installed in `node_modules`, most likely through `package.json`
15
13
  // - automatically installed by us, to `.netlify/plugins/`
16
- const resolvePluginsPath = async function ({
14
+ export const resolvePluginsPath = async function ({
17
15
  pluginsOptions,
18
16
  siteInfo,
19
17
  buildDir,
@@ -152,5 +150,3 @@ const resolveMissingPluginPath = async function ({ pluginOptions, pluginOptions:
152
150
  const isMissingPlugin = function ({ isMissing }) {
153
151
  return isMissing
154
152
  }
155
-
156
- module.exports = { resolvePluginsPath }
@@ -1,15 +1,15 @@
1
- 'use strict'
1
+ import { fileURLToPath } from 'url'
2
2
 
3
- const execa = require('execa')
3
+ import execa from 'execa'
4
4
 
5
- const { addErrorInfo } = require('../error/info')
6
- const { logLoadingPlugins, logOutdatedPlugins, logIncompatiblePlugins } = require('../log/messages/compatibility')
7
- const { measureDuration } = require('../time/main')
5
+ import { addErrorInfo } from '../error/info.js'
6
+ import { logLoadingPlugins, logOutdatedPlugins, logIncompatiblePlugins } from '../log/messages/compatibility.js'
7
+ import { measureDuration } from '../time/main.js'
8
8
 
9
- const { getEventFromChild } = require('./ipc')
10
- const { getSpawnInfo } = require('./options')
9
+ import { getEventFromChild } from './ipc.js'
10
+ import { getSpawnInfo } from './options.js'
11
11
 
12
- const CHILD_MAIN_FILE = `${__dirname}/child/main.js`
12
+ const CHILD_MAIN_FILE = fileURLToPath(new URL('child/main.js', import.meta.url))
13
13
 
14
14
  // Start child processes used by all plugins
15
15
  // We fire plugins through child processes so that:
@@ -28,7 +28,7 @@ const tStartPlugins = async function ({ pluginsOptions, buildDir, childEnv, logs
28
28
  return { childProcesses }
29
29
  }
30
30
 
31
- const startPlugins = measureDuration(tStartPlugins, 'start_plugins')
31
+ export const startPlugins = measureDuration(tStartPlugins, 'start_plugins')
32
32
 
33
33
  const startPlugin = async function ({ pluginDir, nodePath, buildDir, childEnv }) {
34
34
  const childProcess = execa.node(CHILD_MAIN_FILE, {
@@ -53,7 +53,7 @@ const startPlugin = async function ({ pluginDir, nodePath, buildDir, childEnv })
53
53
  }
54
54
 
55
55
  // Stop all plugins child processes
56
- const stopPlugins = function (childProcesses) {
56
+ export const stopPlugins = function (childProcesses) {
57
57
  childProcesses.forEach(stopPlugin)
58
58
  }
59
59
 
@@ -64,5 +64,3 @@ const stopPlugin = function ({ childProcess }) {
64
64
 
65
65
  childProcess.kill()
66
66
  }
67
-
68
- module.exports = { startPlugins, stopPlugins }
@@ -1,10 +1,8 @@
1
- 'use strict'
2
-
3
- const { listCorePlugins, isCorePlugin } = require('./list')
1
+ import { listCorePlugins, isCorePlugin } from './list.js'
4
2
 
5
3
  // Add core plugins and user plugins together.
6
4
  // Do not allow user override of core plugins.
7
- const addCorePlugins = function ({ netlifyConfig: { plugins }, constants }) {
5
+ export const addCorePlugins = function ({ netlifyConfig: { plugins }, constants }) {
8
6
  const corePlugins = listCorePlugins(constants)
9
7
  const allCorePlugins = corePlugins
10
8
  .map((corePlugin) => addCoreProperties(corePlugin, plugins))
@@ -49,5 +47,3 @@ const normalizePluginOptions = function ({
49
47
  }) {
50
48
  return { packageName, pluginPath, pinnedVersion, loadedFrom, origin, inputs }
51
49
  }
52
-
53
- module.exports = { addCorePlugins }
@@ -1,13 +1,11 @@
1
- 'use strict'
1
+ import { platform } from 'process'
2
2
 
3
- const { platform } = require('process')
3
+ import execa from 'execa'
4
4
 
5
- const execa = require('execa')
6
-
7
- const { addErrorInfo } = require('../error/info')
8
- const { getBuildCommandDescription } = require('../log/description')
9
- const { logBuildCommandStart } = require('../log/messages/steps')
10
- const { getBuildCommandStdio, handleBuildCommandOutput } = require('../log/stream')
5
+ import { addErrorInfo } from '../error/info.js'
6
+ import { getBuildCommandDescription } from '../log/description.js'
7
+ import { logBuildCommandStart } from '../log/messages/steps.js'
8
+ import { getBuildCommandStdio, handleBuildCommandOutput } from '../log/stream.js'
11
9
 
12
10
  // Fire `build.command`
13
11
  const coreStep = async function ({
@@ -67,7 +65,7 @@ const hasBuildCommand = function ({
67
65
  return buildCommand !== undefined && buildCommand !== ''
68
66
  }
69
67
 
70
- const buildCommandCore = {
68
+ export const buildCommandCore = {
71
69
  event: 'onBuild',
72
70
  coreStep,
73
71
  coreStepId: 'build_command',
@@ -75,5 +73,3 @@ const buildCommandCore = {
75
73
  coreStepDescription,
76
74
  condition: hasBuildCommand,
77
75
  }
78
-
79
- module.exports = { buildCommandCore }
@@ -1,16 +1,14 @@
1
- 'use strict'
1
+ import net from 'net'
2
+ import { normalize, resolve, relative } from 'path'
3
+ import { promisify } from 'util'
2
4
 
3
- const net = require('net')
4
- const { normalize, resolve, relative } = require('path')
5
- const { promisify } = require('util')
5
+ import pEvent from 'p-event'
6
6
 
7
- const pEvent = require('p-event')
7
+ import { addErrorInfo } from '../../error/info.js'
8
+ import { runsAfterDeploy } from '../../plugins/events.js'
9
+ import { addAsyncErrorMessage } from '../../utils/errors.js'
8
10
 
9
- const { addErrorInfo } = require('../../error/info')
10
- const { runsAfterDeploy } = require('../../plugins/events')
11
- const { addAsyncErrorMessage } = require('../../utils/errors')
12
-
13
- const createBuildbotClient = function (buildbotServerSocket) {
11
+ export const createBuildbotClient = function (buildbotServerSocket) {
14
12
  const connectionOpts = getConnectionOpts(buildbotServerSocket)
15
13
  const client = net.createConnection(connectionOpts)
16
14
  return client
@@ -30,9 +28,9 @@ const eConnectBuildbotClient = async function (client) {
30
28
  await pEvent(client, 'connect')
31
29
  }
32
30
 
33
- const connectBuildbotClient = addAsyncErrorMessage(eConnectBuildbotClient, 'Could not connect to buildbot')
31
+ export const connectBuildbotClient = addAsyncErrorMessage(eConnectBuildbotClient, 'Could not connect to buildbot')
34
32
 
35
- const closeBuildbotClient = async function (client) {
33
+ export const closeBuildbotClient = async function (client) {
36
34
  if (client.destroyed) {
37
35
  return
38
36
  }
@@ -56,7 +54,7 @@ const getNextParsedResponsePromise = addAsyncErrorMessage(
56
54
  'Invalid response from buildbot',
57
55
  )
58
56
 
59
- const deploySiteWithBuildbotClient = async function ({ client, events, buildDir, repositoryRoot, constants }) {
57
+ export const deploySiteWithBuildbotClient = async function ({ client, events, buildDir, repositoryRoot, constants }) {
60
58
  const action = shouldWaitForPostProcessing(events) ? 'deploySiteAndAwaitLive' : 'deploySite'
61
59
  const deployDir = getDeployDir({ buildDir, repositoryRoot, constants })
62
60
  const payload = { action, deployDir }
@@ -102,10 +100,3 @@ const shouldWaitForPostProcessing = function (events) {
102
100
  const hasPostDeployLogic = function (event) {
103
101
  return runsAfterDeploy(event)
104
102
  }
105
-
106
- module.exports = {
107
- createBuildbotClient,
108
- connectBuildbotClient,
109
- closeBuildbotClient,
110
- deploySiteWithBuildbotClient,
111
- }
@@ -1,14 +1,12 @@
1
- 'use strict'
1
+ import { saveUpdatedConfig, restoreUpdatedConfig } from '../../core/config.js'
2
+ import { logDeploySuccess } from '../../log/messages/plugins.js'
2
3
 
3
- const { saveUpdatedConfig, restoreUpdatedConfig } = require('../../core/config')
4
- const { logDeploySuccess } = require('../../log/messages/plugins')
5
-
6
- const {
4
+ import {
7
5
  createBuildbotClient,
8
6
  connectBuildbotClient,
9
7
  closeBuildbotClient,
10
8
  deploySiteWithBuildbotClient,
11
- } = require('./buildbot_client')
9
+ } from './buildbot_client.js'
12
10
 
13
11
  const coreStep = async function ({
14
12
  buildDir,
@@ -63,7 +61,7 @@ const shouldDeploy = function ({ buildbotServerSocket }) {
63
61
  return buildbotServerSocket !== undefined
64
62
  }
65
63
 
66
- const deploySite = {
64
+ export const deploySite = {
67
65
  event: 'onPostBuild',
68
66
  coreStep,
69
67
  coreStepId: 'deploy_site',
@@ -71,5 +69,3 @@ const deploySite = {
71
69
  coreStepDescription: () => 'Deploy site',
72
70
  condition: shouldDeploy,
73
71
  }
74
-
75
- module.exports = { deploySite }
@@ -1,15 +1,13 @@
1
- 'use strict'
1
+ import readdirp from 'readdirp'
2
2
 
3
- const readdirp = require('readdirp')
4
-
5
- const { addErrorInfo } = require('../../error/info')
3
+ import { addErrorInfo } from '../../error/info.js'
6
4
 
7
5
  const MODULE_NOT_FOUND_CODE = 'MODULE_NOT_FOUND'
8
6
  const MODULE_NOT_FOUND_ESBUILD_REGEXP = /^Could not resolve ['"]([^'"]+)/
9
7
  const MODULE_NOT_FOUND_REGEXP = /Cannot find module ['"]([^'"]+)/
10
8
 
11
9
  // Handle errors coming from zip-it-and-ship-it
12
- const getZipError = async function (error, functionsSrc) {
10
+ export const getZipError = async function (error, functionsSrc) {
13
11
  const moduleNotFoundError = await getModuleNotFoundError(error, functionsSrc)
14
12
 
15
13
  if (moduleNotFoundError) {
@@ -151,7 +149,7 @@ package = "@netlify/plugin-functions-install-core"
151
149
  }
152
150
 
153
151
  // We need to load the site's `package.json` when bundling Functions. This is
154
- // because `optionalDependencies` can make `require()` fail, but we don't want
152
+ // because `optionalDependencies` can make `import()` fail, but we don't want
155
153
  // to error then. However, if the `package.json` is invalid, we fail the build.
156
154
  const isPackageJsonError = function (error) {
157
155
  return error.message.includes(PACKAGE_JSON_ORIGINAL_MESSAGE)
@@ -163,5 +161,3 @@ const getPackageJsonError = function (error) {
163
161
  addErrorInfo(error, { type: 'resolveConfig' })
164
162
  return error
165
163
  }
166
-
167
- module.exports = { getZipError }
@@ -1,6 +1,4 @@
1
- 'use strict'
2
-
3
- const getZisiFeatureFlags = (featureFlags) => ({
1
+ export const getZisiFeatureFlags = (featureFlags) => ({
4
2
  ...featureFlags,
5
3
  buildGoSource: featureFlags.buildbot_build_go_functions,
6
4
  defaultEsModulesToEsbuild: featureFlags.buildbot_es_modules_esbuild,
@@ -9,5 +7,3 @@ const getZisiFeatureFlags = (featureFlags) => ({
9
7
  parseWithEsbuild: featureFlags.buildbot_zisi_esbuild_parser,
10
8
  traceWithNft: featureFlags.buildbot_zisi_trace_nft,
11
9
  })
12
-
13
- module.exports = { getZisiFeatureFlags }
@@ -1,18 +1,15 @@
1
- 'use strict'
1
+ import { join, resolve } from 'path'
2
2
 
3
- const { join, resolve } = require('path')
3
+ import { zipFunctions } from '@netlify/zip-it-and-ship-it'
4
+ import mapObject from 'map-obj'
5
+ import pathExists from 'path-exists'
4
6
 
5
- // We can't use destructuring for zisi as we rely on spies for the `zipFunctions` method within our tests
6
- const zipItAndShipIt = require('@netlify/zip-it-and-ship-it')
7
- const mapObject = require('map-obj')
8
- const pathExists = require('path-exists')
7
+ import { log } from '../../log/logger.js'
8
+ import { logBundleResults, logFunctionsNonExistingDir, logFunctionsToBundle } from '../../log/messages/core_steps.js'
9
9
 
10
- const { log } = require('../../log/logger')
11
- const { logBundleResults, logFunctionsNonExistingDir, logFunctionsToBundle } = require('../../log/messages/core_steps')
12
-
13
- const { getZipError } = require('./error')
14
- const { getZisiFeatureFlags } = require('./feature_flags')
15
- const { getUserAndInternalFunctions, validateFunctionsSrc } = require('./utils')
10
+ import { getZipError } from './error.js'
11
+ import { getZisiFeatureFlags } from './feature_flags.js'
12
+ import { getUserAndInternalFunctions, validateFunctionsSrc } from './utils.js'
16
13
 
17
14
  // Returns `true` if at least one of the functions has been configured to use
18
15
  // esbuild.
@@ -182,7 +179,7 @@ const hasFunctionsDirectories = async function ({ buildDir, constants: { INTERNA
182
179
  return await pathExists(internalFunctionsSrc)
183
180
  }
184
181
 
185
- const bundleFunctions = {
182
+ export const bundleFunctions = {
186
183
  event: 'onBuild',
187
184
  coreStep,
188
185
  coreStepId: 'functions_bundling',
@@ -191,4 +188,13 @@ const bundleFunctions = {
191
188
  condition: hasFunctionsDirectories,
192
189
  }
193
190
 
194
- module.exports = { bundleFunctions }
191
+ // Named imports with ES modules cannot be mocked (unlike CommonJS) because
192
+ // they are bound at load time.
193
+ // However, some of our tests are asserting which arguments are passed to
194
+ // `zip-it-and-ship-it` methods. Therefore, we need to use an intermediary
195
+ // function and export them so tests can use it.
196
+ export const zipItAndShipIt = {
197
+ async zipFunctions(...args) {
198
+ return await zipFunctions(...args)
199
+ },
200
+ }
@@ -1,16 +1,14 @@
1
- 'use strict'
1
+ import { stat } from 'fs'
2
+ import { relative } from 'path'
3
+ import { promisify } from 'util'
2
4
 
3
- const { stat } = require('fs')
4
- const { relative } = require('path')
5
- const { promisify } = require('util')
5
+ import { listFunctions } from '@netlify/zip-it-and-ship-it'
6
6
 
7
- const { listFunctions } = require('@netlify/zip-it-and-ship-it')
7
+ import { addErrorInfo } from '../../error/info.js'
8
8
 
9
- const pStat = promisify(stat)
10
-
11
- const { addErrorInfo } = require('../../error/info')
9
+ import { getZisiFeatureFlags } from './feature_flags.js'
12
10
 
13
- const { getZisiFeatureFlags } = require('./feature_flags')
11
+ const pStat = promisify(stat)
14
12
 
15
13
  // Returns the `mainFile` of each function found in `functionsSrc`, relative to
16
14
  // `functionsSrc`.
@@ -24,7 +22,7 @@ const getRelativeFunctionMainFiles = async function ({ featureFlags, functionsSr
24
22
  return functions.map(({ mainFile }) => relative(functionsSrc, mainFile))
25
23
  }
26
24
 
27
- const getUserAndInternalFunctions = ({
25
+ export const getUserAndInternalFunctions = ({
28
26
  featureFlags,
29
27
  functionsSrc,
30
28
  functionsSrcExists,
@@ -42,7 +40,7 @@ const getUserAndInternalFunctions = ({
42
40
  // Returns `true` if the functions directory exists and is valid. Returns
43
41
  // `false` if it doesn't exist. Throws an error if it's invalid or can't
44
42
  // be accessed.
45
- const validateFunctionsSrc = async function ({ functionsSrc, relativeFunctionsSrc }) {
43
+ export const validateFunctionsSrc = async function ({ functionsSrc, relativeFunctionsSrc }) {
46
44
  if (functionsSrc === undefined) {
47
45
  return false
48
46
  }
@@ -69,5 +67,3 @@ const validateFunctionsSrc = async function ({ functionsSrc, relativeFunctionsSr
69
67
  throw error
70
68
  }
71
69
  }
72
-
73
- module.exports = { getUserAndInternalFunctions, validateFunctionsSrc }
@@ -1,11 +1,9 @@
1
- 'use strict'
1
+ import pathExists from 'path-exists'
2
2
 
3
- const pathExists = require('path-exists')
4
-
5
- const { installFunctionDependencies } = require('../../install/functions')
3
+ import { installFunctionDependencies } from '../../install/functions.js'
6
4
 
7
5
  // Plugin to package Netlify functions with @netlify/zip-it-and-ship-it
8
- const onPreBuild = async function ({ constants: { FUNCTIONS_SRC, IS_LOCAL } }) {
6
+ export const onPreBuild = async function ({ constants: { FUNCTIONS_SRC, IS_LOCAL } }) {
9
7
  if (!(await pathExists(FUNCTIONS_SRC))) {
10
8
  return {}
11
9
  }
@@ -13,5 +11,3 @@ const onPreBuild = async function ({ constants: { FUNCTIONS_SRC, IS_LOCAL } }) {
13
11
  await installFunctionDependencies(FUNCTIONS_SRC, IS_LOCAL)
14
12
  return {}
15
13
  }
16
-
17
- module.exports = { onPreBuild }
@@ -1,8 +1,13 @@
1
- 'use strict'
1
+ import { createRequire } from 'module'
2
+ import { fileURLToPath } from 'url'
2
3
 
3
- const { LOCAL_INSTALL_PLUGIN_NAME } = require('../install/local')
4
+ import { LOCAL_INSTALL_PLUGIN_NAME } from '../install/local.js'
4
5
 
5
- const FUNCTIONS_INSTALL_PLUGIN = `${__dirname}/functions_install/index.js`
6
+ // TODO: use `import.resolve()` once it is available without any experimental
7
+ // flags
8
+ const require = createRequire(import.meta.url)
9
+
10
+ const FUNCTIONS_INSTALL_PLUGIN = fileURLToPath(new URL('functions_install/index.js', import.meta.url))
6
11
 
7
12
  // List of core plugin names
8
13
  const FUNCTIONS_INSTALL_PLUGIN_NAME = '@netlify/plugin-functions-install-core'
@@ -12,7 +17,7 @@ const CORE_PLUGINS = new Set([FUNCTIONS_INSTALL_PLUGIN_NAME, LOCAL_INSTALL_PLUGI
12
17
  const EDGE_HANDLERS_PLUGIN_PATH = require.resolve(EDGE_HANDLERS_PLUGIN_NAME)
13
18
 
14
19
  // Plugins that are installed and enabled by default
15
- const listCorePlugins = function ({ FUNCTIONS_SRC, EDGE_HANDLERS_SRC }) {
20
+ export const listCorePlugins = function ({ FUNCTIONS_SRC, EDGE_HANDLERS_SRC }) {
16
21
  const functionsInstallPlugin = getFunctionsInstallPlugin(FUNCTIONS_SRC)
17
22
  const edgeHandlersPlugin = getEdgeHandlersPlugin(EDGE_HANDLERS_SRC)
18
23
  return [functionsInstallPlugin, edgeHandlersPlugin].filter(Boolean)
@@ -38,8 +43,6 @@ const getEdgeHandlersPlugin = function (EDGE_HANDLERS_SRC) {
38
43
  return { package: EDGE_HANDLERS_PLUGIN_NAME, pluginPath: EDGE_HANDLERS_PLUGIN_PATH }
39
44
  }
40
45
 
41
- const isCorePlugin = function (packageName) {
46
+ export const isCorePlugin = function (packageName) {
42
47
  return CORE_PLUGINS.has(packageName)
43
48
  }
44
-
45
- module.exports = { listCorePlugins, isCorePlugin }
package/src/status/add.js CHANGED
@@ -1,7 +1,5 @@
1
- 'use strict'
2
-
3
1
  // Merge plugin status to the list of plugin statuses.
4
- const addStatus = function ({ newStatus, statuses, event, packageName, pluginPackageJson: { version } = {} }) {
2
+ export const addStatus = function ({ newStatus, statuses, event, packageName, pluginPackageJson: { version } = {} }) {
5
3
  // Either:
6
4
  // - `build.command`
7
5
  // - no status was set
@@ -36,5 +34,3 @@ const canOverrideStatus = function (formerStatus, newStatus) {
36
34
 
37
35
  // Possible status states, ordered by severity.
38
36
  const STATES = ['success', 'canceled_plugin', 'failed_plugin', 'failed_build']
39
-
40
- module.exports = { addStatus }
@@ -1,9 +1,7 @@
1
- 'use strict'
2
-
3
- const stripAnsi = require('strip-ansi')
1
+ import stripAnsi from 'strip-ansi'
4
2
 
5
3
  // Remove colors from statuses
6
- const removeStatusesColors = function (statuses) {
4
+ export const removeStatusesColors = function (statuses) {
7
5
  return statuses.map(removeStatusColors)
8
6
  }
9
7
 
@@ -23,5 +21,3 @@ const removeAttrColor = function (status, attribute) {
23
21
  const valueA = stripAnsi(value)
24
22
  return { [attribute]: valueA }
25
23
  }
26
-
27
- module.exports = { removeStatusesColors }
@@ -1,15 +1,11 @@
1
- 'use strict'
2
-
3
- const { addErrorInfo } = require('../error/info')
4
- const { getFullErrorInfo } = require('../error/parse/parse')
5
- const { serializeErrorStatus } = require('../error/parse/serialize_status')
1
+ import { addErrorInfo } from '../error/info.js'
2
+ import { getFullErrorInfo } from '../error/parse/parse.js'
3
+ import { serializeErrorStatus } from '../error/parse/serialize_status.js'
6
4
 
7
5
  // Errors that happen during plugin loads should be reported as error statuses
8
- const addPluginLoadErrorStatus = function ({ error, packageName, version, debug }) {
6
+ export const addPluginLoadErrorStatus = function ({ error, packageName, version, debug }) {
9
7
  const fullErrorInfo = getFullErrorInfo({ error, colors: false, debug })
10
8
  const errorStatus = serializeErrorStatus({ fullErrorInfo, state: 'failed_build' })
11
9
  const statuses = [{ ...errorStatus, event: 'load', packageName, version }]
12
10
  addErrorInfo(error, { statuses })
13
11
  }
14
-
15
- module.exports = { addPluginLoadErrorStatus }
@@ -1,12 +1,10 @@
1
- 'use strict'
1
+ import { handleBuildError } from '../error/handle.js'
2
+ import { logStatuses } from '../log/messages/status.js'
2
3
 
3
- const { handleBuildError } = require('../error/handle')
4
- const { logStatuses } = require('../log/messages/status')
5
-
6
- const { removeStatusesColors } = require('./colors')
4
+ import { removeStatusesColors } from './colors.js'
7
5
 
8
6
  // Report plugin statuses to the console and API
9
- const reportStatuses = async function ({
7
+ export const reportStatuses = async function ({
10
8
  statuses,
11
9
  childEnv,
12
10
  api,
@@ -128,5 +126,3 @@ const sendApiStatus = async function ({
128
126
  await handleBuildError(error, { errorMonitor, netlifyConfig, childEnv, mode, logs, debug, testOpts })
129
127
  }
130
128
  }
131
-
132
- module.exports = { reportStatuses }