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,10 +1,8 @@
1
- import utils from '../../utils/index.cjs'
1
+ import { log } from '../../utils/command-helpers.mjs'
2
2
 
3
3
  import { createOpenAdminCommand, openAdmin } from './open-admin.mjs'
4
4
  import { createOpenSiteCommand, openSite } from './open-site.mjs'
5
5
 
6
- const { log } = utils
7
-
8
6
  /**
9
7
  * The open command
10
8
  * @param {import('commander').OptionValues} options
@@ -4,7 +4,7 @@ import { basename } from 'path'
4
4
  import inquirer from 'inquirer'
5
5
  import { findBestMatch } from 'string-similarity'
6
6
 
7
- import utils from '../../utils/command-helpers.cjs'
7
+ import { NETLIFYDEVERR, chalk, log } from '../../utils/command-helpers.mjs'
8
8
 
9
9
  import { getRecipe, listRecipes } from './common.mjs'
10
10
  import { createRecipesListCommand } from './recipes-list.mjs'
@@ -32,7 +32,7 @@ const recipesCommand = async (recipeName, options, command) => {
32
32
  throw error
33
33
  }
34
34
 
35
- utils.log(`${utils.NETLIFYDEVERR} ${utils.chalk.yellow(recipeName)} is not a valid recipe name.`)
35
+ log(`${NETLIFYDEVERR} ${chalk.yellow(recipeName)} is not a valid recipe name.`)
36
36
 
37
37
  const recipes = await listRecipes()
38
38
  const recipeNames = recipes.map(({ name }) => name)
@@ -43,7 +43,7 @@ const recipesCommand = async (recipeName, options, command) => {
43
43
  const prompt = inquirer.prompt({
44
44
  type: 'confirm',
45
45
  name: 'suggestion',
46
- message: `Did you mean ${utils.chalk.blue(suggestion)}`,
46
+ message: `Did you mean ${chalk.blue(suggestion)}`,
47
47
  default: false,
48
48
  })
49
49
 
@@ -3,19 +3,18 @@
3
3
  import inquirer from 'inquirer'
4
4
  import pick from 'lodash/pick.js'
5
5
  import parseGitHubUrl from 'parse-github-url'
6
- import prettyjson from 'prettyjson'
6
+ import { render } from 'prettyjson'
7
7
 
8
+ import { chalk, error, getTerminalLink, log, logJson, warn } from '../../utils/command-helpers.mjs'
9
+ import execa from '../../utils/execa.mjs'
8
10
  import getRepoData from '../../utils/get-repo-data.mjs'
9
- import utils from '../../utils/index.cjs'
10
- import { getGitHubToken } from '../../utils/init/config-github.cjs'
11
- import { configureRepo } from '../../utils/init/config.cjs'
12
- import { createRepo, getTemplatesFromGitHub, validateTemplate } from '../../utils/sites/utils.cjs'
11
+ import { getGitHubToken } from '../../utils/init/config-github.mjs'
12
+ import { configureRepo } from '../../utils/init/config.mjs'
13
+ import { createRepo, getTemplatesFromGitHub, validateTemplate } from '../../utils/sites/utils.mjs'
13
14
  import { track } from '../../utils/telemetry/index.mjs'
14
15
 
15
16
  import { getSiteNameInput } from './sites-create.mjs'
16
17
 
17
- const { chalk, error, execa, getTerminalLink, log, logJson, warn } = utils
18
-
19
18
  export const fetchTemplates = async (token) => {
20
19
  const templatesFromGithubOrg = await getTemplatesFromGitHub(token)
21
20
 
@@ -170,7 +169,7 @@ const sitesCreateTemplate = async (repository, options, command) => {
170
169
 
171
170
  const siteUrl = site.ssl_url || site.url
172
171
  log(
173
- prettyjson.render({
172
+ render({
174
173
  'Admin URL': site.admin_url,
175
174
  URL: siteUrl,
176
175
  'Site ID': site.id,
@@ -4,14 +4,12 @@ import inquirer from 'inquirer'
4
4
  import pick from 'lodash/pick.js'
5
5
  import prettyjson from 'prettyjson'
6
6
 
7
+ import { chalk, error, log, logJson, warn } from '../../utils/command-helpers.mjs'
7
8
  import getRepoData from '../../utils/get-repo-data.mjs'
8
- import utils from '../../utils/index.cjs'
9
- import { configureRepo } from '../../utils/init/config.cjs'
9
+ import { configureRepo } from '../../utils/init/config.mjs'
10
10
  import { track } from '../../utils/telemetry/index.mjs'
11
11
  import { link } from '../link/index.mjs'
12
12
 
13
- const { chalk, error, log, logJson, warn } = utils
14
-
15
13
  export const getSiteNameInput = async (name) => {
16
14
  if (!name) {
17
15
  const { name: nameInput } = await inquirer.prompt([
@@ -1,9 +1,7 @@
1
1
  // @ts-check
2
2
  import inquirer from 'inquirer'
3
3
 
4
- import utils from '../../utils/index.cjs'
5
-
6
- const { chalk, error, exit, log } = utils
4
+ import { chalk, error, exit, log } from '../../utils/command-helpers.mjs'
7
5
 
8
6
  /**
9
7
  * The sites:delete command
@@ -1,9 +1,7 @@
1
1
  // @ts-check
2
2
  import { listSites } from '../../lib/api.mjs'
3
3
  import { startSpinner, stopSpinner } from '../../lib/spinner.cjs'
4
- import utils from '../../utils/index.cjs'
5
-
6
- const { chalk, log, logJson } = utils
4
+ import { chalk, log, logJson } from '../../utils/command-helpers.mjs'
7
5
 
8
6
  /**
9
7
  * The sites:list command
@@ -2,9 +2,7 @@
2
2
  import { get } from 'dot-prop'
3
3
  import prettyjson from 'prettyjson'
4
4
 
5
- import utils from '../../utils/index.cjs'
6
-
7
- const { error, log, warn } = utils
5
+ import { error, log, warn } from '../../utils/command-helpers.mjs'
8
6
 
9
7
  /**
10
8
  * The status:hooks command
@@ -2,12 +2,10 @@
2
2
  import clean from 'clean-deep'
3
3
  import prettyjson from 'prettyjson'
4
4
 
5
- import utils from '../../utils/index.cjs'
5
+ import { chalk, error, exit, getToken, log, logJson, warn } from '../../utils/command-helpers.mjs'
6
6
 
7
7
  import { createStatusHooksCommand } from './status-hooks.mjs'
8
8
 
9
- const { chalk, error, exit, getToken, log, logJson, warn } = utils
10
-
11
9
  /**
12
10
  * The status command
13
11
  * @param {import('commander').OptionValues} options
@@ -1,11 +1,9 @@
1
1
  // @ts-check
2
2
  import inquirer from 'inquirer'
3
3
 
4
- import utils from '../../utils/index.cjs'
4
+ import { chalk, log } from '../../utils/command-helpers.mjs'
5
5
  import { login } from '../login/index.mjs'
6
6
 
7
- const { chalk, log } = utils
8
-
9
7
  const LOGIN_NEW = 'I would like to login to a new account'
10
8
 
11
9
  /**
@@ -1,9 +1,7 @@
1
1
  // @ts-check
2
- import utils from '../../utils/index.cjs'
2
+ import { exit, log } from '../../utils/command-helpers.mjs'
3
3
  import { track } from '../../utils/telemetry/index.mjs'
4
4
 
5
- const { exit, log } = utils
6
-
7
5
  /**
8
6
  * The unlink command
9
7
  * @param {import('commander').OptionValues} options
@@ -3,11 +3,9 @@ import pWaitFor from 'p-wait-for'
3
3
  import prettyjson from 'prettyjson'
4
4
 
5
5
  import { startSpinner, stopSpinner } from '../../lib/spinner.cjs'
6
- import utils from '../../utils/index.cjs'
6
+ import { chalk, error, log } from '../../utils/command-helpers.mjs'
7
7
  import { init } from '../init/index.mjs'
8
8
 
9
- const { chalk, error, log } = utils
10
-
11
9
  // 1 second
12
10
  const INIT_WAIT = 1e3
13
11
 
@@ -0,0 +1,14 @@
1
+ // @ts-check
2
+
3
+ /**
4
+ * @param {any} account
5
+ * @param {string} capability
6
+ * @returns {boolean}
7
+ */
8
+ const supportsBooleanCapability = (account, capability) => Boolean(account?.capabilities?.[capability]?.included)
9
+
10
+ /**
11
+ * @param {any} account
12
+ * @returns {boolean}
13
+ */
14
+ export const supportsBackgroundFunctions = (account) => supportsBooleanCapability(account, 'background_functions')
package/src/lib/api.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { warn } from '../utils/command-helpers.cjs'
1
+ import { warn } from '../utils/command-helpers.mjs'
2
2
 
3
3
  export const cancelDeploy = async ({ api, deployId }) => {
4
4
  try {
@@ -2,7 +2,7 @@
2
2
  import { existsSync, mkdirSync, writeFileSync } from 'fs'
3
3
  import { dirname } from 'path'
4
4
 
5
- import { sortOptions, warn } from '../../utils/command-helpers.cjs'
5
+ import { sortOptions, warn } from '../../utils/command-helpers.mjs'
6
6
 
7
7
  import { AUTOCOMPLETION_FILE } from './constants.mjs'
8
8
 
@@ -0,0 +1,4 @@
1
+ export const DIST_IMPORT_MAP_PATH = 'edge-functions-import-map.json'
2
+ export const INTERNAL_EDGE_FUNCTIONS_FOLDER = 'edge-functions'
3
+ export const EDGE_FUNCTIONS_FOLDER = 'edge-functions-dist'
4
+ export const PUBLIC_URL_PATH = '.netlify/internal/edge-functions'
@@ -1,14 +1,14 @@
1
1
  // @ts-check
2
- const { stat } = require('fs').promises
3
- const { join } = require('path')
2
+ import { stat } from 'fs/promises'
3
+ import { join } from 'path'
4
4
 
5
- const { getPathInProject } = require('../settings.cjs')
5
+ import { getPathInProject } from '../settings.cjs'
6
6
 
7
- const { EDGE_FUNCTIONS_FOLDER, PUBLIC_URL_PATH } = require('./consts.cjs')
7
+ import { EDGE_FUNCTIONS_FOLDER, PUBLIC_URL_PATH } from './consts.mjs'
8
8
 
9
9
  const distPath = getPathInProject([EDGE_FUNCTIONS_FOLDER])
10
10
 
11
- const deployFileNormalizer = (rootDir, file) => {
11
+ export const deployFileNormalizer = (rootDir, file) => {
12
12
  const absoluteDistPath = join(rootDir, distPath)
13
13
  const isEdgeFunction = file.root === absoluteDistPath
14
14
  const normalizedPath = isEdgeFunction ? `${PUBLIC_URL_PATH}/${file.normalizedPath}` : file.normalizedPath
@@ -19,7 +19,7 @@ const deployFileNormalizer = (rootDir, file) => {
19
19
  }
20
20
  }
21
21
 
22
- const getDistPathIfExists = async ({ rootDir }) => {
22
+ export const getDistPathIfExists = async ({ rootDir }) => {
23
23
  try {
24
24
  const absoluteDistPath = join(rootDir, distPath)
25
25
  const stats = await stat(absoluteDistPath)
@@ -34,10 +34,4 @@ const getDistPathIfExists = async ({ rootDir }) => {
34
34
  }
35
35
  }
36
36
 
37
- const isEdgeFunctionFile = (filePath) => filePath.startsWith(`${PUBLIC_URL_PATH}/`)
38
-
39
- module.exports = {
40
- deployFileNormalizer,
41
- getDistPathIfExists,
42
- isEdgeFunctionFile,
43
- }
37
+ export const isEdgeFunctionFile = (filePath) => filePath.startsWith(`${PUBLIC_URL_PATH}/`)
@@ -1,4 +1,4 @@
1
- module.exports = {
1
+ const headers = {
2
2
  ForwardedHost: 'x-forwarded-host',
3
3
  ForwardedProtocol: 'x-forwarded-proto',
4
4
  Functions: 'x-deno-functions',
@@ -8,3 +8,5 @@ module.exports = {
8
8
  IP: 'x-nf-client-connection-ip',
9
9
  Site: 'X-NF-Site-Info',
10
10
  }
11
+
12
+ export default headers
@@ -1,13 +1,13 @@
1
1
  // @ts-check
2
- const { promises: fs } = require('fs')
3
- const { dirname, join, resolve } = require('path')
4
- const { cwd } = require('process')
5
- const { pathToFileURL } = require('url')
2
+ import { readFile, stat } from 'fs/promises'
3
+ import { dirname, join, resolve } from 'path'
4
+ import { cwd } from 'process'
5
+ import { pathToFileURL } from 'url'
6
6
 
7
- const { warn } = require('../../utils/command-helpers.cjs')
8
- const { getPathInProject } = require('../settings.cjs')
7
+ import { warn } from '../../utils/command-helpers.mjs'
8
+ import { getPathInProject } from '../settings.cjs'
9
9
 
10
- const { INTERNAL_EDGE_FUNCTIONS_FOLDER } = require('./consts.cjs')
10
+ import { INTERNAL_EDGE_FUNCTIONS_FOLDER } from './consts.mjs'
11
11
 
12
12
  /**
13
13
  * Reads an import map from a path and returns the parsed data, if it exists
@@ -18,7 +18,7 @@ const { INTERNAL_EDGE_FUNCTIONS_FOLDER } = require('./consts.cjs')
18
18
  */
19
19
  const getImportMap = async (importMapPath) => {
20
20
  try {
21
- const data = await fs.readFile(importMapPath)
21
+ const data = await readFile(importMapPath)
22
22
  const importMap = JSON.parse(data)
23
23
 
24
24
  return importMap
@@ -29,19 +29,25 @@ const getImportMap = async (importMapPath) => {
29
29
  }
30
30
  }
31
31
 
32
- const getInternalFunctions = async () => {
32
+ export const getInternalFunctions = async () => {
33
33
  const path = join(cwd(), getPathInProject([INTERNAL_EDGE_FUNCTIONS_FOLDER]))
34
34
 
35
35
  try {
36
- const stats = await fs.stat(path)
36
+ const stats = await stat(path)
37
37
 
38
38
  if (!stats.isDirectory()) {
39
- throw new Error('Path is not a directory')
39
+ throw new Error('Internal edge functions directory expected')
40
40
  }
41
+ } catch {
42
+ return {
43
+ functions: [],
44
+ path: null,
45
+ }
46
+ }
41
47
 
48
+ try {
42
49
  const manifestPath = join(path, 'manifest.json')
43
- // eslint-disable-next-line import/no-dynamic-require, n/global-require
44
- const manifest = require(manifestPath)
50
+ const manifest = JSON.parse(await readFile(manifestPath))
45
51
 
46
52
  if (manifest.version !== 1) {
47
53
  throw new Error('Unsupported manifest format')
@@ -75,5 +81,3 @@ const getInternalFunctions = async () => {
75
81
  }
76
82
  }
77
83
  }
78
-
79
- module.exports = { getInternalFunctions }
@@ -1,20 +1,20 @@
1
1
  // @ts-check
2
- const { Buffer } = require('buffer')
3
- const { relative } = require('path')
4
- const { cwd, env } = require('process')
2
+ import { Buffer } from 'buffer'
3
+ import { relative } from 'path'
4
+ import { cwd, env } from 'process'
5
5
 
6
- const getAvailablePort = require('get-port')
7
- const { v4: generateUUID } = require('uuid')
6
+ import getAvailablePort from 'get-port'
7
+ import { v4 as generateUUID } from 'uuid'
8
8
 
9
- const { NETLIFYDEVERR, NETLIFYDEVWARN, chalk, error: printError, log } = require('../../utils/command-helpers.cjs')
10
- const { getGeoLocation } = require('../geo-location.cjs')
11
- const { getPathInProject } = require('../settings.cjs')
12
- const { startSpinner, stopSpinner } = require('../spinner.cjs')
9
+ import { NETLIFYDEVERR, NETLIFYDEVWARN, chalk, error as printError, log } from '../../utils/command-helpers.mjs'
10
+ import { getGeoLocation } from '../geo-location.mjs'
11
+ import { getPathInProject } from '../settings.cjs'
12
+ import { startSpinner, stopSpinner } from '../spinner.cjs'
13
13
 
14
- const { DIST_IMPORT_MAP_PATH } = require('./consts.cjs')
15
- const headers = require('./headers.cjs')
16
- const { getInternalFunctions } = require('./internal.cjs')
17
- const { EdgeFunctionsRegistry } = require('./registry.cjs')
14
+ import { DIST_IMPORT_MAP_PATH } from './consts.mjs'
15
+ import headers from './headers.mjs'
16
+ import { getInternalFunctions } from './internal.mjs'
17
+ import { EdgeFunctionsRegistry } from './registry.mjs'
18
18
 
19
19
  const headersSymbol = Symbol('Edge Functions Headers')
20
20
 
@@ -40,20 +40,20 @@ const getDownloadUpdateFunctions = () => {
40
40
  }
41
41
  }
42
42
 
43
- const handleProxyRequest = (req, proxyReq) => {
43
+ export const handleProxyRequest = (req, proxyReq) => {
44
44
  Object.entries(req[headersSymbol]).forEach(([header, value]) => {
45
45
  proxyReq.setHeader(header, value)
46
46
  })
47
47
  }
48
48
 
49
- const createSiteInfoHeader = (siteInfo = {}) => {
49
+ export const createSiteInfoHeader = (siteInfo = {}) => {
50
50
  const { id, name, url } = siteInfo
51
51
  const site = { id, name, url }
52
52
  const siteString = JSON.stringify(site)
53
53
  return Buffer.from(siteString).toString('base64')
54
54
  }
55
55
 
56
- const initializeProxy = async ({
56
+ export const initializeProxy = async ({
57
57
  config,
58
58
  configPath,
59
59
  env: configEnv,
@@ -88,7 +88,7 @@ const initializeProxy = async ({
88
88
  port: isolatePort,
89
89
  projectDir,
90
90
  })
91
- const hasEdgeFunctions = userFunctionsPath !== undefined || internalFunctions.length !== 0
91
+ const hasEdgeFunctions = userFunctionsPath !== undefined || internalFunctionsPath
92
92
 
93
93
  return async (req) => {
94
94
  if (req.headers[headers.Passthrough] !== undefined || !hasEdgeFunctions) {
@@ -145,7 +145,7 @@ const initializeProxy = async ({
145
145
  }
146
146
  }
147
147
 
148
- const isEdgeFunctionsRequest = (req) => req[headersSymbol] !== undefined
148
+ export const isEdgeFunctionsRequest = (req) => req[headersSymbol] !== undefined
149
149
 
150
150
  const prepareServer = async ({
151
151
  certificatePath,
@@ -195,5 +195,3 @@ const prepareServer = async ({
195
195
  printError(error.message, { exit: false })
196
196
  }
197
197
  }
198
-
199
- module.exports = { handleProxyRequest, initializeProxy, isEdgeFunctionsRequest, createSiteInfoHeader }
@@ -1,7 +1,7 @@
1
1
  // @ts-check
2
- const { fileURLToPath } = require('url')
2
+ import { fileURLToPath } from 'url'
3
3
 
4
- const { NETLIFYDEVERR, NETLIFYDEVLOG, chalk, log, warn, watchDebounced } = require('../../utils/command-helpers.cjs')
4
+ import { NETLIFYDEVERR, NETLIFYDEVLOG, chalk, log, warn, watchDebounced } from '../../utils/command-helpers.mjs'
5
5
 
6
6
  /**
7
7
  * @typedef EdgeFunction
@@ -26,7 +26,7 @@ const { NETLIFYDEVERR, NETLIFYDEVLOG, chalk, log, warn, watchDebounced } = requi
26
26
 
27
27
  /** @typedef {(EdgeFunctionDeclarationWithPath | EdgeFunctionDeclarationWithPattern) } EdgeFunctionDeclaration */
28
28
 
29
- class EdgeFunctionsRegistry {
29
+ export class EdgeFunctionsRegistry {
30
30
  /**
31
31
  * @param {Object} opts
32
32
  * @param {import('@netlify/edge-bundler')} opts.bundler
@@ -448,5 +448,3 @@ class EdgeFunctionsRegistry {
448
448
  this.directoryWatchers.set(directory, watcher)
449
449
  }
450
450
  }
451
-
452
- module.exports = { EdgeFunctionsRegistry }
@@ -1,18 +1,18 @@
1
1
  // @ts-check
2
- const path = require('path')
3
- const process = require('process')
2
+ import path from 'path'
3
+ import process from 'process'
4
4
 
5
- const { fetchLatest, fetchVersion, newerVersion, updateAvailable } = require('gh-release-fetch')
6
- const isExe = require('isexe')
5
+ import { fetchLatest, fetchVersion, newerVersion, updateAvailable } from 'gh-release-fetch'
6
+ import isExe from 'isexe'
7
7
 
8
- const { NETLIFYDEVWARN, error, getTerminalLink, log } = require('../utils/command-helpers.cjs')
9
- const execa = require('../utils/execa.cjs')
8
+ import { NETLIFYDEVWARN, error, getTerminalLink, log } from '../utils/command-helpers.mjs'
9
+ import execa from '../utils/execa.mjs'
10
10
 
11
11
  const isWindows = () => process.platform === 'win32'
12
12
 
13
13
  const getRepository = ({ packageName }) => `netlify/${packageName}`
14
14
 
15
- const getExecName = ({ execName }) => (isWindows() ? `${execName}.exe` : execName)
15
+ export const getExecName = ({ execName }) => (isWindows() ? `${execName}.exe` : execName)
16
16
 
17
17
  const getOptions = () => {
18
18
  // this is used in out CI tests to avoid hitting GitHub API limit
@@ -33,7 +33,14 @@ const isVersionOutdated = async ({ currentVersion, latestVersion, packageName })
33
33
  return outdated
34
34
  }
35
35
 
36
- const shouldFetchLatestVersion = async ({ binPath, execArgs, execName, latestVersion, packageName, pattern }) => {
36
+ export const shouldFetchLatestVersion = async ({
37
+ binPath,
38
+ execArgs,
39
+ execName,
40
+ latestVersion,
41
+ packageName,
42
+ pattern,
43
+ }) => {
37
44
  const execPath = path.join(binPath, getExecName({ execName }))
38
45
 
39
46
  const exists = await isExe(execPath, { ignoreErrors: true })
@@ -69,7 +76,7 @@ const shouldFetchLatestVersion = async ({ binPath, execArgs, execName, latestVer
69
76
  }
70
77
  }
71
78
 
72
- const getArch = () => {
79
+ export const getArch = () => {
73
80
  switch (process.arch) {
74
81
  case 'x64':
75
82
  return 'amd64'
@@ -91,7 +98,7 @@ const getArch = () => {
91
98
  * @param {string} config.packageName
92
99
  * @param {string} [config.latestVersion ]
93
100
  */
94
- const fetchLatestVersion = async ({ destination, execName, extension, latestVersion, packageName }) => {
101
+ export const fetchLatestVersion = async ({ destination, execName, extension, latestVersion, packageName }) => {
95
102
  const win = isWindows()
96
103
  const arch = getArch()
97
104
  const platform = win ? 'windows' : process.platform
@@ -133,5 +140,3 @@ ${issueLink}`)
133
140
  error(error_)
134
141
  }
135
142
  }
136
-
137
- module.exports = { getArch, getExecName, shouldFetchLatestVersion, fetchLatestVersion }
@@ -1,16 +1,16 @@
1
- const { NETLIFYDEVERR, NETLIFYDEVLOG } = require('../../utils/index.cjs')
1
+ import { NETLIFYDEVERR, NETLIFYDEVLOG } from '../../utils/command-helpers.mjs'
2
2
 
3
- const { formatLambdaError, styleFunctionName } = require('./utils.cjs')
3
+ import { formatLambdaError, styleFunctionName } from './utils.mjs'
4
4
 
5
5
  const BACKGROUND_FUNCTION_STATUS_CODE = 202
6
6
 
7
- const handleBackgroundFunction = (functionName, response) => {
7
+ export const handleBackgroundFunction = (functionName, response) => {
8
8
  console.log(`${NETLIFYDEVLOG} Queueing background function ${styleFunctionName(functionName)} for execution`)
9
9
  response.status(BACKGROUND_FUNCTION_STATUS_CODE)
10
10
  response.end()
11
11
  }
12
12
 
13
- const handleBackgroundFunctionResult = (functionName, err) => {
13
+ export const handleBackgroundFunctionResult = (functionName, err) => {
14
14
  if (err) {
15
15
  console.log(
16
16
  `${NETLIFYDEVERR} Error during background function ${styleFunctionName(functionName)} execution:`,
@@ -20,5 +20,3 @@ const handleBackgroundFunctionResult = (functionName, err) => {
20
20
  console.log(`${NETLIFYDEVLOG} Done executing background function ${styleFunctionName(functionName)}`)
21
21
  }
22
22
  }
23
-
24
- module.exports = { handleBackgroundFunction, handleBackgroundFunctionResult }
@@ -1,7 +1,7 @@
1
1
  // The function configuration keys returned by @netlify/config are not an exact
2
2
  // match to the properties that @netlify/zip-it-and-ship-it expects. We do that
3
3
  // translation here.
4
- const normalizeFunctionsConfig = ({ functionsConfig = {}, projectRoot, siteEnv = {} }) =>
4
+ export const normalizeFunctionsConfig = ({ functionsConfig = {}, projectRoot, siteEnv = {} }) =>
5
5
  Object.entries(functionsConfig).reduce(
6
6
  (result, [pattern, config]) => ({
7
7
  ...result,
@@ -19,5 +19,3 @@ const normalizeFunctionsConfig = ({ functionsConfig = {}, projectRoot, siteEnv =
19
19
  }),
20
20
  {},
21
21
  )
22
-
23
- module.exports = { normalizeFunctionsConfig }
@@ -5,9 +5,9 @@ import { parse as parseContentType } from 'content-type'
5
5
  import multiparty from 'multiparty'
6
6
  import getRawBody from 'raw-body'
7
7
 
8
- import { warn } from '../../utils/command-helpers.cjs'
8
+ import { warn } from '../../utils/command-helpers.mjs'
9
9
  import { BACKGROUND } from '../../utils/functions/index.mjs'
10
- import { capitalize } from '../string.cjs'
10
+ import { capitalize } from '../string.mjs'
11
11
 
12
12
  const getFormHandler = function ({ functionsRegistry }) {
13
13
  const handlers = ['submission-created', `submission-created${BACKGROUND}`]
@@ -1,11 +1,11 @@
1
1
  // @ts-check
2
- const { stdout } = require('process')
2
+ import { stdout } from 'process'
3
3
 
4
- const { getBinaryPath: getFunctionsProxyPath } = require('@netlify/local-functions-proxy')
4
+ import { getBinaryPath as getFunctionsProxyPath } from '@netlify/local-functions-proxy'
5
5
 
6
- const { execa } = require('../../utils/index.cjs')
6
+ import execa from '../../utils/execa.mjs'
7
7
 
8
- const runFunctionsProxy = ({ binaryPath, context, directory, event, name, timeout }) => {
8
+ export const runFunctionsProxy = ({ binaryPath, context, directory, event, name, timeout }) => {
9
9
  const functionsProxyPath = getFunctionsProxyPath()
10
10
  const requestData = {
11
11
  resource: '',
@@ -43,5 +43,3 @@ const runFunctionsProxy = ({ binaryPath, context, directory, event, name, timeou
43
43
 
44
44
  return proxyProcess
45
45
  }
46
-
47
- module.exports = { runFunctionsProxy }
@@ -8,7 +8,7 @@ const DEBOUNCE_INTERVAL = 300
8
8
  // This allows us to discard any duplicate filesystem events, while ensuring
9
9
  // that actual updates happening during the zip operation will be executed
10
10
  // after it finishes (only the last update will run).
11
- const memoizedBuild = ({ cache, cacheKey, command }) => {
11
+ export const memoizedBuild = ({ cache, cacheKey, command }) => {
12
12
  if (cache[cacheKey] === undefined) {
13
13
  cache[cacheKey] = {
14
14
  // eslint-disable-next-line promise/prefer-await-to-then
@@ -29,5 +29,3 @@ const memoizedBuild = ({ cache, cacheKey, command }) => {
29
29
 
30
30
  return cache[cacheKey].task
31
31
  }
32
-
33
- module.exports = { memoizedBuild }
@@ -1,9 +1,8 @@
1
1
  // @ts-check
2
- const CronParser = require('cron-parser')
2
+ import CronParser from 'cron-parser'
3
3
 
4
- const { error: errorExit } = require('../../utils/command-helpers.cjs')
5
-
6
- const BACKGROUND_SUFFIX = '-background'
4
+ import { error as errorExit } from '../../utils/command-helpers.mjs'
5
+ import { BACKGROUND } from '../../utils/functions/get-functions.mjs'
7
6
 
8
7
  // Returns a new set with all elements of `setA` that don't exist in `setB`.
9
8
  const difference = (setA, setB) => new Set([...setA].filter((item) => !setB.has(item)))
@@ -15,7 +14,7 @@ const getNextRun = function (schedule) {
15
14
  return cron.next().toDate()
16
15
  }
17
16
 
18
- class NetlifyFunction {
17
+ export default class NetlifyFunction {
19
18
  constructor({
20
19
  config,
21
20
  directory,
@@ -40,7 +39,7 @@ class NetlifyFunction {
40
39
 
41
40
  // Determines whether this is a background function based on the function
42
41
  // name.
43
- this.isBackground = name.endsWith(BACKGROUND_SUFFIX)
42
+ this.isBackground = name.endsWith(BACKGROUND)
44
43
 
45
44
  const functionConfig = config.functions && config.functions[name]
46
45
  this.schedule = functionConfig && functionConfig.schedule
@@ -143,5 +142,3 @@ class NetlifyFunction {
143
142
  return url.href
144
143
  }
145
144
  }
146
-
147
- module.exports = { NetlifyFunction }