netlify-cli 12.2.10 → 12.2.11

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 (139) hide show
  1. package/npm-shrinkwrap.json +219 -1422
  2. package/package.json +3 -7
  3. package/src/commands/addons/addons-auth.mjs +2 -3
  4. package/src/commands/addons/addons-config.mjs +2 -3
  5. package/src/commands/addons/addons-create.mjs +2 -3
  6. package/src/commands/addons/addons-delete.mjs +1 -3
  7. package/src/commands/addons/addons-list.mjs +1 -3
  8. package/src/commands/api/api.mjs +1 -3
  9. package/src/commands/base-command.mjs +3 -3
  10. package/src/commands/build/build.mjs +3 -3
  11. package/src/commands/deploy/deploy.mjs +13 -16
  12. package/src/commands/dev/dev-exec.mjs +2 -3
  13. package/src/commands/dev/dev.mjs +15 -21
  14. package/src/commands/env/env-clone.mjs +2 -3
  15. package/src/commands/env/env-get.mjs +2 -3
  16. package/src/commands/env/env-import.mjs +2 -3
  17. package/src/commands/env/env-list.mjs +2 -4
  18. package/src/commands/env/env-set.mjs +3 -8
  19. package/src/commands/env/env-unset.mjs +2 -3
  20. package/src/commands/functions/functions-build.mjs +1 -3
  21. package/src/commands/functions/functions-create.mjs +3 -3
  22. package/src/commands/functions/functions-invoke.mjs +1 -3
  23. package/src/commands/functions/functions-list.mjs +1 -3
  24. package/src/commands/functions/functions-serve.mjs +1 -2
  25. package/src/commands/functions/functions.mjs +1 -1
  26. package/src/commands/graph/graph-config-write.mjs +1 -3
  27. package/src/commands/graph/graph-edit.mjs +2 -3
  28. package/src/commands/graph/graph-handler.mjs +1 -3
  29. package/src/commands/graph/graph-init.mjs +2 -3
  30. package/src/commands/graph/graph-library.mjs +1 -3
  31. package/src/commands/graph/graph-operations.mjs +1 -3
  32. package/src/commands/graph/graph-pull.mjs +1 -3
  33. package/src/commands/init/init.mjs +2 -4
  34. package/src/commands/link/link.mjs +1 -3
  35. package/src/commands/lm/lm-setup.mjs +2 -3
  36. package/src/commands/login/login.mjs +1 -3
  37. package/src/commands/logout/logout.mjs +1 -3
  38. package/src/commands/main.mjs +3 -3
  39. package/src/commands/open/open-admin.mjs +2 -3
  40. package/src/commands/open/open-site.mjs +2 -3
  41. package/src/commands/open/open.mjs +1 -3
  42. package/src/commands/recipes/recipes.mjs +3 -3
  43. package/src/commands/sites/sites-create-template.mjs +7 -8
  44. package/src/commands/sites/sites-create.mjs +2 -4
  45. package/src/commands/sites/sites-delete.mjs +1 -3
  46. package/src/commands/sites/sites-list.mjs +1 -3
  47. package/src/commands/status/status-hooks.mjs +1 -3
  48. package/src/commands/status/status.mjs +1 -3
  49. package/src/commands/switch/switch.mjs +1 -3
  50. package/src/commands/unlink/unlink.mjs +1 -3
  51. package/src/commands/watch/watch.mjs +1 -3
  52. package/src/lib/account.mjs +14 -0
  53. package/src/lib/api.mjs +1 -1
  54. package/src/lib/completion/generate-autocompletion.mjs +1 -1
  55. package/src/lib/edge-functions/consts.mjs +4 -0
  56. package/src/lib/edge-functions/{deploy.cjs → deploy.mjs} +7 -13
  57. package/src/lib/edge-functions/{headers.cjs → headers.mjs} +3 -1
  58. package/src/lib/edge-functions/{internal.cjs → internal.mjs} +19 -15
  59. package/src/lib/edge-functions/{proxy.cjs → proxy.mjs} +18 -20
  60. package/src/lib/edge-functions/{registry.cjs → registry.mjs} +3 -5
  61. package/src/lib/{exec-fetcher.cjs → exec-fetcher.mjs} +17 -12
  62. package/src/lib/functions/{background.cjs → background.mjs} +4 -6
  63. package/src/lib/functions/{config.cjs → config.mjs} +1 -3
  64. package/src/lib/functions/form-submissions-handler.mjs +2 -2
  65. package/src/lib/functions/{local-proxy.cjs → local-proxy.mjs} +4 -6
  66. package/src/lib/functions/{memoized-build.cjs → memoized-build.mjs} +1 -3
  67. package/src/lib/functions/{netlify-function.cjs → netlify-function.mjs} +5 -8
  68. package/src/lib/functions/{registry.cjs → registry.mjs} +12 -14
  69. package/src/lib/functions/runtimes/go/{index.cjs → index.mjs} +10 -10
  70. package/src/lib/functions/runtimes/{index.cjs → index.mjs} +12 -7
  71. package/src/lib/functions/runtimes/js/builders/{netlify-lambda.cjs → netlify-lambda.mjs} +13 -10
  72. package/src/lib/functions/runtimes/js/builders/{zisi.cjs → zisi.mjs} +15 -13
  73. package/src/lib/functions/runtimes/js/{index.cjs → index.mjs} +12 -12
  74. package/src/lib/functions/runtimes/rust/{index.cjs → index.mjs} +15 -15
  75. package/src/lib/functions/scheduled.mjs +1 -1
  76. package/src/lib/functions/server.mjs +6 -7
  77. package/src/lib/functions/{synchronous.cjs → synchronous.mjs} +5 -7
  78. package/src/lib/functions/{utils.cjs → utils.mjs} +6 -21
  79. package/src/lib/{geo-location.cjs → geo-location.mjs} +3 -5
  80. package/src/lib/http-agent.mjs +1 -1
  81. package/src/lib/{log.cjs → log.mjs} +3 -7
  82. package/src/lib/one-graph/cli-client.mjs +2 -2
  83. package/src/lib/one-graph/cli-netlify-graph.mjs +2 -3
  84. package/src/lib/path.mjs +1 -0
  85. package/src/lib/{render-error-remplate.cjs → render-error-template.mjs} +8 -4
  86. package/src/lib/{string.cjs → string.mjs} +1 -3
  87. package/src/recipes/vscode/index.mjs +1 -1
  88. package/src/utils/addons/diffs/options.mjs +1 -1
  89. package/src/utils/addons/prepare.mjs +1 -1
  90. package/src/utils/addons/prompts.mjs +1 -1
  91. package/src/utils/addons/render.mjs +1 -1
  92. package/src/utils/{command-helpers.cjs → command-helpers.mjs} +45 -64
  93. package/src/utils/{deferred.cjs → create-deferred.mjs} +1 -1
  94. package/src/utils/deploy/constants.mjs +19 -0
  95. package/src/utils/deploy/{deploy-site.cjs → deploy-site.mjs} +15 -17
  96. package/src/utils/deploy/{hash-files.cjs → hash-files.mjs} +7 -5
  97. package/src/utils/deploy/{hash-fns.cjs → hash-fns.mjs} +11 -8
  98. package/src/utils/deploy/{hasher-segments.cjs → hasher-segments.mjs} +10 -17
  99. package/src/utils/deploy/{upload-files.cjs → upload-files.mjs} +5 -5
  100. package/src/utils/deploy/{util.cjs → util.mjs} +8 -20
  101. package/src/utils/detect-server-settings.mjs +2 -2
  102. package/src/utils/{dev.cjs → dev.mjs} +13 -21
  103. package/src/utils/{dot-env.cjs → dot-env.mjs} +7 -9
  104. package/src/utils/env/{index.cjs → index.mjs} +11 -24
  105. package/src/utils/execa.mjs +17 -0
  106. package/src/utils/get-global-config.mjs +40 -0
  107. package/src/utils/get-repo-data.mjs +1 -1
  108. package/src/utils/{gh-auth.cjs → gh-auth.mjs} +10 -12
  109. package/src/utils/gitignore.mjs +1 -1
  110. package/src/utils/{headers.cjs → headers.mjs} +4 -11
  111. package/src/utils/init/{config-github.cjs → config-github.mjs} +6 -8
  112. package/src/utils/init/{config-manual.cjs → config-manual.mjs} +4 -4
  113. package/src/utils/init/{config.cjs → config.mjs} +4 -5
  114. package/src/utils/init/{frameworks.cjs → frameworks.mjs} +2 -5
  115. package/src/utils/init/{node-version.cjs → node-version.mjs} +6 -8
  116. package/src/utils/init/{plugins.cjs → plugins.mjs} +3 -5
  117. package/src/utils/init/{utils.cjs → utils.mjs} +27 -23
  118. package/src/utils/live-tunnel.mjs +3 -3
  119. package/src/utils/lm/install.mjs +3 -3
  120. package/src/utils/lm/requirements.mjs +1 -1
  121. package/src/utils/lm/steps.mjs +1 -1
  122. package/src/utils/lm/ui.mjs +1 -1
  123. package/src/utils/{open-browser.cjs → open-browser.mjs} +5 -5
  124. package/src/utils/{parse-raw-flags.cjs → parse-raw-flags.mjs} +2 -7
  125. package/src/utils/proxy.mjs +14 -10
  126. package/src/utils/{redirects.cjs → redirects.mjs} +3 -7
  127. package/src/utils/{rules-proxy.cjs → rules-proxy.mjs} +19 -19
  128. package/src/utils/sites/{utils.cjs → utils.mjs} +6 -6
  129. package/src/utils/telemetry/telemetry.mjs +2 -2
  130. package/src/utils/telemetry/validation.mjs +1 -1
  131. package/src/lib/account.cjs +0 -9
  132. package/src/lib/edge-functions/consts.cjs +0 -11
  133. package/src/lib/edge-functions/index.cjs +0 -6
  134. package/src/lib/path.cjs +0 -3
  135. package/src/utils/deploy/constants.cjs +0 -31
  136. package/src/utils/deploy/index.cjs +0 -4
  137. package/src/utils/execa.cjs +0 -12
  138. package/src/utils/get-global-config.cjs +0 -47
  139. package/src/utils/index.cjs +0 -22
@@ -1,7 +1,7 @@
1
1
  // @ts-check
2
2
  import AsciiTable from 'ascii-table'
3
3
 
4
- import { chalk } from '../command-helpers.cjs'
4
+ import { chalk } from '../command-helpers.mjs'
5
5
 
6
6
  export const renderMissingValues = function (values, manifest) {
7
7
  const display = values
@@ -1,22 +1,21 @@
1
1
  // @ts-check
2
- const { once } = require('events')
3
- const os = require('os')
4
- const process = require('process')
5
- const { format, inspect } = require('util')
2
+ import { once } from 'events'
3
+ import os from 'os'
4
+ import process from 'process'
5
+ import { format, inspect } from 'util'
6
6
 
7
- // eslint-disable-next-line no-restricted-modules
8
- const { Instance: ChalkInstance } = require('chalk')
9
- const chokidar = require('chokidar')
10
- const decache = require('decache')
11
- const WSL = require('is-wsl')
12
- const debounce = require('lodash/debounce')
13
- const { default: omit } = require('omit.js')
14
- const terminalLink = require('terminal-link')
7
+ // eslint-disable-next-line no-restricted-imports
8
+ import chalkModule from 'chalk'
9
+ import chokidar from 'chokidar'
10
+ import decache from 'decache'
11
+ import WSL from 'is-wsl'
12
+ import debounce from 'lodash/debounce.js'
13
+ import terminalLink from 'terminal-link'
15
14
 
16
- const { name, version } = require('../../package.json')
17
- const { clearSpinner, startSpinner } = require('../lib/spinner.cjs')
15
+ import { clearSpinner, startSpinner } from '../lib/spinner.cjs'
18
16
 
19
- const getGlobalConfig = require('./get-global-config.cjs')
17
+ import getGlobalConfig from './get-global-config.mjs'
18
+ import getPackageJson from './get-package-json.mjs'
20
19
 
21
20
  /** The parsed process argv without the binary only arguments and flags */
22
21
  const argv = process.argv.slice(2)
@@ -28,13 +27,13 @@ const argv = process.argv.slice(2)
28
27
  */
29
28
  const safeChalk = function (noColors) {
30
29
  if (noColors) {
31
- const colorlessChalk = new ChalkInstance({ level: 0 })
30
+ const colorlessChalk = new chalkModule.Instance({ level: 0 })
32
31
  return colorlessChalk
33
32
  }
34
- return new ChalkInstance()
33
+ return new chalkModule.Instance()
35
34
  }
36
35
 
37
- const chalk = safeChalk(argv.includes('--json'))
36
+ export const chalk = safeChalk(argv.includes('--json'))
38
37
 
39
38
  /**
40
39
  * Adds the filler to the start of the string
@@ -43,24 +42,26 @@ const chalk = safeChalk(argv.includes('--json'))
43
42
  * @param {string} [filler]
44
43
  * @returns {string}
45
44
  */
46
- const padLeft = (str, count, filler = ' ') => str.padStart(str.length + count, filler)
45
+ export const padLeft = (str, count, filler = ' ') => str.padStart(str.length + count, filler)
47
46
 
48
47
  const platform = WSL ? 'wsl' : os.platform()
49
48
  const arch = os.arch() === 'ia32' ? 'x86' : os.arch()
50
49
 
51
- const USER_AGENT = `${name}/${version} ${platform}-${arch} node-${process.version}`
50
+ const { name, version } = await getPackageJson()
51
+
52
+ export const USER_AGENT = `${name}/${version} ${platform}-${arch} node-${process.version}`
52
53
 
53
54
  /** A list of base command flags that needs to be sorted down on documentation and on help pages */
54
55
  const BASE_FLAGS = new Set(['--debug', '--httpProxy', '--httpProxyCertificateFilename'])
55
56
 
56
- const NETLIFY_CYAN = chalk.rgb(40, 180, 170)
57
+ export const NETLIFY_CYAN = chalk.rgb(40, 180, 170)
57
58
 
58
- const NETLIFYDEV = `${chalk.greenBright('◈')} ${NETLIFY_CYAN('Netlify Dev')} ${chalk.greenBright('◈')}`
59
- const NETLIFYDEVLOG = `${chalk.greenBright('◈')}`
60
- const NETLIFYDEVWARN = `${chalk.yellowBright('◈')}`
61
- const NETLIFYDEVERR = `${chalk.redBright('◈')}`
59
+ export const NETLIFYDEV = `${chalk.greenBright('◈')} ${NETLIFY_CYAN('Netlify Dev')} ${chalk.greenBright('◈')}`
60
+ export const NETLIFYDEVLOG = `${chalk.greenBright('◈')}`
61
+ export const NETLIFYDEVWARN = `${chalk.yellowBright('◈')}`
62
+ export const NETLIFYDEVERR = `${chalk.redBright('◈')}`
62
63
 
63
- const BANG = process.platform === 'win32' ? '»' : '›'
64
+ export const BANG = process.platform === 'win32' ? '»' : '›'
64
65
 
65
66
  /**
66
67
  * Sorts two options so that the base flags are at the bottom of the list
@@ -70,7 +71,7 @@ const BANG = process.platform === 'win32' ? '»' : '›'
70
71
  * @example
71
72
  * options.sort(sortOptions)
72
73
  */
73
- const sortOptions = (optionA, optionB) => {
74
+ export const sortOptions = (optionA, optionB) => {
74
75
  // base flags should be always at the bottom
75
76
  if (BASE_FLAGS.has(optionA.long) || BASE_FLAGS.has(optionB.long)) {
76
77
  return -1
@@ -88,7 +89,7 @@ const TOKEN_TIMEOUT = 3e5
88
89
  * @param {object} config.ticket
89
90
  * @returns
90
91
  */
91
- const pollForToken = async ({ api, ticket }) => {
92
+ export const pollForToken = async ({ api, ticket }) => {
92
93
  const spinner = startSpinner({ text: 'Waiting for authorization...' })
93
94
  try {
94
95
  const accessToken = await api.getAccessToken(ticket, { timeout: TOKEN_TIMEOUT })
@@ -118,7 +119,7 @@ const pollForToken = async ({ api, ticket }) => {
118
119
  * @param {string} [tokenFromOptions] optional token from the provided --auth options
119
120
  * @returns {Promise<[null|string, 'flag' | 'env' |'config' |'not found']>}
120
121
  */
121
- const getToken = async (tokenFromOptions) => {
122
+ export const getToken = async (tokenFromOptions) => {
122
123
  // 1. First honor command flag --auth
123
124
  if (tokenFromOptions) {
124
125
  return [tokenFromOptions, 'flag']
@@ -146,13 +147,13 @@ const isDefaultJson = () => argv[0] === 'functions:invoke' || (argv[0] === 'api'
146
147
  * logs a json message
147
148
  * @param {string|object} message
148
149
  */
149
- const logJson = (message = '') => {
150
+ export const logJson = (message = '') => {
150
151
  if (argv.includes('--json') || isDefaultJson()) {
151
152
  process.stdout.write(JSON.stringify(message, null, 2))
152
153
  }
153
154
  }
154
155
 
155
- const log = (message = '', ...args) => {
156
+ export const log = (message = '', ...args) => {
156
157
  // If --silent or --json flag passed disable logger
157
158
  if (argv.includes('--json') || argv.includes('--silent') || isDefaultJson()) {
158
159
  return
@@ -165,7 +166,7 @@ const log = (message = '', ...args) => {
165
166
  * logs a warning message
166
167
  * @param {string} message
167
168
  */
168
- const warn = (message = '') => {
169
+ export const warn = (message = '') => {
169
170
  const bang = chalk.yellow(BANG)
170
171
  log(` ${bang} Warning: ${message}`)
171
172
  }
@@ -176,7 +177,7 @@ const warn = (message = '') => {
176
177
  * @param {object} [options]
177
178
  * @param {boolean} [options.exit]
178
179
  */
179
- const error = (message = '', options = {}) => {
180
+ export const error = (message = '', options = {}) => {
180
181
  const err = message instanceof Error ? message : new Error(message)
181
182
  if (options.exit === false) {
182
183
  const bang = chalk.red(BANG)
@@ -190,18 +191,21 @@ const error = (message = '', options = {}) => {
190
191
  }
191
192
  }
192
193
 
193
- const exit = (code = 0) => {
194
+ export const exit = (code = 0) => {
194
195
  process.exit(code)
195
196
  }
196
197
 
197
198
  // When `build.publish` is not set by the user, the CLI behavior differs in
198
199
  // several ways. It detects it by checking if `build.publish` is `undefined`.
199
200
  // However, `@netlify/config` adds a default value to `build.publish`.
200
- // This removes it.
201
- const normalizeConfig = (config) =>
202
- config.build.publishOrigin === 'default'
203
- ? { ...config, build: omit(config.build, ['publish', 'publishOrigin']) }
204
- : config
201
+ // This removes 'publish' and 'publishOrigin' in this case.
202
+ export const normalizeConfig = (config) => {
203
+ // Unused var here is in order to omit 'publish' from build config
204
+ // eslint-disable-next-line no-unused-vars
205
+ const { publish, publishOrigin, ...build } = config.build
206
+
207
+ return publishOrigin === 'default' ? { ...config, build } : config
208
+ }
205
209
 
206
210
  const DEBOUNCE_WAIT = 100
207
211
 
@@ -215,7 +219,7 @@ const DEBOUNCE_WAIT = 100
215
219
  * @param {() => any} [opts.onChange]
216
220
  * @param {() => any} [opts.onUnlink]
217
221
  */
218
- const watchDebounced = async (target, { depth, onAdd = () => {}, onChange = () => {}, onUnlink = () => {} }) => {
222
+ export const watchDebounced = async (target, { depth, onAdd = () => {}, onChange = () => {}, onUnlink = () => {} }) => {
219
223
  const watcher = chokidar.watch(target, { depth, ignored: /node_modules/, ignoreInitial: true })
220
224
 
221
225
  await once(watcher, 'ready')
@@ -241,27 +245,4 @@ const watchDebounced = async (target, { depth, onAdd = () => {}, onChange = () =
241
245
  return watcher
242
246
  }
243
247
 
244
- const getTerminalLink = (text, url) => terminalLink(text, url, { fallback: () => `${text} ${url}` })
245
-
246
- module.exports = {
247
- BANG,
248
- chalk,
249
- error,
250
- exit,
251
- getTerminalLink,
252
- getToken,
253
- log,
254
- logJson,
255
- NETLIFY_CYAN,
256
- NETLIFYDEV,
257
- NETLIFYDEVERR,
258
- NETLIFYDEVLOG,
259
- NETLIFYDEVWARN,
260
- normalizeConfig,
261
- padLeft,
262
- pollForToken,
263
- sortOptions,
264
- USER_AGENT,
265
- warn,
266
- watchDebounced,
267
- }
248
+ export const getTerminalLink = (text, url) => terminalLink(text, url, { fallback: () => `${text} ${url}` })
@@ -10,4 +10,4 @@ const createDeferred = () => {
10
10
  return { promise, reject: rejectDeferred, resolve: resolveDeferred }
11
11
  }
12
12
 
13
- module.exports = { createDeferred }
13
+ export default createDeferred
@@ -0,0 +1,19 @@
1
+ // Local deploy timeout in ms: 20 mins
2
+ export const DEFAULT_DEPLOY_TIMEOUT = 1_200_000
3
+ // Concurrent file hash calls
4
+ export const DEFAULT_CONCURRENT_HASH = 100
5
+ // Number of concurrent uploads
6
+ export const DEFAULT_CONCURRENT_UPLOAD = 5
7
+ // Number of files
8
+ export const DEFAULT_SYNC_LIMIT = 100
9
+ // Number of times to retry an upload
10
+ export const DEFAULT_MAX_RETRY = 5
11
+
12
+ export const UPLOAD_RANDOM_FACTOR = 0.5
13
+ // 5 seconds
14
+ export const UPLOAD_INITIAL_DELAY = 5000
15
+ // 1.5 minute (90s)
16
+ export const UPLOAD_MAX_DELAY = 90_000
17
+
18
+ // 1 second
19
+ export const DEPLOY_POLL = 1000
@@ -1,23 +1,23 @@
1
- const cleanDeep = require('clean-deep')
2
- const tempy = require('tempy')
1
+ import cleanDeep from 'clean-deep'
2
+ import tempy from 'tempy'
3
3
 
4
- const edgeFunctions = require('../../lib/edge-functions/index.cjs')
5
- const { rmdirRecursiveAsync } = require('../../lib/fs.cjs')
6
- const { warn } = require('../command-helpers.cjs')
4
+ import { deployFileNormalizer, getDistPathIfExists, isEdgeFunctionFile } from '../../lib/edge-functions/deploy.mjs'
5
+ import { rmdirRecursiveAsync } from '../../lib/fs.cjs'
6
+ import { warn } from '../command-helpers.mjs'
7
7
 
8
- const {
8
+ import {
9
9
  DEFAULT_CONCURRENT_HASH,
10
10
  DEFAULT_CONCURRENT_UPLOAD,
11
11
  DEFAULT_DEPLOY_TIMEOUT,
12
12
  DEFAULT_MAX_RETRY,
13
13
  DEFAULT_SYNC_LIMIT,
14
- } = require('./constants.cjs')
15
- const { hashFiles } = require('./hash-files.cjs')
16
- const { hashFns } = require('./hash-fns.cjs')
17
- const { uploadFiles } = require('./upload-files.cjs')
18
- const { getUploadList, waitForDeploy, waitForDiff } = require('./util.cjs')
14
+ } from './constants.mjs'
15
+ import hashFiles from './hash-files.mjs'
16
+ import hashFns from './hash-fns.mjs'
17
+ import uploadFiles from './upload-files.mjs'
18
+ import { getUploadList, waitForDeploy, waitForDiff } from './util.mjs'
19
19
 
20
- const deploySite = async (
20
+ export const deploySite = async (
21
21
  api,
22
22
  siteId,
23
23
  dir,
@@ -54,7 +54,7 @@ const deploySite = async (
54
54
  phase: 'start',
55
55
  })
56
56
 
57
- const edgeFunctionsDistPath = await edgeFunctions.getDistPathIfExists({ rootDir })
57
+ const edgeFunctionsDistPath = await getDistPathIfExists({ rootDir })
58
58
  const [{ files, filesShaMap }, { fnShaMap, functionSchedules, functions, functionsWithNativeModules }] =
59
59
  await Promise.all([
60
60
  hashFiles({
@@ -63,7 +63,7 @@ const deploySite = async (
63
63
  directories: [configPath, dir, edgeFunctionsDistPath].filter(Boolean),
64
64
  filter,
65
65
  hashAlgorithm,
66
- normalizer: edgeFunctions.deployFileNormalizer.bind(null, rootDir),
66
+ normalizer: deployFileNormalizer.bind(null, rootDir),
67
67
  statusCb,
68
68
  }),
69
69
  hashFns(fnDir, {
@@ -79,7 +79,7 @@ const deploySite = async (
79
79
  siteEnv,
80
80
  }),
81
81
  ])
82
- const edgeFunctionsCount = Object.keys(files).filter(edgeFunctions.isEdgeFunctionFile).length
82
+ const edgeFunctionsCount = Object.keys(files).filter(isEdgeFunctionFile).length
83
83
  const filesCount = Object.keys(files).length - edgeFunctionsCount
84
84
  const functionsCount = Object.keys(functions).length
85
85
  const stats = buildStatsString([
@@ -186,5 +186,3 @@ const buildStatsString = (possibleParts) => {
186
186
 
187
187
  return parts.length > 1 ? `${message} and ${parts[parts.length - 1]}` : message
188
188
  }
189
-
190
- module.exports = { deploySite }
@@ -1,9 +1,11 @@
1
- const { promisify } = require('util')
1
+ import { promisify } from 'util'
2
2
 
3
- const walker = require('folder-walker')
4
- const pump = promisify(require('pump'))
3
+ import walker from 'folder-walker'
4
+ import pumpModule from 'pump'
5
5
 
6
- const { fileFilterCtor, fileNormalizerCtor, hasherCtor, manifestCollectorCtor } = require('./hasher-segments.cjs')
6
+ import { fileFilterCtor, fileNormalizerCtor, hasherCtor, manifestCollectorCtor } from './hasher-segments.mjs'
7
+
8
+ const pump = promisify(pumpModule)
7
9
 
8
10
  const hashFiles = async ({
9
11
  assetType = 'file',
@@ -33,4 +35,4 @@ const hashFiles = async ({
33
35
  return { files, filesShaMap }
34
36
  }
35
37
 
36
- module.exports = { hashFiles }
38
+ export default hashFiles
@@ -1,10 +1,13 @@
1
- const path = require('path')
2
- const { promisify } = require('util')
1
+ import { readFile } from 'fs/promises'
2
+ import path from 'path'
3
+ import { promisify } from 'util'
3
4
 
4
- const fromArray = require('from2-array')
5
- const pump = promisify(require('pump'))
5
+ import fromArray from 'from2-array'
6
+ import pumpModule from 'pump'
6
7
 
7
- const { hasherCtor, manifestCollectorCtor } = require('./hasher-segments.cjs')
8
+ import { hasherCtor, manifestCollectorCtor } from './hasher-segments.mjs'
9
+
10
+ const pump = promisify(pumpModule)
8
11
 
9
12
  // Maximum age of functions manifest (2 minutes).
10
13
  const MANIFEST_FILE_TTL = 12e4
@@ -26,8 +29,8 @@ const getFunctionZips = async ({
26
29
 
27
30
  if (manifestPath) {
28
31
  try {
29
- // eslint-disable-next-line import/no-dynamic-require, n/global-require
30
- const { functions, timestamp } = require(manifestPath)
32
+ // read manifest.json file
33
+ const { functions, timestamp } = JSON.parse(await readFile(manifestPath))
31
34
  const manifestAge = Date.now() - timestamp
32
35
 
33
36
  if (manifestAge > MANIFEST_FILE_TTL) {
@@ -131,4 +134,4 @@ const hashFns = async (
131
134
  return { functionSchedules, functions, functionsWithNativeModules, fnShaMap }
132
135
  }
133
136
 
134
- module.exports = { hashFns }
137
+ export default hashFns
@@ -1,15 +1,15 @@
1
- const flushWriteStream = require('flush-write-stream')
2
- const hasha = require('hasha')
3
- const transform = require('parallel-transform')
4
- const { objCtor: objFilterCtor } = require('through2-filter')
5
- const { obj: map } = require('through2-map')
1
+ import flushWriteStream from 'flush-write-stream'
2
+ import hasha from 'hasha'
3
+ import transform from 'parallel-transform'
4
+ import { objCtor as objFilterCtor } from 'through2-filter'
5
+ import { obj as map } from 'through2-map'
6
6
 
7
- const { normalizePath } = require('./util.cjs')
7
+ import { normalizePath } from './util.mjs'
8
8
 
9
9
  // a parallel transform stream segment ctor that hashes fileObj's created by folder-walker
10
10
  // TODO: use promises instead of callbacks
11
11
  /* eslint-disable promise/prefer-await-to-callbacks */
12
- const hasherCtor = ({ concurrentHash, hashAlgorithm }) => {
12
+ export const hasherCtor = ({ concurrentHash, hashAlgorithm }) => {
13
13
  const hashaOpts = { algorithm: hashAlgorithm }
14
14
  if (!concurrentHash) throw new Error('Missing required opts')
15
15
  return transform(concurrentHash, { objectMode: true }, async (fileObj, cb) => {
@@ -24,7 +24,7 @@ const hasherCtor = ({ concurrentHash, hashAlgorithm }) => {
24
24
  }
25
25
 
26
26
  // Inject normalized file names into normalizedPath and assetType
27
- const fileNormalizerCtor = ({ assetType, normalizer: normalizeFunction }) =>
27
+ export const fileNormalizerCtor = ({ assetType, normalizer: normalizeFunction }) =>
28
28
  map((fileObj) => {
29
29
  const normalizedFile = { ...fileObj, assetType, normalizedPath: normalizePath(fileObj.relname) }
30
30
 
@@ -36,7 +36,7 @@ const fileNormalizerCtor = ({ assetType, normalizer: normalizeFunction }) =>
36
36
  })
37
37
 
38
38
  // A writable stream segment ctor that normalizes file paths, and writes shaMap's
39
- const manifestCollectorCtor = (filesObj, shaMap, { assetType, statusCb }) => {
39
+ export const manifestCollectorCtor = (filesObj, shaMap, { assetType, statusCb }) => {
40
40
  if (!statusCb || !assetType) throw new Error('Missing required options')
41
41
  return flushWriteStream.obj((fileObj, _, cb) => {
42
42
  filesObj[fileObj.normalizedPath] = fileObj.hash
@@ -60,11 +60,4 @@ const manifestCollectorCtor = (filesObj, shaMap, { assetType, statusCb }) => {
60
60
  /* eslint-enable promise/prefer-await-to-callbacks */
61
61
 
62
62
  // transform stream ctor that filters folder-walker results for only files
63
- const fileFilterCtor = objFilterCtor((fileObj) => fileObj.type === 'file')
64
-
65
- module.exports = {
66
- hasherCtor,
67
- fileNormalizerCtor,
68
- manifestCollectorCtor,
69
- fileFilterCtor,
70
- }
63
+ export const fileFilterCtor = objFilterCtor((fileObj) => fileObj.type === 'file')
@@ -1,9 +1,9 @@
1
- const fs = require('fs')
1
+ import fs from 'fs'
2
2
 
3
- const backoff = require('backoff')
4
- const pMap = require('p-map')
3
+ import backoff from 'backoff'
4
+ import pMap from 'p-map'
5
5
 
6
- const { UPLOAD_INITIAL_DELAY, UPLOAD_MAX_DELAY, UPLOAD_RANDOM_FACTOR } = require('./constants.cjs')
6
+ import { UPLOAD_INITIAL_DELAY, UPLOAD_MAX_DELAY, UPLOAD_RANDOM_FACTOR } from './constants.mjs'
7
7
 
8
8
  const uploadFiles = async (api, deployId, uploadList, { concurrentUpload, maxRetry, statusCb }) => {
9
9
  if (!concurrentUpload || !statusCb || !maxRetry) throw new Error('Missing required option concurrentUpload')
@@ -115,4 +115,4 @@ const retryUpload = (uploadFn, maxRetry) =>
115
115
  tryUpload()
116
116
  })
117
117
 
118
- module.exports = { uploadFiles }
118
+ export default uploadFiles
@@ -1,24 +1,19 @@
1
- const { sep } = require('path')
1
+ import { sep } from 'path'
2
2
 
3
- const pWaitFor = require('p-wait-for')
3
+ import pWaitFor from 'p-wait-for'
4
4
 
5
- const { DEPLOY_POLL } = require('./constants.cjs')
5
+ import { DEPLOY_POLL } from './constants.mjs'
6
6
 
7
7
  // normalize windows paths to unix paths
8
- const normalizePath = (relname) => {
8
+ export const normalizePath = (relname) => {
9
9
  if (relname.includes('#') || relname.includes('?')) {
10
10
  throw new Error(`Invalid filename ${relname}. Deployed filenames cannot contain # or ? characters`)
11
11
  }
12
- return (
13
- relname
14
- .split(sep)
15
- // .map(segment => encodeURI(segment)) // TODO I'm fairly certain we shouldn't encodeURI here, thats only for the file upload step
16
- .join('/')
17
- )
12
+ return relname.split(sep).join('/')
18
13
  }
19
14
 
20
15
  // poll an async deployId until its done diffing
21
- const waitForDiff = async (api, deployId, siteId, timeout) => {
16
+ export const waitForDiff = async (api, deployId, siteId, timeout) => {
22
17
  // capture ready deploy during poll
23
18
  let deploy
24
19
 
@@ -56,7 +51,7 @@ const waitForDiff = async (api, deployId, siteId, timeout) => {
56
51
  }
57
52
 
58
53
  // Poll a deployId until its ready
59
- const waitForDeploy = async (api, deployId, siteId, timeout) => {
54
+ export const waitForDeploy = async (api, deployId, siteId, timeout) => {
60
55
  // capture ready deploy during poll
61
56
  let deploy
62
57
 
@@ -93,14 +88,7 @@ const waitForDeploy = async (api, deployId, siteId, timeout) => {
93
88
  }
94
89
 
95
90
  // Transform the fileShaMap and fnShaMap into a generic shaMap that file-uploader.js can use
96
- const getUploadList = (required, shaMap) => {
91
+ export const getUploadList = (required, shaMap) => {
97
92
  if (!required || !shaMap) return []
98
93
  return required.flatMap((sha) => shaMap[sha])
99
94
  }
100
-
101
- module.exports = {
102
- normalizePath,
103
- waitForDiff,
104
- waitForDeploy,
105
- getUploadList,
106
- }
@@ -10,8 +10,8 @@ import isPlainObject from 'is-plain-obj'
10
10
 
11
11
  import { readFileAsyncCatchError } from '../lib/fs.cjs'
12
12
 
13
- import { NETLIFYDEVWARN, chalk, log } from './command-helpers.cjs'
14
- import { acquirePort } from './dev.cjs'
13
+ import { NETLIFYDEVWARN, chalk, log } from './command-helpers.mjs'
14
+ import { acquirePort } from './dev.mjs'
15
15
  import { getInternalFunctionsDir } from './functions/index.mjs'
16
16
 
17
17
  const formatProperty = (str) => chalk.magenta(`'${str}'`)
@@ -1,15 +1,15 @@
1
1
  // @ts-check
2
- const process = require('process')
2
+ import process from 'process'
3
3
 
4
- const { get } = require('dot-prop')
5
- const getPort = require('get-port')
6
- const jwt = require('jsonwebtoken')
7
- const isEmpty = require('lodash/isEmpty')
4
+ import { get } from 'dot-prop'
5
+ import getPort from 'get-port'
6
+ import jwt from 'jsonwebtoken'
7
+ import isEmpty from 'lodash/isEmpty.js'
8
8
 
9
- const { supportsBackgroundFunctions } = require('../lib/account.cjs')
9
+ import { supportsBackgroundFunctions } from '../lib/account.mjs'
10
10
 
11
- const { NETLIFYDEVLOG, chalk, error, log, warn } = require('./command-helpers.cjs')
12
- const { loadDotEnvFiles } = require('./dot-env.cjs')
11
+ import { NETLIFYDEVLOG, chalk, error, log, warn } from './command-helpers.mjs'
12
+ import { loadDotEnvFiles } from './dot-env.mjs'
13
13
 
14
14
  // Possible sources of environment variables. For the purpose of printing log messages only. Order does not matter.
15
15
  const ENV_VAR_SOURCES = {
@@ -98,7 +98,7 @@ const BACKGROUND_FUNCTION_TIMEOUT = 900
98
98
  * @param {*} config.siteInfo
99
99
  * @returns
100
100
  */
101
- const getSiteInformation = async ({ api, offline, site, siteInfo }) => {
101
+ export const getSiteInformation = async ({ api, offline, site, siteInfo }) => {
102
102
  if (site.id && !offline) {
103
103
  validateSiteInfo({ site, siteInfo })
104
104
  const [accounts, addons] = await Promise.all([getAccounts({ api }), getAddons({ api, site })])
@@ -139,7 +139,7 @@ const getEnvSourceName = (source) => {
139
139
 
140
140
  // Takes a set of environment variables in the format provided by @netlify/config, augments it with variables from both
141
141
  // dot-env files and the process itself, and injects into `process.env`.
142
- const injectEnvVariables = async ({ devConfig, env, site }) => {
142
+ export const injectEnvVariables = async ({ devConfig, env, site }) => {
143
143
  const environment = new Map(Object.entries(env))
144
144
  const dotEnvFiles = await loadDotEnvFiles({ envFiles: devConfig.envFiles, projectDir: site.root })
145
145
 
@@ -186,7 +186,7 @@ const injectEnvVariables = async ({ devConfig, env, site }) => {
186
186
  process.env.NETLIFY_DEV = 'true'
187
187
  }
188
188
 
189
- const acquirePort = async ({ configuredPort, defaultPort, errorMessage }) => {
189
+ export const acquirePort = async ({ configuredPort, defaultPort, errorMessage }) => {
190
190
  const acquiredPort = await getPort({ port: configuredPort || defaultPort })
191
191
  if (configuredPort && acquiredPort !== configuredPort) {
192
192
  throw new Error(`${errorMessage}: '${configuredPort}'`)
@@ -199,7 +199,7 @@ const acquirePort = async ({ configuredPort, defaultPort, errorMessage }) => {
199
199
  // - netlify_token -- the bearer token for the Netlify API
200
200
  // - authlify_token_id -- the authlify token ID stored for the site after
201
201
  // enabling API Authentication.
202
- const generateNetlifyGraphJWT = ({ authlifyTokenId, netlifyToken, siteId }) => {
202
+ export const generateNetlifyGraphJWT = ({ authlifyTokenId, netlifyToken, siteId }) => {
203
203
  const claims = {
204
204
  netlify_token: netlifyToken,
205
205
  authlify_token_id: authlifyTokenId,
@@ -215,17 +215,9 @@ const generateNetlifyGraphJWT = ({ authlifyTokenId, netlifyToken, siteId }) => {
215
215
  )
216
216
  }
217
217
 
218
- const processOnExit = (fn) => {
218
+ export const processOnExit = (fn) => {
219
219
  const signals = ['SIGINT', 'SIGTERM', 'SIGQUIT', 'SIGHUP', 'exit']
220
220
  signals.forEach((signal) => {
221
221
  process.on(signal, fn)
222
222
  })
223
223
  }
224
-
225
- module.exports = {
226
- getSiteInformation,
227
- injectEnvVariables,
228
- acquirePort,
229
- generateNetlifyGraphJWT,
230
- processOnExit,
231
- }
@@ -1,14 +1,14 @@
1
1
  // @ts-check
2
- const { readFile } = require('fs').promises
3
- const path = require('path')
2
+ import { readFile } from 'fs/promises'
3
+ import path from 'path'
4
4
 
5
- const dotenv = require('dotenv')
5
+ import dotenv from 'dotenv'
6
6
 
7
- const { isFileAsync } = require('../lib/fs.cjs')
7
+ import { isFileAsync } from '../lib/fs.cjs'
8
8
 
9
- const { warn } = require('./command-helpers.cjs')
9
+ import { warn } from './command-helpers.mjs'
10
10
 
11
- const loadDotEnvFiles = async function ({ envFiles, projectDir }) {
11
+ export const loadDotEnvFiles = async function ({ envFiles, projectDir }) {
12
12
  const response = await tryLoadDotEnvFiles({ projectDir, dotenvFiles: envFiles })
13
13
 
14
14
  const filesWithWarning = response.filter((el) => el.warning)
@@ -22,7 +22,7 @@ const loadDotEnvFiles = async function ({ envFiles, projectDir }) {
22
22
  // in the user configuration, the order is highest to lowest
23
23
  const defaultEnvFiles = ['.env.development.local', '.env.local', '.env.development', '.env']
24
24
 
25
- const tryLoadDotEnvFiles = async ({ projectDir, dotenvFiles = defaultEnvFiles }) => {
25
+ export const tryLoadDotEnvFiles = async ({ projectDir, dotenvFiles = defaultEnvFiles }) => {
26
26
  const results = await Promise.all(
27
27
  dotenvFiles.map(async (file) => {
28
28
  const filepath = path.resolve(projectDir, file)
@@ -45,5 +45,3 @@ const tryLoadDotEnvFiles = async ({ projectDir, dotenvFiles = defaultEnvFiles })
45
45
  // we return in order of lowest to highest priority
46
46
  return results.filter(Boolean).reverse()
47
47
  }
48
-
49
- module.exports = { loadDotEnvFiles, tryLoadDotEnvFiles }