netlify-cli 8.1.3 → 8.1.4

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 (191) hide show
  1. package/README.md +12 -13
  2. package/bin/run +38 -2
  3. package/npm-shrinkwrap.json +1052 -7693
  4. package/package.json +12 -36
  5. package/scripts/postinstall.js +13 -0
  6. package/src/commands/addons/addons-auth.js +50 -0
  7. package/src/commands/addons/addons-config.js +180 -0
  8. package/src/commands/addons/addons-create.js +131 -0
  9. package/src/commands/addons/addons-delete.js +60 -0
  10. package/src/commands/addons/addons-list.js +62 -0
  11. package/src/commands/addons/addons.js +44 -0
  12. package/src/commands/addons/index.js +3 -24
  13. package/src/commands/api/api.js +75 -0
  14. package/src/commands/api/index.js +5 -0
  15. package/src/commands/base-command.js +502 -0
  16. package/src/commands/build/build.js +58 -0
  17. package/src/commands/build/index.js +3 -61
  18. package/src/commands/completion/completion.js +56 -0
  19. package/src/commands/completion/index.js +5 -0
  20. package/src/commands/{deploy.js → deploy/deploy.js} +295 -275
  21. package/src/commands/deploy/index.js +5 -0
  22. package/src/commands/dev/dev-exec.js +35 -0
  23. package/src/commands/dev/dev-trace.js +47 -0
  24. package/src/commands/dev/dev.js +340 -0
  25. package/src/commands/dev/index.js +3 -335
  26. package/src/commands/env/env-get.js +51 -0
  27. package/src/commands/env/env-import.js +93 -0
  28. package/src/commands/env/env-list.js +63 -0
  29. package/src/commands/env/env-set.js +67 -0
  30. package/src/commands/env/env-unset.js +66 -0
  31. package/src/commands/env/env.js +42 -0
  32. package/src/commands/env/index.js +3 -23
  33. package/src/commands/functions/functions-build.js +59 -0
  34. package/src/commands/functions/{create.js → functions-create.js} +130 -94
  35. package/src/commands/functions/functions-invoke.js +273 -0
  36. package/src/commands/functions/functions-list.js +106 -0
  37. package/src/commands/functions/functions-serve.js +63 -0
  38. package/src/commands/functions/functions.js +47 -0
  39. package/src/commands/functions/index.js +3 -45
  40. package/src/commands/index.js +7 -0
  41. package/src/commands/init/index.js +6 -0
  42. package/src/commands/{init.js → init/init.js} +79 -68
  43. package/src/commands/link/index.js +6 -0
  44. package/src/{utils/link/link-by-prompt.js → commands/link/link.js} +141 -14
  45. package/src/commands/lm/index.js +3 -19
  46. package/src/commands/lm/lm-info.js +42 -0
  47. package/src/commands/lm/lm-install.js +33 -0
  48. package/src/commands/lm/lm-setup.js +106 -0
  49. package/src/commands/lm/lm-uninstall.js +25 -0
  50. package/src/commands/lm/lm.js +34 -0
  51. package/src/commands/login/index.js +6 -0
  52. package/src/commands/login/login.js +55 -0
  53. package/src/commands/logout/index.js +5 -0
  54. package/src/commands/logout/logout.js +43 -0
  55. package/src/commands/main.js +206 -0
  56. package/src/commands/open/index.js +3 -39
  57. package/src/commands/open/open-admin.js +60 -0
  58. package/src/commands/open/open-site.js +53 -0
  59. package/src/commands/open/open.js +40 -0
  60. package/src/commands/sites/index.js +5 -20
  61. package/src/commands/sites/sites-create.js +187 -0
  62. package/src/commands/sites/sites-delete.js +104 -0
  63. package/src/commands/sites/sites-list.js +90 -0
  64. package/src/commands/sites/sites.js +32 -0
  65. package/src/commands/status/index.js +3 -118
  66. package/src/commands/status/status-hooks.js +69 -0
  67. package/src/commands/status/status.js +124 -0
  68. package/src/commands/switch/index.js +5 -0
  69. package/src/commands/switch/switch.js +50 -0
  70. package/src/commands/unlink/index.js +5 -0
  71. package/src/commands/unlink/unlink.js +48 -0
  72. package/src/commands/watch/index.js +5 -0
  73. package/src/commands/watch/watch.js +131 -0
  74. package/src/functions-templates/javascript/stripe-charge/package-lock.json +6 -6
  75. package/src/functions-templates/javascript/stripe-subscription/package-lock.json +6 -6
  76. package/src/lib/build.js +21 -7
  77. package/src/lib/completion/constants.js +6 -0
  78. package/src/lib/completion/generate-autocompletion.js +36 -0
  79. package/src/lib/completion/index.js +5 -0
  80. package/src/lib/completion/script.js +72 -0
  81. package/src/lib/exec-fetcher.js +5 -3
  82. package/src/lib/fs.js +54 -36
  83. package/src/lib/functions/background.js +1 -1
  84. package/src/lib/functions/form-submissions-handler.js +2 -1
  85. package/src/lib/functions/local-proxy.js +2 -1
  86. package/src/lib/functions/netlify-function.js +4 -1
  87. package/src/lib/functions/registry.js +4 -6
  88. package/src/lib/functions/runtimes/go/index.js +2 -1
  89. package/src/lib/functions/runtimes/js/builders/netlify-lambda.js +6 -4
  90. package/src/lib/functions/runtimes/js/builders/zisi.js +3 -3
  91. package/src/lib/functions/runtimes/rust/index.js +4 -3
  92. package/src/lib/functions/server.js +2 -3
  93. package/src/lib/functions/synchronous.js +2 -1
  94. package/src/lib/functions/utils.js +2 -3
  95. package/src/lib/functions/watcher.js +1 -0
  96. package/src/lib/http-agent.js +5 -5
  97. package/src/lib/log.js +2 -1
  98. package/src/lib/settings.js +16 -1
  99. package/src/lib/spinner.js +22 -0
  100. package/src/utils/addons/diffs/index.js +1 -0
  101. package/src/utils/addons/diffs/options.js +3 -1
  102. package/src/utils/addons/prepare.js +13 -6
  103. package/src/utils/addons/prompts.js +2 -1
  104. package/src/utils/addons/render.js +3 -1
  105. package/src/utils/command-helpers.js +136 -42
  106. package/src/utils/create-stream-promise.js +5 -5
  107. package/src/utils/deferred.js +1 -0
  108. package/src/utils/deploy/deploy-site.js +1 -1
  109. package/src/utils/deploy/index.js +4 -0
  110. package/src/utils/detect-server-settings.js +10 -12
  111. package/src/utils/dev.js +18 -10
  112. package/src/utils/dot-env.js +4 -2
  113. package/src/utils/{edge-handlers.js → functions/edge-handlers.js} +8 -7
  114. package/src/utils/functions/functions.js +36 -0
  115. package/src/utils/{get-functions.js → functions/get-functions.js} +2 -1
  116. package/src/utils/functions/index.js +8 -26
  117. package/src/utils/get-global-config.js +3 -2
  118. package/src/utils/get-repo-data.js +8 -1
  119. package/src/utils/gh-auth.js +1 -0
  120. package/src/utils/gitignore.js +7 -5
  121. package/src/utils/headers.js +1 -2
  122. package/src/utils/index.js +42 -0
  123. package/src/utils/init/config-github.js +12 -5
  124. package/src/utils/init/config-manual.js +9 -2
  125. package/src/utils/init/config.js +13 -7
  126. package/src/utils/init/frameworks.js +1 -0
  127. package/src/utils/init/node-version.js +4 -2
  128. package/src/utils/init/utils.js +10 -6
  129. package/src/utils/live-tunnel.js +3 -4
  130. package/src/utils/lm/install.js +10 -15
  131. package/src/utils/lm/requirements.js +3 -1
  132. package/src/utils/lm/steps.js +1 -1
  133. package/src/utils/lm/ui.js +7 -3
  134. package/src/utils/open-browser.js +8 -2
  135. package/src/utils/parse-raw-flags.js +4 -4
  136. package/src/utils/proxy.js +6 -5
  137. package/src/utils/read-repo-url.js +1 -0
  138. package/src/utils/redirects.js +2 -2
  139. package/src/utils/rules-proxy.js +2 -1
  140. package/src/utils/state-config.js +1 -1
  141. package/src/utils/telemetry/index.js +2 -113
  142. package/src/utils/telemetry/request.js +3 -1
  143. package/src/utils/telemetry/telemetry.js +117 -0
  144. package/src/utils/telemetry/validation.js +13 -12
  145. package/src/utils/traffic-mesh.js +3 -3
  146. package/oclif.manifest.json +0 -1
  147. package/src/commands/addons/auth.js +0 -42
  148. package/src/commands/addons/config.js +0 -177
  149. package/src/commands/addons/create.js +0 -127
  150. package/src/commands/addons/delete.js +0 -69
  151. package/src/commands/addons/list.js +0 -54
  152. package/src/commands/api.js +0 -84
  153. package/src/commands/dev/exec.js +0 -32
  154. package/src/commands/dev/trace.js +0 -61
  155. package/src/commands/env/get.js +0 -44
  156. package/src/commands/env/import.js +0 -90
  157. package/src/commands/env/list.js +0 -49
  158. package/src/commands/env/set.js +0 -64
  159. package/src/commands/env/unset.js +0 -58
  160. package/src/commands/functions/build.js +0 -60
  161. package/src/commands/functions/invoke.js +0 -277
  162. package/src/commands/functions/list.js +0 -102
  163. package/src/commands/functions/serve.js +0 -70
  164. package/src/commands/link.js +0 -133
  165. package/src/commands/lm/info.js +0 -36
  166. package/src/commands/lm/install.js +0 -30
  167. package/src/commands/lm/setup.js +0 -107
  168. package/src/commands/lm/uninstall.js +0 -17
  169. package/src/commands/login.js +0 -54
  170. package/src/commands/logout.js +0 -37
  171. package/src/commands/open/admin.js +0 -51
  172. package/src/commands/open/site.js +0 -43
  173. package/src/commands/sites/create.js +0 -191
  174. package/src/commands/sites/delete.js +0 -116
  175. package/src/commands/sites/list.js +0 -84
  176. package/src/commands/status/hooks.js +0 -60
  177. package/src/commands/switch.js +0 -44
  178. package/src/commands/unlink.js +0 -38
  179. package/src/commands/watch.js +0 -115
  180. package/src/hooks/init.js +0 -46
  181. package/src/index.js +0 -25
  182. package/src/lib/help.js +0 -26
  183. package/src/utils/chalk.js +0 -16
  184. package/src/utils/check-command-inputs.js +0 -21
  185. package/src/utils/command.js +0 -261
  186. package/src/utils/detect-functions-builder.js +0 -25
  187. package/src/utils/difference.js +0 -4
  188. package/src/utils/header.js +0 -18
  189. package/src/utils/logo.js +0 -11
  190. package/src/utils/show-help.js +0 -5
  191. package/src/utils/telemetry/tracked-command.js +0 -51
package/src/lib/fs.js CHANGED
@@ -1,22 +1,22 @@
1
- const fs = require('fs')
2
- const { promisify } = require('util')
1
+ // @ts-check
2
+ const {
3
+ constants,
4
+ promises: { access, readFile, rm, stat },
5
+ } = require('fs')
6
+ const { version } = require('process')
3
7
 
4
8
  const del = require('del')
5
- const makeDir = require('make-dir')
6
- const pathType = require('path-type')
9
+ const { gte, parse } = require('semver')
7
10
 
8
- const statAsync = promisify(fs.stat)
9
- const readFileAsync = promisify(fs.readFile)
10
- const writeFileAsync = promisify(fs.writeFile)
11
- const rmFileAsync = promisify(fs.unlink)
12
- const copyFileAsync = promisify(fs.copyFile)
13
- const accessAsync = promisify(fs.access)
14
- const mkdtempAsync = promisify(fs.mkdtemp)
15
- const appendFileAsync = promisify(fs.appendFile)
11
+ const NODE_VERSION = parse(version)
16
12
 
17
- const readFileAsyncCatchError = async (filepath) => {
13
+ /**
14
+ * reads a file async and catches potential errors
15
+ * @param {string} filePath
16
+ */
17
+ const readFileAsyncCatchError = async (filePath) => {
18
18
  try {
19
- return { content: await readFileAsync(filepath) }
19
+ return { content: await readFile(filePath, 'utf-8') }
20
20
  } catch (error) {
21
21
  return { error }
22
22
  }
@@ -24,42 +24,60 @@ const readFileAsyncCatchError = async (filepath) => {
24
24
 
25
25
  const fileExistsAsync = async (filePath) => {
26
26
  try {
27
- await accessAsync(filePath, fs.F_OK)
27
+ await access(filePath, constants.F_OK)
28
28
  return true
29
29
  } catch {
30
30
  return false
31
31
  }
32
32
  }
33
33
 
34
- const isDirectoryAsync = (filePath) => pathType.isDirectory(filePath)
35
- const isFileAsync = (filePath) => pathType.isFile(filePath)
36
-
37
- const mkdirRecursiveSync = (path) => makeDir.sync(path)
38
- const mkdirRecursiveAsync = (path) => makeDir(path)
34
+ /**
35
+ * Removes a directory recursively and async
36
+ * @param {string} path
37
+ * @returns {Promise<void>}
38
+ */
39
+ const rmdirRecursiveAsync = async (path) => {
40
+ if (gte(NODE_VERSION, '14.14.0')) {
41
+ return await rm(path, { force: true, recursive: true })
42
+ }
43
+ await del(path, { force: true })
44
+ }
39
45
 
40
- const rmdirRecursiveAsync = (path) => del(path, { force: true })
41
- const safelyRmdirRecursiveAsync = async (path) => {
46
+ /**
47
+ * calls stat async with a function and catches potential errors
48
+ * @param {string} filePath
49
+ * @param {keyof import('fs').StatsBase<number>} type For example `isDirectory` or `isFile`
50
+ */
51
+ const isType = async (filePath, type) => {
42
52
  try {
43
- await rmdirRecursiveAsync(path)
44
- } catch (error) {
45
- // no-op
53
+ const stats = await stat(filePath)
54
+ // @ts-ignore
55
+ return typeof stats[type] === 'function' ? stats[type]() : stats[type]
56
+ } catch (error_) {
57
+ if (error_.code === 'ENOENT') {
58
+ return false
59
+ }
60
+
61
+ throw error_
46
62
  }
47
63
  }
48
64
 
65
+ /**
66
+ * Checks if the provided filePath is a file
67
+ * @param {string} filePath
68
+ */
69
+ const isFileAsync = (filePath) => isType(filePath, 'isFile')
70
+
71
+ /**
72
+ * Checks if the provided filePath is a directory
73
+ * @param {string} filePath
74
+ */
75
+ const isDirectoryAsync = (filePath) => isType(filePath, 'isDirectory')
76
+
49
77
  module.exports = {
50
- statAsync,
51
- readFileAsync,
52
- readFileAsyncCatchError,
53
- writeFileAsync,
54
- rmFileAsync,
55
- copyFileAsync,
56
78
  fileExistsAsync,
57
79
  isDirectoryAsync,
58
80
  isFileAsync,
59
- mkdirRecursiveSync,
60
- mkdirRecursiveAsync,
81
+ readFileAsyncCatchError,
61
82
  rmdirRecursiveAsync,
62
- safelyRmdirRecursiveAsync,
63
- mkdtempAsync,
64
- appendFileAsync,
65
83
  }
@@ -1,4 +1,4 @@
1
- const { NETLIFYDEVERR, NETLIFYDEVLOG } = require('../../utils/logo')
1
+ const { NETLIFYDEVERR, NETLIFYDEVLOG } = require('../../utils')
2
2
 
3
3
  const { formatLambdaError, styleFunctionName } = require('./utils')
4
4
 
@@ -1,11 +1,12 @@
1
+ // @ts-check
1
2
  const { Readable } = require('stream')
2
3
 
3
4
  const { parse: parseContentType } = require('content-type')
4
5
  const multiparty = require('multiparty')
5
6
  const getRawBody = require('raw-body')
6
7
 
8
+ const { BACKGROUND } = require('../../utils')
7
9
  const { warn } = require('../../utils/command-helpers')
8
- const { BACKGROUND } = require('../../utils/get-functions')
9
10
  const { capitalize } = require('../string')
10
11
 
11
12
  const createFormSubmissionHandler = function ({ functionsRegistry, siteUrl }) {
@@ -1,8 +1,9 @@
1
+ // @ts-check
1
2
  const { stdout } = require('process')
2
3
 
3
4
  const { getBinaryPath: getFunctionsProxyPath } = require('@netlify/local-functions-proxy')
4
5
 
5
- const execa = require('../../utils/execa')
6
+ const { execa } = require('../../utils')
6
7
 
7
8
  const runFunctionsProxy = ({ binaryPath, context, directory, event, name, timeout }) => {
8
9
  const functionsProxyPath = getFunctionsProxyPath()
@@ -1,8 +1,11 @@
1
+ // @ts-check
1
2
  const { error: errorExit } = require('../../utils/command-helpers')
2
- const { difference } = require('../../utils/difference')
3
3
 
4
4
  const BACKGROUND_SUFFIX = '-background'
5
5
 
6
+ // Returns a new set with all elements of `setA` that don't exist in `setB`.
7
+ const difference = (setA, setB) => new Set([...setA].filter((item) => !setB.has(item)))
8
+
6
9
  class NetlifyFunction {
7
10
  constructor({ config, directory, mainFile, name, projectRoot, runtime, timeoutBackground, timeoutSynchronous }) {
8
11
  this.config = config
@@ -1,10 +1,8 @@
1
+ // @ts-check
2
+ const { mkdir } = require('fs').promises
1
3
  const { env } = require('process')
2
4
 
3
- const chalk = require('chalk')
4
-
5
- const { log, warn } = require('../../utils/command-helpers')
6
- const { NETLIFYDEVERR, NETLIFYDEVLOG } = require('../../utils/logo')
7
- const { mkdirRecursiveAsync } = require('../fs')
5
+ const { NETLIFYDEVERR, NETLIFYDEVLOG, chalk, log, warn } = require('../../utils')
8
6
  const { getLogMessage } = require('../log')
9
7
 
10
8
  const { NetlifyFunction } = require('./netlify-function')
@@ -45,7 +43,7 @@ class FunctionsRegistry {
45
43
  }
46
44
 
47
45
  static async prepareDirectoryScan(directory) {
48
- await mkdirRecursiveAsync(directory)
46
+ await mkdir(directory, { recursive: true })
49
47
 
50
48
  // We give runtimes the opportunity to react to a directory scan and run
51
49
  // additional logic before the directory is read. So if they implement a
@@ -1,3 +1,4 @@
1
+ // @ts-check
1
2
  const { dirname, extname } = require('path')
2
3
  const { platform } = require('process')
3
4
 
@@ -5,7 +6,7 @@ const tempy = require('tempy')
5
6
 
6
7
  const isWindows = platform === 'win32'
7
8
 
8
- const execa = require('../../../../utils/execa')
9
+ const { execa } = require('../../../../utils')
9
10
  const { runFunctionsProxy } = require('../../local-proxy')
10
11
 
11
12
  const build = async ({ binaryPath, functionDirectory }) => {
@@ -1,9 +1,11 @@
1
+ // @ts-check
2
+ const { readFile } = require('fs').promises
1
3
  const { resolve } = require('path')
2
4
 
3
- const execa = require('execa')
4
5
  const minimist = require('minimist')
5
6
 
6
- const { fileExistsAsync, readFileAsync } = require('../../../../fs')
7
+ const { execa } = require('../../../../../utils')
8
+ const { fileExistsAsync } = require('../../../../fs')
7
9
  const { memoizedBuild } = require('../../../memoized-build')
8
10
 
9
11
  const detectNetlifyLambda = async function ({ packageJson } = {}) {
@@ -59,8 +61,8 @@ module.exports = async function handler() {
59
61
  return false
60
62
  }
61
63
 
62
- const content = await readFileAsync('package.json')
63
- const packageJson = JSON.parse(content, { encoding: 'utf8' })
64
+ const content = await readFile('package.json', 'utf-8')
65
+ const packageJson = JSON.parse(content)
64
66
  return detectNetlifyLambda({ packageJson })
65
67
  }
66
68
  module.exports.detectNetlifyLambda = detectNetlifyLambda
@@ -1,3 +1,4 @@
1
+ const { writeFile } = require('fs').promises
1
2
  const path = require('path')
2
3
 
3
4
  const { zipFunction } = require('@netlify/zip-it-and-ship-it')
@@ -6,8 +7,7 @@ const makeDir = require('make-dir')
6
7
  const readPkgUp = require('read-pkg-up')
7
8
  const sourceMapSupport = require('source-map-support')
8
9
 
9
- const { NETLIFYDEVERR } = require('../../../../../utils/logo')
10
- const { writeFileAsync } = require('../../../../fs')
10
+ const { NETLIFYDEVERR } = require('../../../../../utils')
11
11
  const { getPathInProject } = require('../../../../settings')
12
12
  const { normalizeFunctionsConfig } = require('../../../config')
13
13
  const { memoizedBuild } = require('../../../memoized-build')
@@ -47,7 +47,7 @@ const buildFunction = async ({ cache, config, directory, func, hasTypeModule, pr
47
47
  // some projects include a package.json with "type=module", forcing Node to interpret every descending file
48
48
  // as ESM. ZISI outputs CJS, so we emit an overriding directive into the output directory.
49
49
  if (hasTypeModule) {
50
- await writeFileAsync(
50
+ await writeFile(
51
51
  path.join(functionPath, `package.json`),
52
52
  JSON.stringify({
53
53
  type: 'commonjs',
@@ -1,3 +1,5 @@
1
+ // @ts-check
2
+ const { readFile } = require('fs').promises
1
3
  const { dirname, extname, join, resolve } = require('path')
2
4
  const { platform } = require('process')
3
5
 
@@ -6,8 +8,7 @@ const toml = require('toml')
6
8
 
7
9
  const isWindows = platform === 'win32'
8
10
 
9
- const execa = require('../../../../utils/execa')
10
- const { readFileAsync } = require('../../../fs')
11
+ const { execa } = require('../../../../utils')
11
12
  const { getPathInProject } = require('../../../settings')
12
13
  const { runFunctionsProxy } = require('../../local-proxy')
13
14
 
@@ -36,7 +37,7 @@ const getBuildFunction =
36
37
 
37
38
  const getCrateName = async (cwd) => {
38
39
  const manifestPath = await findUp('Cargo.toml', { cwd, type: 'file' })
39
- const manifest = await readFileAsync(manifestPath)
40
+ const manifest = await readFile(manifestPath, 'utf-8')
40
41
  const { package } = toml.parse(manifest)
41
42
 
42
43
  return package.name
@@ -1,8 +1,7 @@
1
+ // @ts-check
1
2
  const jwtDecode = require('jwt-decode')
2
3
 
3
- const { error: errorExit, log } = require('../../utils/command-helpers')
4
- const { getInternalFunctionsDir } = require('../../utils/functions')
5
- const { NETLIFYDEVERR, NETLIFYDEVLOG } = require('../../utils/logo')
4
+ const { NETLIFYDEVERR, NETLIFYDEVLOG, error: errorExit, getInternalFunctionsDir, log } = require('../../utils')
6
5
 
7
6
  const { handleBackgroundFunction, handleBackgroundFunctionResult } = require('./background')
8
7
  const { createFormSubmissionHandler } = require('./form-submissions-handler')
@@ -1,6 +1,7 @@
1
+ // @ts-check
1
2
  const { Buffer } = require('buffer')
2
3
 
3
- const { NETLIFYDEVERR } = require('../../utils/logo')
4
+ const { NETLIFYDEVERR } = require('../../utils')
4
5
 
5
6
  const { detectAwsSdkError } = require('./utils')
6
7
 
@@ -1,6 +1,5 @@
1
- const chalk = require('chalk')
2
-
3
- const { warn } = require('../../utils/command-helpers')
1
+ // @ts-check
2
+ const { chalk, warn } = require('../../utils')
4
3
  const { getLogMessage } = require('../log')
5
4
 
6
5
  const DEFAULT_LAMBDA_OPTIONS = {
@@ -1,3 +1,4 @@
1
+ // @ts-check
1
2
  const chokidar = require('chokidar')
2
3
  const decache = require('decache')
3
4
  const debounce = require('lodash/debounce')
@@ -1,10 +1,10 @@
1
+ // @ts-check
2
+ const { readFile } = require('fs').promises
3
+
1
4
  const { HttpsProxyAgent } = require('https-proxy-agent')
2
5
  const waitPort = require('wait-port')
3
6
 
4
- const { exit, log } = require('../utils/command-helpers')
5
- const { NETLIFYDEVERR, NETLIFYDEVWARN } = require('../utils/logo')
6
-
7
- const fs = require('./fs')
7
+ const { NETLIFYDEVERR, NETLIFYDEVWARN, exit, log } = require('../utils')
8
8
 
9
9
  // https://github.com/TooTallNate/node-https-proxy-agent/issues/89
10
10
  class HttpsProxyAgentWithCA extends HttpsProxyAgent {
@@ -66,7 +66,7 @@ const tryGetAgent = async ({ certificateFile, httpProxy }) => {
66
66
  let certificate
67
67
  if (certificateFile) {
68
68
  try {
69
- certificate = await fs.readFileAsync(certificateFile)
69
+ certificate = await readFile(certificateFile)
70
70
  } catch (error) {
71
71
  response = { warning: `Could not read certificate file '${certificateFile}'.`, message: error.message }
72
72
  }
package/src/lib/log.js CHANGED
@@ -1,6 +1,7 @@
1
- const chalk = require('chalk')
2
1
  const dotProp = require('dot-prop')
3
2
 
3
+ const { chalk } = require('../utils')
4
+
4
5
  const RED_BACKGROUND = chalk.red('-background')
5
6
  const [PRO, BUSINESS, ENTERPRISE] = ['Pro', 'Business', 'Enterprise'].map((plan) => chalk.magenta(plan))
6
7
  const BACKGROUND_FUNCTIONS_WARNING = `A serverless function ending in \`${RED_BACKGROUND}\` was detected.
@@ -6,17 +6,32 @@ const envPaths = require('env-paths')
6
6
  const OSBasedPaths = envPaths('netlify', { suffix: '' })
7
7
  const NETLIFY_HOME = '.netlify'
8
8
 
9
- // Deprecated method to get netlify's home config - ~/.netlify/...
9
+ /**
10
+ * Deprecated method to get netlify's home config - ~/.netlify/...
11
+ * @deprecated
12
+ * @param {string[]} paths
13
+ * @returns {string}
14
+ */
10
15
  const getLegacyPathInHome = (paths) => {
11
16
  const pathInHome = path.join(os.homedir(), NETLIFY_HOME, ...paths)
12
17
  return pathInHome
13
18
  }
14
19
 
20
+ /**
21
+ * get a global path on the os base path
22
+ * @param {string[]} paths
23
+ * @returns {string}
24
+ */
15
25
  const getPathInHome = (paths) => {
16
26
  const pathInHome = path.join(OSBasedPaths.config, ...paths)
17
27
  return pathInHome
18
28
  }
19
29
 
30
+ /**
31
+ * get a path inside the project folder
32
+ * @param {string[]} paths
33
+ * @returns {string}
34
+ */
20
35
  const getPathInProject = (paths) => {
21
36
  const pathInProject = path.join(NETLIFY_HOME, ...paths)
22
37
  return pathInProject
@@ -1,15 +1,31 @@
1
+ // @ts-check
1
2
  const logSymbols = require('log-symbols')
2
3
  const ora = require('ora')
3
4
 
5
+ /**
6
+ * Creates a spinner with the following text
7
+ * @param {object} config
8
+ * @param {string} config.text
9
+ * @returns {ora.Ora}
10
+ */
4
11
  const startSpinner = ({ text }) =>
5
12
  ora({
6
13
  text,
7
14
  }).start()
8
15
 
16
+ /**
17
+ * Stops the spinner with the following text
18
+ * @param {object} config
19
+ * @param {ora.Ora} config.spinner
20
+ * @param {object} [config.error]
21
+ * @param {string} [config.text]
22
+ * @returns {void}
23
+ */
9
24
  const stopSpinner = ({ error, spinner, text }) => {
10
25
  if (!spinner) {
11
26
  return
12
27
  }
28
+ // TODO: refactor no package needed `log-symbols` for that
13
29
  const symbol = error ? logSymbols.error : logSymbols.success
14
30
  spinner.stopAndPersist({
15
31
  text,
@@ -17,6 +33,12 @@ const stopSpinner = ({ error, spinner, text }) => {
17
33
  })
18
34
  }
19
35
 
36
+ /**
37
+ * Clears the spinner
38
+ * @param {object} config
39
+ * @param {ora.Ora} config.spinner
40
+ * @returns {void}
41
+ */
20
42
  const clearSpinner = ({ spinner }) => {
21
43
  if (spinner) {
22
44
  spinner.stop()
@@ -1,3 +1,4 @@
1
+ // @ts-check
1
2
  const concordance = require('concordance')
2
3
 
3
4
  const { concordanceDiffOptions, concordanceOptions } = require('./options')
@@ -1,5 +1,7 @@
1
+ // @ts-check
1
2
  const ansiStyles = require('ansi-styles')
2
- const chalk = require('chalk')
3
+
4
+ const { chalk } = require('../../command-helpers')
3
5
 
4
6
  const forceColor = new chalk.Instance({ level: 1 })
5
7
 
@@ -1,6 +1,5 @@
1
- const chalk = require('chalk')
2
-
3
- const { error, exit, log, warn } = require('../command-helpers')
1
+ // @ts-check
2
+ const { chalk, error, exit, log, warn } = require('../command-helpers')
4
3
 
5
4
  const ADDON_VALIDATION = {
6
5
  EXISTS: 'EXISTS',
@@ -81,17 +80,25 @@ const getAddons = async ({ api, siteId }) => {
81
80
  return addons
82
81
  }
83
82
 
84
- const prepareAddonCommand = async ({ addonName, context, validation }) => {
85
- const { netlify } = context
83
+ /**
84
+ *
85
+ * @param {object} config
86
+ * @param {import('../../commands/base-command').BaseCommand} config.command
87
+ * @param {string} [config.addonName]
88
+ * @param {keyof ADDON_VALIDATION} [config.validation]
89
+ */
90
+ const prepareAddonCommand = async ({ addonName, command, validation }) => {
91
+ const { netlify } = command
86
92
  const { api, site } = netlify
87
93
  const siteId = site.id
88
94
  if (!siteId) {
89
95
  error('No site id found, please run inside a site folder or `netlify link`')
90
96
  }
91
97
 
92
- await context.authenticate()
98
+ await command.authenticate()
93
99
 
94
100
  const [manifest, siteData, addons] = await Promise.all([
101
+ // TODO: check as `getAddonManifest` did not accept a parameter error
95
102
  addonName ? getAddonManifest({ api, addonName, error }) : Promise.resolve(),
96
103
  getSiteData({ api, siteId }),
97
104
  getAddons({ api, siteId }),
@@ -1,4 +1,5 @@
1
- const chalk = require('chalk')
1
+ // @ts-check
2
+ const { chalk } = require('../command-helpers')
2
3
 
3
4
  /* programmatically generate CLI prompts */
4
5
  module.exports = function generatePrompts(settings) {
@@ -1,5 +1,7 @@
1
+ // @ts-check
1
2
  const AsciiTable = require('ascii-table')
2
- const chalk = require('chalk')
3
+
4
+ const { chalk } = require('../command-helpers')
3
5
 
4
6
  const missingValues = function (values, manifest) {
5
7
  const display = values