netlify-cli 8.0.7 → 8.1.0-rc

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 (183) hide show
  1. package/bin/run +81 -3
  2. package/npm-shrinkwrap.json +305 -2105
  3. package/package.json +10 -33
  4. package/src/commands/addons/addons-auth.js +50 -0
  5. package/src/commands/addons/addons-config.js +180 -0
  6. package/src/commands/addons/addons-create.js +129 -0
  7. package/src/commands/addons/addons-delete.js +59 -0
  8. package/src/commands/addons/addons-list.js +62 -0
  9. package/src/commands/addons/addons.js +49 -0
  10. package/src/commands/addons/index.js +3 -24
  11. package/src/commands/api/api.js +83 -0
  12. package/src/commands/api/index.js +5 -0
  13. package/src/commands/base-command.js +322 -0
  14. package/src/commands/build/build.js +58 -0
  15. package/src/commands/build/index.js +3 -61
  16. package/src/commands/completion/completion.js +18 -0
  17. package/src/commands/completion/index.js +5 -0
  18. package/src/commands/{deploy.js → deploy/deploy.js} +306 -278
  19. package/src/commands/deploy/index.js +5 -0
  20. package/src/commands/dev/dev-exec.js +39 -0
  21. package/src/commands/dev/dev-trace.js +50 -0
  22. package/src/commands/dev/dev.js +349 -0
  23. package/src/commands/dev/index.js +3 -335
  24. package/src/commands/env/env-get.js +51 -0
  25. package/src/commands/env/env-import.js +93 -0
  26. package/src/commands/env/env-list.js +63 -0
  27. package/src/commands/env/env-set.js +67 -0
  28. package/src/commands/env/env-unset.js +66 -0
  29. package/src/commands/env/env.js +47 -0
  30. package/src/commands/env/index.js +3 -23
  31. package/src/commands/functions/functions-build.js +59 -0
  32. package/src/commands/functions/{create.js → functions-create.js} +133 -94
  33. package/src/commands/functions/functions-invoke.js +276 -0
  34. package/src/commands/functions/functions-list.js +107 -0
  35. package/src/commands/functions/functions-serve.js +63 -0
  36. package/src/commands/functions/functions.js +53 -0
  37. package/src/commands/functions/index.js +3 -45
  38. package/src/commands/index.js +5 -0
  39. package/src/commands/init/index.js +6 -0
  40. package/src/commands/{init.js → init/init.js} +79 -68
  41. package/src/commands/link/index.js +6 -0
  42. package/src/{utils/link/link-by-prompt.js → commands/link/link.js} +153 -14
  43. package/src/commands/lm/index.js +3 -19
  44. package/src/commands/lm/lm-info.js +42 -0
  45. package/src/commands/lm/lm-install.js +36 -0
  46. package/src/commands/lm/lm-setup.js +106 -0
  47. package/src/commands/lm/lm-uninstall.js +25 -0
  48. package/src/commands/lm/lm.js +39 -0
  49. package/src/commands/login/index.js +6 -0
  50. package/src/commands/login/login.js +52 -0
  51. package/src/commands/logout/index.js +5 -0
  52. package/src/commands/logout/logout.js +43 -0
  53. package/src/commands/main.js +117 -0
  54. package/src/commands/open/index.js +3 -39
  55. package/src/commands/open/open-admin.js +56 -0
  56. package/src/commands/open/open-site.js +49 -0
  57. package/src/commands/open/open.js +42 -0
  58. package/src/commands/sites/index.js +5 -20
  59. package/src/commands/sites/sites-create.js +184 -0
  60. package/src/commands/sites/sites-delete.js +108 -0
  61. package/src/commands/sites/sites-list.js +89 -0
  62. package/src/commands/sites/sites.js +36 -0
  63. package/src/commands/status/index.js +3 -118
  64. package/src/commands/status/status-hooks.js +73 -0
  65. package/src/commands/status/status.js +125 -0
  66. package/src/commands/switch/index.js +5 -0
  67. package/src/commands/switch/switch.js +50 -0
  68. package/src/commands/unlink/index.js +5 -0
  69. package/src/commands/unlink/unlink.js +48 -0
  70. package/src/commands/watch/index.js +5 -0
  71. package/src/commands/watch/watch.js +121 -0
  72. package/src/lib/build.js +21 -7
  73. package/src/lib/exec-fetcher.js +5 -3
  74. package/src/lib/fs.js +54 -36
  75. package/src/lib/functions/background.js +1 -1
  76. package/src/lib/functions/form-submissions-handler.js +2 -1
  77. package/src/lib/functions/local-proxy.js +2 -1
  78. package/src/lib/functions/netlify-function.js +4 -1
  79. package/src/lib/functions/registry.js +4 -6
  80. package/src/lib/functions/runtimes/go/index.js +2 -1
  81. package/src/lib/functions/runtimes/js/builders/netlify-lambda.js +6 -4
  82. package/src/lib/functions/runtimes/js/builders/zisi.js +3 -3
  83. package/src/lib/functions/runtimes/rust/index.js +4 -3
  84. package/src/lib/functions/server.js +2 -3
  85. package/src/lib/functions/synchronous.js +2 -1
  86. package/src/lib/functions/utils.js +2 -3
  87. package/src/lib/functions/watcher.js +1 -0
  88. package/src/lib/http-agent.js +3 -5
  89. package/src/lib/log.js +2 -1
  90. package/src/lib/spinner.js +22 -0
  91. package/src/utils/addons/diffs/index.js +1 -0
  92. package/src/utils/addons/diffs/options.js +3 -1
  93. package/src/utils/addons/prepare.js +13 -6
  94. package/src/utils/addons/prompts.js +2 -1
  95. package/src/utils/addons/render.js +3 -1
  96. package/src/utils/command-helpers.js +156 -43
  97. package/src/utils/create-stream-promise.js +5 -5
  98. package/src/utils/deferred.js +1 -0
  99. package/src/utils/deploy/deploy-site.js +1 -1
  100. package/src/utils/deploy/index.js +4 -0
  101. package/src/utils/detect-server-settings.js +10 -12
  102. package/src/utils/dev.js +18 -10
  103. package/src/utils/dot-env.js +4 -2
  104. package/src/utils/{edge-handlers.js → functions/edge-handlers.js} +8 -7
  105. package/src/utils/functions/functions.js +36 -0
  106. package/src/utils/{get-functions.js → functions/get-functions.js} +2 -1
  107. package/src/utils/functions/index.js +8 -26
  108. package/src/utils/get-global-config.js +3 -2
  109. package/src/utils/get-repo-data.js +1 -0
  110. package/src/utils/gh-auth.js +1 -0
  111. package/src/utils/gitignore.js +7 -5
  112. package/src/utils/header.js +2 -2
  113. package/src/utils/headers.js +1 -2
  114. package/src/utils/index.js +42 -0
  115. package/src/utils/init/config-github.js +12 -5
  116. package/src/utils/init/config-manual.js +9 -2
  117. package/src/utils/init/config.js +13 -7
  118. package/src/utils/init/frameworks.js +1 -0
  119. package/src/utils/init/node-version.js +4 -2
  120. package/src/utils/init/plugins.js +1 -0
  121. package/src/utils/init/utils.js +10 -6
  122. package/src/utils/live-tunnel.js +3 -4
  123. package/src/utils/lm/install.js +10 -15
  124. package/src/utils/lm/requirements.js +3 -1
  125. package/src/utils/lm/steps.js +1 -1
  126. package/src/utils/lm/ui.js +7 -3
  127. package/src/utils/open-browser.js +8 -2
  128. package/src/utils/parse-raw-flags.js +4 -4
  129. package/src/utils/proxy.js +6 -5
  130. package/src/utils/read-repo-url.js +1 -0
  131. package/src/utils/redirects.js +2 -2
  132. package/src/utils/rules-proxy.js +2 -1
  133. package/src/utils/state-config.js +1 -1
  134. package/src/utils/telemetry/index.js +2 -113
  135. package/src/utils/telemetry/request.js +3 -1
  136. package/src/utils/telemetry/telemetry.js +117 -0
  137. package/src/utils/telemetry/validation.js +13 -12
  138. package/src/utils/traffic-mesh.js +3 -3
  139. package/oclif.manifest.json +0 -1
  140. package/src/commands/addons/auth.js +0 -42
  141. package/src/commands/addons/config.js +0 -177
  142. package/src/commands/addons/create.js +0 -127
  143. package/src/commands/addons/delete.js +0 -69
  144. package/src/commands/addons/list.js +0 -54
  145. package/src/commands/api.js +0 -84
  146. package/src/commands/dev/exec.js +0 -32
  147. package/src/commands/dev/trace.js +0 -61
  148. package/src/commands/env/get.js +0 -44
  149. package/src/commands/env/import.js +0 -90
  150. package/src/commands/env/list.js +0 -49
  151. package/src/commands/env/set.js +0 -64
  152. package/src/commands/env/unset.js +0 -58
  153. package/src/commands/functions/build.js +0 -60
  154. package/src/commands/functions/invoke.js +0 -277
  155. package/src/commands/functions/list.js +0 -102
  156. package/src/commands/functions/serve.js +0 -70
  157. package/src/commands/link.js +0 -133
  158. package/src/commands/lm/info.js +0 -36
  159. package/src/commands/lm/install.js +0 -30
  160. package/src/commands/lm/setup.js +0 -107
  161. package/src/commands/lm/uninstall.js +0 -17
  162. package/src/commands/login.js +0 -54
  163. package/src/commands/logout.js +0 -37
  164. package/src/commands/open/admin.js +0 -51
  165. package/src/commands/open/site.js +0 -43
  166. package/src/commands/sites/create.js +0 -191
  167. package/src/commands/sites/delete.js +0 -116
  168. package/src/commands/sites/list.js +0 -84
  169. package/src/commands/status/hooks.js +0 -60
  170. package/src/commands/switch.js +0 -44
  171. package/src/commands/unlink.js +0 -38
  172. package/src/commands/watch.js +0 -115
  173. package/src/hooks/init.js +0 -46
  174. package/src/index.js +0 -25
  175. package/src/lib/help.js +0 -26
  176. package/src/utils/chalk.js +0 -16
  177. package/src/utils/check-command-inputs.js +0 -21
  178. package/src/utils/command.js +0 -262
  179. package/src/utils/detect-functions-builder.js +0 -25
  180. package/src/utils/difference.js +0 -4
  181. package/src/utils/logo.js +0 -11
  182. package/src/utils/show-help.js +0 -5
  183. package/src/utils/telemetry/tracked-command.js +0 -51
@@ -0,0 +1,121 @@
1
+ const cli = require('cli-ux').default
2
+ const pWaitFor = require('p-wait-for')
3
+ const prettyjson = require('prettyjson')
4
+
5
+ const { chalk, error, generateExamplesHelp, log } = require('../../utils')
6
+ const { init } = require('../init')
7
+
8
+ // 1 second
9
+ const INIT_WAIT = 1e3
10
+
11
+ // 1 second
12
+ const BUILD_FINISH_INTERVAL = 1e3
13
+ // 20 minutes
14
+ const BUILD_FINISH_TIMEOUT = 12e5
15
+
16
+ const waitForBuildFinish = async function (api, siteId) {
17
+ let firstPass = true
18
+
19
+ const waitForBuildToFinish = async function () {
20
+ const builds = await api.listSiteBuilds({ siteId })
21
+ // build.error
22
+ const currentBuilds = builds.filter((build) => !build.done)
23
+
24
+ // if build.error
25
+ // @TODO implement build error messages into this
26
+
27
+ if (!currentBuilds || currentBuilds.length === 0) {
28
+ cli.action.stop()
29
+ return true
30
+ }
31
+ firstPass = false
32
+ return false
33
+ }
34
+
35
+ await pWaitFor(waitForBuildToFinish, {
36
+ interval: BUILD_FINISH_INTERVAL,
37
+ timeout: BUILD_FINISH_TIMEOUT,
38
+ message: 'Timeout while waiting for deploy to finish',
39
+ })
40
+
41
+ // return only when build done or timeout happens
42
+ return firstPass
43
+ }
44
+
45
+ /**
46
+ * The watch command
47
+ * @param {import('commander').OptionValues} options
48
+ * @param {import('../base-command').BaseCommand} command
49
+ */
50
+ const watch = async (options, command) => {
51
+ await command.authenticate()
52
+ const client = command.netlify.api
53
+ let siteId = command.netlify.site.id
54
+
55
+ if (!siteId) {
56
+ // TODO: build init command
57
+ const siteData = await init({}, command)
58
+ siteId = siteData.id
59
+ }
60
+
61
+ // wait for 1 sec for everything to kickoff
62
+ console.time('Deploy time')
63
+ await cli.wait(INIT_WAIT)
64
+
65
+ // Get latest commit and look for that
66
+ // git rev-parse HEAD
67
+
68
+ // if no sha, its a manual "triggered deploy"
69
+ //
70
+ // {
71
+ // "id": "5b4e23db82d3f1780abd74f3",
72
+ // "deploy_id": "5b4e23db82d3f1780abd74f2",
73
+ // "sha": "pull/1/head",
74
+ // "log": [],
75
+ // "done": false,
76
+ // "error": null,
77
+ // "created_at": "2018-07-17T17:14:03.423Z"
78
+ // }
79
+ //
80
+ cli.action.start('Waiting for active site deploys to complete')
81
+ try {
82
+ // Fetch all builds!
83
+ // const builds = await client.listSiteBuilds({siteId})
84
+ //
85
+ // // Filter down to any that are not done
86
+ // const buildsToWatch = builds.filter((build) => {
87
+ // return !build.done
88
+ // })
89
+
90
+ const noActiveBuilds = await waitForBuildFinish(client, siteId)
91
+
92
+ const siteData = await client.getSite({ siteId })
93
+
94
+ const message = chalk.cyanBright.bold.underline(noActiveBuilds ? 'Last build' : 'Deploy complete')
95
+ log()
96
+ log(message)
97
+ log(
98
+ prettyjson.render({
99
+ URL: siteData.ssl_url || siteData.url,
100
+ Admin: siteData.admin_url,
101
+ }),
102
+ )
103
+ console.timeEnd('Deploy time')
104
+ } catch (error_) {
105
+ error(error_)
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Creates the `netlify watch` command
111
+ * @param {import('../base-command').BaseCommand} program
112
+ * @returns
113
+ */
114
+ const createWatchCommand = (program) =>
115
+ program
116
+ .command('watch')
117
+ .description('Watch for site deploy to finish')
118
+ .addHelpText('after', generateExamplesHelp([`netlify watch`, `git push && netlify watch`]))
119
+ .action(watch)
120
+
121
+ module.exports = { createWatchCommand }
package/src/lib/build.js CHANGED
@@ -1,15 +1,24 @@
1
+ // @ts-check
1
2
  const build = require('@netlify/build')
2
3
 
4
+ /**
5
+ * The buildConfig + a missing cachedConfig
6
+ * @typedef BuildConfig
7
+ * @type {Parameters<import('@netlify/build/src/core/main')>[0] & {cachedConfig: any}}
8
+ */
9
+
3
10
  // We have already resolved the configuration using `@netlify/config`
4
11
  // This is stored as `netlify.cachedConfig` and can be passed to
5
12
  // `@netlify/build --cachedConfig`.
6
- const getBuildOptions = ({
7
- context: {
8
- netlify: { cachedConfig },
9
- },
10
- flags: { debug, dry, json, offline, silent },
11
- token,
12
- }) => ({
13
+ /**
14
+ *
15
+ * @param {object} config
16
+ * @param {*} config.cachedConfig
17
+ * @param {string} config.token
18
+ * @param {import('commander').OptionValues} config.options
19
+ * @returns {BuildConfig}
20
+ */
21
+ const getBuildOptions = ({ cachedConfig, options: { debug, dry, json, offline, silent }, token }) => ({
13
22
  cachedConfig,
14
23
  token,
15
24
  dry,
@@ -24,6 +33,11 @@ const getBuildOptions = ({
24
33
  },
25
34
  })
26
35
 
36
+ /**
37
+ * run the build command
38
+ * @param {BuildConfig} options
39
+ * @returns
40
+ */
27
41
  const runBuild = async (options) => {
28
42
  const { configMutations, netlifyConfig: newConfig, severityCode: exitCode } = await build(options)
29
43
  return { exitCode, newConfig, configMutations }
@@ -1,12 +1,14 @@
1
+ // @ts-check
1
2
  const path = require('path')
2
3
  const process = require('process')
3
4
 
4
- const execa = require('execa')
5
5
  const { fetchLatest, fetchVersion, newerVersion, updateAvailable } = require('gh-release-fetch')
6
6
  const isExe = require('isexe')
7
7
 
8
- const { log } = require('../utils/command-helpers')
9
- const { NETLIFYDEVWARN } = require('../utils/logo')
8
+ // cannot directly import from ../utils as it would create a circular dependency.
9
+ // the file `src/utils/live-tunnel.js` depends on this file
10
+ const { NETLIFYDEVWARN, log } = require('../utils/command-helpers')
11
+ const execa = require('../utils/execa')
10
12
 
11
13
  const isWindows = () => process.platform === 'win32'
12
14
 
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,12 +1,10 @@
1
+ const { readFile } = require('fs').promises
1
2
  const { URL } = require('url')
2
3
 
3
4
  const { HttpsProxyAgent } = require('https-proxy-agent')
4
5
  const waitPort = require('wait-port')
5
6
 
6
- const { exit, log } = require('../utils/command-helpers')
7
- const { NETLIFYDEVERR, NETLIFYDEVWARN } = require('../utils/logo')
8
-
9
- const fs = require('./fs')
7
+ const { NETLIFYDEVERR, NETLIFYDEVWARN, exit, log } = require('../utils')
10
8
 
11
9
  // https://github.com/TooTallNate/node-https-proxy-agent/issues/89
12
10
  class HttpsProxyAgentWithCA extends HttpsProxyAgent {
@@ -68,7 +66,7 @@ const tryGetAgent = async ({ certificateFile, httpProxy }) => {
68
66
  let certificate
69
67
  if (certificateFile) {
70
68
  try {
71
- certificate = await fs.readFileAsync(certificateFile)
69
+ certificate = await readFile(certificateFile)
72
70
  } catch (error) {
73
71
  response = { warning: `Could not read certificate file '${certificateFile}'.`, message: error.message }
74
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.
@@ -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 {object} [config.error]
20
+ * @param {ora.Ora} config.spinner
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