netlify-cli 12.2.10 → 12.3.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 (139) hide show
  1. package/npm-shrinkwrap.json +315 -1191
  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 +14 -17
  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} +19 -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,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 }
@@ -1,26 +1,26 @@
1
1
  // @ts-check
2
- const { mkdir } = require('fs').promises
3
- const { extname, isAbsolute, join } = require('path')
4
- const { env } = require('process')
2
+ import { mkdir } from 'fs/promises'
3
+ import { extname, isAbsolute, join } from 'path'
4
+ import { env } from 'process'
5
5
 
6
- const {
7
- NETLIFYDEVERR,
8
- NETLIFYDEVLOG,
9
- NETLIFYDEVWARN,
6
+ import {
10
7
  chalk,
11
8
  getTerminalLink,
12
9
  log,
10
+ NETLIFYDEVERR,
11
+ NETLIFYDEVLOG,
12
+ NETLIFYDEVWARN,
13
13
  warn,
14
14
  watchDebounced,
15
- } = require('../../utils/index.cjs')
16
- const { getLogMessage } = require('../log.cjs')
15
+ } from '../../utils/command-helpers.mjs'
16
+ import { getLogMessage } from '../log.mjs'
17
17
 
18
- const { NetlifyFunction } = require('./netlify-function.cjs')
19
- const runtimes = require('./runtimes/index.cjs')
18
+ import NetlifyFunction from './netlify-function.mjs'
19
+ import runtimes from './runtimes/index.mjs'
20
20
 
21
21
  const ZIP_EXTENSION = '.zip'
22
22
 
23
- class FunctionsRegistry {
23
+ export class FunctionsRegistry {
24
24
  constructor({ capabilities, config, isConnected = false, projectRoot, settings, timeouts }) {
25
25
  this.capabilities = capabilities
26
26
  this.config = config
@@ -262,5 +262,3 @@ class FunctionsRegistry {
262
262
  }
263
263
  }
264
264
  }
265
-
266
- module.exports = { FunctionsRegistry }
@@ -1,13 +1,15 @@
1
1
  // @ts-check
2
- const { dirname, extname } = require('path')
3
- const { platform } = require('process')
2
+ import { dirname, extname } from 'path'
3
+ import { platform } from 'process'
4
4
 
5
- const tempy = require('tempy')
5
+ import tempy from 'tempy'
6
+
7
+ import execa from '../../../../utils/execa.mjs'
8
+ import { runFunctionsProxy } from '../../local-proxy.mjs'
6
9
 
7
10
  const isWindows = platform === 'win32'
8
11
 
9
- const { execa } = require('../../../../utils/index.cjs')
10
- const { runFunctionsProxy } = require('../../local-proxy.cjs')
12
+ export const name = 'go'
11
13
 
12
14
  const build = async ({ binaryPath, functionDirectory }) => {
13
15
  try {
@@ -37,14 +39,14 @@ const checkGoInstallation = async ({ cwd }) => {
37
39
  }
38
40
  }
39
41
 
40
- const getBuildFunction = ({ func }) => {
42
+ export const getBuildFunction = ({ func }) => {
41
43
  const functionDirectory = dirname(func.mainFile)
42
44
  const binaryPath = tempy.file(isWindows ? { extension: 'exe' } : undefined)
43
45
 
44
46
  return () => build({ binaryPath, functionDirectory })
45
47
  }
46
48
 
47
- const invokeFunction = async ({ context, event, func, timeout }) => {
49
+ export const invokeFunction = async ({ context, event, func, timeout }) => {
48
50
  const { stdout } = await runFunctionsProxy({
49
51
  binaryPath: func.buildData.binaryPath,
50
52
  context,
@@ -70,10 +72,8 @@ const invokeFunction = async ({ context, event, func, timeout }) => {
70
72
  }
71
73
  }
72
74
 
73
- const onRegister = (func) => {
75
+ export const onRegister = (func) => {
74
76
  const isSource = extname(func.mainFile) === '.go'
75
77
 
76
78
  return isSource ? func : null
77
79
  }
78
-
79
- module.exports = { getBuildFunction, invokeFunction, name: 'go', onRegister }
@@ -1,11 +1,12 @@
1
- const go = require('./go/index.cjs')
2
- const js = require('./js/index.cjs')
3
- const rust = require('./rust/index.cjs')
4
-
1
+ /* eslint-disable import/no-namespace */
2
+ import * as go from './go/index.mjs'
3
+ import * as js from './js/index.mjs'
4
+ import * as rust from './rust/index.mjs'
5
+ /* eslint-enable import/no-namespace */
5
6
  /**
6
7
  * @callback BuildFunction
7
8
  * @param {object} func
8
- * @returns {Promise<{srcFiles: string[], buildPath?: string>}
9
+ * @returns {Promise<{srcFiles: string[], buildPath?: string}>}
9
10
  */
10
11
 
11
12
  /**
@@ -41,6 +42,10 @@ const rust = require('./rust/index.cjs')
41
42
  * @property {string} name
42
43
  */
43
44
 
44
- const runtimes = [js, go, rust].reduce((res, runtime) => ({ ...res, [runtime.name]: runtime }), {})
45
+ const runtimes = {
46
+ [go.name]: go,
47
+ [js.name]: js,
48
+ [rust.name]: rust,
49
+ }
45
50
 
46
- module.exports = runtimes
51
+ export default runtimes
@@ -1,14 +1,14 @@
1
1
  // @ts-check
2
- const { readFile } = require('fs').promises
3
- const { resolve } = require('path')
2
+ import { readFile } from 'fs/promises'
3
+ import { resolve } from 'path'
4
4
 
5
- const minimist = require('minimist')
5
+ import minimist from 'minimist'
6
6
 
7
- const { execa } = require('../../../../../utils/index.cjs')
8
- const { fileExistsAsync } = require('../../../../fs.cjs')
9
- const { memoizedBuild } = require('../../../memoized-build.cjs')
7
+ import execa from '../../../../../utils/execa.mjs'
8
+ import { fileExistsAsync } from '../../../../fs.cjs'
9
+ import { memoizedBuild } from '../../../memoized-build.mjs'
10
10
 
11
- const detectNetlifyLambda = async function ({ packageJson } = {}) {
11
+ export const detectNetlifyLambda = async function ({ packageJson } = {}) {
12
12
  const { dependencies, devDependencies, scripts } = packageJson || {}
13
13
  if (!((dependencies && dependencies['netlify-lambda']) || (devDependencies && devDependencies['netlify-lambda']))) {
14
14
  return false
@@ -19,7 +19,11 @@ const detectNetlifyLambda = async function ({ packageJson } = {}) {
19
19
  // eslint-disable-next-line fp/no-loops
20
20
  for (const [key, script] of matchingScripts) {
21
21
  // E.g. ["netlify-lambda", "build", "functions/folder"]
22
- const match = minimist(script.split(' '))
22
+ const match = minimist(script.split(' '), {
23
+ // these are all valid options for netlify-lambda
24
+ boolean: ['s', 'static'],
25
+ string: ['c', 'config', 'p', 'port', 'b', 'babelrc', 't', 'timeout'],
26
+ })
23
27
  // We are not interested in 'netlify-lambda' and 'build' commands
24
28
  const functionDirectories = match._.slice(2)
25
29
  if (functionDirectories.length === 1) {
@@ -54,7 +58,7 @@ const detectNetlifyLambda = async function ({ packageJson } = {}) {
54
58
  return false
55
59
  }
56
60
 
57
- module.exports = async function handler() {
61
+ export default async function handler() {
58
62
  const exists = await fileExistsAsync('package.json')
59
63
  if (!exists) {
60
64
  return false
@@ -64,4 +68,3 @@ module.exports = async function handler() {
64
68
  const packageJson = JSON.parse(content)
65
69
  return detectNetlifyLambda({ packageJson })
66
70
  }
67
- module.exports.detectNetlifyLambda = detectNetlifyLambda
@@ -1,14 +1,17 @@
1
- const { mkdir, writeFile } = require('fs').promises
2
- const path = require('path')
1
+ import { mkdir, writeFile } from 'fs/promises'
2
+ import { createRequire } from 'module'
3
+ import path from 'path'
3
4
 
4
- const decache = require('decache')
5
- const readPkgUp = require('read-pkg-up')
6
- const sourceMapSupport = require('source-map-support')
5
+ import decache from 'decache'
6
+ import readPkgUp from 'read-pkg-up'
7
+ import sourceMapSupport from 'source-map-support'
7
8
 
8
- const { NETLIFYDEVERR } = require('../../../../../utils/index.cjs')
9
- const { getPathInProject } = require('../../../../settings.cjs')
10
- const { normalizeFunctionsConfig } = require('../../../config.cjs')
11
- const { memoizedBuild } = require('../../../memoized-build.cjs')
9
+ import { NETLIFYDEVERR } from '../../../../../utils/command-helpers.mjs'
10
+ import { getPathInProject } from '../../../../settings.cjs'
11
+ import { normalizeFunctionsConfig } from '../../../config.mjs'
12
+ import { memoizedBuild } from '../../../memoized-build.mjs'
13
+
14
+ const require = createRequire(import.meta.url)
12
15
 
13
16
  const addFunctionsConfigDefaults = (config) => ({
14
17
  ...config,
@@ -26,6 +29,7 @@ const buildFunction = async ({ cache, config, directory, func, hasTypeModule, pr
26
29
  }
27
30
  const functionDirectory = path.dirname(func.mainFile)
28
31
 
32
+ // performance
29
33
  const { zipFunction } = await import('@netlify/zip-it-and-ship-it')
30
34
 
31
35
  // If we have a function at `functions/my-func/index.js` and we pass
@@ -71,7 +75,7 @@ const buildFunction = async ({ cache, config, directory, func, hasTypeModule, pr
71
75
  * @param {string} params.mainFile
72
76
  * @param {string} params.projectRoot
73
77
  */
74
- const parseForSchedule = async ({ config, mainFile, projectRoot }) => {
78
+ export const parseForSchedule = async ({ config, mainFile, projectRoot }) => {
75
79
  const { listFunction } = await import('@netlify/zip-it-and-ship-it')
76
80
  const listedFunction = await listFunction(mainFile, {
77
81
  config: netlifyConfigToZisiConfig({ config, projectRoot }),
@@ -104,7 +108,7 @@ const getTargetDirectory = async ({ errorExit }) => {
104
108
  const netlifyConfigToZisiConfig = ({ config, projectRoot }) =>
105
109
  addFunctionsConfigDefaults(normalizeFunctionsConfig({ functionsConfig: config.functions, projectRoot }))
106
110
 
107
- module.exports = async ({ config, directory, errorExit, func, projectRoot }) => {
111
+ export default async function handler({ config, directory, errorExit, func, projectRoot }) {
108
112
  const functionsConfig = netlifyConfigToZisiConfig({ config, projectRoot })
109
113
 
110
114
  const packageJson = await readPkgUp(func.mainFile)
@@ -138,5 +142,3 @@ module.exports = async ({ config, directory, errorExit, func, projectRoot }) =>
138
142
  target: targetDirectory,
139
143
  }
140
144
  }
141
-
142
- module.exports.parseForSchedule = parseForSchedule
@@ -1,12 +1,14 @@
1
- const { dirname } = require('path')
1
+ import { dirname } from 'path'
2
2
 
3
- const lambdaLocal = require('lambda-local')
4
- const winston = require('winston')
3
+ import lambdaLocal from 'lambda-local'
4
+ import winston from 'winston'
5
5
 
6
- const detectNetlifyLambdaBuilder = require('./builders/netlify-lambda.cjs')
7
- const detectZisiBuilder = require('./builders/zisi.cjs')
6
+ import detectNetlifyLambdaBuilder from './builders/netlify-lambda.mjs'
7
+ import detectZisiBuilder, { parseForSchedule } from './builders/zisi.mjs'
8
8
 
9
- const SECONDS_TO_MILLISECONDS = 1e3
9
+ export const name = 'js'
10
+
11
+ const SECONDS_TO_MILLISECONDS = 1000
10
12
 
11
13
  let netlifyLambdaDetectorCache
12
14
 
@@ -28,7 +30,7 @@ const detectNetlifyLambdaWithCache = () => {
28
30
  return netlifyLambdaDetectorCache
29
31
  }
30
32
 
31
- const getBuildFunction = async ({ config, directory, errorExit, func, projectRoot }) => {
33
+ export const getBuildFunction = async ({ config, directory, errorExit, func, projectRoot }) => {
32
34
  const netlifyLambdaBuilder = await detectNetlifyLambdaWithCache()
33
35
 
34
36
  if (netlifyLambdaBuilder) {
@@ -46,12 +48,12 @@ const getBuildFunction = async ({ config, directory, errorExit, func, projectRoo
46
48
  // main file otherwise.
47
49
  const functionDirectory = dirname(func.mainFile)
48
50
  const srcFiles = functionDirectory === directory ? [func.mainFile] : [functionDirectory]
49
- const schedule = await detectZisiBuilder.parseForSchedule({ mainFile: func.mainFile, config, projectRoot })
51
+ const schedule = await parseForSchedule({ mainFile: func.mainFile, config, projectRoot })
50
52
 
51
53
  return () => ({ schedule, srcFiles })
52
54
  }
53
55
 
54
- const invokeFunction = async ({ context, event, func, timeout }) => {
56
+ export const invokeFunction = async ({ context, event, func, timeout }) => {
55
57
  // If a function builder has defined a `buildPath` property, we use it.
56
58
  // Otherwise, we'll invoke the function's main file.
57
59
  const lambdaPath = (func.buildData && func.buildData.buildPath) || func.mainFile
@@ -66,7 +68,7 @@ const invokeFunction = async ({ context, event, func, timeout }) => {
66
68
  return result
67
69
  }
68
70
 
69
- const onDirectoryScan = async () => {
71
+ export const onDirectoryScan = async () => {
70
72
  const netlifyLambdaBuilder = await detectNetlifyLambdaWithCache()
71
73
 
72
74
  // Before we start a directory scan, we check whether netlify-lambda is being
@@ -76,5 +78,3 @@ const onDirectoryScan = async () => {
76
78
  await netlifyLambdaBuilder.build()
77
79
  }
78
80
  }
79
-
80
- module.exports = { getBuildFunction, invokeFunction, name: 'js', onDirectoryScan }
@@ -1,16 +1,18 @@
1
1
  // @ts-check
2
- const { readFile } = require('fs').promises
3
- const { dirname, extname, join, resolve } = require('path')
4
- const { platform } = require('process')
2
+ import { readFile } from 'fs/promises'
3
+ import { dirname, extname, join, resolve } from 'path'
4
+ import { platform } from 'process'
5
5
 
6
- const findUp = require('find-up')
7
- const toml = require('toml')
6
+ import findUp from 'find-up'
7
+ import toml from 'toml'
8
+
9
+ import execa from '../../../../utils/execa.mjs'
10
+ import { getPathInProject } from '../../../settings.cjs'
11
+ import { runFunctionsProxy } from '../../local-proxy.mjs'
8
12
 
9
13
  const isWindows = platform === 'win32'
10
14
 
11
- const { execa } = require('../../../../utils/index.cjs')
12
- const { getPathInProject } = require('../../../settings.cjs')
13
- const { runFunctionsProxy } = require('../../local-proxy.cjs')
15
+ export const name = 'rs'
14
16
 
15
17
  const build = async ({ func }) => {
16
18
  const functionDirectory = dirname(func.mainFile)
@@ -30,7 +32,7 @@ const build = async ({ func }) => {
30
32
  }
31
33
  }
32
34
 
33
- const getBuildFunction =
35
+ export const getBuildFunction =
34
36
  ({ func }) =>
35
37
  () =>
36
38
  build({ func })
@@ -38,12 +40,12 @@ const getBuildFunction =
38
40
  const getCrateName = async (cwd) => {
39
41
  const manifestPath = await findUp('Cargo.toml', { cwd, type: 'file' })
40
42
  const manifest = await readFile(manifestPath, 'utf-8')
41
- const { package } = toml.parse(manifest)
43
+ const { package: CargoPackage } = toml.parse(manifest)
42
44
 
43
- return package.name
45
+ return CargoPackage.name
44
46
  }
45
47
 
46
- const invokeFunction = async ({ context, event, func, timeout }) => {
48
+ export const invokeFunction = async ({ context, event, func, timeout }) => {
47
49
  const { stdout } = await runFunctionsProxy({
48
50
  binaryPath: func.buildData.binaryPath,
49
51
  context,
@@ -69,10 +71,8 @@ const invokeFunction = async ({ context, event, func, timeout }) => {
69
71
  }
70
72
  }
71
73
 
72
- const onRegister = (func) => {
74
+ export const onRegister = (func) => {
73
75
  const isSource = extname(func.mainFile) === '.rs'
74
76
 
75
77
  return isSource ? func : null
76
78
  }
77
-
78
- module.exports = { getBuildFunction, invokeFunction, name: 'rs', onRegister }
@@ -2,7 +2,7 @@ import AnsiToHtml from 'ansi-to-html'
2
2
 
3
3
  import { CLOCKWORK_USERAGENT } from '../../utils/functions/index.mjs'
4
4
 
5
- import { formatLambdaError } from './utils.cjs'
5
+ import { formatLambdaError } from './utils.mjs'
6
6
 
7
7
  const ansiToHtml = new AnsiToHtml()
8
8
 
@@ -2,17 +2,16 @@
2
2
  import { get } from 'dot-prop'
3
3
  import jwtDecode from 'jwt-decode'
4
4
 
5
+ import { NETLIFYDEVERR, NETLIFYDEVLOG, error as errorExit, log } from '../../utils/command-helpers.mjs'
6
+ import { generateNetlifyGraphJWT } from '../../utils/dev.mjs'
5
7
  import { CLOCKWORK_USERAGENT, getInternalFunctionsDir } from '../../utils/functions/index.mjs'
6
- import utils from '../../utils/index.cjs'
7
8
 
8
- import { handleBackgroundFunction, handleBackgroundFunctionResult } from './background.cjs'
9
+ import { handleBackgroundFunction, handleBackgroundFunctionResult } from './background.mjs'
9
10
  import { createFormSubmissionHandler } from './form-submissions-handler.mjs'
10
- import { FunctionsRegistry } from './registry.cjs'
11
+ import { FunctionsRegistry } from './registry.mjs'
11
12
  import { handleScheduledFunction } from './scheduled.mjs'
12
- import { handleSynchronousFunction } from './synchronous.cjs'
13
- import { shouldBase64Encode } from './utils.cjs'
14
-
15
- const { NETLIFYDEVERR, NETLIFYDEVLOG, error: errorExit, generateNetlifyGraphJWT, log } = utils
13
+ import { handleSynchronousFunction } from './synchronous.mjs'
14
+ import { shouldBase64Encode } from './utils.mjs'
16
15
 
17
16
  const buildClientContext = function (headers) {
18
17
  // inject a client context based on auth header, ported over from netlify-lambda (https://github.com/netlify/netlify-lambda/pull/57)
@@ -1,10 +1,10 @@
1
1
  // @ts-check
2
- const { Buffer } = require('buffer')
2
+ import { Buffer } from 'buffer'
3
3
 
4
- const { NETLIFYDEVERR } = require('../../utils/index.cjs')
5
- const renderErrorTemplate = require('../render-error-remplate.cjs')
4
+ import { NETLIFYDEVERR } from '../../utils/command-helpers.mjs'
5
+ import renderErrorTemplate from '../render-error-template.mjs'
6
6
 
7
- const { detectAwsSdkError } = require('./utils.cjs')
7
+ import { detectAwsSdkError } from './utils.mjs'
8
8
 
9
9
  const addHeaders = (headers, response) => {
10
10
  if (!headers) {
@@ -16,7 +16,7 @@ const addHeaders = (headers, response) => {
16
16
  })
17
17
  }
18
18
 
19
- const handleSynchronousFunction = function (err, result, request, response) {
19
+ export const handleSynchronousFunction = function (err, result, request, response) {
20
20
  if (err) {
21
21
  return handleErr(err, request, response)
22
22
  }
@@ -82,5 +82,3 @@ const validateLambdaResponse = (lambdaResponse) => {
82
82
 
83
83
  return {}
84
84
  }
85
-
86
- module.exports = { handleSynchronousFunction }
@@ -1,14 +1,8 @@
1
1
  // @ts-check
2
- const { chalk, warn } = require('../../utils/index.cjs')
3
- const { getLogMessage } = require('../log.cjs')
2
+ import { chalk, warn } from '../../utils/command-helpers.mjs'
3
+ import { getLogMessage } from '../log.mjs'
4
4
 
5
- const DEFAULT_LAMBDA_OPTIONS = {
6
- verboseLevel: 3,
7
- }
8
-
9
- const SECONDS_TO_MILLISECONDS = 1000
10
-
11
- const detectAwsSdkError = ({ error }) => {
5
+ export const detectAwsSdkError = ({ error }) => {
12
6
  const isAwsSdkError = error && error.errorMessage && error.errorMessage.includes("Cannot find module 'aws-sdk'")
13
7
 
14
8
  if (isAwsSdkError) {
@@ -16,7 +10,7 @@ const detectAwsSdkError = ({ error }) => {
16
10
  }
17
11
  }
18
12
 
19
- const formatLambdaError = (err) => chalk.red(`${err.errorType}: ${err.errorMessage}`)
13
+ export const formatLambdaError = (err) => chalk.red(`${err.errorType}: ${err.errorMessage}`)
20
14
 
21
15
  // should be equivalent to https://github.com/netlify/proxy/blob/main/pkg/functions/request.go#L105
22
16
  const exceptionsList = new Set([
@@ -33,7 +27,7 @@ const exceptionsList = new Set([
33
27
  * @param {string | undefined} contentType
34
28
  * @returns {boolean}
35
29
  */
36
- const shouldBase64Encode = function (contentType) {
30
+ export const shouldBase64Encode = function (contentType) {
37
31
  if (!contentType) {
38
32
  return true
39
33
  }
@@ -57,13 +51,4 @@ const shouldBase64Encode = function (contentType) {
57
51
  return true
58
52
  }
59
53
 
60
- const styleFunctionName = (name) => chalk.magenta(name)
61
-
62
- module.exports = {
63
- detectAwsSdkError,
64
- DEFAULT_LAMBDA_OPTIONS,
65
- formatLambdaError,
66
- SECONDS_TO_MILLISECONDS,
67
- shouldBase64Encode,
68
- styleFunctionName,
69
- }
54
+ export const styleFunctionName = (name) => chalk.magenta(name)
@@ -1,5 +1,5 @@
1
1
  // @ts-check
2
- const fetch = require('node-fetch')
2
+ import fetch from 'node-fetch'
3
3
 
4
4
  const API_URL = 'https://netlifind.netlify.app'
5
5
  const STATE_GEO_PROPERTY = 'geolocation'
@@ -24,7 +24,7 @@ const REQUEST_TIMEOUT = 1e4
24
24
  * @property {string} timezone
25
25
  */
26
26
 
27
- const mockLocation = {
27
+ export const mockLocation = {
28
28
  city: 'San Francisco',
29
29
  country: { code: 'US', name: 'United States' },
30
30
  subdivision: { code: 'CA', name: 'California' },
@@ -44,7 +44,7 @@ const mockLocation = {
44
44
  * @param {import('../utils/state-config.mjs').default} params.state
45
45
  * @returns {Promise<GeoLocation>}
46
46
  */
47
- const getGeoLocation = async ({ geoCountry, mode, offline, state }) => {
47
+ export const getGeoLocation = async ({ geoCountry, mode, offline, state }) => {
48
48
  const cacheObject = state.get(STATE_GEO_PROPERTY)
49
49
 
50
50
  // If `--country` was used, we also set `--mode=mock`.
@@ -117,5 +117,3 @@ const getGeoLocationFromAPI = async () => {
117
117
 
118
118
  return geo
119
119
  }
120
-
121
- module.exports = { getGeoLocation, mockLocation }
@@ -4,7 +4,7 @@ import { readFile } from 'fs/promises'
4
4
  import HttpsProxyAgent from 'https-proxy-agent'
5
5
  import waitPort from 'wait-port'
6
6
 
7
- import { NETLIFYDEVERR, NETLIFYDEVWARN, exit, log } from '../utils/command-helpers.cjs'
7
+ import { NETLIFYDEVERR, NETLIFYDEVWARN, exit, log } from '../utils/command-helpers.mjs'
8
8
 
9
9
  // https://github.com/TooTallNate/node-https-proxy-agent/issues/89
10
10
  // Maybe replace with https://github.com/delvedor/hpagent
@@ -1,6 +1,6 @@
1
- const dotProp = require('dot-prop')
1
+ import dotProp from 'dot-prop'
2
2
 
3
- const { chalk } = require('../utils/index.cjs')
3
+ import { chalk } from '../utils/command-helpers.mjs'
4
4
 
5
5
  const RED_BACKGROUND = chalk.red('-background')
6
6
  const [PRO, BUSINESS, ENTERPRISE] = ['Pro', 'Business', 'Enterprise'].map((plan) => chalk.magenta(plan))
@@ -24,8 +24,4 @@ const messages = {
24
24
  },
25
25
  }
26
26
 
27
- const getLogMessage = (key) => dotProp.get(messages, key, 'Missing Log Message Key')
28
-
29
- module.exports = {
30
- getLogMessage,
31
- }
27
+ export const getLogMessage = (key) => dotProp.get(messages, key, 'Missing Log Message Key')
@@ -13,8 +13,9 @@ import gitRepoInfo from 'git-repo-info'
13
13
  import WSL from 'is-wsl'
14
14
  import { GraphQL, InternalConsole, NetlifyGraph, NetlifyGraphLockfile, OneGraphClient } from 'netlify-onegraph-internal'
15
15
 
16
+ import { chalk, error, log, warn, watchDebounced } from '../../utils/command-helpers.mjs'
17
+ import execa from '../../utils/execa.mjs'
16
18
  import getPackageJson from '../../utils/get-package-json.mjs'
17
- import utils from '../../utils/index.cjs'
18
19
 
19
20
  import {
20
21
  generateFunctionsFile,
@@ -28,7 +29,6 @@ import {
28
29
  writeGraphQLSchemaFile,
29
30
  } from './cli-netlify-graph.mjs'
30
31
 
31
- const { chalk, error, execa, log, warn, watchDebounced } = utils
32
32
  const { parse } = GraphQL
33
33
  const { defaultExampleOperationsDoc, extractFunctionsFromOperationDoc } = NetlifyGraph
34
34
 
@@ -10,11 +10,10 @@ import inquirer from 'inquirer'
10
10
  import inquirerAutocompletePrompt from 'inquirer-autocomplete-prompt'
11
11
  import { GraphQL, GraphQLHelpers, IncludedCodegen, InternalConsole, NetlifyGraph } from 'netlify-onegraph-internal'
12
12
 
13
+ import { chalk, error, log, warn } from '../../utils/command-helpers.mjs'
13
14
  import detectServerSettings from '../../utils/detect-server-settings.mjs'
15
+ import execa from '../../utils/execa.mjs'
14
16
  import { getFunctionsDir } from '../../utils/functions/index.mjs'
15
- import utils from '../../utils/index.cjs'
16
-
17
- const { chalk, error, execa, log, warn } = utils
18
17
 
19
18
  const { printSchema } = GraphQL
20
19
 
@@ -0,0 +1 @@
1
+ export const normalizeBackslash = (path) => path.replace(/\\/g, '/')
@@ -1,17 +1,21 @@
1
- const { readFile } = require('fs').promises
2
- const { join } = require('path')
1
+ import { readFile } from 'fs/promises'
2
+ import { dirname, join } from 'path'
3
+ import { fileURLToPath } from 'url'
3
4
 
4
5
  let errorTemplateFile
6
+ const dir = dirname(fileURLToPath(import.meta.url))
5
7
 
6
8
  const renderErrorTemplate = async (errString, templatePath, functionType) => {
7
9
  const errorDetailsRegex = /<!--@ERROR-DETAILS-->/g
8
10
  const functionTypeRegex = /<!--@FUNCTION-TYPE-->/g
11
+
9
12
  try {
10
- errorTemplateFile = errorTemplateFile || (await readFile(join(__dirname, templatePath), 'utf-8'))
13
+ errorTemplateFile = errorTemplateFile || (await readFile(join(dir, templatePath), 'utf-8'))
14
+
11
15
  return errorTemplateFile.replace(errorDetailsRegex, errString).replace(functionTypeRegex, functionType)
12
16
  } catch {
13
17
  return errString
14
18
  }
15
19
  }
16
20
 
17
- module.exports = renderErrorTemplate
21
+ export default renderErrorTemplate
@@ -1,5 +1,3 @@
1
- const capitalize = function (t) {
1
+ export const capitalize = function (t) {
2
2
  return t.replace(/(^\w|\s\w)/g, (string) => string.toUpperCase())
3
3
  }
4
-
5
- module.exports = { capitalize }
@@ -3,7 +3,7 @@ import { join } from 'path'
3
3
  import execa from 'execa'
4
4
  import inquirer from 'inquirer'
5
5
 
6
- import { NETLIFYDEVLOG, NETLIFYDEVWARN, chalk, error, log } from '../../utils/command-helpers.cjs'
6
+ import { NETLIFYDEVLOG, NETLIFYDEVWARN, chalk, error, log } from '../../utils/command-helpers.mjs'
7
7
 
8
8
  import { applySettings, getSettings, writeSettings } from './settings.mjs'
9
9