@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,10 +1,8 @@
1
- 'use strict'
2
-
3
- const { cancelBuild } = require('../error/cancel')
4
- const { handleBuildError } = require('../error/handle')
5
- const { getFullErrorInfo, parseErrorInfo } = require('../error/parse/parse')
6
- const { serializeErrorStatus } = require('../error/parse/serialize_status')
7
- const { isSoftFailEvent } = require('../plugins/events')
1
+ import { cancelBuild } from '../error/cancel.js'
2
+ import { handleBuildError } from '../error/handle.js'
3
+ import { getFullErrorInfo, parseErrorInfo } from '../error/parse/parse.js'
4
+ import { serializeErrorStatus } from '../error/parse/serialize_status.js'
5
+ import { isSoftFailEvent } from '../plugins/events.js'
8
6
 
9
7
  // Handle build command errors and plugin errors:
10
8
  // - usually, propagate the error to make the build stop.
@@ -13,7 +11,7 @@ const { isSoftFailEvent } = require('../plugins/events')
13
11
  // stop, but are still reported, and prevent future events from the same
14
12
  // plugin.
15
13
  // This also computes error statuses that are sent to the API.
16
- const handleStepError = function ({
14
+ export const handleStepError = function ({
17
15
  event,
18
16
  newError,
19
17
  childEnv,
@@ -90,7 +88,7 @@ const handleFailBuild = function ({ fullErrorInfo, newError }) {
90
88
  }
91
89
 
92
90
  // Unlike community plugins, core plugin bugs should be handled as system errors
93
- const getPluginErrorType = function (error, loadedFrom) {
91
+ export const getPluginErrorType = function (error, loadedFrom) {
94
92
  if (!isCorePluginBug(error, loadedFrom)) {
95
93
  return {}
96
94
  }
@@ -102,5 +100,3 @@ const isCorePluginBug = function (error, loadedFrom) {
102
100
  const { severity } = parseErrorInfo(error)
103
101
  return severity === 'warning' && loadedFrom === 'core'
104
102
  }
105
-
106
- module.exports = { handleStepError, getPluginErrorType }
package/src/steps/get.js CHANGED
@@ -1,14 +1,12 @@
1
- 'use strict'
2
-
3
- const { listEvents } = require('../plugins/events')
4
- const { buildCommandCore } = require('../plugins_core/build_command')
5
- const { deploySite } = require('../plugins_core/deploy')
6
- const { bundleFunctions } = require('../plugins_core/functions')
1
+ import { EVENTS } from '../plugins/events.js'
2
+ import { buildCommandCore } from '../plugins_core/build_command.js'
3
+ import { deploySite } from '../plugins_core/deploy/index.js'
4
+ import { bundleFunctions } from '../plugins_core/functions/index.js'
7
5
 
8
6
  // Get all build steps
9
- const getSteps = async function (steps) {
7
+ export const getSteps = function (steps) {
10
8
  const stepsA = addCoreSteps(steps)
11
- const stepsB = await sortSteps(stepsA)
9
+ const stepsB = sortSteps(stepsA)
12
10
  const events = getEvents(stepsB)
13
11
  return { steps: stepsB, events }
14
12
  }
@@ -18,8 +16,7 @@ const addCoreSteps = function (steps) {
18
16
  }
19
17
 
20
18
  // Sort plugin steps by event order.
21
- const sortSteps = async function (steps) {
22
- const EVENTS = await listEvents()
19
+ const sortSteps = function (steps) {
23
20
  return EVENTS.flatMap((event) => steps.filter((step) => step.event === event))
24
21
  }
25
22
 
@@ -32,5 +29,3 @@ const getEvents = function (steps) {
32
29
  const getEvent = function ({ event }) {
33
30
  return event
34
31
  }
35
-
36
- module.exports = { getSteps }
@@ -1,16 +1,14 @@
1
- 'use strict'
1
+ import { addErrorInfo } from '../error/info.js'
2
+ import { logStepCompleted } from '../log/messages/ipc.js'
3
+ import { pipePluginOutput, unpipePluginOutput } from '../log/stream.js'
4
+ import { callChild } from '../plugins/ipc.js'
5
+ import { getSuccessStatus } from '../status/success.js'
2
6
 
3
- const { addErrorInfo } = require('../error/info')
4
- const { logStepCompleted } = require('../log/messages/ipc')
5
- const { pipePluginOutput, unpipePluginOutput } = require('../log/stream')
6
- const { callChild } = require('../plugins/ipc')
7
- const { getSuccessStatus } = require('../status/success')
8
-
9
- const { getPluginErrorType } = require('./error')
10
- const { updateNetlifyConfig, listConfigSideFiles } = require('./update_config')
7
+ import { getPluginErrorType } from './error.js'
8
+ import { updateNetlifyConfig, listConfigSideFiles } from './update_config.js'
11
9
 
12
10
  // Fire a plugin step
13
- const firePluginStep = async function ({
11
+ export const firePluginStep = async function ({
14
12
  event,
15
13
  childProcess,
16
14
  packageName,
@@ -85,5 +83,3 @@ const firePluginStep = async function ({
85
83
  logStepCompleted(logs, verbose)
86
84
  }
87
85
  }
88
-
89
- module.exports = { firePluginStep }
@@ -1,12 +1,10 @@
1
- 'use strict'
1
+ import { logTimer } from '../log/messages/core.js'
2
+ import { logStepSuccess } from '../log/messages/steps.js'
2
3
 
3
- const { logTimer } = require('../log/messages/core')
4
- const { logStepSuccess } = require('../log/messages/steps')
5
-
6
- const { handleStepError } = require('./error')
4
+ import { handleStepError } from './error.js'
7
5
 
8
6
  // Retrieve the return value of a step
9
- const getStepReturn = function ({
7
+ export const getStepReturn = function ({
10
8
  event,
11
9
  packageName,
12
10
  newError,
@@ -52,5 +50,3 @@ const getStepReturn = function ({
52
50
 
53
51
  return { newEnvChanges, netlifyConfig, configMutations, headersPath, redirectsPath, newStatus, timers }
54
52
  }
55
-
56
- module.exports = { getStepReturn }
@@ -1,17 +1,15 @@
1
1
  /* eslint-disable max-lines */
2
- 'use strict'
2
+ import { addMutableConstants } from '../core/constants.js'
3
+ import { logStepStart } from '../log/messages/steps.js'
4
+ import { runsAlsoOnBuildFailure, runsOnlyOnBuildFailure } from '../plugins/events.js'
5
+ import { measureDuration, normalizeTimerName } from '../time/main.js'
3
6
 
4
- const { addMutableConstants } = require('../core/constants')
5
- const { logStepStart } = require('../log/messages/steps')
6
- const { runsAlsoOnBuildFailure, runsOnlyOnBuildFailure } = require('../plugins/events')
7
- const { measureDuration, normalizeTimerName } = require('../time/main')
8
-
9
- const { fireCoreStep } = require('./core_step')
10
- const { firePluginStep } = require('./plugin')
11
- const { getStepReturn } = require('./return')
7
+ import { fireCoreStep } from './core_step.js'
8
+ import { firePluginStep } from './plugin.js'
9
+ import { getStepReturn } from './return.js'
12
10
 
13
11
  // Run a step (core, build command or plugin)
14
- const runStep = async function ({
12
+ export const runStep = async function ({
15
13
  event,
16
14
  childProcess,
17
15
  packageName,
@@ -299,6 +297,4 @@ const tFireStep = function ({
299
297
  verbose,
300
298
  })
301
299
  }
302
-
303
- module.exports = { runStep }
304
300
  /* eslint-enable max-lines */
@@ -1,19 +1,17 @@
1
1
  /* eslint-disable max-lines */
2
- 'use strict'
2
+ import pReduce from 'p-reduce'
3
3
 
4
- const pReduce = require('p-reduce')
4
+ import { addErrorInfo } from '../error/info.js'
5
+ import { addStatus } from '../status/add.js'
5
6
 
6
- const { addErrorInfo } = require('../error/info')
7
- const { addStatus } = require('../status/add')
8
-
9
- const { runStep } = require('./run_step')
7
+ import { runStep } from './run_step.js'
10
8
 
11
9
  // Run all steps.
12
10
  // Each step can change some state: last `error`, environment variables changes,
13
11
  // list of `failedPlugins` (that ran `utils.build.failPlugin()`).
14
12
  // If an error arises, runs `onError` events.
15
13
  // Runs `onEnd` events at the end, whether an error was thrown or not.
16
- const runSteps = async function ({
14
+ export const runSteps = async function ({
17
15
  steps,
18
16
  buildbotServerSocket,
19
17
  events,
@@ -178,6 +176,4 @@ const runSteps = async function ({
178
176
  configMutations: configMutationsB,
179
177
  }
180
178
  }
181
-
182
- module.exports = { runSteps }
183
179
  /* eslint-enable max-lines */
@@ -1,18 +1,16 @@
1
- 'use strict'
1
+ import { isDeepStrictEqual } from 'util'
2
2
 
3
- const { isDeepStrictEqual } = require('util')
3
+ import pFilter from 'p-filter'
4
+ import pathExists from 'path-exists'
4
5
 
5
- const pFilter = require('p-filter')
6
- const pathExists = require('path-exists')
7
-
8
- const { resolveUpdatedConfig } = require('../core/config')
9
- const { addErrorInfo } = require('../error/info')
10
- const { logConfigOnUpdate } = require('../log/messages/config')
11
- const { logConfigMutations } = require('../log/messages/mutations')
6
+ import { resolveUpdatedConfig } from '../core/config.js'
7
+ import { addErrorInfo } from '../error/info.js'
8
+ import { logConfigOnUpdate } from '../log/messages/config.js'
9
+ import { logConfigMutations } from '../log/messages/mutations.js'
12
10
 
13
11
  // If `netlifyConfig` was updated or `_redirects` was created, the configuration
14
12
  // is updated by calling `@netlify/config` again.
15
- const updateNetlifyConfig = async function ({
13
+ export const updateNetlifyConfig = async function ({
16
14
  configOpts,
17
15
  netlifyConfig,
18
16
  headersPath,
@@ -36,7 +34,7 @@ const updateNetlifyConfig = async function ({
36
34
  headersPath: headersPathA,
37
35
  redirectsPath: redirectsPathA,
38
36
  } = await resolveUpdatedConfig(configOpts, configMutationsA)
39
- await logConfigOnUpdate({ logs, netlifyConfig: netlifyConfigA, debug })
37
+ logConfigOnUpdate({ logs, netlifyConfig: netlifyConfigA, debug })
40
38
  // eslint-disable-next-line fp/no-mutation,no-param-reassign
41
39
  errorParams.netlifyConfig = netlifyConfigA
42
40
  return {
@@ -67,7 +65,7 @@ const haveConfigSideFilesChanged = async function (configSideFiles, headersPath,
67
65
  // This is useful when applying configuration mutations since those files
68
66
  // sometimes have higher priority and should therefore be deleted in order to
69
67
  // apply any configuration update on `netlify.toml`.
70
- const listConfigSideFiles = async function (sideFiles) {
68
+ export const listConfigSideFiles = async function (sideFiles) {
71
69
  const configSideFiles = await pFilter(sideFiles, pathExists)
72
70
  // eslint-disable-next-line fp/no-mutating-methods
73
71
  return configSideFiles.sort()
@@ -93,5 +91,3 @@ const validateConfigMutation = function ({ value, keysString }) {
93
91
  Please set this property to a specific value instead.`)
94
92
  }
95
93
  }
96
-
97
- module.exports = { updateNetlifyConfig, listConfigSideFiles }
@@ -1,13 +1,11 @@
1
- 'use strict'
1
+ import { platform } from 'process'
2
2
 
3
- const { platform } = require('process')
3
+ import got from 'got'
4
+ import osName from 'os-name'
4
5
 
5
- const got = require('got')
6
- const osName = require('os-name')
7
-
8
- const { addErrorInfo } = require('../error/info')
9
- const { roundTimerToMillisecs } = require('../time/measure')
10
- const { ROOT_PACKAGE_JSON } = require('../utils/json')
6
+ import { addErrorInfo } from '../error/info.js'
7
+ import { roundTimerToMillisecs } from '../time/measure.js'
8
+ import { ROOT_PACKAGE_JSON } from '../utils/json.js'
11
9
 
12
10
  const DEFAULT_TELEMETRY_TIMEOUT = 1200
13
11
  const DEFAULT_TELEMETRY_CONFIG = {
@@ -17,7 +15,7 @@ const DEFAULT_TELEMETRY_CONFIG = {
17
15
  }
18
16
 
19
17
  // Send telemetry request when build completes
20
- const trackBuildComplete = async function ({
18
+ export const trackBuildComplete = async function ({
21
19
  deployId,
22
20
  buildId,
23
21
  status,
@@ -136,5 +134,3 @@ const getInstallType = function (origin, loadedFrom) {
136
134
 
137
135
  return loadedFrom
138
136
  }
139
-
140
- module.exports = { trackBuildComplete }
@@ -1,13 +1,11 @@
1
- 'use strict'
2
-
3
- const { createTimer, TOP_PARENT_TAG } = require('./main')
1
+ import { createTimer, TOP_PARENT_TAG } from './main.js'
4
2
 
5
3
  // Some timers are computed based on others:
6
4
  // - `others` is `total` minus the other timers
7
5
  // - `run_plugins` is the sum of all plugins
8
6
  // - `run_netlify_build_per_type` aggregates timers but per system/plugin/user
9
7
  // - each plugin timer is the sum of its event handlers
10
- const addAggregatedTimers = function (timers) {
8
+ export const addAggregatedTimers = function (timers) {
11
9
  const timersA = addRunPluginsTimer(timers)
12
10
  const timersB = addPluginTimers(timersA)
13
11
  const timersC = addOthersTimers(timersB)
@@ -146,5 +144,3 @@ const getTimerDuration = function ({ durationNs }) {
146
144
  const reduceSum = function (sum, number) {
147
145
  return sum + number
148
146
  }
149
-
150
- module.exports = { addAggregatedTimers }
package/src/time/main.js CHANGED
@@ -1,12 +1,10 @@
1
- 'use strict'
1
+ import slugify from '@sindresorhus/slugify'
2
+ import keepFuncProps from 'keep-func-props'
2
3
 
3
- const slugify = require('@sindresorhus/slugify')
4
- const keepFuncProps = require('keep-func-props')
5
-
6
- const { startTimer, endTimer } = require('./measure')
4
+ import { startTimer, endTimer } from './measure.js'
7
5
 
8
6
  // Initialize the `timers` array
9
- const initTimers = function () {
7
+ export const initTimers = function () {
10
8
  return []
11
9
  }
12
10
 
@@ -29,10 +27,10 @@ const kMeasureDuration = function (func, stageTag, { parentTag, category } = {})
29
27
  }
30
28
 
31
29
  // Ensure the wrapped function `name` is not `anonymous` in stack traces
32
- const measureDuration = keepFuncProps(kMeasureDuration)
30
+ export const measureDuration = keepFuncProps(kMeasureDuration)
33
31
 
34
32
  // Create a new object representing a completed timer
35
- const createTimer = function (
33
+ export const createTimer = function (
36
34
  stageTag,
37
35
  durationNs,
38
36
  { metricName = DEFAULT_METRIC_NAME, parentTag = TOP_PARENT_TAG, category, tags } = {},
@@ -41,12 +39,10 @@ const createTimer = function (
41
39
  }
42
40
 
43
41
  const DEFAULT_METRIC_NAME = 'buildbot.build.stage.duration'
44
- const TOP_PARENT_TAG = 'run_netlify_build'
42
+ export const TOP_PARENT_TAG = 'run_netlify_build'
45
43
 
46
44
  // Make sure the timer name does not include special characters.
47
45
  // For example, the `packageName` of local plugins includes dots.
48
- const normalizeTimerName = function (name) {
46
+ export const normalizeTimerName = function (name) {
49
47
  return slugify(name, { separator: '_' })
50
48
  }
51
-
52
- module.exports = { initTimers, measureDuration, normalizeTimerName, createTimer, TOP_PARENT_TAG }
@@ -1,14 +1,12 @@
1
- 'use strict'
2
-
3
- const { hrtime } = require('process')
1
+ import { hrtime } from 'process'
4
2
 
5
3
  // Starts a timer
6
- const startTimer = function () {
4
+ export const startTimer = function () {
7
5
  return hrtime()
8
6
  }
9
7
 
10
8
  // Stops a timer
11
- const endTimer = function ([startSecs, startNsecs]) {
9
+ export const endTimer = function ([startSecs, startNsecs]) {
12
10
  const [endSecs, endNsecs] = hrtime()
13
11
  const durationNs = (endSecs - startSecs) * NANOSECS_TO_SECS + endNsecs - startNsecs
14
12
  return durationNs
@@ -16,11 +14,9 @@ const endTimer = function ([startSecs, startNsecs]) {
16
14
 
17
15
  // statsd expects milliseconds integers.
18
16
  // To prevent double rounding errors, rounding should only be applied once.
19
- const roundTimerToMillisecs = function (durationNs) {
17
+ export const roundTimerToMillisecs = function (durationNs) {
20
18
  return Math.round(durationNs / NANOSECS_TO_MSECS)
21
19
  }
22
20
 
23
21
  const NANOSECS_TO_SECS = 1e9
24
22
  const NANOSECS_TO_MSECS = 1e6
25
-
26
- module.exports = { startTimer, endTimer, roundTimerToMillisecs }
@@ -1,18 +1,16 @@
1
- 'use strict'
1
+ import { promisify } from 'util'
2
2
 
3
- const { promisify } = require('util')
3
+ import StatsdClient from 'statsd-client'
4
4
 
5
- const StatsdClient = require('statsd-client')
6
-
7
- const { addAggregatedTimers } = require('./aggregate')
8
- const { roundTimerToMillisecs } = require('./measure')
5
+ import { addAggregatedTimers } from './aggregate.js'
6
+ import { roundTimerToMillisecs } from './measure.js'
9
7
 
10
8
  // TODO: replace with `timers/promises` after dropping Node < 15.0.0
11
9
  const pSetTimeout = promisify(setTimeout)
12
10
 
13
11
  // Record the duration of a build phase, for monitoring.
14
12
  // Sends to statsd daemon.
15
- const reportTimers = async function ({ timers, statsdOpts: { host, port }, framework }) {
13
+ export const reportTimers = async function ({ timers, statsdOpts: { host, port }, framework }) {
16
14
  if (host === undefined) {
17
15
  return
18
16
  }
@@ -59,5 +57,3 @@ const closeClient = async function (client) {
59
57
 
60
58
  // See https://github.com/msiebuhr/node-statsd-client/blob/45a93ee4c94ca72f244a40b06cb542d4bd7c3766/lib/EphemeralSocket.js#L81
61
59
  const CLOSE_TIMEOUT = 11
62
-
63
- module.exports = { reportTimers }
@@ -1,8 +1,6 @@
1
- 'use strict'
2
-
3
1
  // Wrap an async function so it prepends an error message on exceptions.
4
2
  // This helps locate errors.
5
- const addAsyncErrorMessage = function (asyncFunc, message) {
3
+ export const addAsyncErrorMessage = function (asyncFunc, message) {
6
4
  return async (...args) => {
7
5
  try {
8
6
  return await asyncFunc(...args)
@@ -12,5 +10,3 @@ const addAsyncErrorMessage = function (asyncFunc, message) {
12
10
  }
13
11
  }
14
12
  }
15
-
16
- module.exports = { addAsyncErrorMessage }
package/src/utils/json.js CHANGED
@@ -1,12 +1,11 @@
1
- 'use strict'
1
+ import { promises as fs, readFileSync } from 'fs'
2
+ import { fileURLToPath } from 'url'
2
3
 
3
- const { promises: fs, readFileSync } = require('fs')
4
-
5
- const ROOT_PACKAGE_JSON_PATH = `${__dirname}/../../package.json`
4
+ const ROOT_PACKAGE_JSON_PATH = fileURLToPath(new URL('../../package.json', import.meta.url))
6
5
 
7
6
  // TODO: Replace with dynamic `import()` once it is supported without
8
7
  // experimental flags
9
- const importJsonFile = async function (filePath) {
8
+ export const importJsonFile = async function (filePath) {
10
9
  const fileContents = await fs.readFile(filePath, 'utf8')
11
10
  return JSON.parse(fileContents)
12
11
  }
@@ -17,6 +16,4 @@ const importJsonFileSync = function (filePath) {
17
16
  return JSON.parse(fileContents)
18
17
  }
19
18
 
20
- const ROOT_PACKAGE_JSON = importJsonFileSync(ROOT_PACKAGE_JSON_PATH)
21
-
22
- module.exports = { importJsonFile, ROOT_PACKAGE_JSON }
19
+ export const ROOT_PACKAGE_JSON = importJsonFileSync(ROOT_PACKAGE_JSON_PATH)
package/src/utils/omit.js CHANGED
@@ -1,10 +1,6 @@
1
- 'use strict'
2
-
3
- const filterObj = require('filter-obj')
1
+ import filterObj from 'filter-obj'
4
2
 
5
3
  // lodash.omit is 1400 lines of codes. filter-obj is much smaller and simpler.
6
- const omit = function (obj, keys) {
4
+ export const omit = function (obj, keys) {
7
5
  return filterObj(obj, (key) => !keys.includes(key))
8
6
  }
9
-
10
- module.exports = { omit }
@@ -1,11 +1,9 @@
1
- 'use strict'
1
+ import { dirname } from 'path'
2
2
 
3
- const { dirname } = require('path')
4
-
5
- const readPkgUp = require('read-pkg-up')
3
+ import readPkgUp from 'read-pkg-up'
6
4
 
7
5
  // Retrieve `package.json` from a specific directory
8
- const getPackageJson = async function (cwd, { normalize } = {}) {
6
+ export const getPackageJson = async function (cwd, { normalize } = {}) {
9
7
  const packageObj = await getPackageObj({ cwd, normalize })
10
8
  if (packageObj === undefined) {
11
9
  return { packageJson: {} }
@@ -23,5 +21,3 @@ const getPackageObj = async function ({ cwd, normalize = true }) {
23
21
  // thrown. We return `undefined` then.
24
22
  } catch (error) {}
25
23
  }
26
-
27
- module.exports = { getPackageJson }
@@ -1,14 +1,10 @@
1
- 'use strict'
2
-
3
- const filterObj = require('filter-obj')
1
+ import filterObj from 'filter-obj'
4
2
 
5
3
  // Remove falsy values from object
6
- const removeFalsy = function (obj) {
4
+ export const removeFalsy = function (obj) {
7
5
  return filterObj(obj, isDefined)
8
6
  }
9
7
 
10
8
  const isDefined = function (key, value) {
11
9
  return value !== undefined && value !== ''
12
10
  }
13
-
14
- module.exports = { removeFalsy }
@@ -1,9 +1,13 @@
1
- 'use strict'
1
+ import { createRequire } from 'module'
2
2
 
3
- const resolveLib = require('resolve')
3
+ import { async as resolveLib } from 'resolve'
4
+
5
+ // TODO: use `import.resolve()` once it is available without any experimental
6
+ // flags
7
+ const require = createRequire(import.meta.url)
4
8
 
5
9
  // Like `resolvePath()` but does not throw
6
- const tryResolvePath = async function (path, basedir) {
10
+ export const tryResolvePath = async function (path, basedir) {
7
11
  try {
8
12
  const resolvedPath = await resolvePath(path, basedir)
9
13
  return { path: resolvedPath }
@@ -13,7 +17,7 @@ const tryResolvePath = async function (path, basedir) {
13
17
  }
14
18
 
15
19
  // This throws if the package cannot be found
16
- const resolvePath = async function (path, basedir) {
20
+ export const resolvePath = async function (path, basedir) {
17
21
  try {
18
22
  return await resolvePathWithBasedir(path, basedir)
19
23
  // Fallback.
@@ -40,5 +44,3 @@ const resolvePathWithBasedir = function (path, basedir) {
40
44
  })
41
45
  })
42
46
  }
43
-
44
- module.exports = { tryResolvePath, resolvePath }
@@ -1,38 +1,34 @@
1
- 'use strict'
2
-
3
- const { major, minor, patch, clean: cleanVersion, lt: ltVersion, minVersion } = require('semver')
1
+ import semver from 'semver'
4
2
 
5
3
  // Compare two versions by their major versions.
6
4
  // Takes into account the special rules for `0.*.*` and `0.0.*` versions.
7
- const isPreviousMajor = function (versionA, versionB) {
8
- return ltVersion(getMajor(versionA), getMajor(versionB))
5
+ export const isPreviousMajor = function (versionA, versionB) {
6
+ return semver.lt(getMajor(versionA), getMajor(versionB))
9
7
  }
10
8
 
11
9
  // Remove minor/patch numbers
12
10
  const getMajor = function (version) {
13
- return minVersion(getMajorVersion(version)).version
11
+ return semver.minVersion(getMajorVersion(version)).version
14
12
  }
15
13
 
16
14
  // According to semver, the second number is the major release number for
17
15
  // `0.*.*` versions and the third for `0.0.*`. This is how `^` behaves with the
18
16
  // `semver` module which is used by `npm`.
19
- const getMajorVersion = function (version) {
20
- if (!version || cleanVersion(version) === null) {
17
+ export const getMajorVersion = function (version) {
18
+ if (!version || semver.clean(version) === null) {
21
19
  return
22
20
  }
23
21
 
24
- const majorVersion = major(version)
22
+ const majorVersion = semver.major(version)
25
23
  if (majorVersion !== 0) {
26
24
  return `${majorVersion}`
27
25
  }
28
26
 
29
- const minorVersion = minor(version)
27
+ const minorVersion = semver.minor(version)
30
28
  if (minorVersion !== 0) {
31
29
  return `${majorVersion}.${minorVersion}`
32
30
  }
33
31
 
34
- const patchVersion = patch(version)
32
+ const patchVersion = semver.patch(version)
35
33
  return `${majorVersion}.${minorVersion}.${patchVersion}`
36
34
  }
37
-
38
- module.exports = { isPreviousMajor, getMajorVersion }
@@ -3,7 +3,7 @@ type GlobPattern = string
3
3
  /* eslint-disable camelcase -- some properties are named in snake case in this API */
4
4
  type FunctionsObject = {
5
5
  /**
6
- * a list of additional paths to include in the function bundle. Although our build system includes statically referenced files (like `require("./some-file.js")`) by default, `included_files` lets you specify additional files or directories and reference them dynamically in function code. You can use `*` to match any character or prefix an entry with `!` to exclude files. Paths are relative to the [base directory](https://docs.netlify.com/configure-builds/get-started/#definitions-1).
6
+ * a list of additional paths to include in the function bundle. Although our build system includes statically referenced files (like `import * from "./some-file.js"`) by default, `included_files` lets you specify additional files or directories and reference them dynamically in function code. You can use `*` to match any character or prefix an entry with `!` to exclude files. Paths are relative to the [base directory](https://docs.netlify.com/configure-builds/get-started/#definitions-1).
7
7
  */
8
8
  included_files?: string[]
9
9
  } & (