netlify-cli 12.2.9 → 12.2.11
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.
- package/npm-shrinkwrap.json +255 -1458
- package/package.json +3 -7
- package/src/commands/addons/addons-auth.mjs +2 -3
- package/src/commands/addons/addons-config.mjs +2 -3
- package/src/commands/addons/addons-create.mjs +2 -3
- package/src/commands/addons/addons-delete.mjs +1 -3
- package/src/commands/addons/addons-list.mjs +1 -3
- package/src/commands/api/api.mjs +1 -3
- package/src/commands/base-command.mjs +3 -3
- package/src/commands/build/build.mjs +3 -3
- package/src/commands/deploy/deploy.mjs +13 -16
- package/src/commands/dev/dev-exec.mjs +2 -3
- package/src/commands/dev/dev.mjs +15 -21
- package/src/commands/env/env-clone.mjs +2 -3
- package/src/commands/env/env-get.mjs +2 -3
- package/src/commands/env/env-import.mjs +2 -3
- package/src/commands/env/env-list.mjs +2 -4
- package/src/commands/env/env-set.mjs +3 -8
- package/src/commands/env/env-unset.mjs +2 -3
- package/src/commands/functions/functions-build.mjs +1 -3
- package/src/commands/functions/functions-create.mjs +3 -3
- package/src/commands/functions/functions-invoke.mjs +1 -3
- package/src/commands/functions/functions-list.mjs +1 -3
- package/src/commands/functions/functions-serve.mjs +1 -2
- package/src/commands/functions/functions.mjs +1 -1
- package/src/commands/graph/graph-config-write.mjs +1 -3
- package/src/commands/graph/graph-edit.mjs +2 -3
- package/src/commands/graph/graph-handler.mjs +1 -3
- package/src/commands/graph/graph-init.mjs +2 -3
- package/src/commands/graph/graph-library.mjs +1 -3
- package/src/commands/graph/graph-operations.mjs +1 -3
- package/src/commands/graph/graph-pull.mjs +1 -3
- package/src/commands/init/init.mjs +2 -4
- package/src/commands/link/link.mjs +1 -3
- package/src/commands/lm/lm-setup.mjs +2 -3
- package/src/commands/login/login.mjs +1 -3
- package/src/commands/logout/logout.mjs +1 -3
- package/src/commands/main.mjs +3 -3
- package/src/commands/open/open-admin.mjs +2 -3
- package/src/commands/open/open-site.mjs +2 -3
- package/src/commands/open/open.mjs +1 -3
- package/src/commands/recipes/recipes.mjs +3 -3
- package/src/commands/sites/sites-create-template.mjs +7 -8
- package/src/commands/sites/sites-create.mjs +2 -4
- package/src/commands/sites/sites-delete.mjs +1 -3
- package/src/commands/sites/sites-list.mjs +1 -3
- package/src/commands/status/status-hooks.mjs +1 -3
- package/src/commands/status/status.mjs +1 -3
- package/src/commands/switch/switch.mjs +1 -3
- package/src/commands/unlink/unlink.mjs +1 -3
- package/src/commands/watch/watch.mjs +1 -3
- package/src/lib/account.mjs +14 -0
- package/src/lib/api.mjs +1 -1
- package/src/lib/completion/generate-autocompletion.mjs +1 -1
- package/src/lib/edge-functions/consts.mjs +4 -0
- package/src/lib/edge-functions/{deploy.cjs → deploy.mjs} +7 -13
- package/src/lib/edge-functions/{headers.cjs → headers.mjs} +3 -1
- package/src/lib/edge-functions/{internal.cjs → internal.mjs} +24 -20
- package/src/lib/edge-functions/{proxy.cjs → proxy.mjs} +18 -20
- package/src/lib/edge-functions/{registry.cjs → registry.mjs} +16 -7
- package/src/lib/{exec-fetcher.cjs → exec-fetcher.mjs} +17 -12
- package/src/lib/functions/{background.cjs → background.mjs} +4 -6
- package/src/lib/functions/{config.cjs → config.mjs} +1 -3
- package/src/lib/functions/form-submissions-handler.mjs +2 -2
- package/src/lib/functions/{local-proxy.cjs → local-proxy.mjs} +4 -6
- package/src/lib/functions/{memoized-build.cjs → memoized-build.mjs} +1 -3
- package/src/lib/functions/{netlify-function.cjs → netlify-function.mjs} +5 -8
- package/src/lib/functions/{registry.cjs → registry.mjs} +12 -14
- package/src/lib/functions/runtimes/go/{index.cjs → index.mjs} +10 -10
- package/src/lib/functions/runtimes/{index.cjs → index.mjs} +12 -7
- package/src/lib/functions/runtimes/js/builders/{netlify-lambda.cjs → netlify-lambda.mjs} +13 -10
- package/src/lib/functions/runtimes/js/builders/{zisi.cjs → zisi.mjs} +15 -13
- package/src/lib/functions/runtimes/js/{index.cjs → index.mjs} +12 -12
- package/src/lib/functions/runtimes/rust/{index.cjs → index.mjs} +15 -15
- package/src/lib/functions/scheduled.mjs +1 -1
- package/src/lib/functions/server.mjs +6 -7
- package/src/lib/functions/{synchronous.cjs → synchronous.mjs} +5 -7
- package/src/lib/functions/{utils.cjs → utils.mjs} +6 -21
- package/src/lib/{geo-location.cjs → geo-location.mjs} +3 -5
- package/src/lib/http-agent.mjs +1 -1
- package/src/lib/{log.cjs → log.mjs} +3 -7
- package/src/lib/one-graph/cli-client.mjs +2 -2
- package/src/lib/one-graph/cli-netlify-graph.mjs +2 -3
- package/src/lib/path.mjs +1 -0
- package/src/lib/{render-error-remplate.cjs → render-error-template.mjs} +8 -4
- package/src/lib/{string.cjs → string.mjs} +1 -3
- package/src/recipes/vscode/index.mjs +1 -1
- package/src/utils/addons/diffs/options.mjs +1 -1
- package/src/utils/addons/prepare.mjs +1 -1
- package/src/utils/addons/prompts.mjs +1 -1
- package/src/utils/addons/render.mjs +1 -1
- package/src/utils/{command-helpers.cjs → command-helpers.mjs} +45 -64
- package/src/utils/{deferred.cjs → create-deferred.mjs} +1 -1
- package/src/utils/deploy/constants.mjs +19 -0
- package/src/utils/deploy/{deploy-site.cjs → deploy-site.mjs} +15 -17
- package/src/utils/deploy/{hash-files.cjs → hash-files.mjs} +7 -5
- package/src/utils/deploy/{hash-fns.cjs → hash-fns.mjs} +11 -8
- package/src/utils/deploy/{hasher-segments.cjs → hasher-segments.mjs} +10 -17
- package/src/utils/deploy/{upload-files.cjs → upload-files.mjs} +5 -5
- package/src/utils/deploy/{util.cjs → util.mjs} +8 -20
- package/src/utils/detect-server-settings.mjs +2 -2
- package/src/utils/{dev.cjs → dev.mjs} +13 -21
- package/src/utils/{dot-env.cjs → dot-env.mjs} +7 -9
- package/src/utils/env/{index.cjs → index.mjs} +11 -24
- package/src/utils/execa.mjs +17 -0
- package/src/utils/get-global-config.mjs +40 -0
- package/src/utils/get-repo-data.mjs +1 -1
- package/src/utils/{gh-auth.cjs → gh-auth.mjs} +10 -12
- package/src/utils/gitignore.mjs +1 -1
- package/src/utils/{headers.cjs → headers.mjs} +4 -11
- package/src/utils/init/{config-github.cjs → config-github.mjs} +6 -8
- package/src/utils/init/{config-manual.cjs → config-manual.mjs} +4 -4
- package/src/utils/init/{config.cjs → config.mjs} +4 -5
- package/src/utils/init/{frameworks.cjs → frameworks.mjs} +2 -5
- package/src/utils/init/{node-version.cjs → node-version.mjs} +6 -8
- package/src/utils/init/{plugins.cjs → plugins.mjs} +3 -5
- package/src/utils/init/{utils.cjs → utils.mjs} +27 -23
- package/src/utils/live-tunnel.mjs +3 -3
- package/src/utils/lm/install.mjs +3 -3
- package/src/utils/lm/requirements.mjs +1 -1
- package/src/utils/lm/steps.mjs +1 -1
- package/src/utils/lm/ui.mjs +1 -1
- package/src/utils/{open-browser.cjs → open-browser.mjs} +5 -5
- package/src/utils/{parse-raw-flags.cjs → parse-raw-flags.mjs} +2 -7
- package/src/utils/proxy.mjs +14 -10
- package/src/utils/{redirects.cjs → redirects.mjs} +3 -7
- package/src/utils/{rules-proxy.cjs → rules-proxy.mjs} +19 -19
- package/src/utils/sites/{utils.cjs → utils.mjs} +6 -6
- package/src/utils/telemetry/telemetry.mjs +2 -2
- package/src/utils/telemetry/validation.mjs +1 -1
- package/src/lib/account.cjs +0 -9
- package/src/lib/edge-functions/consts.cjs +0 -11
- package/src/lib/edge-functions/index.cjs +0 -6
- package/src/lib/path.cjs +0 -3
- package/src/utils/deploy/constants.cjs +0 -31
- package/src/utils/deploy/index.cjs +0 -4
- package/src/utils/execa.cjs +0 -12
- package/src/utils/get-global-config.cjs +0 -47
- package/src/utils/index.cjs +0 -22
|
@@ -3,7 +3,7 @@ import { join } from 'path'
|
|
|
3
3
|
import execa from 'execa'
|
|
4
4
|
import inquirer from 'inquirer'
|
|
5
5
|
|
|
6
|
-
import { NETLIFYDEVLOG, NETLIFYDEVWARN, chalk, error, log } from '../../utils/command-helpers.
|
|
6
|
+
import { NETLIFYDEVLOG, NETLIFYDEVWARN, chalk, error, log } from '../../utils/command-helpers.mjs'
|
|
7
7
|
|
|
8
8
|
import { applySettings, getSettings, writeSettings } from './settings.mjs'
|
|
9
9
|
|
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { once } from 'events'
|
|
3
|
+
import os from 'os'
|
|
4
|
+
import process from 'process'
|
|
5
|
+
import { format, inspect } from 'util'
|
|
6
6
|
|
|
7
|
-
// eslint-disable-next-line no-restricted-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const terminalLink = require('terminal-link')
|
|
7
|
+
// eslint-disable-next-line no-restricted-imports
|
|
8
|
+
import chalkModule from 'chalk'
|
|
9
|
+
import chokidar from 'chokidar'
|
|
10
|
+
import decache from 'decache'
|
|
11
|
+
import WSL from 'is-wsl'
|
|
12
|
+
import debounce from 'lodash/debounce.js'
|
|
13
|
+
import terminalLink from 'terminal-link'
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
const { clearSpinner, startSpinner } = require('../lib/spinner.cjs')
|
|
15
|
+
import { clearSpinner, startSpinner } from '../lib/spinner.cjs'
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
import getGlobalConfig from './get-global-config.mjs'
|
|
18
|
+
import getPackageJson from './get-package-json.mjs'
|
|
20
19
|
|
|
21
20
|
/** The parsed process argv without the binary only arguments and flags */
|
|
22
21
|
const argv = process.argv.slice(2)
|
|
@@ -28,13 +27,13 @@ const argv = process.argv.slice(2)
|
|
|
28
27
|
*/
|
|
29
28
|
const safeChalk = function (noColors) {
|
|
30
29
|
if (noColors) {
|
|
31
|
-
const colorlessChalk = new
|
|
30
|
+
const colorlessChalk = new chalkModule.Instance({ level: 0 })
|
|
32
31
|
return colorlessChalk
|
|
33
32
|
}
|
|
34
|
-
return new
|
|
33
|
+
return new chalkModule.Instance()
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
const chalk = safeChalk(argv.includes('--json'))
|
|
36
|
+
export const chalk = safeChalk(argv.includes('--json'))
|
|
38
37
|
|
|
39
38
|
/**
|
|
40
39
|
* Adds the filler to the start of the string
|
|
@@ -43,24 +42,26 @@ const chalk = safeChalk(argv.includes('--json'))
|
|
|
43
42
|
* @param {string} [filler]
|
|
44
43
|
* @returns {string}
|
|
45
44
|
*/
|
|
46
|
-
const padLeft = (str, count, filler = ' ') => str.padStart(str.length + count, filler)
|
|
45
|
+
export const padLeft = (str, count, filler = ' ') => str.padStart(str.length + count, filler)
|
|
47
46
|
|
|
48
47
|
const platform = WSL ? 'wsl' : os.platform()
|
|
49
48
|
const arch = os.arch() === 'ia32' ? 'x86' : os.arch()
|
|
50
49
|
|
|
51
|
-
const
|
|
50
|
+
const { name, version } = await getPackageJson()
|
|
51
|
+
|
|
52
|
+
export const USER_AGENT = `${name}/${version} ${platform}-${arch} node-${process.version}`
|
|
52
53
|
|
|
53
54
|
/** A list of base command flags that needs to be sorted down on documentation and on help pages */
|
|
54
55
|
const BASE_FLAGS = new Set(['--debug', '--httpProxy', '--httpProxyCertificateFilename'])
|
|
55
56
|
|
|
56
|
-
const NETLIFY_CYAN = chalk.rgb(40, 180, 170)
|
|
57
|
+
export const NETLIFY_CYAN = chalk.rgb(40, 180, 170)
|
|
57
58
|
|
|
58
|
-
const NETLIFYDEV = `${chalk.greenBright('◈')} ${NETLIFY_CYAN('Netlify Dev')} ${chalk.greenBright('◈')}`
|
|
59
|
-
const NETLIFYDEVLOG = `${chalk.greenBright('◈')}`
|
|
60
|
-
const NETLIFYDEVWARN = `${chalk.yellowBright('◈')}`
|
|
61
|
-
const NETLIFYDEVERR = `${chalk.redBright('◈')}`
|
|
59
|
+
export const NETLIFYDEV = `${chalk.greenBright('◈')} ${NETLIFY_CYAN('Netlify Dev')} ${chalk.greenBright('◈')}`
|
|
60
|
+
export const NETLIFYDEVLOG = `${chalk.greenBright('◈')}`
|
|
61
|
+
export const NETLIFYDEVWARN = `${chalk.yellowBright('◈')}`
|
|
62
|
+
export const NETLIFYDEVERR = `${chalk.redBright('◈')}`
|
|
62
63
|
|
|
63
|
-
const BANG = process.platform === 'win32' ? '»' : '›'
|
|
64
|
+
export const BANG = process.platform === 'win32' ? '»' : '›'
|
|
64
65
|
|
|
65
66
|
/**
|
|
66
67
|
* Sorts two options so that the base flags are at the bottom of the list
|
|
@@ -70,7 +71,7 @@ const BANG = process.platform === 'win32' ? '»' : '›'
|
|
|
70
71
|
* @example
|
|
71
72
|
* options.sort(sortOptions)
|
|
72
73
|
*/
|
|
73
|
-
const sortOptions = (optionA, optionB) => {
|
|
74
|
+
export const sortOptions = (optionA, optionB) => {
|
|
74
75
|
// base flags should be always at the bottom
|
|
75
76
|
if (BASE_FLAGS.has(optionA.long) || BASE_FLAGS.has(optionB.long)) {
|
|
76
77
|
return -1
|
|
@@ -88,7 +89,7 @@ const TOKEN_TIMEOUT = 3e5
|
|
|
88
89
|
* @param {object} config.ticket
|
|
89
90
|
* @returns
|
|
90
91
|
*/
|
|
91
|
-
const pollForToken = async ({ api, ticket }) => {
|
|
92
|
+
export const pollForToken = async ({ api, ticket }) => {
|
|
92
93
|
const spinner = startSpinner({ text: 'Waiting for authorization...' })
|
|
93
94
|
try {
|
|
94
95
|
const accessToken = await api.getAccessToken(ticket, { timeout: TOKEN_TIMEOUT })
|
|
@@ -118,7 +119,7 @@ const pollForToken = async ({ api, ticket }) => {
|
|
|
118
119
|
* @param {string} [tokenFromOptions] optional token from the provided --auth options
|
|
119
120
|
* @returns {Promise<[null|string, 'flag' | 'env' |'config' |'not found']>}
|
|
120
121
|
*/
|
|
121
|
-
const getToken = async (tokenFromOptions) => {
|
|
122
|
+
export const getToken = async (tokenFromOptions) => {
|
|
122
123
|
// 1. First honor command flag --auth
|
|
123
124
|
if (tokenFromOptions) {
|
|
124
125
|
return [tokenFromOptions, 'flag']
|
|
@@ -146,13 +147,13 @@ const isDefaultJson = () => argv[0] === 'functions:invoke' || (argv[0] === 'api'
|
|
|
146
147
|
* logs a json message
|
|
147
148
|
* @param {string|object} message
|
|
148
149
|
*/
|
|
149
|
-
const logJson = (message = '') => {
|
|
150
|
+
export const logJson = (message = '') => {
|
|
150
151
|
if (argv.includes('--json') || isDefaultJson()) {
|
|
151
152
|
process.stdout.write(JSON.stringify(message, null, 2))
|
|
152
153
|
}
|
|
153
154
|
}
|
|
154
155
|
|
|
155
|
-
const log = (message = '', ...args) => {
|
|
156
|
+
export const log = (message = '', ...args) => {
|
|
156
157
|
// If --silent or --json flag passed disable logger
|
|
157
158
|
if (argv.includes('--json') || argv.includes('--silent') || isDefaultJson()) {
|
|
158
159
|
return
|
|
@@ -165,7 +166,7 @@ const log = (message = '', ...args) => {
|
|
|
165
166
|
* logs a warning message
|
|
166
167
|
* @param {string} message
|
|
167
168
|
*/
|
|
168
|
-
const warn = (message = '') => {
|
|
169
|
+
export const warn = (message = '') => {
|
|
169
170
|
const bang = chalk.yellow(BANG)
|
|
170
171
|
log(` ${bang} Warning: ${message}`)
|
|
171
172
|
}
|
|
@@ -176,7 +177,7 @@ const warn = (message = '') => {
|
|
|
176
177
|
* @param {object} [options]
|
|
177
178
|
* @param {boolean} [options.exit]
|
|
178
179
|
*/
|
|
179
|
-
const error = (message = '', options = {}) => {
|
|
180
|
+
export const error = (message = '', options = {}) => {
|
|
180
181
|
const err = message instanceof Error ? message : new Error(message)
|
|
181
182
|
if (options.exit === false) {
|
|
182
183
|
const bang = chalk.red(BANG)
|
|
@@ -190,18 +191,21 @@ const error = (message = '', options = {}) => {
|
|
|
190
191
|
}
|
|
191
192
|
}
|
|
192
193
|
|
|
193
|
-
const exit = (code = 0) => {
|
|
194
|
+
export const exit = (code = 0) => {
|
|
194
195
|
process.exit(code)
|
|
195
196
|
}
|
|
196
197
|
|
|
197
198
|
// When `build.publish` is not set by the user, the CLI behavior differs in
|
|
198
199
|
// several ways. It detects it by checking if `build.publish` is `undefined`.
|
|
199
200
|
// However, `@netlify/config` adds a default value to `build.publish`.
|
|
200
|
-
// This removes
|
|
201
|
-
const normalizeConfig = (config) =>
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
201
|
+
// This removes 'publish' and 'publishOrigin' in this case.
|
|
202
|
+
export const normalizeConfig = (config) => {
|
|
203
|
+
// Unused var here is in order to omit 'publish' from build config
|
|
204
|
+
// eslint-disable-next-line no-unused-vars
|
|
205
|
+
const { publish, publishOrigin, ...build } = config.build
|
|
206
|
+
|
|
207
|
+
return publishOrigin === 'default' ? { ...config, build } : config
|
|
208
|
+
}
|
|
205
209
|
|
|
206
210
|
const DEBOUNCE_WAIT = 100
|
|
207
211
|
|
|
@@ -215,7 +219,7 @@ const DEBOUNCE_WAIT = 100
|
|
|
215
219
|
* @param {() => any} [opts.onChange]
|
|
216
220
|
* @param {() => any} [opts.onUnlink]
|
|
217
221
|
*/
|
|
218
|
-
const watchDebounced = async (target, { depth, onAdd = () => {}, onChange = () => {}, onUnlink = () => {} }) => {
|
|
222
|
+
export const watchDebounced = async (target, { depth, onAdd = () => {}, onChange = () => {}, onUnlink = () => {} }) => {
|
|
219
223
|
const watcher = chokidar.watch(target, { depth, ignored: /node_modules/, ignoreInitial: true })
|
|
220
224
|
|
|
221
225
|
await once(watcher, 'ready')
|
|
@@ -241,27 +245,4 @@ const watchDebounced = async (target, { depth, onAdd = () => {}, onChange = () =
|
|
|
241
245
|
return watcher
|
|
242
246
|
}
|
|
243
247
|
|
|
244
|
-
const getTerminalLink = (text, url) => terminalLink(text, url, { fallback: () => `${text} ${url}` })
|
|
245
|
-
|
|
246
|
-
module.exports = {
|
|
247
|
-
BANG,
|
|
248
|
-
chalk,
|
|
249
|
-
error,
|
|
250
|
-
exit,
|
|
251
|
-
getTerminalLink,
|
|
252
|
-
getToken,
|
|
253
|
-
log,
|
|
254
|
-
logJson,
|
|
255
|
-
NETLIFY_CYAN,
|
|
256
|
-
NETLIFYDEV,
|
|
257
|
-
NETLIFYDEVERR,
|
|
258
|
-
NETLIFYDEVLOG,
|
|
259
|
-
NETLIFYDEVWARN,
|
|
260
|
-
normalizeConfig,
|
|
261
|
-
padLeft,
|
|
262
|
-
pollForToken,
|
|
263
|
-
sortOptions,
|
|
264
|
-
USER_AGENT,
|
|
265
|
-
warn,
|
|
266
|
-
watchDebounced,
|
|
267
|
-
}
|
|
248
|
+
export const getTerminalLink = (text, url) => terminalLink(text, url, { fallback: () => `${text} ${url}` })
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Local deploy timeout in ms: 20 mins
|
|
2
|
+
export const DEFAULT_DEPLOY_TIMEOUT = 1_200_000
|
|
3
|
+
// Concurrent file hash calls
|
|
4
|
+
export const DEFAULT_CONCURRENT_HASH = 100
|
|
5
|
+
// Number of concurrent uploads
|
|
6
|
+
export const DEFAULT_CONCURRENT_UPLOAD = 5
|
|
7
|
+
// Number of files
|
|
8
|
+
export const DEFAULT_SYNC_LIMIT = 100
|
|
9
|
+
// Number of times to retry an upload
|
|
10
|
+
export const DEFAULT_MAX_RETRY = 5
|
|
11
|
+
|
|
12
|
+
export const UPLOAD_RANDOM_FACTOR = 0.5
|
|
13
|
+
// 5 seconds
|
|
14
|
+
export const UPLOAD_INITIAL_DELAY = 5000
|
|
15
|
+
// 1.5 minute (90s)
|
|
16
|
+
export const UPLOAD_MAX_DELAY = 90_000
|
|
17
|
+
|
|
18
|
+
// 1 second
|
|
19
|
+
export const DEPLOY_POLL = 1000
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import cleanDeep from 'clean-deep'
|
|
2
|
+
import tempy from 'tempy'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import { deployFileNormalizer, getDistPathIfExists, isEdgeFunctionFile } from '../../lib/edge-functions/deploy.mjs'
|
|
5
|
+
import { rmdirRecursiveAsync } from '../../lib/fs.cjs'
|
|
6
|
+
import { warn } from '../command-helpers.mjs'
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
import {
|
|
9
9
|
DEFAULT_CONCURRENT_HASH,
|
|
10
10
|
DEFAULT_CONCURRENT_UPLOAD,
|
|
11
11
|
DEFAULT_DEPLOY_TIMEOUT,
|
|
12
12
|
DEFAULT_MAX_RETRY,
|
|
13
13
|
DEFAULT_SYNC_LIMIT,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
} from './constants.mjs'
|
|
15
|
+
import hashFiles from './hash-files.mjs'
|
|
16
|
+
import hashFns from './hash-fns.mjs'
|
|
17
|
+
import uploadFiles from './upload-files.mjs'
|
|
18
|
+
import { getUploadList, waitForDeploy, waitForDiff } from './util.mjs'
|
|
19
19
|
|
|
20
|
-
const deploySite = async (
|
|
20
|
+
export const deploySite = async (
|
|
21
21
|
api,
|
|
22
22
|
siteId,
|
|
23
23
|
dir,
|
|
@@ -54,7 +54,7 @@ const deploySite = async (
|
|
|
54
54
|
phase: 'start',
|
|
55
55
|
})
|
|
56
56
|
|
|
57
|
-
const edgeFunctionsDistPath = await
|
|
57
|
+
const edgeFunctionsDistPath = await getDistPathIfExists({ rootDir })
|
|
58
58
|
const [{ files, filesShaMap }, { fnShaMap, functionSchedules, functions, functionsWithNativeModules }] =
|
|
59
59
|
await Promise.all([
|
|
60
60
|
hashFiles({
|
|
@@ -63,7 +63,7 @@ const deploySite = async (
|
|
|
63
63
|
directories: [configPath, dir, edgeFunctionsDistPath].filter(Boolean),
|
|
64
64
|
filter,
|
|
65
65
|
hashAlgorithm,
|
|
66
|
-
normalizer:
|
|
66
|
+
normalizer: deployFileNormalizer.bind(null, rootDir),
|
|
67
67
|
statusCb,
|
|
68
68
|
}),
|
|
69
69
|
hashFns(fnDir, {
|
|
@@ -79,7 +79,7 @@ const deploySite = async (
|
|
|
79
79
|
siteEnv,
|
|
80
80
|
}),
|
|
81
81
|
])
|
|
82
|
-
const edgeFunctionsCount = Object.keys(files).filter(
|
|
82
|
+
const edgeFunctionsCount = Object.keys(files).filter(isEdgeFunctionFile).length
|
|
83
83
|
const filesCount = Object.keys(files).length - edgeFunctionsCount
|
|
84
84
|
const functionsCount = Object.keys(functions).length
|
|
85
85
|
const stats = buildStatsString([
|
|
@@ -186,5 +186,3 @@ const buildStatsString = (possibleParts) => {
|
|
|
186
186
|
|
|
187
187
|
return parts.length > 1 ? `${message} and ${parts[parts.length - 1]}` : message
|
|
188
188
|
}
|
|
189
|
-
|
|
190
|
-
module.exports = { deploySite }
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { promisify } from 'util'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import walker from 'folder-walker'
|
|
4
|
+
import pumpModule from 'pump'
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
import { fileFilterCtor, fileNormalizerCtor, hasherCtor, manifestCollectorCtor } from './hasher-segments.mjs'
|
|
7
|
+
|
|
8
|
+
const pump = promisify(pumpModule)
|
|
7
9
|
|
|
8
10
|
const hashFiles = async ({
|
|
9
11
|
assetType = 'file',
|
|
@@ -33,4 +35,4 @@ const hashFiles = async ({
|
|
|
33
35
|
return { files, filesShaMap }
|
|
34
36
|
}
|
|
35
37
|
|
|
36
|
-
|
|
38
|
+
export default hashFiles
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { readFile } from 'fs/promises'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import { promisify } from 'util'
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
import fromArray from 'from2-array'
|
|
6
|
+
import pumpModule from 'pump'
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
import { hasherCtor, manifestCollectorCtor } from './hasher-segments.mjs'
|
|
9
|
+
|
|
10
|
+
const pump = promisify(pumpModule)
|
|
8
11
|
|
|
9
12
|
// Maximum age of functions manifest (2 minutes).
|
|
10
13
|
const MANIFEST_FILE_TTL = 12e4
|
|
@@ -26,8 +29,8 @@ const getFunctionZips = async ({
|
|
|
26
29
|
|
|
27
30
|
if (manifestPath) {
|
|
28
31
|
try {
|
|
29
|
-
//
|
|
30
|
-
const { functions, timestamp } =
|
|
32
|
+
// read manifest.json file
|
|
33
|
+
const { functions, timestamp } = JSON.parse(await readFile(manifestPath))
|
|
31
34
|
const manifestAge = Date.now() - timestamp
|
|
32
35
|
|
|
33
36
|
if (manifestAge > MANIFEST_FILE_TTL) {
|
|
@@ -131,4 +134,4 @@ const hashFns = async (
|
|
|
131
134
|
return { functionSchedules, functions, functionsWithNativeModules, fnShaMap }
|
|
132
135
|
}
|
|
133
136
|
|
|
134
|
-
|
|
137
|
+
export default hashFns
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import flushWriteStream from 'flush-write-stream'
|
|
2
|
+
import hasha from 'hasha'
|
|
3
|
+
import transform from 'parallel-transform'
|
|
4
|
+
import { objCtor as objFilterCtor } from 'through2-filter'
|
|
5
|
+
import { obj as map } from 'through2-map'
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
import { normalizePath } from './util.mjs'
|
|
8
8
|
|
|
9
9
|
// a parallel transform stream segment ctor that hashes fileObj's created by folder-walker
|
|
10
10
|
// TODO: use promises instead of callbacks
|
|
11
11
|
/* eslint-disable promise/prefer-await-to-callbacks */
|
|
12
|
-
const hasherCtor = ({ concurrentHash, hashAlgorithm }) => {
|
|
12
|
+
export const hasherCtor = ({ concurrentHash, hashAlgorithm }) => {
|
|
13
13
|
const hashaOpts = { algorithm: hashAlgorithm }
|
|
14
14
|
if (!concurrentHash) throw new Error('Missing required opts')
|
|
15
15
|
return transform(concurrentHash, { objectMode: true }, async (fileObj, cb) => {
|
|
@@ -24,7 +24,7 @@ const hasherCtor = ({ concurrentHash, hashAlgorithm }) => {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
// Inject normalized file names into normalizedPath and assetType
|
|
27
|
-
const fileNormalizerCtor = ({ assetType, normalizer: normalizeFunction }) =>
|
|
27
|
+
export const fileNormalizerCtor = ({ assetType, normalizer: normalizeFunction }) =>
|
|
28
28
|
map((fileObj) => {
|
|
29
29
|
const normalizedFile = { ...fileObj, assetType, normalizedPath: normalizePath(fileObj.relname) }
|
|
30
30
|
|
|
@@ -36,7 +36,7 @@ const fileNormalizerCtor = ({ assetType, normalizer: normalizeFunction }) =>
|
|
|
36
36
|
})
|
|
37
37
|
|
|
38
38
|
// A writable stream segment ctor that normalizes file paths, and writes shaMap's
|
|
39
|
-
const manifestCollectorCtor = (filesObj, shaMap, { assetType, statusCb }) => {
|
|
39
|
+
export const manifestCollectorCtor = (filesObj, shaMap, { assetType, statusCb }) => {
|
|
40
40
|
if (!statusCb || !assetType) throw new Error('Missing required options')
|
|
41
41
|
return flushWriteStream.obj((fileObj, _, cb) => {
|
|
42
42
|
filesObj[fileObj.normalizedPath] = fileObj.hash
|
|
@@ -60,11 +60,4 @@ const manifestCollectorCtor = (filesObj, shaMap, { assetType, statusCb }) => {
|
|
|
60
60
|
/* eslint-enable promise/prefer-await-to-callbacks */
|
|
61
61
|
|
|
62
62
|
// transform stream ctor that filters folder-walker results for only files
|
|
63
|
-
const fileFilterCtor = objFilterCtor((fileObj) => fileObj.type === 'file')
|
|
64
|
-
|
|
65
|
-
module.exports = {
|
|
66
|
-
hasherCtor,
|
|
67
|
-
fileNormalizerCtor,
|
|
68
|
-
manifestCollectorCtor,
|
|
69
|
-
fileFilterCtor,
|
|
70
|
-
}
|
|
63
|
+
export const fileFilterCtor = objFilterCtor((fileObj) => fileObj.type === 'file')
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import fs from 'fs'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import backoff from 'backoff'
|
|
4
|
+
import pMap from 'p-map'
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
import { UPLOAD_INITIAL_DELAY, UPLOAD_MAX_DELAY, UPLOAD_RANDOM_FACTOR } from './constants.mjs'
|
|
7
7
|
|
|
8
8
|
const uploadFiles = async (api, deployId, uploadList, { concurrentUpload, maxRetry, statusCb }) => {
|
|
9
9
|
if (!concurrentUpload || !statusCb || !maxRetry) throw new Error('Missing required option concurrentUpload')
|
|
@@ -115,4 +115,4 @@ const retryUpload = (uploadFn, maxRetry) =>
|
|
|
115
115
|
tryUpload()
|
|
116
116
|
})
|
|
117
117
|
|
|
118
|
-
|
|
118
|
+
export default uploadFiles
|
|
@@ -1,24 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
import { sep } from 'path'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import pWaitFor from 'p-wait-for'
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import { DEPLOY_POLL } from './constants.mjs'
|
|
6
6
|
|
|
7
7
|
// normalize windows paths to unix paths
|
|
8
|
-
const normalizePath = (relname) => {
|
|
8
|
+
export const normalizePath = (relname) => {
|
|
9
9
|
if (relname.includes('#') || relname.includes('?')) {
|
|
10
10
|
throw new Error(`Invalid filename ${relname}. Deployed filenames cannot contain # or ? characters`)
|
|
11
11
|
}
|
|
12
|
-
return (
|
|
13
|
-
relname
|
|
14
|
-
.split(sep)
|
|
15
|
-
// .map(segment => encodeURI(segment)) // TODO I'm fairly certain we shouldn't encodeURI here, thats only for the file upload step
|
|
16
|
-
.join('/')
|
|
17
|
-
)
|
|
12
|
+
return relname.split(sep).join('/')
|
|
18
13
|
}
|
|
19
14
|
|
|
20
15
|
// poll an async deployId until its done diffing
|
|
21
|
-
const waitForDiff = async (api, deployId, siteId, timeout) => {
|
|
16
|
+
export const waitForDiff = async (api, deployId, siteId, timeout) => {
|
|
22
17
|
// capture ready deploy during poll
|
|
23
18
|
let deploy
|
|
24
19
|
|
|
@@ -56,7 +51,7 @@ const waitForDiff = async (api, deployId, siteId, timeout) => {
|
|
|
56
51
|
}
|
|
57
52
|
|
|
58
53
|
// Poll a deployId until its ready
|
|
59
|
-
const waitForDeploy = async (api, deployId, siteId, timeout) => {
|
|
54
|
+
export const waitForDeploy = async (api, deployId, siteId, timeout) => {
|
|
60
55
|
// capture ready deploy during poll
|
|
61
56
|
let deploy
|
|
62
57
|
|
|
@@ -93,14 +88,7 @@ const waitForDeploy = async (api, deployId, siteId, timeout) => {
|
|
|
93
88
|
}
|
|
94
89
|
|
|
95
90
|
// Transform the fileShaMap and fnShaMap into a generic shaMap that file-uploader.js can use
|
|
96
|
-
const getUploadList = (required, shaMap) => {
|
|
91
|
+
export const getUploadList = (required, shaMap) => {
|
|
97
92
|
if (!required || !shaMap) return []
|
|
98
93
|
return required.flatMap((sha) => shaMap[sha])
|
|
99
94
|
}
|
|
100
|
-
|
|
101
|
-
module.exports = {
|
|
102
|
-
normalizePath,
|
|
103
|
-
waitForDiff,
|
|
104
|
-
waitForDeploy,
|
|
105
|
-
getUploadList,
|
|
106
|
-
}
|
|
@@ -10,8 +10,8 @@ import isPlainObject from 'is-plain-obj'
|
|
|
10
10
|
|
|
11
11
|
import { readFileAsyncCatchError } from '../lib/fs.cjs'
|
|
12
12
|
|
|
13
|
-
import { NETLIFYDEVWARN, chalk, log } from './command-helpers.
|
|
14
|
-
import { acquirePort } from './dev.
|
|
13
|
+
import { NETLIFYDEVWARN, chalk, log } from './command-helpers.mjs'
|
|
14
|
+
import { acquirePort } from './dev.mjs'
|
|
15
15
|
import { getInternalFunctionsDir } from './functions/index.mjs'
|
|
16
16
|
|
|
17
17
|
const formatProperty = (str) => chalk.magenta(`'${str}'`)
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
|
|
2
|
+
import process from 'process'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import { get } from 'dot-prop'
|
|
5
|
+
import getPort from 'get-port'
|
|
6
|
+
import jwt from 'jsonwebtoken'
|
|
7
|
+
import isEmpty from 'lodash/isEmpty.js'
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
import { supportsBackgroundFunctions } from '../lib/account.mjs'
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
import { NETLIFYDEVLOG, chalk, error, log, warn } from './command-helpers.mjs'
|
|
12
|
+
import { loadDotEnvFiles } from './dot-env.mjs'
|
|
13
13
|
|
|
14
14
|
// Possible sources of environment variables. For the purpose of printing log messages only. Order does not matter.
|
|
15
15
|
const ENV_VAR_SOURCES = {
|
|
@@ -98,7 +98,7 @@ const BACKGROUND_FUNCTION_TIMEOUT = 900
|
|
|
98
98
|
* @param {*} config.siteInfo
|
|
99
99
|
* @returns
|
|
100
100
|
*/
|
|
101
|
-
const getSiteInformation = async ({ api, offline, site, siteInfo }) => {
|
|
101
|
+
export const getSiteInformation = async ({ api, offline, site, siteInfo }) => {
|
|
102
102
|
if (site.id && !offline) {
|
|
103
103
|
validateSiteInfo({ site, siteInfo })
|
|
104
104
|
const [accounts, addons] = await Promise.all([getAccounts({ api }), getAddons({ api, site })])
|
|
@@ -139,7 +139,7 @@ const getEnvSourceName = (source) => {
|
|
|
139
139
|
|
|
140
140
|
// Takes a set of environment variables in the format provided by @netlify/config, augments it with variables from both
|
|
141
141
|
// dot-env files and the process itself, and injects into `process.env`.
|
|
142
|
-
const injectEnvVariables = async ({ devConfig, env, site }) => {
|
|
142
|
+
export const injectEnvVariables = async ({ devConfig, env, site }) => {
|
|
143
143
|
const environment = new Map(Object.entries(env))
|
|
144
144
|
const dotEnvFiles = await loadDotEnvFiles({ envFiles: devConfig.envFiles, projectDir: site.root })
|
|
145
145
|
|
|
@@ -186,7 +186,7 @@ const injectEnvVariables = async ({ devConfig, env, site }) => {
|
|
|
186
186
|
process.env.NETLIFY_DEV = 'true'
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
-
const acquirePort = async ({ configuredPort, defaultPort, errorMessage }) => {
|
|
189
|
+
export const acquirePort = async ({ configuredPort, defaultPort, errorMessage }) => {
|
|
190
190
|
const acquiredPort = await getPort({ port: configuredPort || defaultPort })
|
|
191
191
|
if (configuredPort && acquiredPort !== configuredPort) {
|
|
192
192
|
throw new Error(`${errorMessage}: '${configuredPort}'`)
|
|
@@ -199,7 +199,7 @@ const acquirePort = async ({ configuredPort, defaultPort, errorMessage }) => {
|
|
|
199
199
|
// - netlify_token -- the bearer token for the Netlify API
|
|
200
200
|
// - authlify_token_id -- the authlify token ID stored for the site after
|
|
201
201
|
// enabling API Authentication.
|
|
202
|
-
const generateNetlifyGraphJWT = ({ authlifyTokenId, netlifyToken, siteId }) => {
|
|
202
|
+
export const generateNetlifyGraphJWT = ({ authlifyTokenId, netlifyToken, siteId }) => {
|
|
203
203
|
const claims = {
|
|
204
204
|
netlify_token: netlifyToken,
|
|
205
205
|
authlify_token_id: authlifyTokenId,
|
|
@@ -215,17 +215,9 @@ const generateNetlifyGraphJWT = ({ authlifyTokenId, netlifyToken, siteId }) => {
|
|
|
215
215
|
)
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
-
const processOnExit = (fn) => {
|
|
218
|
+
export const processOnExit = (fn) => {
|
|
219
219
|
const signals = ['SIGINT', 'SIGTERM', 'SIGQUIT', 'SIGHUP', 'exit']
|
|
220
220
|
signals.forEach((signal) => {
|
|
221
221
|
process.on(signal, fn)
|
|
222
222
|
})
|
|
223
223
|
}
|
|
224
|
-
|
|
225
|
-
module.exports = {
|
|
226
|
-
getSiteInformation,
|
|
227
|
-
injectEnvVariables,
|
|
228
|
-
acquirePort,
|
|
229
|
-
generateNetlifyGraphJWT,
|
|
230
|
-
processOnExit,
|
|
231
|
-
}
|