netlify-cli 8.0.13 → 8.1.0-rc.2
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/README.md +12 -13
- package/bin/run +38 -2
- package/npm-shrinkwrap.json +260 -6244
- package/package.json +13 -35
- package/src/commands/addons/addons-auth.js +50 -0
- package/src/commands/addons/addons-config.js +180 -0
- package/src/commands/addons/addons-create.js +131 -0
- package/src/commands/addons/addons-delete.js +60 -0
- package/src/commands/addons/addons-list.js +62 -0
- package/src/commands/addons/addons.js +44 -0
- package/src/commands/addons/index.js +3 -24
- package/src/commands/api/api.js +75 -0
- package/src/commands/api/index.js +5 -0
- package/src/commands/base-command.js +509 -0
- package/src/commands/build/build.js +58 -0
- package/src/commands/build/index.js +3 -61
- package/src/commands/completion/completion.js +36 -0
- package/src/commands/completion/index.js +5 -0
- package/src/commands/{deploy.js → deploy/deploy.js} +295 -275
- package/src/commands/deploy/index.js +5 -0
- package/src/commands/dev/dev-exec.js +35 -0
- package/src/commands/dev/dev-trace.js +47 -0
- package/src/commands/dev/dev.js +340 -0
- package/src/commands/dev/index.js +3 -335
- package/src/commands/env/env-get.js +51 -0
- package/src/commands/env/env-import.js +93 -0
- package/src/commands/env/env-list.js +63 -0
- package/src/commands/env/env-set.js +67 -0
- package/src/commands/env/env-unset.js +66 -0
- package/src/commands/env/env.js +42 -0
- package/src/commands/env/index.js +3 -23
- package/src/commands/functions/functions-build.js +59 -0
- package/src/commands/functions/{create.js → functions-create.js} +130 -94
- package/src/commands/functions/functions-invoke.js +273 -0
- package/src/commands/functions/functions-list.js +106 -0
- package/src/commands/functions/functions-serve.js +63 -0
- package/src/commands/functions/functions.js +47 -0
- package/src/commands/functions/index.js +3 -45
- package/src/commands/index.js +7 -0
- package/src/commands/init/index.js +6 -0
- package/src/commands/{init.js → init/init.js} +79 -68
- package/src/commands/link/index.js +6 -0
- package/src/{utils/link/link-by-prompt.js → commands/link/link.js} +141 -14
- package/src/commands/lm/index.js +3 -19
- package/src/commands/lm/lm-info.js +42 -0
- package/src/commands/lm/lm-install.js +33 -0
- package/src/commands/lm/lm-setup.js +106 -0
- package/src/commands/lm/lm-uninstall.js +25 -0
- package/src/commands/lm/lm.js +34 -0
- package/src/commands/login/index.js +6 -0
- package/src/commands/login/login.js +55 -0
- package/src/commands/logout/index.js +5 -0
- package/src/commands/logout/logout.js +43 -0
- package/src/commands/main.js +188 -0
- package/src/commands/open/index.js +3 -39
- package/src/commands/open/open-admin.js +60 -0
- package/src/commands/open/open-site.js +53 -0
- package/src/commands/open/open.js +38 -0
- package/src/commands/sites/index.js +5 -20
- package/src/commands/sites/sites-create.js +187 -0
- package/src/commands/sites/sites-delete.js +104 -0
- package/src/commands/sites/sites-list.js +89 -0
- package/src/commands/sites/sites.js +32 -0
- package/src/commands/status/index.js +3 -118
- package/src/commands/status/status-hooks.js +69 -0
- package/src/commands/status/status.js +124 -0
- package/src/commands/switch/index.js +5 -0
- package/src/commands/switch/switch.js +50 -0
- package/src/commands/unlink/index.js +5 -0
- package/src/commands/unlink/unlink.js +48 -0
- package/src/commands/watch/index.js +5 -0
- package/src/commands/watch/watch.js +121 -0
- package/src/lib/build.js +21 -7
- package/src/lib/exec-fetcher.js +5 -3
- package/src/lib/fs.js +54 -36
- package/src/lib/functions/background.js +1 -1
- package/src/lib/functions/form-submissions-handler.js +2 -1
- package/src/lib/functions/local-proxy.js +2 -1
- package/src/lib/functions/netlify-function.js +4 -1
- package/src/lib/functions/registry.js +4 -6
- package/src/lib/functions/runtimes/go/index.js +2 -1
- package/src/lib/functions/runtimes/js/builders/netlify-lambda.js +6 -4
- package/src/lib/functions/runtimes/js/builders/zisi.js +3 -3
- package/src/lib/functions/runtimes/rust/index.js +4 -3
- package/src/lib/functions/server.js +2 -3
- package/src/lib/functions/synchronous.js +2 -1
- package/src/lib/functions/utils.js +2 -3
- package/src/lib/functions/watcher.js +1 -0
- package/src/lib/http-agent.js +5 -5
- package/src/lib/log.js +2 -1
- package/src/lib/spinner.js +22 -0
- package/src/utils/addons/diffs/index.js +1 -0
- package/src/utils/addons/diffs/options.js +3 -1
- package/src/utils/addons/prepare.js +13 -6
- package/src/utils/addons/prompts.js +2 -1
- package/src/utils/addons/render.js +3 -1
- package/src/utils/command-helpers.js +116 -43
- package/src/utils/create-stream-promise.js +5 -5
- package/src/utils/deferred.js +1 -0
- package/src/utils/deploy/deploy-site.js +1 -1
- package/src/utils/deploy/index.js +4 -0
- package/src/utils/detect-server-settings.js +10 -12
- package/src/utils/dev.js +18 -10
- package/src/utils/dot-env.js +4 -2
- package/src/utils/{edge-handlers.js → functions/edge-handlers.js} +8 -7
- package/src/utils/functions/functions.js +36 -0
- package/src/utils/{get-functions.js → functions/get-functions.js} +2 -1
- package/src/utils/functions/index.js +8 -26
- package/src/utils/get-global-config.js +3 -2
- package/src/utils/get-repo-data.js +1 -0
- package/src/utils/gh-auth.js +1 -0
- package/src/utils/gitignore.js +7 -5
- package/src/utils/headers.js +1 -2
- package/src/utils/index.js +42 -0
- package/src/utils/init/config-github.js +12 -5
- package/src/utils/init/config-manual.js +9 -2
- package/src/utils/init/config.js +13 -7
- package/src/utils/init/frameworks.js +1 -0
- package/src/utils/init/node-version.js +4 -2
- package/src/utils/init/plugins.js +2 -4
- package/src/utils/init/utils.js +10 -6
- package/src/utils/live-tunnel.js +3 -4
- package/src/utils/lm/install.js +10 -15
- package/src/utils/lm/requirements.js +3 -1
- package/src/utils/lm/steps.js +1 -1
- package/src/utils/lm/ui.js +7 -3
- package/src/utils/open-browser.js +8 -2
- package/src/utils/parse-raw-flags.js +4 -4
- package/src/utils/proxy.js +6 -5
- package/src/utils/read-repo-url.js +1 -0
- package/src/utils/redirects.js +3 -5
- package/src/utils/rules-proxy.js +2 -1
- package/src/utils/state-config.js +1 -1
- package/src/utils/telemetry/index.js +2 -113
- package/src/utils/telemetry/request.js +3 -1
- package/src/utils/telemetry/telemetry.js +117 -0
- package/src/utils/telemetry/validation.js +13 -12
- package/src/utils/traffic-mesh.js +3 -3
- package/oclif.manifest.json +0 -1
- package/src/commands/addons/auth.js +0 -42
- package/src/commands/addons/config.js +0 -177
- package/src/commands/addons/create.js +0 -127
- package/src/commands/addons/delete.js +0 -69
- package/src/commands/addons/list.js +0 -54
- package/src/commands/api.js +0 -84
- package/src/commands/dev/exec.js +0 -32
- package/src/commands/dev/trace.js +0 -61
- package/src/commands/env/get.js +0 -44
- package/src/commands/env/import.js +0 -90
- package/src/commands/env/list.js +0 -49
- package/src/commands/env/set.js +0 -64
- package/src/commands/env/unset.js +0 -58
- package/src/commands/functions/build.js +0 -60
- package/src/commands/functions/invoke.js +0 -277
- package/src/commands/functions/list.js +0 -102
- package/src/commands/functions/serve.js +0 -70
- package/src/commands/link.js +0 -133
- package/src/commands/lm/info.js +0 -36
- package/src/commands/lm/install.js +0 -30
- package/src/commands/lm/setup.js +0 -107
- package/src/commands/lm/uninstall.js +0 -17
- package/src/commands/login.js +0 -54
- package/src/commands/logout.js +0 -37
- package/src/commands/open/admin.js +0 -51
- package/src/commands/open/site.js +0 -43
- package/src/commands/sites/create.js +0 -191
- package/src/commands/sites/delete.js +0 -116
- package/src/commands/sites/list.js +0 -84
- package/src/commands/status/hooks.js +0 -60
- package/src/commands/switch.js +0 -44
- package/src/commands/unlink.js +0 -38
- package/src/commands/watch.js +0 -115
- package/src/hooks/init.js +0 -46
- package/src/index.js +0 -25
- package/src/lib/help.js +0 -26
- package/src/utils/chalk.js +0 -16
- package/src/utils/check-command-inputs.js +0 -21
- package/src/utils/command.js +0 -261
- package/src/utils/detect-functions-builder.js +0 -25
- package/src/utils/difference.js +0 -4
- package/src/utils/header.js +0 -18
- package/src/utils/logo.js +0 -11
- package/src/utils/show-help.js +0 -5
- package/src/utils/telemetry/tracked-command.js +0 -51
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
const { readFile } = require('fs').promises
|
|
1
3
|
const { dirname, extname, join, resolve } = require('path')
|
|
2
4
|
const { platform } = require('process')
|
|
3
5
|
|
|
@@ -6,8 +8,7 @@ const toml = require('toml')
|
|
|
6
8
|
|
|
7
9
|
const isWindows = platform === 'win32'
|
|
8
10
|
|
|
9
|
-
const execa = require('../../../../utils
|
|
10
|
-
const { readFileAsync } = require('../../../fs')
|
|
11
|
+
const { execa } = require('../../../../utils')
|
|
11
12
|
const { getPathInProject } = require('../../../settings')
|
|
12
13
|
const { runFunctionsProxy } = require('../../local-proxy')
|
|
13
14
|
|
|
@@ -36,7 +37,7 @@ const getBuildFunction =
|
|
|
36
37
|
|
|
37
38
|
const getCrateName = async (cwd) => {
|
|
38
39
|
const manifestPath = await findUp('Cargo.toml', { cwd, type: 'file' })
|
|
39
|
-
const manifest = await
|
|
40
|
+
const manifest = await readFile(manifestPath, 'utf-8')
|
|
40
41
|
const { package } = toml.parse(manifest)
|
|
41
42
|
|
|
42
43
|
return package.name
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
const jwtDecode = require('jwt-decode')
|
|
2
3
|
|
|
3
|
-
const { error: errorExit, log } = require('../../utils
|
|
4
|
-
const { getInternalFunctionsDir } = require('../../utils/functions')
|
|
5
|
-
const { NETLIFYDEVERR, NETLIFYDEVLOG } = require('../../utils/logo')
|
|
4
|
+
const { NETLIFYDEVERR, NETLIFYDEVLOG, error: errorExit, getInternalFunctionsDir, log } = require('../../utils')
|
|
6
5
|
|
|
7
6
|
const { handleBackgroundFunction, handleBackgroundFunctionResult } = require('./background')
|
|
8
7
|
const { createFormSubmissionHandler } = require('./form-submissions-handler')
|
package/src/lib/http-agent.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
const { readFile } = require('fs').promises
|
|
3
|
+
|
|
1
4
|
const { HttpsProxyAgent } = require('https-proxy-agent')
|
|
2
5
|
const waitPort = require('wait-port')
|
|
3
6
|
|
|
4
|
-
const { exit, log } = require('../utils
|
|
5
|
-
const { NETLIFYDEVERR, NETLIFYDEVWARN } = require('../utils/logo')
|
|
6
|
-
|
|
7
|
-
const fs = require('./fs')
|
|
7
|
+
const { NETLIFYDEVERR, NETLIFYDEVWARN, exit, log } = require('../utils')
|
|
8
8
|
|
|
9
9
|
// https://github.com/TooTallNate/node-https-proxy-agent/issues/89
|
|
10
10
|
class HttpsProxyAgentWithCA extends HttpsProxyAgent {
|
|
@@ -66,7 +66,7 @@ const tryGetAgent = async ({ certificateFile, httpProxy }) => {
|
|
|
66
66
|
let certificate
|
|
67
67
|
if (certificateFile) {
|
|
68
68
|
try {
|
|
69
|
-
certificate = await
|
|
69
|
+
certificate = await readFile(certificateFile)
|
|
70
70
|
} catch (error) {
|
|
71
71
|
response = { warning: `Could not read certificate file '${certificateFile}'.`, message: error.message }
|
|
72
72
|
}
|
package/src/lib/log.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
const chalk = require('chalk')
|
|
2
1
|
const dotProp = require('dot-prop')
|
|
3
2
|
|
|
3
|
+
const { chalk } = require('../utils')
|
|
4
|
+
|
|
4
5
|
const RED_BACKGROUND = chalk.red('-background')
|
|
5
6
|
const [PRO, BUSINESS, ENTERPRISE] = ['Pro', 'Business', 'Enterprise'].map((plan) => chalk.magenta(plan))
|
|
6
7
|
const BACKGROUND_FUNCTIONS_WARNING = `A serverless function ending in \`${RED_BACKGROUND}\` was detected.
|
package/src/lib/spinner.js
CHANGED
|
@@ -1,15 +1,31 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
const logSymbols = require('log-symbols')
|
|
2
3
|
const ora = require('ora')
|
|
3
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Creates a spinner with the following text
|
|
7
|
+
* @param {object} config
|
|
8
|
+
* @param {string} config.text
|
|
9
|
+
* @returns {ora.Ora}
|
|
10
|
+
*/
|
|
4
11
|
const startSpinner = ({ text }) =>
|
|
5
12
|
ora({
|
|
6
13
|
text,
|
|
7
14
|
}).start()
|
|
8
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Stops the spinner with the following text
|
|
18
|
+
* @param {object} config
|
|
19
|
+
* @param {object} [config.error]
|
|
20
|
+
* @param {ora.Ora} config.spinner
|
|
21
|
+
* @param {string} config.text
|
|
22
|
+
* @returns {void}
|
|
23
|
+
*/
|
|
9
24
|
const stopSpinner = ({ error, spinner, text }) => {
|
|
10
25
|
if (!spinner) {
|
|
11
26
|
return
|
|
12
27
|
}
|
|
28
|
+
// TODO: refactor no package needed `log-symbols` for that
|
|
13
29
|
const symbol = error ? logSymbols.error : logSymbols.success
|
|
14
30
|
spinner.stopAndPersist({
|
|
15
31
|
text,
|
|
@@ -17,6 +33,12 @@ const stopSpinner = ({ error, spinner, text }) => {
|
|
|
17
33
|
})
|
|
18
34
|
}
|
|
19
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Clears the spinner
|
|
38
|
+
* @param {object} config
|
|
39
|
+
* @param {ora.Ora} config.spinner
|
|
40
|
+
* @returns {void}
|
|
41
|
+
*/
|
|
20
42
|
const clearSpinner = ({ spinner }) => {
|
|
21
43
|
if (spinner) {
|
|
22
44
|
spinner.stop()
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { error, exit, log, warn } = require('../command-helpers')
|
|
1
|
+
// @ts-check
|
|
2
|
+
const { chalk, error, exit, log, warn } = require('../command-helpers')
|
|
4
3
|
|
|
5
4
|
const ADDON_VALIDATION = {
|
|
6
5
|
EXISTS: 'EXISTS',
|
|
@@ -81,17 +80,25 @@ const getAddons = async ({ api, siteId }) => {
|
|
|
81
80
|
return addons
|
|
82
81
|
}
|
|
83
82
|
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
/**
|
|
84
|
+
*
|
|
85
|
+
* @param {object} config
|
|
86
|
+
* @param {import('../../commands/base-command').BaseCommand} config.command
|
|
87
|
+
* @param {string} [config.addonName]
|
|
88
|
+
* @param {keyof ADDON_VALIDATION} [config.validation]
|
|
89
|
+
*/
|
|
90
|
+
const prepareAddonCommand = async ({ addonName, command, validation }) => {
|
|
91
|
+
const { netlify } = command
|
|
86
92
|
const { api, site } = netlify
|
|
87
93
|
const siteId = site.id
|
|
88
94
|
if (!siteId) {
|
|
89
95
|
error('No site id found, please run inside a site folder or `netlify link`')
|
|
90
96
|
}
|
|
91
97
|
|
|
92
|
-
await
|
|
98
|
+
await command.authenticate()
|
|
93
99
|
|
|
94
100
|
const [manifest, siteData, addons] = await Promise.all([
|
|
101
|
+
// TODO: check as `getAddonManifest` did not accept a parameter error
|
|
95
102
|
addonName ? getAddonManifest({ api, addonName, error }) : Promise.resolve(),
|
|
96
103
|
getSiteData({ api, siteId }),
|
|
97
104
|
getAddons({ api, siteId }),
|
|
@@ -1,33 +1,83 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
const os = require('os')
|
|
1
3
|
const process = require('process')
|
|
2
4
|
const { format, inspect } = require('util')
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
6
|
+
// eslint-disable-next-line local-rules/no-direct-chalk-import
|
|
7
|
+
const { Instance: ChalkInstance } = require('chalk')
|
|
8
|
+
const WSL = require('is-wsl')
|
|
9
|
+
const { default: omit } = require('omit.js')
|
|
7
10
|
|
|
11
|
+
const { name, version } = require('../../package.json')
|
|
8
12
|
const { clearSpinner, startSpinner } = require('../lib/spinner')
|
|
9
13
|
|
|
10
|
-
const chalkInstance = require('./chalk')
|
|
11
14
|
const getGlobalConfig = require('./get-global-config')
|
|
12
15
|
|
|
16
|
+
/** The parsed process argv without the binary only arguments and flags */
|
|
17
|
+
const argv = process.argv.slice(2)
|
|
18
|
+
/**
|
|
19
|
+
* Chalk instance for CLI that can be initialized with no colors mode
|
|
20
|
+
* needed for json outputs where we don't want to have colors
|
|
21
|
+
* @param {boolean} noColors - disable chalk colors
|
|
22
|
+
* @return {object} - default or custom chalk instance
|
|
23
|
+
*/
|
|
24
|
+
const safeChalk = function (noColors) {
|
|
25
|
+
if (noColors) {
|
|
26
|
+
const colorlessChalk = new ChalkInstance({ level: 0 })
|
|
27
|
+
return colorlessChalk
|
|
28
|
+
}
|
|
29
|
+
return new ChalkInstance()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const chalk = safeChalk(argv.includes('--json'))
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Adds the filler to the start of the string
|
|
36
|
+
* @param {string} str
|
|
37
|
+
* @param {number} count
|
|
38
|
+
* @param {string} [filler]
|
|
39
|
+
* @returns {string}
|
|
40
|
+
*/
|
|
41
|
+
const padLeft = (str, count, filler = ' ') => str.padStart(str.length + count, filler)
|
|
42
|
+
|
|
43
|
+
const platform = WSL ? 'wsl' : os.platform()
|
|
44
|
+
const arch = os.arch() === 'ia32' ? 'x86' : os.arch()
|
|
45
|
+
|
|
46
|
+
const USER_AGENT = `${name}/${version} ${platform}-${arch} node-${process.version}`
|
|
47
|
+
|
|
13
48
|
const { NETLIFY_AUTH_TOKEN } = process.env
|
|
14
49
|
|
|
15
|
-
//
|
|
16
|
-
const
|
|
50
|
+
// eslint-disable-next-line no-magic-numbers
|
|
51
|
+
const NETLIFY_CYAN = chalk.rgb(40, 180, 170)
|
|
17
52
|
|
|
18
|
-
const
|
|
53
|
+
const NETLIFYDEV = `${chalk.greenBright('◈')} ${NETLIFY_CYAN('Netlify Dev')} ${chalk.greenBright('◈')}`
|
|
54
|
+
const NETLIFYDEVLOG = `${chalk.greenBright('◈')}`
|
|
55
|
+
const NETLIFYDEVWARN = `${chalk.yellowBright('◈')}`
|
|
56
|
+
const NETLIFYDEVERR = `${chalk.redBright('◈')}`
|
|
19
57
|
|
|
20
|
-
const
|
|
58
|
+
const BANG = process.platform === 'win32' ? '»' : '›'
|
|
59
|
+
|
|
60
|
+
// Poll Token timeout 5 Minutes
|
|
61
|
+
const TOKEN_TIMEOUT = 3e5
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
*
|
|
65
|
+
* @param {object} config
|
|
66
|
+
* @param {import('netlify').NetlifyAPI} config.api
|
|
67
|
+
* @param {object} config.ticket
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
70
|
+
const pollForToken = async ({ api, ticket }) => {
|
|
21
71
|
const spinner = startSpinner({ text: 'Waiting for authorization...' })
|
|
22
72
|
try {
|
|
23
73
|
const accessToken = await api.getAccessToken(ticket, { timeout: TOKEN_TIMEOUT })
|
|
24
74
|
if (!accessToken) {
|
|
25
|
-
|
|
75
|
+
error('Could not retrieve access token')
|
|
26
76
|
}
|
|
27
77
|
return accessToken
|
|
28
|
-
} catch (
|
|
29
|
-
if (
|
|
30
|
-
|
|
78
|
+
} catch (error_) {
|
|
79
|
+
if (error_.name === 'TimeoutError') {
|
|
80
|
+
error(
|
|
31
81
|
`Timed out waiting for authorization. If you do not have a ${chalk.bold.greenBright(
|
|
32
82
|
'Netlify',
|
|
33
83
|
)} account, please create one at ${chalk.magenta(
|
|
@@ -35,29 +85,22 @@ const pollForToken = async ({ api, exitWithError, ticket }) => {
|
|
|
35
85
|
)}, then run ${chalk.cyanBright('netlify login')} again.`,
|
|
36
86
|
)
|
|
37
87
|
} else {
|
|
38
|
-
|
|
88
|
+
error(error_)
|
|
39
89
|
}
|
|
40
90
|
} finally {
|
|
41
91
|
clearSpinner({ spinner })
|
|
42
92
|
}
|
|
43
93
|
}
|
|
44
94
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
return argv.auth
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const getToken = async (authFromFlag) => {
|
|
56
|
-
const tokenFromFlag = authFromFlag || getAuthArg(argv)
|
|
57
|
-
|
|
95
|
+
/**
|
|
96
|
+
* Get a netlify token
|
|
97
|
+
* @param {string} [tokenFromOptions] optional token from the provided --auth options
|
|
98
|
+
* @returns {Promise<[null|string, 'flag' | 'env' |'config' |'not found']>}
|
|
99
|
+
*/
|
|
100
|
+
const getToken = async (tokenFromOptions) => {
|
|
58
101
|
// 1. First honor command flag --auth
|
|
59
|
-
if (
|
|
60
|
-
return [
|
|
102
|
+
if (tokenFromOptions) {
|
|
103
|
+
return [tokenFromOptions, 'flag']
|
|
61
104
|
}
|
|
62
105
|
// 2. then Check ENV var
|
|
63
106
|
if (NETLIFY_AUTH_TOKEN && NETLIFY_AUTH_TOKEN !== 'null') {
|
|
@@ -75,33 +118,58 @@ const getToken = async (authFromFlag) => {
|
|
|
75
118
|
|
|
76
119
|
// 'api' command uses JSON output by default
|
|
77
120
|
// 'functions:invoke' need to return the data from the function as is
|
|
78
|
-
const isDefaultJson = () => argv
|
|
121
|
+
const isDefaultJson = () => argv[0] === 'functions:invoke' || (argv[0] === 'api' && !argv.includes('--list'))
|
|
79
122
|
|
|
123
|
+
/**
|
|
124
|
+
* logs a json message
|
|
125
|
+
* @param {string|object} message
|
|
126
|
+
*/
|
|
80
127
|
const logJson = (message = '') => {
|
|
81
|
-
if (argv.json || isDefaultJson()) {
|
|
128
|
+
if (argv.includes('--json') || isDefaultJson()) {
|
|
82
129
|
process.stdout.write(JSON.stringify(message, null, 2))
|
|
83
130
|
}
|
|
84
131
|
}
|
|
85
132
|
|
|
86
133
|
const log = (message = '', ...args) => {
|
|
87
|
-
|
|
88
|
-
if (argv.
|
|
134
|
+
// If --silent or --json flag passed disable logger
|
|
135
|
+
if (argv.includes('--json') || argv.includes('--silent') || isDefaultJson()) {
|
|
89
136
|
return
|
|
90
137
|
}
|
|
91
138
|
message = typeof message === 'string' ? message : inspect(message)
|
|
92
139
|
process.stdout.write(`${format(message, ...args)}\n`)
|
|
93
140
|
}
|
|
94
141
|
|
|
142
|
+
/**
|
|
143
|
+
* logs a warning message
|
|
144
|
+
* @param {string} message
|
|
145
|
+
*/
|
|
95
146
|
const warn = (message = '') => {
|
|
96
|
-
|
|
147
|
+
const bang = chalk.yellow(BANG)
|
|
148
|
+
log(` ${bang} Warning: ${message}`)
|
|
97
149
|
}
|
|
98
150
|
|
|
151
|
+
/**
|
|
152
|
+
* throws an error or log it
|
|
153
|
+
* @param {string|Error} message
|
|
154
|
+
* @param {object} [options]
|
|
155
|
+
* @param {boolean} [options.exit]
|
|
156
|
+
*/
|
|
99
157
|
const error = (message = '', options = {}) => {
|
|
100
|
-
|
|
158
|
+
const err = message instanceof Error ? message : new Error(message)
|
|
159
|
+
if (options.exit === false) {
|
|
160
|
+
const bang = chalk.red(BANG)
|
|
161
|
+
if (process.env.DEBUG) {
|
|
162
|
+
process.stderr.write(` ${bang} Warning: ${err.stack.split('\n').join(`\n ${bang} `)}`)
|
|
163
|
+
} else {
|
|
164
|
+
process.stderr.write(` ${bang} ${err.name}: ${err.message}\n`)
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
throw err
|
|
168
|
+
}
|
|
101
169
|
}
|
|
102
170
|
|
|
103
171
|
const exit = (code = 0) => {
|
|
104
|
-
|
|
172
|
+
process.exit(code)
|
|
105
173
|
}
|
|
106
174
|
|
|
107
175
|
// When `build.publish` is not set by the user, the CLI behavior differs in
|
|
@@ -114,15 +182,20 @@ const normalizeConfig = (config) =>
|
|
|
114
182
|
: config
|
|
115
183
|
|
|
116
184
|
module.exports = {
|
|
117
|
-
argv,
|
|
118
|
-
getCwd,
|
|
119
|
-
pollForToken,
|
|
120
|
-
log,
|
|
121
|
-
logJson,
|
|
122
185
|
getToken,
|
|
123
|
-
|
|
124
|
-
|
|
186
|
+
exit,
|
|
187
|
+
padLeft,
|
|
188
|
+
logJson,
|
|
189
|
+
log,
|
|
125
190
|
warn,
|
|
126
191
|
error,
|
|
127
|
-
|
|
192
|
+
chalk,
|
|
193
|
+
pollForToken,
|
|
194
|
+
normalizeConfig,
|
|
195
|
+
USER_AGENT,
|
|
196
|
+
NETLIFY_CYAN,
|
|
197
|
+
NETLIFYDEV,
|
|
198
|
+
NETLIFYDEVLOG,
|
|
199
|
+
NETLIFYDEVWARN,
|
|
200
|
+
NETLIFYDEVERR,
|
|
128
201
|
}
|
|
@@ -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 }
|
package/src/utils/deferred.js
CHANGED
|
@@ -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
|
|
@@ -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 {
|
|
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,
|
|
111
|
+
const handleStaticServer = async ({ devConfig, options, projectDir }) => {
|
|
114
112
|
validateNumberProperty({ devConfig, property: 'staticServerPort' })
|
|
115
113
|
|
|
116
|
-
if (
|
|
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 =
|
|
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 {
|
|
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,
|
|
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 (
|
|
274
|
+
if (options.dir || devConfig.framework === '#static') {
|
|
277
275
|
// serving files statically without a framework server
|
|
278
|
-
settings = await handleStaticServer({
|
|
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({
|
|
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 {
|
|
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
|
-
|
|
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 (
|
|
56
|
-
|
|
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 (
|
|
65
|
-
|
|
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
|
-
|
|
93
|
-
|
|
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
|
|
package/src/utils/dot-env.js
CHANGED
|
@@ -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
|
|
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
|
|
37
|
+
const content = await readFile(filepath, 'utf-8')
|
|
36
38
|
const env = dotenv.parse(content)
|
|
37
39
|
return { file, env }
|
|
38
40
|
}),
|