netlify-cli 8.1.3 → 8.1.4
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 +1052 -7693
- package/package.json +12 -36
- package/scripts/postinstall.js +13 -0
- 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 +502 -0
- package/src/commands/build/build.js +58 -0
- package/src/commands/build/index.js +3 -61
- package/src/commands/completion/completion.js +56 -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 +206 -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 +40 -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 +90 -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 +131 -0
- package/src/functions-templates/javascript/stripe-charge/package-lock.json +6 -6
- package/src/functions-templates/javascript/stripe-subscription/package-lock.json +6 -6
- package/src/lib/build.js +21 -7
- package/src/lib/completion/constants.js +6 -0
- package/src/lib/completion/generate-autocompletion.js +36 -0
- package/src/lib/completion/index.js +5 -0
- package/src/lib/completion/script.js +72 -0
- 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/settings.js +16 -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 +136 -42
- 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 +8 -1
- 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/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 +2 -2
- 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,33 +1,102 @@
|
|
|
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
|
+
|
|
48
|
+
/** A list of base command flags that needs to be sorted down on documentation and on help pages */
|
|
49
|
+
const BASE_FLAGS = new Set(['--debug', '--httpProxy', '--httpProxyCertificateFilename'])
|
|
50
|
+
|
|
13
51
|
const { NETLIFY_AUTH_TOKEN } = process.env
|
|
14
52
|
|
|
15
|
-
//
|
|
16
|
-
const
|
|
53
|
+
// eslint-disable-next-line no-magic-numbers
|
|
54
|
+
const NETLIFY_CYAN = chalk.rgb(40, 180, 170)
|
|
55
|
+
|
|
56
|
+
const NETLIFYDEV = `${chalk.greenBright('◈')} ${NETLIFY_CYAN('Netlify Dev')} ${chalk.greenBright('◈')}`
|
|
57
|
+
const NETLIFYDEVLOG = `${chalk.greenBright('◈')}`
|
|
58
|
+
const NETLIFYDEVWARN = `${chalk.yellowBright('◈')}`
|
|
59
|
+
const NETLIFYDEVERR = `${chalk.redBright('◈')}`
|
|
60
|
+
|
|
61
|
+
const BANG = process.platform === 'win32' ? '»' : '›'
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Sorts two options so that the base flags are at the bottom of the list
|
|
65
|
+
* @param {import('commander').Option} optionA
|
|
66
|
+
* @param {import('commander').Option} optionB
|
|
67
|
+
* @returns {number}
|
|
68
|
+
* @example
|
|
69
|
+
* options.sort(sortOptions)
|
|
70
|
+
*/
|
|
71
|
+
const sortOptions = (optionA, optionB) => {
|
|
72
|
+
// base flags should be always at the bottom
|
|
73
|
+
if (BASE_FLAGS.has(optionA.long) || BASE_FLAGS.has(optionB.long)) {
|
|
74
|
+
return -1
|
|
75
|
+
}
|
|
76
|
+
return optionA.long.localeCompare(optionB.long)
|
|
77
|
+
}
|
|
17
78
|
|
|
18
|
-
|
|
79
|
+
// Poll Token timeout 5 Minutes
|
|
80
|
+
const TOKEN_TIMEOUT = 3e5
|
|
19
81
|
|
|
20
|
-
|
|
82
|
+
/**
|
|
83
|
+
*
|
|
84
|
+
* @param {object} config
|
|
85
|
+
* @param {import('netlify').NetlifyAPI} config.api
|
|
86
|
+
* @param {object} config.ticket
|
|
87
|
+
* @returns
|
|
88
|
+
*/
|
|
89
|
+
const pollForToken = async ({ api, ticket }) => {
|
|
21
90
|
const spinner = startSpinner({ text: 'Waiting for authorization...' })
|
|
22
91
|
try {
|
|
23
92
|
const accessToken = await api.getAccessToken(ticket, { timeout: TOKEN_TIMEOUT })
|
|
24
93
|
if (!accessToken) {
|
|
25
|
-
|
|
94
|
+
error('Could not retrieve access token')
|
|
26
95
|
}
|
|
27
96
|
return accessToken
|
|
28
|
-
} catch (
|
|
29
|
-
if (
|
|
30
|
-
|
|
97
|
+
} catch (error_) {
|
|
98
|
+
if (error_.name === 'TimeoutError') {
|
|
99
|
+
error(
|
|
31
100
|
`Timed out waiting for authorization. If you do not have a ${chalk.bold.greenBright(
|
|
32
101
|
'Netlify',
|
|
33
102
|
)} account, please create one at ${chalk.magenta(
|
|
@@ -35,29 +104,22 @@ const pollForToken = async ({ api, exitWithError, ticket }) => {
|
|
|
35
104
|
)}, then run ${chalk.cyanBright('netlify login')} again.`,
|
|
36
105
|
)
|
|
37
106
|
} else {
|
|
38
|
-
|
|
107
|
+
error(error_)
|
|
39
108
|
}
|
|
40
109
|
} finally {
|
|
41
110
|
clearSpinner({ spinner })
|
|
42
111
|
}
|
|
43
112
|
}
|
|
44
113
|
|
|
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
|
-
|
|
114
|
+
/**
|
|
115
|
+
* Get a netlify token
|
|
116
|
+
* @param {string} [tokenFromOptions] optional token from the provided --auth options
|
|
117
|
+
* @returns {Promise<[null|string, 'flag' | 'env' |'config' |'not found']>}
|
|
118
|
+
*/
|
|
119
|
+
const getToken = async (tokenFromOptions) => {
|
|
58
120
|
// 1. First honor command flag --auth
|
|
59
|
-
if (
|
|
60
|
-
return [
|
|
121
|
+
if (tokenFromOptions) {
|
|
122
|
+
return [tokenFromOptions, 'flag']
|
|
61
123
|
}
|
|
62
124
|
// 2. then Check ENV var
|
|
63
125
|
if (NETLIFY_AUTH_TOKEN && NETLIFY_AUTH_TOKEN !== 'null') {
|
|
@@ -75,33 +137,58 @@ const getToken = async (authFromFlag) => {
|
|
|
75
137
|
|
|
76
138
|
// 'api' command uses JSON output by default
|
|
77
139
|
// 'functions:invoke' need to return the data from the function as is
|
|
78
|
-
const isDefaultJson = () => argv
|
|
140
|
+
const isDefaultJson = () => argv[0] === 'functions:invoke' || (argv[0] === 'api' && !argv.includes('--list'))
|
|
79
141
|
|
|
142
|
+
/**
|
|
143
|
+
* logs a json message
|
|
144
|
+
* @param {string|object} message
|
|
145
|
+
*/
|
|
80
146
|
const logJson = (message = '') => {
|
|
81
|
-
if (argv.json || isDefaultJson()) {
|
|
147
|
+
if (argv.includes('--json') || isDefaultJson()) {
|
|
82
148
|
process.stdout.write(JSON.stringify(message, null, 2))
|
|
83
149
|
}
|
|
84
150
|
}
|
|
85
151
|
|
|
86
152
|
const log = (message = '', ...args) => {
|
|
87
|
-
|
|
88
|
-
if (argv.
|
|
153
|
+
// If --silent or --json flag passed disable logger
|
|
154
|
+
if (argv.includes('--json') || argv.includes('--silent') || isDefaultJson()) {
|
|
89
155
|
return
|
|
90
156
|
}
|
|
91
157
|
message = typeof message === 'string' ? message : inspect(message)
|
|
92
158
|
process.stdout.write(`${format(message, ...args)}\n`)
|
|
93
159
|
}
|
|
94
160
|
|
|
161
|
+
/**
|
|
162
|
+
* logs a warning message
|
|
163
|
+
* @param {string} message
|
|
164
|
+
*/
|
|
95
165
|
const warn = (message = '') => {
|
|
96
|
-
|
|
166
|
+
const bang = chalk.yellow(BANG)
|
|
167
|
+
log(` ${bang} Warning: ${message}`)
|
|
97
168
|
}
|
|
98
169
|
|
|
170
|
+
/**
|
|
171
|
+
* throws an error or log it
|
|
172
|
+
* @param {string|Error} message
|
|
173
|
+
* @param {object} [options]
|
|
174
|
+
* @param {boolean} [options.exit]
|
|
175
|
+
*/
|
|
99
176
|
const error = (message = '', options = {}) => {
|
|
100
|
-
|
|
177
|
+
const err = message instanceof Error ? message : new Error(message)
|
|
178
|
+
if (options.exit === false) {
|
|
179
|
+
const bang = chalk.red(BANG)
|
|
180
|
+
if (process.env.DEBUG) {
|
|
181
|
+
process.stderr.write(` ${bang} Warning: ${err.stack.split('\n').join(`\n ${bang} `)}`)
|
|
182
|
+
} else {
|
|
183
|
+
process.stderr.write(` ${bang} ${err.name}: ${err.message}\n`)
|
|
184
|
+
}
|
|
185
|
+
} else {
|
|
186
|
+
throw err
|
|
187
|
+
}
|
|
101
188
|
}
|
|
102
189
|
|
|
103
190
|
const exit = (code = 0) => {
|
|
104
|
-
|
|
191
|
+
process.exit(code)
|
|
105
192
|
}
|
|
106
193
|
|
|
107
194
|
// When `build.publish` is not set by the user, the CLI behavior differs in
|
|
@@ -114,15 +201,22 @@ const normalizeConfig = (config) =>
|
|
|
114
201
|
: config
|
|
115
202
|
|
|
116
203
|
module.exports = {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
204
|
+
BANG,
|
|
205
|
+
chalk,
|
|
206
|
+
error,
|
|
207
|
+
exit,
|
|
208
|
+
getToken,
|
|
120
209
|
log,
|
|
121
210
|
logJson,
|
|
122
|
-
|
|
211
|
+
NETLIFY_CYAN,
|
|
212
|
+
NETLIFYDEV,
|
|
213
|
+
NETLIFYDEVERR,
|
|
214
|
+
NETLIFYDEVLOG,
|
|
215
|
+
NETLIFYDEVWARN,
|
|
123
216
|
normalizeConfig,
|
|
124
|
-
|
|
217
|
+
padLeft,
|
|
218
|
+
pollForToken,
|
|
219
|
+
sortOptions,
|
|
220
|
+
USER_AGENT,
|
|
125
221
|
warn,
|
|
126
|
-
error,
|
|
127
|
-
exit,
|
|
128
222
|
}
|
|
@@ -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
|
}),
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
const fs = require('fs').promises
|
|
1
3
|
const path = require('path')
|
|
2
4
|
|
|
3
|
-
const { cancelDeploy, uploadEdgeHandlers } = require('
|
|
4
|
-
const { readFileAsyncCatchError
|
|
5
|
-
const { startSpinner, stopSpinner } = require('
|
|
6
|
-
|
|
7
|
-
const { error, warn } = require('./command-helpers')
|
|
5
|
+
const { cancelDeploy, uploadEdgeHandlers } = require('../../lib/api')
|
|
6
|
+
const { readFileAsyncCatchError } = require('../../lib/fs')
|
|
7
|
+
const { startSpinner, stopSpinner } = require('../../lib/spinner')
|
|
8
|
+
const { error } = require('../command-helpers')
|
|
8
9
|
|
|
9
10
|
const MANIFEST_FILENAME = 'manifest.json'
|
|
10
11
|
const EDGE_HANDLERS_FOLDER = '.netlify/edge-handlers'
|
|
@@ -12,7 +13,7 @@ const EDGE_HANDLERS_FOLDER = '.netlify/edge-handlers'
|
|
|
12
13
|
const validateEdgeHandlerFolder = async ({ site }) => {
|
|
13
14
|
try {
|
|
14
15
|
const resolvedFolder = path.resolve(site.root, EDGE_HANDLERS_FOLDER)
|
|
15
|
-
const stat = await
|
|
16
|
+
const stat = await fs.stat(resolvedFolder)
|
|
16
17
|
if (!stat.isDirectory()) {
|
|
17
18
|
error(`Edge Handlers folder ${EDGE_HANDLERS_FOLDER} must be a path to a directory`)
|
|
18
19
|
}
|
|
@@ -77,7 +78,7 @@ const deployEdgeHandlers = async ({ api, deployId, silent, site }) => {
|
|
|
77
78
|
} catch (error_) {
|
|
78
79
|
const text = `Failed deploying Edge Handlers: ${error_.message}`
|
|
79
80
|
stopSpinner({ spinner, text, error: true })
|
|
80
|
-
await cancelDeploy({ api, deployId
|
|
81
|
+
await cancelDeploy({ api, deployId })
|
|
81
82
|
// no need to report the error again
|
|
82
83
|
error('')
|
|
83
84
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
const { resolve } = require('path')
|
|
3
|
+
|
|
4
|
+
const { isDirectoryAsync, isFileAsync } = require('../../lib/fs')
|
|
5
|
+
const { getPathInProject } = require('../../lib/settings')
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* retrieves the function directory out of the flags or config
|
|
9
|
+
* @param {object} param
|
|
10
|
+
* @param {object} param.config
|
|
11
|
+
* @param {import('commander').OptionValues} param.options The options from the commander
|
|
12
|
+
* @param {string} [defaultValue]
|
|
13
|
+
* @returns {string}
|
|
14
|
+
*/
|
|
15
|
+
const getFunctionsDir = ({ config, options }, defaultValue) =>
|
|
16
|
+
options.functions ||
|
|
17
|
+
(config.dev && config.dev.functions) ||
|
|
18
|
+
config.functionsDirectory ||
|
|
19
|
+
(config.dev && config.dev.Functions) ||
|
|
20
|
+
defaultValue
|
|
21
|
+
|
|
22
|
+
const getFunctionsManifestPath = async ({ base }) => {
|
|
23
|
+
const path = resolve(base, getPathInProject(['functions', 'manifest.json']))
|
|
24
|
+
const isFile = await isFileAsync(path)
|
|
25
|
+
|
|
26
|
+
return isFile ? path : null
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const getInternalFunctionsDir = async ({ base }) => {
|
|
30
|
+
const path = resolve(base, getPathInProject(['functions-internal']))
|
|
31
|
+
const isDirectory = await isDirectoryAsync(path)
|
|
32
|
+
|
|
33
|
+
return isDirectory ? path : null
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = { getFunctionsDir, getInternalFunctionsDir, getFunctionsManifestPath }
|
|
@@ -1,27 +1,9 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
config.functionsDirectory ||
|
|
10
|
-
(config.dev && config.dev.Functions) ||
|
|
11
|
-
defaultValue
|
|
12
|
-
|
|
13
|
-
const getFunctionsManifestPath = async ({ base }) => {
|
|
14
|
-
const path = resolve(base, getPathInProject(['functions', 'manifest.json']))
|
|
15
|
-
const isFile = await isFileAsync(path)
|
|
16
|
-
|
|
17
|
-
return isFile ? path : null
|
|
1
|
+
const edgeHandlers = require('./edge-handlers')
|
|
2
|
+
const functions = require('./functions')
|
|
3
|
+
const getFunctions = require('./get-functions')
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
...functions,
|
|
7
|
+
...edgeHandlers,
|
|
8
|
+
...getFunctions,
|
|
18
9
|
}
|
|
19
|
-
|
|
20
|
-
const getInternalFunctionsDir = async ({ base }) => {
|
|
21
|
-
const path = resolve(base, getPathInProject(['functions-internal']))
|
|
22
|
-
const isDirectory = await isDirectoryAsync(path)
|
|
23
|
-
|
|
24
|
-
return isDirectory ? path : null
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
module.exports = { getFunctionsDir, getInternalFunctionsDir, getFunctionsManifestPath }
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
const { readFile } = require('fs').promises
|
|
2
|
+
|
|
1
3
|
const Configstore = require('configstore')
|
|
2
4
|
const memoizeOne = require('memoize-one')
|
|
3
5
|
const { v4: uuidv4 } = require('uuid')
|
|
4
6
|
|
|
5
|
-
const { readFileAsync } = require('../lib/fs')
|
|
6
7
|
const { getLegacyPathInHome, getPathInHome } = require('../lib/settings')
|
|
7
8
|
|
|
8
9
|
const globalConfigDefaults = {
|
|
@@ -19,7 +20,7 @@ const getGlobalConfigOnce = async function () {
|
|
|
19
20
|
let legacyConfig
|
|
20
21
|
// Read legacy config if exists
|
|
21
22
|
try {
|
|
22
|
-
legacyConfig = JSON.parse(await
|
|
23
|
+
legacyConfig = JSON.parse(await readFile(legacyPath))
|
|
23
24
|
} catch {}
|
|
24
25
|
// Use legacy config as default values
|
|
25
26
|
const defaults = { ...globalConfigDefaults, ...legacyConfig }
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
const { dirname } = require('path')
|
|
2
3
|
const process = require('process')
|
|
3
4
|
const util = require('util')
|
|
@@ -10,7 +11,13 @@ const parseGitRemote = require('parse-github-url')
|
|
|
10
11
|
|
|
11
12
|
const { log } = require('./command-helpers')
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param {object} config
|
|
17
|
+
* @param {string} [config.remoteName]
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
const getRepoData = async function ({ remoteName } = {}) {
|
|
14
21
|
try {
|
|
15
22
|
const cwd = process.cwd()
|
|
16
23
|
const [gitConfig, gitDirectory] = await Promise.all([
|
package/src/utils/gh-auth.js
CHANGED
package/src/utils/gitignore.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
const { readFile, writeFile } = require('fs').promises
|
|
1
3
|
const path = require('path')
|
|
2
4
|
|
|
3
5
|
const parseIgnore = require('parse-gitignore')
|
|
4
6
|
|
|
5
|
-
const { fileExistsAsync
|
|
7
|
+
const { fileExistsAsync } = require('../lib/fs')
|
|
6
8
|
|
|
7
9
|
const { log } = require('./command-helpers')
|
|
8
10
|
|
|
@@ -18,14 +20,14 @@ const ensureNetlifyIgnore = async function (dir) {
|
|
|
18
20
|
|
|
19
21
|
/* No .gitignore file. Create one and ignore .netlify folder */
|
|
20
22
|
if (!(await hasGitIgnore(dir))) {
|
|
21
|
-
await
|
|
23
|
+
await writeFile(gitIgnorePath, ignoreContent, 'utf8')
|
|
22
24
|
return false
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
let gitIgnoreContents
|
|
26
28
|
let ignorePatterns
|
|
27
29
|
try {
|
|
28
|
-
gitIgnoreContents = await
|
|
30
|
+
gitIgnoreContents = await readFile(gitIgnorePath, 'utf8')
|
|
29
31
|
ignorePatterns = parseIgnore.parse(gitIgnoreContents)
|
|
30
32
|
} catch (error) {
|
|
31
33
|
// ignore
|
|
@@ -35,8 +37,8 @@ const ensureNetlifyIgnore = async function (dir) {
|
|
|
35
37
|
log()
|
|
36
38
|
log('Adding local .netlify folder to .gitignore file...')
|
|
37
39
|
const newContents = `${gitIgnoreContents}\n${ignoreContent}`
|
|
38
|
-
await
|
|
40
|
+
await writeFile(gitIgnorePath, newContents, 'utf8')
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
43
|
|
|
42
|
-
module.exports = ensureNetlifyIgnore
|
|
44
|
+
module.exports = { ensureNetlifyIgnore }
|