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
@@ -1,262 +0,0 @@
1
- const process = require('process')
2
- const { URL } = require('url')
3
-
4
- const resolveConfig = require('@netlify/config')
5
- const { flags: flagsLib } = require('@oclif/command')
6
- const oclifParser = require('@oclif/parser')
7
- const merge = require('lodash/merge')
8
-
9
- // TODO: use static `import` after migrating this repository to pure ES modules
10
- const jsClient = import('netlify')
11
-
12
- const { getAgent } = require('../lib/http-agent')
13
-
14
- const { argv, chalk, error, exit, getCwd, getToken, log, normalizeConfig, pollForToken } = require('./command-helpers')
15
- const getGlobalConfig = require('./get-global-config')
16
- const { openBrowser } = require('./open-browser')
17
- const StateConfig = require('./state-config')
18
- const { identify, track } = require('./telemetry')
19
- const { TrackedCommand } = require('./telemetry/tracked-command')
20
-
21
- const { NETLIFY_API_URL } = process.env
22
-
23
- // Netlify CLI client id. Lives in bot@netlify.com
24
- // Todo setup client for multiple environments
25
- const CLIENT_ID = 'd6f37de6614df7ae58664cfca524744d73807a377f5ee71f1a254f78412e3750'
26
-
27
- class BaseCommand extends TrackedCommand {
28
- // Initialize context
29
- async init() {
30
- await super.init()
31
-
32
- const cwd = getCwd()
33
-
34
- const [token] = await getToken()
35
-
36
- // Get site id & build state
37
- const state = new StateConfig(cwd)
38
-
39
- const apiUrlOpts = {
40
- userAgent: this.config.userAgent,
41
- }
42
-
43
- if (NETLIFY_API_URL) {
44
- const apiUrl = new URL(NETLIFY_API_URL)
45
- apiUrlOpts.scheme = apiUrl.protocol.slice(0, -1)
46
- apiUrlOpts.host = apiUrl.host
47
- apiUrlOpts.pathPrefix = NETLIFY_API_URL === `${apiUrl.protocol}//${apiUrl.host}` ? '/api/v1' : apiUrl.pathname
48
- }
49
-
50
- const cachedConfig = await this.getConfig({ cwd, state, token, ...apiUrlOpts })
51
- const { buildDir, config, configPath, repositoryRoot, siteInfo } = cachedConfig
52
- const normalizedConfig = normalizeConfig(config)
53
-
54
- const { flags } = this.parse(BaseCommand)
55
- const agent = await getAgent({
56
- httpProxy: flags.httpProxy,
57
- certificateFile: flags.httpProxyCertificateFilename,
58
- })
59
- const apiOpts = { ...apiUrlOpts, agent }
60
- const globalConfig = await getGlobalConfig()
61
-
62
- const { NetlifyAPI } = await jsClient
63
- this.netlify = {
64
- // api methods
65
- api: new NetlifyAPI(token || '', apiOpts),
66
- repositoryRoot,
67
- // current site context
68
- site: {
69
- root: buildDir,
70
- configPath,
71
- get id() {
72
- return state.get('siteId')
73
- },
74
- set id(id) {
75
- state.set('siteId', id)
76
- },
77
- },
78
- // Site information retrieved using the API
79
- siteInfo,
80
- // Configuration from netlify.[toml/yml]
81
- config: normalizedConfig,
82
- // Used to avoid calling @netlify/config again
83
- cachedConfig,
84
- // global cli config
85
- globalConfig,
86
- // state of current site dir
87
- state,
88
- }
89
- }
90
-
91
- // Find and resolve the Netlify configuration
92
- async getConfig({ cwd, host, offline = argv.offline || argv.o, pathPrefix, scheme, state, token }) {
93
- try {
94
- return await resolveConfig({
95
- config: argv.config,
96
- cwd,
97
- context: argv.context || this.commandContext,
98
- debug: argv.debug,
99
- siteId: argv.siteId || (typeof argv.site === 'string' && argv.site) || state.get('siteId'),
100
- token,
101
- mode: 'cli',
102
- host,
103
- pathPrefix,
104
- scheme,
105
- offline,
106
- })
107
- } catch (error_) {
108
- const isUserError = error_.customErrorInfo !== undefined && error_.customErrorInfo.type === 'resolveConfig'
109
-
110
- // If we're failing due to an error thrown by us, it might be because the token we're using is invalid.
111
- // To account for that, we try to retrieve the config again, this time without a token, to avoid making
112
- // any API calls.
113
- //
114
- // @todo Replace this with a mechanism for calling `resolveConfig` with more granularity (i.e. having
115
- // the option to say that we don't need API data.)
116
- if (isUserError && !offline && token) {
117
- return this.getConfig({ cwd, offline: true, state, token })
118
- }
119
-
120
- const message = isUserError ? error_.message : error_.stack
121
- console.error(message)
122
- exit(1)
123
- }
124
- }
125
-
126
- async isLoggedIn() {
127
- try {
128
- await this.netlify.api.getCurrentUser()
129
- return true
130
- } catch {
131
- return false
132
- }
133
- }
134
-
135
- /* Modified flag parser to support global --auth, --json, & --silent flags */
136
- parse(opts, args = this.argv) {
137
- /* Set flags object for commands without flags */
138
- if (!opts.flags) {
139
- opts.flags = {}
140
- }
141
- /* enrich parse with global flags */
142
- const globalFlags = {}
143
- if (!opts.flags.silent) {
144
- globalFlags.silent = {
145
- parse: (value) => value,
146
- description: 'Silence CLI output',
147
- allowNo: false,
148
- type: 'boolean',
149
- }
150
- }
151
- if (!opts.flags.json) {
152
- globalFlags.json = {
153
- parse: (value) => value,
154
- description: 'Output return values as JSON',
155
- allowNo: false,
156
- type: 'boolean',
157
- }
158
- }
159
- if (!opts.flags.auth) {
160
- globalFlags.auth = {
161
- parse: (value) => value,
162
- description: 'Netlify auth token',
163
- input: [],
164
- multiple: false,
165
- type: 'option',
166
- }
167
- }
168
-
169
- // enrich with flags here
170
- opts.flags = { ...opts.flags, ...globalFlags }
171
-
172
- return oclifParser.parse(args, {
173
- context: this,
174
- ...opts,
175
- })
176
- }
177
-
178
- async authenticate(tokenFromFlag) {
179
- const [token] = await getToken(tokenFromFlag)
180
- if (token) {
181
- return token
182
- }
183
- return this.expensivelyAuthenticate()
184
- }
185
-
186
- async expensivelyAuthenticate() {
187
- const webUI = process.env.NETLIFY_WEB_UI || 'https://app.netlify.com'
188
- log(`Logging into your Netlify account...`)
189
-
190
- // Create ticket for auth
191
- const ticket = await this.netlify.api.createTicket({
192
- clientId: CLIENT_ID,
193
- })
194
-
195
- // Open browser for authentication
196
- const authLink = `${webUI}/authorize?response_type=ticket&ticket=${ticket.id}`
197
-
198
- log(`Opening ${authLink}`)
199
- await openBrowser({ url: authLink })
200
-
201
- const accessToken = await pollForToken({
202
- api: this.netlify.api,
203
- ticket,
204
- exitWithError: error,
205
- })
206
-
207
- const { email, full_name: name, id: userId } = await this.netlify.api.getCurrentUser()
208
-
209
- const userData = merge(this.netlify.globalConfig.get(`users.${userId}`), {
210
- id: userId,
211
- name,
212
- email,
213
- auth: {
214
- token: accessToken,
215
- github: {
216
- user: undefined,
217
- token: undefined,
218
- },
219
- },
220
- })
221
- // Set current userId
222
- this.netlify.globalConfig.set('userId', userId)
223
- // Set user data
224
- this.netlify.globalConfig.set(`users.${userId}`, userData)
225
-
226
- await identify({
227
- name,
228
- email,
229
- userId,
230
- })
231
- await track('user_login', {
232
- email,
233
- })
234
-
235
- // Log success
236
- log()
237
- log(`${chalk.greenBright('You are now logged into your Netlify account!')}`)
238
- log()
239
- log(`Run ${chalk.cyanBright('netlify status')} for account details`)
240
- log()
241
- log(`To see all available commands run: ${chalk.cyanBright('netlify help')}`)
242
- log()
243
- return accessToken
244
- }
245
- }
246
-
247
- BaseCommand.strict = false
248
- BaseCommand.flags = {
249
- debug: flagsLib.boolean({
250
- description: 'Print debugging information',
251
- }),
252
- httpProxy: flagsLib.string({
253
- description: 'Proxy server address to route requests through.',
254
- default: process.env.HTTP_PROXY || process.env.HTTPS_PROXY,
255
- }),
256
- httpProxyCertificateFilename: flagsLib.string({
257
- description: 'Certificate file to use when connecting using a proxy server',
258
- default: process.env.NETLIFY_PROXY_CERTIFICATE_FILENAME,
259
- }),
260
- }
261
-
262
- module.exports = BaseCommand
@@ -1,25 +0,0 @@
1
- const fs = require('fs')
2
- const path = require('path')
3
-
4
- const detectFunctionsBuilder = async function (parameters) {
5
- const buildersPath = path.join(__dirname, '..', 'lib', 'functions', 'runtimes', 'js', 'builders')
6
- const detectors = fs
7
- .readdirSync(buildersPath)
8
- // only accept .js detector files
9
- .filter((filename) => filename.endsWith('.js'))
10
- // Sorting by filename
11
- .sort()
12
- // eslint-disable-next-line node/global-require, import/no-dynamic-require
13
- .map((det) => require(path.join(buildersPath, det)))
14
-
15
- // eslint-disable-next-line fp/no-loops
16
- for (const detector of detectors) {
17
- // eslint-disable-next-line no-await-in-loop
18
- const settings = await detector(parameters)
19
- if (settings) {
20
- return settings
21
- }
22
- }
23
- }
24
-
25
- module.exports = { detectFunctionsBuilder }
@@ -1,4 +0,0 @@
1
- // Returns a new set with all elements of `setA` that don't exist in `setB`.
2
- const difference = (setA, setB) => new Set([...setA].filter((item) => !setB.has(item)))
3
-
4
- module.exports = { difference }
package/src/utils/logo.js DELETED
@@ -1,11 +0,0 @@
1
- const chalk = require('chalk')
2
-
3
- // eslint-disable-next-line no-magic-numbers
4
- const NETLIFY_CYAN = chalk.rgb(40, 180, 170)
5
-
6
- module.exports = {
7
- NETLIFYDEV: `${chalk.greenBright('◈')} ${NETLIFY_CYAN('Netlify Dev')} ${chalk.greenBright('◈')}`,
8
- NETLIFYDEVLOG: `${chalk.greenBright('◈')}`,
9
- NETLIFYDEVWARN: `${chalk.yellowBright('◈')}`,
10
- NETLIFYDEVERR: `${chalk.redBright('◈')}`,
11
- }
@@ -1,5 +0,0 @@
1
- const { execSync } = require('child_process')
2
-
3
- module.exports = function showHelp(command) {
4
- execSync(`netlify ${command} --help`, { stdio: [0, 1, 2] })
5
- }
@@ -1,51 +0,0 @@
1
- const { hrtime } = require('process')
2
-
3
- const { Command } = require('@oclif/command')
4
- const { ExitError } = require('@oclif/errors')
5
-
6
- const { track } = require('.')
7
-
8
- const NANO_SECS_TO_MSECS = 1e6
9
-
10
- const getDuration = function (startTime) {
11
- const durationNs = hrtime.bigint() - startTime
12
- return Math.round(Number(durationNs / BigInt(NANO_SECS_TO_MSECS)))
13
- }
14
-
15
- const isSafeError = function (error) {
16
- // The `exit` oclif utility returns an ExitError even when the exit code is 0
17
- return error instanceof ExitError && error.oclif && error.oclif.exit === 0
18
- }
19
-
20
- const getStatus = function (error) {
21
- if (error === undefined || isSafeError(error)) {
22
- return 'success'
23
- }
24
-
25
- return 'error'
26
- }
27
-
28
- class TrackedCommand extends Command {
29
- async init() {
30
- this.analytics = { startTime: hrtime.bigint() }
31
- await super.init()
32
- }
33
-
34
- setAnalyticsPayload(payload) {
35
- this.analytics = { ...this.analytics, payload }
36
- }
37
-
38
- async finally(error) {
39
- const { payload, startTime } = this.analytics
40
- const duration = getDuration(startTime)
41
- const status = getStatus(error)
42
- await track('command', {
43
- ...payload,
44
- command: this.id,
45
- duration,
46
- status,
47
- })
48
- }
49
- }
50
-
51
- module.exports = { TrackedCommand }