@netlify/build 25.0.3 → 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 +4 -2
  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 -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 +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 +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 +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
package/package.json CHANGED
@@ -1,8 +1,10 @@
1
1
  {
2
2
  "name": "@netlify/build",
3
- "version": "25.0.3",
3
+ "version": "26.0.0",
4
4
  "description": "Netlify build module",
5
- "main": "src/core/main.js",
5
+ "type": "module",
6
+ "exports": "./src/core/main.js",
7
+ "main": "./src/core/main.js",
6
8
  "types": "types/index.d.ts",
7
9
  "bin": {
8
10
  "netlify-build": "./src/core/bin.js"
package/src/core/bin.js CHANGED
@@ -1,15 +1,14 @@
1
1
  #!/usr/bin/env node
2
- 'use strict'
3
2
 
4
- const process = require('process')
3
+ import process from 'process'
5
4
 
6
- const filterObj = require('filter-obj')
7
- const yargs = require('yargs')
5
+ import filterObj from 'filter-obj'
6
+ import yargs from 'yargs'
8
7
 
9
- const { normalizeCliFeatureFlags } = require('./feature_flags')
10
- const { FLAGS } = require('./flags')
11
- const build = require('./main')
12
- const { FALLBACK_SEVERITY_ENTRY } = require('./severity')
8
+ import { normalizeCliFeatureFlags } from './feature_flags.js'
9
+ import { FLAGS } from './flags.js'
10
+ import build from './main.js'
11
+ import { FALLBACK_SEVERITY_ENTRY } from './severity.js'
13
12
 
14
13
  // CLI entry point.
15
14
  // Before adding logic to this file, please consider adding it to the main
@@ -1,19 +1,15 @@
1
- /* eslint-disable max-lines */
2
- 'use strict'
1
+ import { resolveConfig, updateConfig, restoreConfig } from '@netlify/config'
2
+ import mapObj from 'map-obj'
3
3
 
4
- const mapObj = require('map-obj')
4
+ import { getChildEnv } from '../env/main.js'
5
+ import { addApiErrorHandlers } from '../error/api.js'
6
+ import { changeErrorType } from '../error/info.js'
7
+ import { logBuildDir, logConfigPath, logConfig, logContext } from '../log/messages/config.js'
8
+ import { logConfigOnUpload, logHeadersOnUpload, logRedirectsOnUpload } from '../log/messages/mutations.js'
9
+ import { measureDuration } from '../time/main.js'
10
+ import { getPackageJson } from '../utils/package.js'
5
11
 
6
- const { getChildEnv } = require('../env/main')
7
- const { addApiErrorHandlers } = require('../error/api')
8
- const { changeErrorType } = require('../error/info')
9
- const { logBuildDir, logConfigPath, logConfig, logContext } = require('../log/messages/config')
10
- const { logConfigOnUpload, logHeadersOnUpload, logRedirectsOnUpload } = require('../log/messages/mutations')
11
- const { measureDuration } = require('../time/main')
12
- const { getPackageJson } = require('../utils/package')
13
-
14
- const { getUserNodeVersion } = require('./user_node_version')
15
-
16
- const netlifyConfigPromise = import('@netlify/config')
12
+ import { getUserNodeVersion } from './user_node_version.js'
17
13
 
18
14
  // Retrieve immutable options passed to `@netlify/config`.
19
15
  // This does not include options which might change during the course of the
@@ -22,7 +18,7 @@ const netlifyConfigPromise = import('@netlify/config')
22
18
  // the build
23
19
  // - If plugins change the configuration, `configMutations` is used instead
24
20
  // In both cases, almost all options should remain the same.
25
- const getConfigOpts = function ({
21
+ export const getConfigOpts = function ({
26
22
  config,
27
23
  defaultConfig,
28
24
  cwd,
@@ -78,7 +74,7 @@ const tLoadConfig = async function ({ configOpts, cachedConfig, cachedConfigPath
78
74
  siteInfo,
79
75
  env,
80
76
  } = await resolveInitialConfig(configOpts, cachedConfig, cachedConfigPath)
81
- await logConfigInfo({ logs, configPath, buildDir, netlifyConfig, context: contextA, debug })
77
+ logConfigInfo({ logs, configPath, buildDir, netlifyConfig, context: contextA, debug })
82
78
 
83
79
  const apiA = addApiErrorHandlers(api)
84
80
  const envValues = mapObj(env, (key, { value }) => [key, value])
@@ -102,20 +98,19 @@ const tLoadConfig = async function ({ configOpts, cachedConfig, cachedConfigPath
102
98
  }
103
99
  }
104
100
 
105
- const loadConfig = measureDuration(tLoadConfig, 'resolve_config')
101
+ export const loadConfig = measureDuration(tLoadConfig, 'resolve_config')
106
102
 
107
103
  // Retrieve initial configuration.
108
104
  // In the buildbot and CLI, we re-use the already parsed `@netlify/config`
109
105
  // return value which is passed as `cachedConfig`/`cachedConfigPath`.
110
106
  const resolveInitialConfig = async function (configOpts, cachedConfig, cachedConfigPath) {
111
- const { resolveConfig } = await netlifyConfigPromise
112
107
  return await resolveConfig({ ...configOpts, cachedConfig, cachedConfigPath })
113
108
  }
114
109
 
115
- const logConfigInfo = async function ({ logs, configPath, buildDir, netlifyConfig, context, debug }) {
110
+ const logConfigInfo = function ({ logs, configPath, buildDir, netlifyConfig, context, debug }) {
116
111
  logBuildDir(logs, buildDir)
117
112
  logConfigPath(logs, configPath)
118
- await logConfig({ logs, netlifyConfig, debug })
113
+ logConfig({ logs, netlifyConfig, debug })
119
114
  logContext(logs, context)
120
115
  }
121
116
 
@@ -126,8 +121,7 @@ const logConfigInfo = async function ({ logs, configPath, buildDir, netlifyConfi
126
121
  // change would create debug logs which would be too verbose.
127
122
  // Errors are propagated and assigned to the specific plugin or core step
128
123
  // which changed the configuration.
129
- const resolveUpdatedConfig = async function (configOpts, configMutations) {
130
- const { resolveConfig } = await netlifyConfigPromise
124
+ export const resolveUpdatedConfig = async function (configOpts, configMutations) {
131
125
  try {
132
126
  return await resolveConfig({ ...configOpts, configMutations, debug: false })
133
127
  } catch (error) {
@@ -141,7 +135,7 @@ const resolveUpdatedConfig = async function (configOpts, configMutations) {
141
135
  // This is only done when `saveConfig` is `true`. This allows performing this
142
136
  // in the buildbot but not in local builds, since only the latter run in a
143
137
  // container and we want to avoid saving files on local machines.
144
- const saveUpdatedConfig = async function ({
138
+ export const saveUpdatedConfig = async function ({
145
139
  configMutations,
146
140
  buildDir,
147
141
  repositoryRoot,
@@ -158,7 +152,6 @@ const saveUpdatedConfig = async function ({
158
152
  return
159
153
  }
160
154
 
161
- const { updateConfig } = await netlifyConfigPromise
162
155
  await updateConfig(configMutations, {
163
156
  buildDir,
164
157
  configPath,
@@ -174,7 +167,7 @@ const saveUpdatedConfig = async function ({
174
167
  await logRedirectsOnUpload({ logs, redirectsPath, debug })
175
168
  }
176
169
 
177
- const restoreUpdatedConfig = async function ({
170
+ export const restoreUpdatedConfig = async function ({
178
171
  configMutations,
179
172
  buildDir,
180
173
  repositoryRoot,
@@ -187,15 +180,5 @@ const restoreUpdatedConfig = async function ({
187
180
  return
188
181
  }
189
182
 
190
- const { restoreConfig } = await netlifyConfigPromise
191
183
  await restoreConfig(configMutations, { buildDir, configPath, headersPath, redirectsPath })
192
184
  }
193
-
194
- module.exports = {
195
- getConfigOpts,
196
- loadConfig,
197
- resolveUpdatedConfig,
198
- saveUpdatedConfig,
199
- restoreUpdatedConfig,
200
- }
201
- /* eslint-enable max-lines */
@@ -1,16 +1,13 @@
1
- 'use strict'
1
+ import { relative, normalize } from 'path'
2
2
 
3
- const { relative, normalize } = require('path')
3
+ import { getCacheDir } from '@netlify/cache-utils'
4
+ import mapObj from 'map-obj'
5
+ import pathExists from 'path-exists'
4
6
 
5
- const mapObj = require('map-obj')
6
- const pathExists = require('path-exists')
7
-
8
- const { ROOT_PACKAGE_JSON } = require('../utils/json')
9
-
10
- const cacheUtilsPromise = import('@netlify/cache-utils')
7
+ import { ROOT_PACKAGE_JSON } from '../utils/json.js'
11
8
 
12
9
  // Retrieve constants passed to plugins
13
- const getConstants = async function ({
10
+ export const getConstants = async function ({
14
11
  configPath,
15
12
  buildDir,
16
13
  functionsDistDir,
@@ -22,7 +19,6 @@ const getConstants = async function ({
22
19
  mode,
23
20
  }) {
24
21
  const isLocal = mode !== 'buildbot'
25
- const { getCacheDir } = await cacheUtilsPromise
26
22
  const normalizedCacheDir = getCacheDir({ cacheDir, cwd: buildDir })
27
23
 
28
24
  const constants = {
@@ -55,7 +51,7 @@ const INTERNAL_FUNCTIONS_SRC = '.netlify/functions-internal'
55
51
  // Retrieve constants which might change during the build if a plugin modifies
56
52
  // `netlifyConfig` or creates some default directories.
57
53
  // Unlike readonly constants, this is called again before each build step.
58
- const addMutableConstants = async function ({
54
+ export const addMutableConstants = async function ({
59
55
  constants,
60
56
  buildDir,
61
57
  netlifyConfig: {
@@ -149,5 +145,3 @@ const CONSTANT_PATHS = new Set([
149
145
  'EDGE_HANDLERS_SRC',
150
146
  'CACHE_DIR',
151
147
  ])
152
-
153
- module.exports = { getConstants, addMutableConstants }
package/src/core/dry.js CHANGED
@@ -1,12 +1,10 @@
1
- 'use strict'
1
+ import pFilter from 'p-filter'
2
2
 
3
- const pFilter = require('p-filter')
4
-
5
- const { logDryRunStart, logDryRunStep, logDryRunEnd } = require('../log/messages/dry')
6
- const { runsOnlyOnBuildFailure } = require('../plugins/events')
3
+ import { logDryRunStart, logDryRunStep, logDryRunEnd } from '../log/messages/dry.js'
4
+ import { runsOnlyOnBuildFailure } from '../plugins/events.js'
7
5
 
8
6
  // If the `dry` flag is specified, do a dry run
9
- const doDryRun = async function ({ buildDir, steps, netlifyConfig, constants, buildbotServerSocket, logs }) {
7
+ export const doDryRun = async function ({ buildDir, steps, netlifyConfig, constants, buildbotServerSocket, logs }) {
10
8
  const successSteps = await pFilter(steps, ({ event, condition }) =>
11
9
  shouldIncludeStep({ buildDir, event, condition, netlifyConfig, constants, buildbotServerSocket }),
12
10
  )
@@ -39,5 +37,3 @@ const shouldIncludeStep = async function ({
39
37
  const getEventLength = function ({ event }) {
40
38
  return event.length
41
39
  }
42
-
43
- module.exports = { doDryRun }
@@ -1,7 +1,5 @@
1
- 'use strict'
2
-
3
1
  // From CLI `--featureFlags=a,b,c` to programmatic `{ a: true, b: true, c: true }`
4
- const normalizeCliFeatureFlags = function (cliFeatureFlags) {
2
+ export const normalizeCliFeatureFlags = function (cliFeatureFlags) {
5
3
  return Object.assign({}, ...cliFeatureFlags.split(',').filter(isNotEmpty).map(getFeatureFlag))
6
4
  }
7
5
 
@@ -14,7 +12,7 @@ const getFeatureFlag = function (name) {
14
12
  }
15
13
 
16
14
  // Default values for feature flags
17
- const DEFAULT_FEATURE_FLAGS = {
15
+ export const DEFAULT_FEATURE_FLAGS = {
18
16
  buildbot_build_go_functions: false,
19
17
  buildbot_create_functions_manifest: false,
20
18
  buildbot_es_modules_esbuild: false,
@@ -23,5 +21,3 @@ const DEFAULT_FEATURE_FLAGS = {
23
21
  buildbot_scheduled_functions: false,
24
22
  zisi_parse_isc: false,
25
23
  }
26
-
27
- module.exports = { normalizeCliFeatureFlags, DEFAULT_FEATURE_FLAGS }
package/src/core/flags.js CHANGED
@@ -1,9 +1,7 @@
1
- 'use strict'
2
-
3
1
  /* eslint eslint-comments/no-use: off, max-lines: off */
4
2
 
5
3
  // All CLI flags
6
- const FLAGS = {
4
+ export const FLAGS = {
7
5
  config: {
8
6
  string: true,
9
7
  describe: `Path to the configuration file.
@@ -129,7 +127,7 @@ Default: false`,
129
127
  describe: `Environment in which this is loaded. Can be:
130
128
  - 'buildbot': within Netlify Buildbot
131
129
  - 'cli': within Netlify CLI
132
- - 'require': through require('@netlify/build')`,
130
+ - 'require': through import('@netlify/build')`,
133
131
  hidden: true,
134
132
  },
135
133
  debug: {
@@ -184,5 +182,3 @@ Default: false`,
184
182
  describe: 'Buffer output instead of printing it',
185
183
  },
186
184
  }
187
-
188
- module.exports = { FLAGS }
@@ -1,8 +1,6 @@
1
- 'use strict'
1
+ import psList from 'ps-list'
2
2
 
3
- const psList = require('ps-list')
4
-
5
- const { logLingeringProcesses } = require('../log/messages/core')
3
+ import { logLingeringProcesses } from '../log/messages/core.js'
6
4
 
7
5
  // Print a warning when some build processes are still running.
8
6
  // We cannot rely on using the process tree:
@@ -20,7 +18,11 @@ const { logLingeringProcesses } = require('../log/messages/core')
20
18
  // Therefore, we run this in a controlled environment only (the buildbot) and
21
19
  // exclude specific processes manually. This is a lesser evil, although still
22
20
  // quite hacky.
23
- const warnOnLingeringProcesses = async function ({ mode, logs, testOpts: { silentLingeringProcesses = false } }) {
21
+ export const warnOnLingeringProcesses = async function ({
22
+ mode,
23
+ logs,
24
+ testOpts: { silentLingeringProcesses = false },
25
+ }) {
24
26
  if (mode !== 'buildbot' || silentLingeringProcesses) {
25
27
  return
26
28
  }
@@ -81,5 +83,3 @@ const IGNORED_COMMANDS = [
81
83
  'jest-worker',
82
84
  'broccoli-babel-transpiler',
83
85
  ]
84
-
85
- module.exports = { warnOnLingeringProcesses }
package/src/core/main.js CHANGED
@@ -1,30 +1,28 @@
1
- 'use strict'
2
-
3
1
  /* eslint-disable max-lines, import/max-dependencies */
4
- const { handleBuildError } = require('../error/handle')
5
- const { getErrorInfo } = require('../error/info')
6
- const { startErrorMonitor } = require('../error/monitor/start')
7
- const { getBufferLogs } = require('../log/logger')
8
- const { logBuildStart, logTimer, logBuildSuccess } = require('../log/messages/core')
9
- const { loadPlugins } = require('../plugins/load')
10
- const { getPluginsOptions } = require('../plugins/options')
11
- const { pinPlugins } = require('../plugins/pinned_version')
12
- const { startPlugins, stopPlugins } = require('../plugins/spawn')
13
- const { addCorePlugins } = require('../plugins_core/add')
14
- const { reportStatuses } = require('../status/report')
15
- const { getSteps } = require('../steps/get')
16
- const { runSteps } = require('../steps/run_steps')
17
- const { trackBuildComplete } = require('../telemetry/main')
18
- const { initTimers, measureDuration } = require('../time/main')
19
- const { reportTimers } = require('../time/report')
2
+ import { handleBuildError } from '../error/handle.js'
3
+ import { getErrorInfo } from '../error/info.js'
4
+ import { startErrorMonitor } from '../error/monitor/start.js'
5
+ import { getBufferLogs } from '../log/logger.js'
6
+ import { logBuildStart, logTimer, logBuildSuccess } from '../log/messages/core.js'
7
+ import { loadPlugins } from '../plugins/load.js'
8
+ import { getPluginsOptions } from '../plugins/options.js'
9
+ import { pinPlugins } from '../plugins/pinned_version.js'
10
+ import { startPlugins, stopPlugins } from '../plugins/spawn.js'
11
+ import { addCorePlugins } from '../plugins_core/add.js'
12
+ import { reportStatuses } from '../status/report.js'
13
+ import { getSteps } from '../steps/get.js'
14
+ import { runSteps } from '../steps/run_steps.js'
15
+ import { trackBuildComplete } from '../telemetry/main.js'
16
+ import { initTimers, measureDuration } from '../time/main.js'
17
+ import { reportTimers } from '../time/report.js'
20
18
 
21
- const { getConfigOpts, loadConfig } = require('./config')
22
- const { getConstants } = require('./constants')
23
- const { doDryRun } = require('./dry')
24
- const { warnOnLingeringProcesses } = require('./lingering')
25
- const { warnOnMissingSideFiles } = require('./missing_side_file')
26
- const { normalizeFlags } = require('./normalize_flags')
27
- const { getSeverity } = require('./severity')
19
+ import { getConfigOpts, loadConfig } from './config.js'
20
+ import { getConstants } from './constants.js'
21
+ import { doDryRun } from './dry.js'
22
+ import { warnOnLingeringProcesses } from './lingering.js'
23
+ import { warnOnMissingSideFiles } from './missing_side_file.js'
24
+ import { normalizeFlags } from './normalize_flags.js'
25
+ import { getSeverity } from './severity.js'
28
26
 
29
27
  /**
30
28
  * Main entry point of Netlify Build.
@@ -50,7 +48,7 @@ const { getSeverity } = require('./severity')
50
48
  * 0 (success), 1 (build cancelled), 2 (user error), 3 (plugin error), 4 (system error). Can be used as exit code.
51
49
  * @returns {string[]} buildResult.logs - When using the `buffer` option, all log messages
52
50
  */
53
- const build = async function (flags = {}) {
51
+ export default async function buildSite(flags = {}) {
54
52
  const {
55
53
  errorMonitor,
56
54
  framework,
@@ -595,7 +593,7 @@ const runBuild = async function ({
595
593
  verbose,
596
594
  })
597
595
 
598
- const { steps, events } = await getSteps(pluginsSteps)
596
+ const { steps, events } = getSteps(pluginsSteps)
599
597
 
600
598
  if (dry) {
601
599
  await doDryRun({ buildDir, steps, netlifyConfig, constants, buildbotServerSocket, logs })
@@ -687,6 +685,4 @@ const telemetryReport = async function ({
687
685
  await handleBuildError(error, errorParams)
688
686
  }
689
687
  }
690
-
691
- module.exports = build
692
688
  /* eslint-enable max-lines, import/max-dependencies */
@@ -1,16 +1,14 @@
1
- 'use strict'
1
+ import { relative } from 'path'
2
2
 
3
- const { relative } = require('path')
3
+ import pathExists from 'path-exists'
4
4
 
5
- const pathExists = require('path-exists')
6
-
7
- const { logMissingSideFile } = require('../log/messages/core')
5
+ import { logMissingSideFile } from '../log/messages/core.js'
8
6
 
9
7
  // Some files like `_headers` and `_redirects` must be copied to the publish
10
8
  // directory to be used in production. When those are present in the repository
11
9
  // but not in the publish directory, this most likely indicates that the build
12
10
  // command accidentally forgot to copy those. We then print a warning message.
13
- const warnOnMissingSideFiles = async function ({
11
+ export const warnOnMissingSideFiles = async function ({
14
12
  buildDir,
15
13
  netlifyConfig: {
16
14
  build: { publish },
@@ -29,5 +27,3 @@ const warnOnMissingSideFile = async function ({ logs, sideFile, buildDir, publis
29
27
 
30
28
  logMissingSideFile(logs, sideFile, relative(buildDir, publish))
31
29
  }
32
-
33
- module.exports = { warnOnMissingSideFiles }
@@ -1,14 +1,12 @@
1
- 'use strict'
1
+ import { env, execPath } from 'process'
2
2
 
3
- const { env, execPath } = require('process')
3
+ import { logFlags } from '../log/messages/config.js'
4
+ import { removeFalsy } from '../utils/remove_falsy.js'
4
5
 
5
- const { logFlags } = require('../log/messages/config')
6
- const { removeFalsy } = require('../utils/remove_falsy')
7
-
8
- const { DEFAULT_FEATURE_FLAGS } = require('./feature_flags')
6
+ import { DEFAULT_FEATURE_FLAGS } from './feature_flags.js'
9
7
 
10
8
  // Normalize CLI flags
11
- const normalizeFlags = function (flags, logs) {
9
+ export const normalizeFlags = function (flags, logs) {
12
10
  const rawFlags = removeFalsy(flags)
13
11
 
14
12
  // Combine the flags object env with the process.env
@@ -67,5 +65,3 @@ const REQUIRE_MODE = 'require'
67
65
  const DEFAULT_FUNCTIONS_DIST = '.netlify/functions/'
68
66
  const DEFAULT_CACHE_DIR = '.netlify/cache/'
69
67
  const DEFAULT_STATSD_PORT = 8125
70
-
71
- module.exports = { normalizeFlags }
@@ -1,8 +1,6 @@
1
- 'use strict'
2
-
3
1
  // Used to extract exit codes and respective status strings
4
2
  // 1|2|3 indicate whether this was a user|plugin|system error.
5
- const getSeverity = function (severity = FALLBACK_SEVERITY) {
3
+ export const getSeverity = function (severity = FALLBACK_SEVERITY) {
6
4
  const severityEntry = severity in SEVERITY_MAP ? SEVERITY_MAP[severity] : FALLBACK_SEVERITY_ENTRY
7
5
  const success = severity === SUCCESS_SEVERITY
8
6
  return { success, ...severityEntry }
@@ -21,6 +19,4 @@ const SEVERITY_MAP = {
21
19
  const SUCCESS_SEVERITY = 'success'
22
20
  // Indicates a bug in our codebase
23
21
  const FALLBACK_SEVERITY = 'error'
24
- const FALLBACK_SEVERITY_ENTRY = SEVERITY_MAP[FALLBACK_SEVERITY]
25
-
26
- module.exports = { getSeverity, FALLBACK_SEVERITY_ENTRY }
22
+ export const FALLBACK_SEVERITY_ENTRY = SEVERITY_MAP[FALLBACK_SEVERITY]
@@ -1,11 +1,9 @@
1
- 'use strict'
1
+ import { version as currentVersion, execPath } from 'process'
2
2
 
3
- const { version: currentVersion, execPath } = require('process')
3
+ import execa from 'execa'
4
+ import semver from 'semver'
4
5
 
5
- const execa = require('execa')
6
- const { clean: cleanVersion } = require('semver')
7
-
8
- const { addErrorInfo } = require('../error/info')
6
+ import { addErrorInfo } from '../error/info.js'
9
7
 
10
8
  // Retrieve Node.js version if the Node.js path is using nvm.
11
9
  // `node.exe` on Windows, `bin/node` on Unix.
@@ -13,11 +11,11 @@ const NVM_NODE_VERSION_REGEXP = /[/\\]v(\d+\.\d+\.\d+)[/\\](bin[/\\]node|node.ex
13
11
 
14
12
  // Retrieve Node.js version from current process
15
13
  const getCurrentNodeVersion = function () {
16
- return cleanVersion(currentVersion)
14
+ return semver.clean(currentVersion)
17
15
  }
18
16
 
19
17
  // Retrieve Node.js version from `--node-path` or fallback to extracting the current Node.js process version
20
- const getUserNodeVersion = async function (nodePath) {
18
+ export const getUserNodeVersion = async function (nodePath) {
21
19
  // No `--node-path` CLI flag, use the current node process version
22
20
  if (nodePath === execPath) {
23
21
  return getCurrentNodeVersion()
@@ -31,7 +29,7 @@ const getUserNodeVersion = async function (nodePath) {
31
29
 
32
30
  // Fallback to actually running `node --version` with the given nodePath
33
31
  const { stdout } = await execa(nodePath, ['--version'], { reject: false })
34
- const version = cleanVersion(stdout)
32
+ const version = semver.clean(stdout)
35
33
 
36
34
  if (version === null) {
37
35
  const error = new Error(`Invalid --node-path CLI flag: ${nodePath}`)
@@ -41,5 +39,3 @@ const getUserNodeVersion = async function (nodePath) {
41
39
 
42
40
  return version
43
41
  }
44
-
45
- module.exports = { getUserNodeVersion }
@@ -1,14 +1,12 @@
1
- 'use strict'
1
+ import { env } from 'process'
2
2
 
3
- const { env } = require('process')
4
-
5
- const filterObj = require('filter-obj')
6
- const mapObj = require('map-obj')
3
+ import filterObj from 'filter-obj'
4
+ import mapObj from 'map-obj'
7
5
 
8
6
  // If plugins modify `process.env`, this is propagated in other plugins and in
9
7
  // `build.command`. Since those are different processes, we figure out when they
10
8
  // do this and communicate the new `process.env` to other processes.
11
- const getNewEnvChanges = function (envBefore, netlifyConfig, netlifyConfigCopy) {
9
+ export const getNewEnvChanges = function (envBefore, netlifyConfig, netlifyConfigCopy) {
12
10
  const processEnvChanges = diffEnv(envBefore, env)
13
11
  const netlifyConfigEnvChanges = diffEnv(netlifyConfig.build.environment, netlifyConfigCopy.build.environment)
14
12
  return { ...processEnvChanges, ...netlifyConfigEnvChanges }
@@ -31,7 +29,7 @@ const setToNull = function (name) {
31
29
 
32
30
  // Set `process.env` changes from a previous different plugin.
33
31
  // Can also merge with a `currentEnv` plain object instead of `process.env`.
34
- const setEnvChanges = function (envChanges, currentEnv = env) {
32
+ export const setEnvChanges = function (envChanges, currentEnv = env) {
35
33
  Object.entries(envChanges).forEach(([name, value]) => {
36
34
  setEnvChange(name, value, currentEnv)
37
35
  })
@@ -52,5 +50,3 @@ const setEnvChange = function (name, value, currentEnv) {
52
50
 
53
51
  currentEnv[name] = value
54
52
  }
55
-
56
- module.exports = { getNewEnvChanges, setEnvChanges }
package/src/env/main.js CHANGED
@@ -1,14 +1,12 @@
1
- 'use strict'
1
+ import { env } from 'process'
2
2
 
3
- const { env } = require('process')
3
+ import filterObj from 'filter-obj'
4
4
 
5
- const filterObj = require('filter-obj')
6
-
7
- const { getParentColorEnv } = require('../log/colors')
5
+ import { getParentColorEnv } from '../log/colors.js'
8
6
 
9
7
  // Retrieve the environment variables passed to plugins and `build.command`
10
8
  // When run locally, this tries to emulate the production environment.
11
- const getChildEnv = function ({ envOpt, env: allConfigEnv }) {
9
+ export const getChildEnv = function ({ envOpt, env: allConfigEnv }) {
12
10
  const parentColorEnv = getParentColorEnv()
13
11
  const parentEnv = { ...env, ...allConfigEnv, ...envOpt, ...parentColorEnv }
14
12
  return filterObj(parentEnv, shouldKeepEnv)
@@ -19,5 +17,3 @@ const shouldKeepEnv = function (key) {
19
17
  }
20
18
 
21
19
  const REMOVED_PARENT_ENV = new Set(['bugsnag_key'])
22
-
23
- module.exports = { getChildEnv }
@@ -1,11 +1,9 @@
1
- 'use strict'
1
+ import { env } from 'process'
2
2
 
3
- const { env } = require('process')
4
-
5
- const filterObj = require('filter-obj')
3
+ import filterObj from 'filter-obj'
6
4
 
7
5
  // Retrieve enviroment variables used in error monitoring
8
- const getEnvMetadata = function (childEnv = env) {
6
+ export const getEnvMetadata = function (childEnv = env) {
9
7
  return filterObj(childEnv, isEnvMetadata)
10
8
  }
11
9
 
@@ -81,5 +79,3 @@ const ENVIRONMENT_VARIABLES = new Set([
81
79
  'GIT_LFS_ENABLED',
82
80
  'GIT_LFS_FETCH_INCLUDE',
83
81
  ])
84
-
85
- module.exports = { getEnvMetadata }
package/src/error/api.js CHANGED
@@ -1,12 +1,10 @@
1
- 'use strict'
1
+ import isPlainObj from 'is-plain-obj'
2
+ import mapObj from 'map-obj'
2
3
 
3
- const isPlainObj = require('is-plain-obj')
4
- const mapObj = require('map-obj')
5
-
6
- const { addErrorInfo } = require('./info')
4
+ import { addErrorInfo } from './info.js'
7
5
 
8
6
  // Wrap `api.*` methods so that they add more error information
9
- const addApiErrorHandlers = function (api) {
7
+ export const addApiErrorHandlers = function (api) {
10
8
  if (api === undefined) {
11
9
  return
12
10
  }
@@ -46,5 +44,3 @@ const redactError = function (error) {
46
44
  }
47
45
 
48
46
  const HEX_REGEXP = /[\da-f]{6,}/g
49
-
50
- module.exports = { addApiErrorHandlers }
@@ -1,13 +1,11 @@
1
- 'use strict'
1
+ import safeJsonStringify from 'safe-json-stringify'
2
2
 
3
- const safeJsonStringify = require('safe-json-stringify')
4
-
5
- const { CUSTOM_ERROR_KEY } = require('./info')
3
+ import { CUSTOM_ERROR_KEY } from './info.js'
6
4
 
7
5
  // Retrieve error information from child process and re-build it in current
8
6
  // process. We need this since errors static properties are not kept by
9
7
  // `v8.serialize()`.
10
- const jsonToError = function ({ name, message, stack, ...errorProps }) {
8
+ export const jsonToError = function ({ name, message, stack, ...errorProps }) {
11
9
  // eslint-disable-next-line unicorn/error-message
12
10
  const error = new Error('')
13
11
 
@@ -36,11 +34,9 @@ const assignErrorProp = function (error, name, value) {
36
34
  }
37
35
 
38
36
  // Inverse of `jsonToError()`.
39
- const errorToJson = function ({ name, message, stack, [CUSTOM_ERROR_KEY]: customError, ...errorProps }) {
37
+ export const errorToJson = function ({ name, message, stack, [CUSTOM_ERROR_KEY]: customError, ...errorProps }) {
40
38
  return {
41
39
  ...safeJsonStringify.ensureProperties(errorProps),
42
40
  ...safeJsonStringify.ensureProperties({ name, message, stack, [CUSTOM_ERROR_KEY]: customError }),
43
41
  }
44
42
  }
45
-
46
- module.exports = { jsonToError, errorToJson }