netlify-cli 9.16.6 → 10.0.0

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 (38) hide show
  1. package/README.md +10 -1
  2. package/npm-shrinkwrap.json +955 -3430
  3. package/package.json +6 -5
  4. package/src/commands/base-command.js +1 -2
  5. package/src/commands/deploy/deploy.js +0 -7
  6. package/src/commands/dev/dev.js +33 -46
  7. package/src/commands/main.js +3 -0
  8. package/src/commands/recipes/common.js +33 -0
  9. package/src/commands/recipes/index.js +8 -0
  10. package/src/commands/recipes/recipes-list.js +34 -0
  11. package/src/commands/recipes/recipes.js +85 -0
  12. package/src/functions-templates/go/hello-world/go.mod +1 -1
  13. package/src/functions-templates/go/scheduled-function/go.mod +1 -1
  14. package/src/functions-templates/javascript/stripe-charge/package-lock.json +6 -6
  15. package/src/functions-templates/javascript/stripe-subscription/package-lock.json +6 -6
  16. package/src/functions-templates/typescript/hello-world/package-lock.json +6 -6
  17. package/src/lib/api.js +1 -72
  18. package/src/lib/edge-functions/consts.js +21 -0
  19. package/src/lib/edge-functions/deploy.js +41 -0
  20. package/src/lib/edge-functions/editor-helper.js +41 -0
  21. package/src/lib/edge-functions/headers.js +6 -0
  22. package/src/lib/edge-functions/index.js +7 -0
  23. package/src/lib/edge-functions/internal.js +75 -0
  24. package/src/lib/edge-functions/proxy.js +133 -0
  25. package/src/lib/edge-functions/registry.js +312 -0
  26. package/src/lib/functions/registry.js +1 -1
  27. package/src/recipes/vscode/index.js +61 -0
  28. package/src/recipes/vscode/settings.js +66 -0
  29. package/src/utils/command-helpers.js +10 -0
  30. package/src/utils/deploy/deploy-site.js +26 -4
  31. package/src/utils/deploy/hash-files.js +12 -7
  32. package/src/utils/deploy/hasher-segments.js +10 -2
  33. package/src/utils/functions/index.js +3 -2
  34. package/src/utils/index.js +0 -2
  35. package/src/utils/proxy.js +86 -12
  36. package/src/commands/dev/dev-trace.js +0 -47
  37. package/src/utils/functions/edge-handlers.js +0 -88
  38. package/src/utils/traffic-mesh.js +0 -219
@@ -1,219 +0,0 @@
1
- // @ts-check
2
- const { EOL } = require('os')
3
- const path = require('path')
4
- const process = require('process')
5
- const rl = require('readline')
6
-
7
- const { getBinaryPath } = require('@netlify/routing-local-proxy')
8
- const waitPort = require('wait-port')
9
-
10
- const { getPathInProject } = require('../lib/settings')
11
- const { clearSpinner, startSpinner, stopSpinner } = require('../lib/spinner')
12
-
13
- const { NETLIFYDEVERR, NETLIFYDEVLOG, NETLIFYDEVWARN, log } = require('./command-helpers')
14
- const { createDeferred } = require('./deferred')
15
- const execa = require('./execa')
16
-
17
- const EDGE_HANDLERS_BUNDLER_CLI_PATH = path.resolve(require.resolve('@netlify/plugin-edge-handlers'), '..', 'cli.js')
18
-
19
- const startForwardProxy = async ({
20
- debug,
21
- frameworkPort,
22
- functionsPort,
23
- jwtRolesPath,
24
- jwtSecret,
25
- locationDb,
26
- port,
27
- publishDir,
28
- }) => {
29
- const args = [
30
- 'run',
31
- '--port',
32
- port,
33
- '--forward-proxy',
34
- `http://localhost:${frameworkPort}`,
35
- '--watch',
36
- publishDir,
37
- '--bundler',
38
- EDGE_HANDLERS_BUNDLER_CLI_PATH,
39
- '--log-file',
40
- getPathInProject(['logs', 'traffic-mesh.log']),
41
- '--progress',
42
- ]
43
-
44
- if (functionsPort) {
45
- args.push('--local-services-uri', `http://localhost:${functionsPort}`)
46
- }
47
-
48
- if (debug) {
49
- args.push('--debug')
50
- }
51
-
52
- if (locationDb) {
53
- args.push('--geo', locationDb)
54
- }
55
-
56
- if (jwtRolesPath) {
57
- args.push('--jwt-roles-path', jwtRolesPath)
58
- }
59
-
60
- if (jwtSecret) {
61
- args.push('--signature-secret', jwtSecret)
62
- }
63
-
64
- const { subprocess } = runProcess({ args })
65
- const { firstBundleReady, forwarder } = forwardMessagesToLog({ subprocess })
66
-
67
- subprocess.on('close', process.exit)
68
- subprocess.on('SIGINT', process.exit)
69
- subprocess.on('SIGTERM', process.exit)
70
- ;['SIGINT', 'SIGTERM', 'SIGQUIT', 'SIGHUP', 'exit'].forEach((signal) => {
71
- process.on(signal, () => {
72
- forwarder.close()
73
-
74
- const sig = signal === 'exit' ? 'SIGTERM' : signal
75
- subprocess.kill(sig, {
76
- forceKillAfterTimeout: PROXY_EXIT_TIMEOUT,
77
- })
78
- })
79
- })
80
-
81
- // Wait until the first traffic-mesh bundle is ready
82
- //
83
- // In case of errors, this delays the startup process until the errors are fixed
84
- await firstBundleReady
85
-
86
- try {
87
- const open = await waitPort({ port, output: 'silent', timeout: PROXY_READY_TIMEOUT })
88
- if (!open) {
89
- throw new Error(`Timed out waiting for forward proxy to be ready on port '${port}'`)
90
- }
91
- return `http://localhost:${port}`
92
- } catch (error) {
93
- log(`${NETLIFYDEVERR}`, error)
94
- }
95
- }
96
-
97
- const forwardMessagesToLog = ({ subprocess }) => {
98
- const { promise: firstBundleReady, reject: firstBundleReject, resolve: firstBundleResolve } = createDeferred()
99
-
100
- let currentId = null
101
- let lastError = null
102
- let lastWasSuccess = false
103
- let spinner = null
104
-
105
- const reset = () => {
106
- currentId = null
107
- spinner = null
108
- }
109
-
110
- const forwarder = rl.createInterface({
111
- input: subprocess.stderr,
112
- })
113
-
114
- forwarder
115
- .on('line', (line) => {
116
- let data
117
- try {
118
- data = JSON.parse(line.trim())
119
- } catch (error) {
120
- log(`${NETLIFYDEVERR} Cannot parse log line as JSON: ${line.trim()}${EOL}${EOL}${error}`)
121
- return
122
- }
123
-
124
- const { error, id, type } = data
125
- switch (type) {
126
- case 'bundle:start':
127
- currentId = id
128
- if (!spinner) {
129
- spinner = startSpinner({ text: 'Processing request remaps, header rules and Edge Handlers...' })
130
- }
131
- break
132
-
133
- case 'bundle:success':
134
- if (currentId !== id) {
135
- return
136
- }
137
-
138
- // Clear spinner if there already is a log line indicating success above,
139
- // instead of appending another line of "Yay, your project was bundled!"
140
- if (lastWasSuccess) {
141
- clearSpinner({ spinner })
142
- } else {
143
- stopSpinner({
144
- spinner,
145
- error: false,
146
- text: 'Done processing request remaps, header rules and Edge Handlers',
147
- })
148
- }
149
- lastWasSuccess = true
150
- lastError = null
151
-
152
- firstBundleResolve()
153
- reset()
154
- break
155
-
156
- case 'bundle:fail': {
157
- if (currentId !== id) {
158
- return
159
- }
160
-
161
- // Only show the error if it's new
162
- const errorMsg = (error && error.msg) || 'Failed processing request remaps, header rules or Edge Handlers'
163
- if (errorMsg === lastError) {
164
- clearSpinner({ spinner })
165
- } else {
166
- stopSpinner({
167
- spinner,
168
- error: true,
169
- text: errorMsg,
170
- })
171
- log(
172
- `${NETLIFYDEVLOG} Change any project configuration file (netlify.toml, _headers, _redirects) or any Edge Handlers file to trigger a re-bundle`,
173
- )
174
- }
175
-
176
- lastWasSuccess = false
177
- lastError = errorMsg
178
- reset()
179
- break
180
- }
181
-
182
- default:
183
- log(`${NETLIFYDEVWARN} Unknown routing-local-proxy event '${type}'`)
184
- break
185
- }
186
- })
187
- .on('close', () => {
188
- if (spinner) {
189
- // Hide the spinner
190
- spinner.stop()
191
- }
192
-
193
- reset()
194
- })
195
- .on('error', (err) => {
196
- stopSpinner({
197
- spinner,
198
- error: true,
199
- text: `${NETLIFYDEVERR} An error occurred while bundling processing the messages from routing-local-proxy: ${err}`,
200
- })
201
-
202
- firstBundleReject(err)
203
- reset()
204
- })
205
-
206
- return { forwarder, firstBundleReady }
207
- }
208
-
209
- // 30 seconds
210
- const PROXY_READY_TIMEOUT = 3e4
211
- // 2 seconds
212
- const PROXY_EXIT_TIMEOUT = 2e3
213
-
214
- const runProcess = ({ args }) => {
215
- const subprocess = execa(getBinaryPath(), args, { stdio: ['inherit', 'inherit', 'pipe'] })
216
- return { subprocess }
217
- }
218
-
219
- module.exports = { runProcess, startForwardProxy }