netlify-cli 8.0.10 → 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 +471 -2182
  3. package/package.json +12 -35
  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 +5 -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 +7 -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 +4 -2
  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 -261
  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
@@ -1,33 +1,121 @@
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
+ const platform = WSL ? 'wsl' : os.platform()
35
+ const arch = os.arch() === 'ia32' ? 'x86' : os.arch()
36
+
37
+ const USER_AGENT = `${name}/${version} ${platform}-${arch} node-${process.version}`
38
+
13
39
  const { NETLIFY_AUTH_TOKEN } = process.env
14
40
 
15
- // 5 Minutes
16
- const TOKEN_TIMEOUT = 3e5
41
+ // eslint-disable-next-line no-magic-numbers
42
+ const NETLIFY_CYAN = chalk.rgb(40, 180, 170)
43
+
44
+ const NETLIFYDEV = `${chalk.greenBright('◈')} ${NETLIFY_CYAN('Netlify Dev')} ${chalk.greenBright('◈')}`
45
+ const NETLIFYDEVLOG = `${chalk.greenBright('◈')}`
46
+ const NETLIFYDEVWARN = `${chalk.yellowBright('◈')}`
47
+ const NETLIFYDEVERR = `${chalk.redBright('◈')}`
48
+
49
+ // eslint-disable-next-line id-length
50
+ const $ = NETLIFY_CYAN('$')
51
+ const BANG = process.platform === 'win32' ? '»' : '›'
52
+
53
+ /**
54
+ * Generates a CommandHelp section for the command
55
+ * @param {string} commandName
56
+ * @param {import('commander').Command} program
57
+ */
58
+ const generateCommandsHelp = (commandName, program) => {
59
+ const cmds = program.commands.filter((cmd) => cmd.name().startsWith(`${commandName}:`))
60
+
61
+ if (cmds.length !== 0) {
62
+ const longestName = Math.max(...cmds.map((cmd) => cmd.name().length)) + 1
63
+ const table = cmds.map((cmd) => {
64
+ const spacer = Array.from({ length: longestName - cmd.name().length })
65
+ .fill()
66
+ .join(' ')
67
+
68
+ return ` ${$} ${cmd.name()}${spacer} ${chalk.grey(cmd.description())}`
69
+ })
70
+ return `
71
+ ${chalk.bold('COMMANDS')}
72
+ ${table.join('\n')}`
73
+ }
74
+ }
17
75
 
18
- const chalk = chalkInstance(argv.json)
76
+ /**
77
+ * Generates the help output for the description
78
+ * @param {string} description
79
+ * @returns {string}
80
+ */
81
+ const generateDescriptionHelp = (description) => `
82
+ ${chalk.bold('DESCRIPTION')}
83
+ ${description.split('\n').join('\n ')}`
84
+
85
+ /**
86
+ * Generates the help output for the examples
87
+ * @param {string[]} examples
88
+ * @returns {string}
89
+ */
90
+ const generateExamplesHelp = (examples) => {
91
+ if (examples.length !== 0) {
92
+ return `
93
+ ${chalk.bold('EXAMPLES')}
94
+ ${examples.map((example) => ` ${$} ${example}`).join('\n')}`
95
+ }
96
+ }
97
+
98
+ // Poll Token timeout 5 Minutes
99
+ const TOKEN_TIMEOUT = 3e5
19
100
 
20
- const pollForToken = async ({ api, exitWithError, ticket }) => {
101
+ /**
102
+ *
103
+ * @param {object} config
104
+ * @param {import('netlify').NetlifyAPI} config.api
105
+ * @param {object} config.ticket
106
+ * @returns
107
+ */
108
+ const pollForToken = async ({ api, ticket }) => {
21
109
  const spinner = startSpinner({ text: 'Waiting for authorization...' })
22
110
  try {
23
111
  const accessToken = await api.getAccessToken(ticket, { timeout: TOKEN_TIMEOUT })
24
112
  if (!accessToken) {
25
- exitWithError('Could not retrieve access token')
113
+ error('Could not retrieve access token')
26
114
  }
27
115
  return accessToken
28
- } catch (error) {
29
- if (error.name === 'TimeoutError') {
30
- exitWithError(
116
+ } catch (error_) {
117
+ if (error_.name === 'TimeoutError') {
118
+ error(
31
119
  `Timed out waiting for authorization. If you do not have a ${chalk.bold.greenBright(
32
120
  'Netlify',
33
121
  )} account, please create one at ${chalk.magenta(
@@ -35,29 +123,22 @@ const pollForToken = async ({ api, exitWithError, ticket }) => {
35
123
  )}, then run ${chalk.cyanBright('netlify login')} again.`,
36
124
  )
37
125
  } else {
38
- exitWithError(error)
126
+ error(error_)
39
127
  }
40
128
  } finally {
41
129
  clearSpinner({ spinner })
42
130
  }
43
131
  }
44
132
 
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
-
133
+ /**
134
+ * Get a netlify token
135
+ * @param {string} [tokenFromOptions] optional token from the provided --auth options
136
+ * @returns {Promise<[null|string, 'flag' | 'env' |'config' |'not found']>}
137
+ */
138
+ const getToken = async (tokenFromOptions) => {
58
139
  // 1. First honor command flag --auth
59
- if (tokenFromFlag) {
60
- return [tokenFromFlag, 'flag']
140
+ if (tokenFromOptions) {
141
+ return [tokenFromOptions, 'flag']
61
142
  }
62
143
  // 2. then Check ENV var
63
144
  if (NETLIFY_AUTH_TOKEN && NETLIFY_AUTH_TOKEN !== 'null') {
@@ -75,33 +156,58 @@ const getToken = async (authFromFlag) => {
75
156
 
76
157
  // 'api' command uses JSON output by default
77
158
  // '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)
159
+ const isDefaultJson = () => argv[0] === 'functions:invoke' || (argv[0] === 'api' && !argv.includes('--list'))
79
160
 
161
+ /**
162
+ * logs a json message
163
+ * @param {string|object} message
164
+ */
80
165
  const logJson = (message = '') => {
81
- if (argv.json || isDefaultJson()) {
166
+ if (argv.includes('--json') || isDefaultJson()) {
82
167
  process.stdout.write(JSON.stringify(message, null, 2))
83
168
  }
84
169
  }
85
170
 
86
171
  const log = (message = '', ...args) => {
87
- /* If --silent or --json flag passed disable logger */
88
- if (argv.silent || argv.json || isDefaultJson()) {
172
+ // If --silent or --json flag passed disable logger
173
+ if (argv.includes('--json') || argv.includes('--silent') || isDefaultJson()) {
89
174
  return
90
175
  }
91
176
  message = typeof message === 'string' ? message : inspect(message)
92
177
  process.stdout.write(`${format(message, ...args)}\n`)
93
178
  }
94
179
 
180
+ /**
181
+ * logs a warning message
182
+ * @param {string} message
183
+ */
95
184
  const warn = (message = '') => {
96
- Errors.warn(message)
185
+ const bang = chalk.yellow(BANG)
186
+ log(` ${bang} Warning: ${message}`)
97
187
  }
98
188
 
189
+ /**
190
+ * throws an error or log it
191
+ * @param {string|Error} message
192
+ * @param {object} [options]
193
+ * @param {boolean} [options.exit]
194
+ */
99
195
  const error = (message = '', options = {}) => {
100
- Errors.error(message, options)
196
+ const err = message instanceof Error ? message : new Error(message)
197
+ if (options.exit === false) {
198
+ const bang = chalk.red(BANG)
199
+ if (process.env.DEBUG) {
200
+ process.stderr.write(` ${bang} Warning: ${err.stack.split('\n').join(`\n ${bang} `)}`)
201
+ } else {
202
+ process.stderr.write(` ${bang} ${err.name}: ${err.message}\n`)
203
+ }
204
+ } else {
205
+ throw err
206
+ }
101
207
  }
102
208
 
103
209
  const exit = (code = 0) => {
104
- Errors.exit(code)
210
+ process.exit(code)
105
211
  }
106
212
 
107
213
  // When `build.publish` is not set by the user, the CLI behavior differs in
@@ -114,15 +220,22 @@ const normalizeConfig = (config) =>
114
220
  : config
115
221
 
116
222
  module.exports = {
117
- argv,
118
- getCwd,
119
- pollForToken,
120
- log,
121
- logJson,
122
223
  getToken,
123
- normalizeConfig,
124
- chalk,
224
+ exit,
225
+ logJson,
226
+ log,
125
227
  warn,
126
228
  error,
127
- exit,
229
+ chalk,
230
+ generateCommandsHelp,
231
+ generateDescriptionHelp,
232
+ generateExamplesHelp,
233
+ pollForToken,
234
+ normalizeConfig,
235
+ USER_AGENT,
236
+ NETLIFY_CYAN,
237
+ NETLIFYDEV,
238
+ NETLIFYDEVLOG,
239
+ NETLIFYDEVWARN,
240
+ NETLIFYDEVERR,
128
241
  }
@@ -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')
@@ -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 hasGitIgnore = async function (dir) {
8
10
  const gitIgnorePath = path.join(dir, '.gitignore')
@@ -16,14 +18,14 @@ const ensureNetlifyIgnore = async function (dir) {
16
18
 
17
19
  /* No .gitignore file. Create one and ignore .netlify folder */
18
20
  if (!(await hasGitIgnore(dir))) {
19
- await writeFileAsync(gitIgnorePath, ignoreContent, 'utf8')
21
+ await writeFile(gitIgnorePath, ignoreContent, 'utf8')
20
22
  return false
21
23
  }
22
24
 
23
25
  let gitIgnoreContents
24
26
  let ignorePatterns
25
27
  try {
26
- gitIgnoreContents = await readFileAsync(gitIgnorePath, 'utf8')
28
+ gitIgnoreContents = await readFile(gitIgnorePath, 'utf8')
27
29
  ignorePatterns = parseIgnore.parse(gitIgnoreContents)
28
30
  } catch (error) {
29
31
  // ignore
@@ -31,8 +33,8 @@ const ensureNetlifyIgnore = async function (dir) {
31
33
  /* Not ignoring .netlify folder. Add to .gitignore */
32
34
  if (!ignorePatterns || !ignorePatterns.patterns.some((pattern) => /(^|\/|\\)\.netlify($|\/|\\)/.test(pattern))) {
33
35
  const newContents = `${gitIgnoreContents}\n${ignoreContent}`
34
- await writeFileAsync(gitIgnorePath, newContents, 'utf8')
36
+ await writeFile(gitIgnorePath, newContents, 'utf8')
35
37
  }
36
38
  }
37
39
 
38
- module.exports = ensureNetlifyIgnore
40
+ module.exports = { ensureNetlifyIgnore }