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
@@ -1,33 +1,102 @@
1
+ // @ts-check
2
+ const os = require('os')
1
3
  const process = require('process')
2
4
  const { format, inspect } = require('util')
3
5
 
4
- const Errors = require('@oclif/errors')
5
- const argv = require('minimist')(process.argv.slice(2))
6
- const omit = require('omit.js').default
6
+ // eslint-disable-next-line local-rules/no-direct-chalk-import
7
+ const { Instance: ChalkInstance } = require('chalk')
8
+ const WSL = require('is-wsl')
9
+ const { default: omit } = require('omit.js')
7
10
 
11
+ const { name, version } = require('../../package.json')
8
12
  const { clearSpinner, startSpinner } = require('../lib/spinner')
9
13
 
10
- const chalkInstance = require('./chalk')
11
14
  const getGlobalConfig = require('./get-global-config')
12
15
 
16
+ /** The parsed process argv without the binary only arguments and flags */
17
+ const argv = process.argv.slice(2)
18
+ /**
19
+ * Chalk instance for CLI that can be initialized with no colors mode
20
+ * needed for json outputs where we don't want to have colors
21
+ * @param {boolean} noColors - disable chalk colors
22
+ * @return {object} - default or custom chalk instance
23
+ */
24
+ const safeChalk = function (noColors) {
25
+ if (noColors) {
26
+ const colorlessChalk = new ChalkInstance({ level: 0 })
27
+ return colorlessChalk
28
+ }
29
+ return new ChalkInstance()
30
+ }
31
+
32
+ const chalk = safeChalk(argv.includes('--json'))
33
+
34
+ /**
35
+ * Adds the filler to the start of the string
36
+ * @param {string} str
37
+ * @param {number} count
38
+ * @param {string} [filler]
39
+ * @returns {string}
40
+ */
41
+ const padLeft = (str, count, filler = ' ') => str.padStart(str.length + count, filler)
42
+
43
+ const platform = WSL ? 'wsl' : os.platform()
44
+ const arch = os.arch() === 'ia32' ? 'x86' : os.arch()
45
+
46
+ const USER_AGENT = `${name}/${version} ${platform}-${arch} node-${process.version}`
47
+
48
+ /** A list of base command flags that needs to be sorted down on documentation and on help pages */
49
+ const BASE_FLAGS = new Set(['--debug', '--httpProxy', '--httpProxyCertificateFilename'])
50
+
13
51
  const { NETLIFY_AUTH_TOKEN } = process.env
14
52
 
15
- // 5 Minutes
16
- const TOKEN_TIMEOUT = 3e5
53
+ // eslint-disable-next-line no-magic-numbers
54
+ const NETLIFY_CYAN = chalk.rgb(40, 180, 170)
55
+
56
+ const NETLIFYDEV = `${chalk.greenBright('◈')} ${NETLIFY_CYAN('Netlify Dev')} ${chalk.greenBright('◈')}`
57
+ const NETLIFYDEVLOG = `${chalk.greenBright('◈')}`
58
+ const NETLIFYDEVWARN = `${chalk.yellowBright('◈')}`
59
+ const NETLIFYDEVERR = `${chalk.redBright('◈')}`
60
+
61
+ const BANG = process.platform === 'win32' ? '»' : '›'
62
+
63
+ /**
64
+ * Sorts two options so that the base flags are at the bottom of the list
65
+ * @param {import('commander').Option} optionA
66
+ * @param {import('commander').Option} optionB
67
+ * @returns {number}
68
+ * @example
69
+ * options.sort(sortOptions)
70
+ */
71
+ const sortOptions = (optionA, optionB) => {
72
+ // base flags should be always at the bottom
73
+ if (BASE_FLAGS.has(optionA.long) || BASE_FLAGS.has(optionB.long)) {
74
+ return -1
75
+ }
76
+ return optionA.long.localeCompare(optionB.long)
77
+ }
17
78
 
18
- const chalk = chalkInstance(argv.json)
79
+ // Poll Token timeout 5 Minutes
80
+ const TOKEN_TIMEOUT = 3e5
19
81
 
20
- const pollForToken = async ({ api, exitWithError, ticket }) => {
82
+ /**
83
+ *
84
+ * @param {object} config
85
+ * @param {import('netlify').NetlifyAPI} config.api
86
+ * @param {object} config.ticket
87
+ * @returns
88
+ */
89
+ const pollForToken = async ({ api, ticket }) => {
21
90
  const spinner = startSpinner({ text: 'Waiting for authorization...' })
22
91
  try {
23
92
  const accessToken = await api.getAccessToken(ticket, { timeout: TOKEN_TIMEOUT })
24
93
  if (!accessToken) {
25
- exitWithError('Could not retrieve access token')
94
+ error('Could not retrieve access token')
26
95
  }
27
96
  return accessToken
28
- } catch (error) {
29
- if (error.name === 'TimeoutError') {
30
- exitWithError(
97
+ } catch (error_) {
98
+ if (error_.name === 'TimeoutError') {
99
+ error(
31
100
  `Timed out waiting for authorization. If you do not have a ${chalk.bold.greenBright(
32
101
  'Netlify',
33
102
  )} account, please create one at ${chalk.magenta(
@@ -35,29 +104,22 @@ const pollForToken = async ({ api, exitWithError, ticket }) => {
35
104
  )}, then run ${chalk.cyanBright('netlify login')} again.`,
36
105
  )
37
106
  } else {
38
- exitWithError(error)
107
+ error(error_)
39
108
  }
40
109
  } finally {
41
110
  clearSpinner({ spinner })
42
111
  }
43
112
  }
44
113
 
45
- const getCwd = () => argv.cwd || process.cwd()
46
-
47
- const getAuthArg = () => {
48
- // If deploy command. Support shorthand 'a' flag
49
- if (argv && argv._ && argv._[0] === 'deploy') {
50
- return argv.auth || argv.a
51
- }
52
- return argv.auth
53
- }
54
-
55
- const getToken = async (authFromFlag) => {
56
- const tokenFromFlag = authFromFlag || getAuthArg(argv)
57
-
114
+ /**
115
+ * Get a netlify token
116
+ * @param {string} [tokenFromOptions] optional token from the provided --auth options
117
+ * @returns {Promise<[null|string, 'flag' | 'env' |'config' |'not found']>}
118
+ */
119
+ const getToken = async (tokenFromOptions) => {
58
120
  // 1. First honor command flag --auth
59
- if (tokenFromFlag) {
60
- return [tokenFromFlag, 'flag']
121
+ if (tokenFromOptions) {
122
+ return [tokenFromOptions, 'flag']
61
123
  }
62
124
  // 2. then Check ENV var
63
125
  if (NETLIFY_AUTH_TOKEN && NETLIFY_AUTH_TOKEN !== 'null') {
@@ -75,33 +137,58 @@ const getToken = async (authFromFlag) => {
75
137
 
76
138
  // 'api' command uses JSON output by default
77
139
  // 'functions:invoke' need to return the data from the function as is
78
- const isDefaultJson = () => argv._[0] === 'functions:invoke' || (argv._[0] === 'api' && argv.list !== true)
140
+ const isDefaultJson = () => argv[0] === 'functions:invoke' || (argv[0] === 'api' && !argv.includes('--list'))
79
141
 
142
+ /**
143
+ * logs a json message
144
+ * @param {string|object} message
145
+ */
80
146
  const logJson = (message = '') => {
81
- if (argv.json || isDefaultJson()) {
147
+ if (argv.includes('--json') || isDefaultJson()) {
82
148
  process.stdout.write(JSON.stringify(message, null, 2))
83
149
  }
84
150
  }
85
151
 
86
152
  const log = (message = '', ...args) => {
87
- /* If --silent or --json flag passed disable logger */
88
- if (argv.silent || argv.json || isDefaultJson()) {
153
+ // If --silent or --json flag passed disable logger
154
+ if (argv.includes('--json') || argv.includes('--silent') || isDefaultJson()) {
89
155
  return
90
156
  }
91
157
  message = typeof message === 'string' ? message : inspect(message)
92
158
  process.stdout.write(`${format(message, ...args)}\n`)
93
159
  }
94
160
 
161
+ /**
162
+ * logs a warning message
163
+ * @param {string} message
164
+ */
95
165
  const warn = (message = '') => {
96
- Errors.warn(message)
166
+ const bang = chalk.yellow(BANG)
167
+ log(` ${bang} Warning: ${message}`)
97
168
  }
98
169
 
170
+ /**
171
+ * throws an error or log it
172
+ * @param {string|Error} message
173
+ * @param {object} [options]
174
+ * @param {boolean} [options.exit]
175
+ */
99
176
  const error = (message = '', options = {}) => {
100
- Errors.error(message, options)
177
+ const err = message instanceof Error ? message : new Error(message)
178
+ if (options.exit === false) {
179
+ const bang = chalk.red(BANG)
180
+ if (process.env.DEBUG) {
181
+ process.stderr.write(` ${bang} Warning: ${err.stack.split('\n').join(`\n ${bang} `)}`)
182
+ } else {
183
+ process.stderr.write(` ${bang} ${err.name}: ${err.message}\n`)
184
+ }
185
+ } else {
186
+ throw err
187
+ }
101
188
  }
102
189
 
103
190
  const exit = (code = 0) => {
104
- Errors.exit(code)
191
+ process.exit(code)
105
192
  }
106
193
 
107
194
  // When `build.publish` is not set by the user, the CLI behavior differs in
@@ -114,15 +201,22 @@ const normalizeConfig = (config) =>
114
201
  : config
115
202
 
116
203
  module.exports = {
117
- argv,
118
- getCwd,
119
- pollForToken,
204
+ BANG,
205
+ chalk,
206
+ error,
207
+ exit,
208
+ getToken,
120
209
  log,
121
210
  logJson,
122
- getToken,
211
+ NETLIFY_CYAN,
212
+ NETLIFYDEV,
213
+ NETLIFYDEVERR,
214
+ NETLIFYDEVLOG,
215
+ NETLIFYDEVWARN,
123
216
  normalizeConfig,
124
- chalk,
217
+ padLeft,
218
+ pollForToken,
219
+ sortOptions,
220
+ USER_AGENT,
125
221
  warn,
126
- error,
127
- exit,
128
222
  }
@@ -1,5 +1,10 @@
1
1
  const { Buffer } = require('buffer')
2
2
 
3
+ const SEC_TO_MILLISEC = 1e3
4
+
5
+ // 6 MiB
6
+ const DEFAULT_BYTES_LIMIT = 6e6
7
+
3
8
  const createStreamPromise = function (stream, timeoutSeconds, bytesLimit = DEFAULT_BYTES_LIMIT) {
4
9
  return new Promise(function streamPromiseFunc(resolve, reject) {
5
10
  let data = []
@@ -41,9 +46,4 @@ const createStreamPromise = function (stream, timeoutSeconds, bytesLimit = DEFAU
41
46
  })
42
47
  }
43
48
 
44
- const SEC_TO_MILLISEC = 1e3
45
-
46
- // 6 MiB
47
- const DEFAULT_BYTES_LIMIT = 6e6
48
-
49
49
  module.exports = { createStreamPromise }
@@ -1,3 +1,4 @@
1
+ // @ts-check
1
2
  const createDeferred = () => {
2
3
  let resolveDeferred
3
4
  let rejectDeferred
@@ -83,7 +83,7 @@ const deploySite = async (
83
83
 
84
84
  if (functionsWithNativeModules.length !== 0) {
85
85
  warn(`Modules with native dependencies\n
86
- ${functionsWithNativeModules.map(({ name }) => `- ${name}`).join('\n')}
86
+ ${functionsWithNativeModules.map(({ name }) => `- ${name}`).join('\n')}
87
87
 
88
88
  The serverless functions above use Node.js modules with native dependencies, which
89
89
  must be installed on a system with the same architecture as the function runtime. A
@@ -0,0 +1,4 @@
1
+ // @ts-check
2
+ const { deploySite } = require('./deploy-site')
3
+
4
+ module.exports = { deploySite }
@@ -4,17 +4,15 @@ const path = require('path')
4
4
  const process = require('process')
5
5
 
6
6
  const { getFramework, listFrameworks } = require('@netlify/framework-info')
7
- const chalk = require('chalk')
8
7
  const fuzzy = require('fuzzy')
9
8
  const getPort = require('get-port')
10
9
  const isPlainObject = require('is-plain-obj')
11
10
 
12
11
  const { readFileAsyncCatchError } = require('../lib/fs')
13
12
 
14
- const { log } = require('./command-helpers')
13
+ const { NETLIFYDEVWARN, chalk, log } = require('./command-helpers')
15
14
  const { acquirePort } = require('./dev')
16
15
  const { getInternalFunctionsDir } = require('./functions')
17
- const { NETLIFYDEVWARN } = require('./logo')
18
16
 
19
17
  const formatProperty = (str) => chalk.magenta(`'${str}'`)
20
18
  const formatValue = (str) => chalk.green(`'${str}'`)
@@ -106,14 +104,14 @@ const getDefaultDist = () => {
106
104
  *
107
105
  * @param {object} param0
108
106
  * @param {import('../commands/dev/types').DevConfig} param0.devConfig
109
- * @param {Record<string, string>} param0.flags
107
+ * @param {import('commander').OptionValues} param0.options
110
108
  * @param {string} param0.projectDir
111
109
  * @returns {Promise<import('./types').BaseServerSettings>}
112
110
  */
113
- const handleStaticServer = async ({ devConfig, flags, projectDir }) => {
111
+ const handleStaticServer = async ({ devConfig, options, projectDir }) => {
114
112
  validateNumberProperty({ devConfig, property: 'staticServerPort' })
115
113
 
116
- if (flags.dir) {
114
+ if (options.dir) {
117
115
  log(`${NETLIFYDEVWARN} Using simple static server because ${formatProperty('--dir')} flag was specified`)
118
116
  } else if (devConfig.framework === '#static') {
119
117
  log(
@@ -131,7 +129,7 @@ const handleStaticServer = async ({ devConfig, flags, projectDir }) => {
131
129
  )
132
130
  }
133
131
 
134
- const dist = flags.dir || devConfig.publish || getDefaultDist()
132
+ const dist = options.dir || devConfig.publish || getDefaultDist()
135
133
  log(`${NETLIFYDEVWARN} Running static server from "${path.relative(path.dirname(projectDir), dist)}"`)
136
134
 
137
135
  const frameworkPort = await acquirePort({
@@ -263,19 +261,19 @@ const handleForcedFramework = async ({ devConfig, projectDir }) => {
263
261
  /**
264
262
  * Get the server settings based on the flags and the devConfig
265
263
  * @param {import('../commands/dev/types').DevConfig} devConfig
266
- * @param {Record<string, string>} flags
264
+ * @param {import('commander').OptionValues} options
267
265
  * @param {string} projectDir
268
266
  * @returns {Promise<import('./types').ServerSettings>}
269
267
  */
270
- const detectServerSettings = async (devConfig, flags, projectDir) => {
268
+ const detectServerSettings = async (devConfig, options, projectDir) => {
271
269
  validateStringProperty({ devConfig, property: 'framework' })
272
270
 
273
271
  /** @type {Partial<import('./types').BaseServerSettings>} */
274
272
  let settings = {}
275
273
 
276
- if (flags.dir || devConfig.framework === '#static') {
274
+ if (options.dir || devConfig.framework === '#static') {
277
275
  // serving files statically without a framework server
278
- settings = await handleStaticServer({ flags, devConfig, projectDir })
276
+ settings = await handleStaticServer({ options, devConfig, projectDir })
279
277
  } else if (devConfig.framework === '#auto') {
280
278
  // this is the default CLI behavior
281
279
 
@@ -284,7 +282,7 @@ const detectServerSettings = async (devConfig, flags, projectDir) => {
284
282
 
285
283
  if (frameworkSettings === undefined && runDetection) {
286
284
  log(`${NETLIFYDEVWARN} No app server detected. Using simple static server`)
287
- settings = await handleStaticServer({ flags, devConfig, projectDir })
285
+ settings = await handleStaticServer({ options, devConfig, projectDir })
288
286
  } else {
289
287
  validateFrameworkConfig({ devConfig })
290
288
  const { command, frameworkPort, dist, framework, env, pollingStrategies = [] } = frameworkSettings || {}
package/src/utils/dev.js CHANGED
@@ -1,15 +1,14 @@
1
+ // @ts-check
1
2
  const process = require('process')
2
3
 
3
- const chalk = require('chalk')
4
4
  const { get } = require('dot-prop')
5
5
  const getPort = require('get-port')
6
6
  const isEmpty = require('lodash/isEmpty')
7
7
 
8
8
  const { supportsBackgroundFunctions } = require('../lib/account')
9
9
 
10
- const { error: failAndExit, log, warn } = require('./command-helpers')
10
+ const { NETLIFYDEVLOG, chalk, error, log, warn } = require('./command-helpers')
11
11
  const { loadDotEnvFiles } = require('./dot-env')
12
- const { NETLIFYDEVLOG } = require('./logo')
13
12
 
14
13
  // Possible sources of environment variables. For the purpose of printing log messages only. Order does not matter.
15
14
  const ENV_VAR_SOURCES = {
@@ -44,7 +43,7 @@ const ERROR_CALL_TO_ACTION =
44
43
 
45
44
  const validateSiteInfo = ({ site, siteInfo }) => {
46
45
  if (isEmpty(siteInfo)) {
47
- failAndExit(`Failed retrieving site information for site ${chalk.yellow(site.id)}. ${ERROR_CALL_TO_ACTION}`)
46
+ error(`Failed retrieving site information for site ${chalk.yellow(site.id)}. ${ERROR_CALL_TO_ACTION}`)
48
47
  }
49
48
  }
50
49
 
@@ -52,8 +51,8 @@ const getAccounts = async ({ api }) => {
52
51
  try {
53
52
  const accounts = await api.listAccountsForUser()
54
53
  return accounts
55
- } catch (error) {
56
- failAndExit(`Failed retrieving user account: ${error.message}. ${ERROR_CALL_TO_ACTION}`)
54
+ } catch (error_) {
55
+ error(`Failed retrieving user account: ${error_.message}. ${ERROR_CALL_TO_ACTION}`)
57
56
  }
58
57
  }
59
58
 
@@ -61,8 +60,8 @@ const getAddons = async ({ api, site }) => {
61
60
  try {
62
61
  const addons = await api.listServiceInstancesForSite({ siteId: site.id })
63
62
  return addons
64
- } catch (error) {
65
- failAndExit(`Failed retrieving addons for site ${chalk.yellow(site.id)}: ${error.message}. ${ERROR_CALL_TO_ACTION}`)
63
+ } catch (error_) {
64
+ error(`Failed retrieving addons for site ${chalk.yellow(site.id)}: ${error_.message}. ${ERROR_CALL_TO_ACTION}`)
66
65
  }
67
66
  }
68
67
 
@@ -89,8 +88,17 @@ const SYNCHRONOUS_FUNCTION_TIMEOUT = 10
89
88
  // default 15 minutes for background functions
90
89
  const BACKGROUND_FUNCTION_TIMEOUT = 900
91
90
 
92
- const getSiteInformation = async ({ flags = {}, api, site, siteInfo }) => {
93
- if (site.id && !flags.offline) {
91
+ /**
92
+ *
93
+ * @param {object} config
94
+ * @param {boolean} config.offline
95
+ * @param {*} config.api
96
+ * @param {*} config.site
97
+ * @param {*} config.siteInfo
98
+ * @returns
99
+ */
100
+ const getSiteInformation = async ({ api, offline, site, siteInfo }) => {
101
+ if (site.id && !offline) {
94
102
  validateSiteInfo({ site, siteInfo })
95
103
  const [accounts, addons] = await Promise.all([getAccounts({ api }), getAddons({ api, site })])
96
104
 
@@ -1,8 +1,10 @@
1
+ // @ts-check
2
+ const { readFile } = require('fs').promises
1
3
  const path = require('path')
2
4
 
3
5
  const dotenv = require('dotenv')
4
6
 
5
- const { isFileAsync, readFileAsync } = require('../lib/fs')
7
+ const { isFileAsync } = require('../lib/fs')
6
8
 
7
9
  const { warn } = require('./command-helpers')
8
10
 
@@ -32,7 +34,7 @@ const tryLoadDotEnvFiles = async ({ projectDir }) => {
32
34
  warning: `Failed reading env variables from file: ${filepath}: ${error.message}`,
33
35
  }
34
36
  }
35
- const content = await readFileAsync(filepath)
37
+ const content = await readFile(filepath, 'utf-8')
36
38
  const env = dotenv.parse(content)
37
39
  return { file, env }
38
40
  }),
@@ -1,10 +1,11 @@
1
+ // @ts-check
2
+ const fs = require('fs').promises
1
3
  const path = require('path')
2
4
 
3
- const { cancelDeploy, uploadEdgeHandlers } = require('../lib/api')
4
- const { readFileAsyncCatchError, statAsync } = require('../lib/fs')
5
- const { startSpinner, stopSpinner } = require('../lib/spinner')
6
-
7
- const { error, warn } = require('./command-helpers')
5
+ const { cancelDeploy, uploadEdgeHandlers } = require('../../lib/api')
6
+ const { readFileAsyncCatchError } = require('../../lib/fs')
7
+ const { startSpinner, stopSpinner } = require('../../lib/spinner')
8
+ const { error } = require('../command-helpers')
8
9
 
9
10
  const MANIFEST_FILENAME = 'manifest.json'
10
11
  const EDGE_HANDLERS_FOLDER = '.netlify/edge-handlers'
@@ -12,7 +13,7 @@ const EDGE_HANDLERS_FOLDER = '.netlify/edge-handlers'
12
13
  const validateEdgeHandlerFolder = async ({ site }) => {
13
14
  try {
14
15
  const resolvedFolder = path.resolve(site.root, EDGE_HANDLERS_FOLDER)
15
- const stat = await statAsync(resolvedFolder)
16
+ const stat = await fs.stat(resolvedFolder)
16
17
  if (!stat.isDirectory()) {
17
18
  error(`Edge Handlers folder ${EDGE_HANDLERS_FOLDER} must be a path to a directory`)
18
19
  }
@@ -77,7 +78,7 @@ const deployEdgeHandlers = async ({ api, deployId, silent, site }) => {
77
78
  } catch (error_) {
78
79
  const text = `Failed deploying Edge Handlers: ${error_.message}`
79
80
  stopSpinner({ spinner, text, error: true })
80
- await cancelDeploy({ api, deployId, warn })
81
+ await cancelDeploy({ api, deployId })
81
82
  // no need to report the error again
82
83
  error('')
83
84
  }
@@ -0,0 +1,36 @@
1
+ // @ts-check
2
+ const { resolve } = require('path')
3
+
4
+ const { isDirectoryAsync, isFileAsync } = require('../../lib/fs')
5
+ const { getPathInProject } = require('../../lib/settings')
6
+
7
+ /**
8
+ * retrieves the function directory out of the flags or config
9
+ * @param {object} param
10
+ * @param {object} param.config
11
+ * @param {import('commander').OptionValues} param.options The options from the commander
12
+ * @param {string} [defaultValue]
13
+ * @returns {string}
14
+ */
15
+ const getFunctionsDir = ({ config, options }, defaultValue) =>
16
+ options.functions ||
17
+ (config.dev && config.dev.functions) ||
18
+ config.functionsDirectory ||
19
+ (config.dev && config.dev.Functions) ||
20
+ defaultValue
21
+
22
+ const getFunctionsManifestPath = async ({ base }) => {
23
+ const path = resolve(base, getPathInProject(['functions', 'manifest.json']))
24
+ const isFile = await isFileAsync(path)
25
+
26
+ return isFile ? path : null
27
+ }
28
+
29
+ const getInternalFunctionsDir = async ({ base }) => {
30
+ const path = resolve(base, getPathInProject(['functions-internal']))
31
+ const isDirectory = await isDirectoryAsync(path)
32
+
33
+ return isDirectory ? path : null
34
+ }
35
+
36
+ module.exports = { getFunctionsDir, getInternalFunctionsDir, getFunctionsManifestPath }
@@ -1,4 +1,5 @@
1
- const { fileExistsAsync } = require('../lib/fs')
1
+ // @ts-check
2
+ const { fileExistsAsync } = require('../../lib/fs')
2
3
 
3
4
  const getUrlPath = (functionName) => `/.netlify/functions/${functionName}`
4
5
 
@@ -1,27 +1,9 @@
1
- const { resolve } = require('path')
2
-
3
- const { isDirectoryAsync, isFileAsync } = require('../../lib/fs')
4
- const { getPathInProject } = require('../../lib/settings')
5
-
6
- const getFunctionsDir = ({ config, flags }, defaultValue) =>
7
- flags.functions ||
8
- (config.dev && config.dev.functions) ||
9
- config.functionsDirectory ||
10
- (config.dev && config.dev.Functions) ||
11
- defaultValue
12
-
13
- const getFunctionsManifestPath = async ({ base }) => {
14
- const path = resolve(base, getPathInProject(['functions', 'manifest.json']))
15
- const isFile = await isFileAsync(path)
16
-
17
- return isFile ? path : null
1
+ const edgeHandlers = require('./edge-handlers')
2
+ const functions = require('./functions')
3
+ const getFunctions = require('./get-functions')
4
+
5
+ module.exports = {
6
+ ...functions,
7
+ ...edgeHandlers,
8
+ ...getFunctions,
18
9
  }
19
-
20
- const getInternalFunctionsDir = async ({ base }) => {
21
- const path = resolve(base, getPathInProject(['functions-internal']))
22
- const isDirectory = await isDirectoryAsync(path)
23
-
24
- return isDirectory ? path : null
25
- }
26
-
27
- module.exports = { getFunctionsDir, getInternalFunctionsDir, getFunctionsManifestPath }
@@ -1,8 +1,9 @@
1
+ const { readFile } = require('fs').promises
2
+
1
3
  const Configstore = require('configstore')
2
4
  const memoizeOne = require('memoize-one')
3
5
  const { v4: uuidv4 } = require('uuid')
4
6
 
5
- const { readFileAsync } = require('../lib/fs')
6
7
  const { getLegacyPathInHome, getPathInHome } = require('../lib/settings')
7
8
 
8
9
  const globalConfigDefaults = {
@@ -19,7 +20,7 @@ const getGlobalConfigOnce = async function () {
19
20
  let legacyConfig
20
21
  // Read legacy config if exists
21
22
  try {
22
- legacyConfig = JSON.parse(await readFileAsync(legacyPath))
23
+ legacyConfig = JSON.parse(await readFile(legacyPath))
23
24
  } catch {}
24
25
  // Use legacy config as default values
25
26
  const defaults = { ...globalConfigDefaults, ...legacyConfig }
@@ -1,3 +1,4 @@
1
+ // @ts-check
1
2
  const { dirname } = require('path')
2
3
  const process = require('process')
3
4
  const util = require('util')
@@ -10,7 +11,13 @@ const parseGitRemote = require('parse-github-url')
10
11
 
11
12
  const { log } = require('./command-helpers')
12
13
 
13
- const getRepoData = async function ({ remoteName }) {
14
+ /**
15
+ *
16
+ * @param {object} config
17
+ * @param {string} [config.remoteName]
18
+ * @returns
19
+ */
20
+ const getRepoData = async function ({ remoteName } = {}) {
14
21
  try {
15
22
  const cwd = process.cwd()
16
23
  const [gitConfig, gitDirectory] = await Promise.all([
@@ -1,3 +1,4 @@
1
+ // @ts-check
1
2
  // A simple ghauth inspired library for getting a personal access token
2
3
  const http = require('http')
3
4
  const process = require('process')
@@ -1,8 +1,10 @@
1
+ // @ts-check
2
+ const { readFile, writeFile } = require('fs').promises
1
3
  const path = require('path')
2
4
 
3
5
  const parseIgnore = require('parse-gitignore')
4
6
 
5
- const { fileExistsAsync, readFileAsync, writeFileAsync } = require('../lib/fs')
7
+ const { fileExistsAsync } = require('../lib/fs')
6
8
 
7
9
  const { log } = require('./command-helpers')
8
10
 
@@ -18,14 +20,14 @@ const ensureNetlifyIgnore = async function (dir) {
18
20
 
19
21
  /* No .gitignore file. Create one and ignore .netlify folder */
20
22
  if (!(await hasGitIgnore(dir))) {
21
- await writeFileAsync(gitIgnorePath, ignoreContent, 'utf8')
23
+ await writeFile(gitIgnorePath, ignoreContent, 'utf8')
22
24
  return false
23
25
  }
24
26
 
25
27
  let gitIgnoreContents
26
28
  let ignorePatterns
27
29
  try {
28
- gitIgnoreContents = await readFileAsync(gitIgnorePath, 'utf8')
30
+ gitIgnoreContents = await readFile(gitIgnorePath, 'utf8')
29
31
  ignorePatterns = parseIgnore.parse(gitIgnoreContents)
30
32
  } catch (error) {
31
33
  // ignore
@@ -35,8 +37,8 @@ const ensureNetlifyIgnore = async function (dir) {
35
37
  log()
36
38
  log('Adding local .netlify folder to .gitignore file...')
37
39
  const newContents = `${gitIgnoreContents}\n${ignoreContent}`
38
- await writeFileAsync(gitIgnorePath, newContents, 'utf8')
40
+ await writeFile(gitIgnorePath, newContents, 'utf8')
39
41
  }
40
42
  }
41
43
 
42
- module.exports = ensureNetlifyIgnore
44
+ module.exports = { ensureNetlifyIgnore }