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
package/src/lib/fs.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
const {
|
|
1
|
+
// @ts-check
|
|
2
|
+
const {
|
|
3
|
+
constants,
|
|
4
|
+
promises: { access, readFile, rm, stat },
|
|
5
|
+
} = require('fs')
|
|
6
|
+
const { version } = require('process')
|
|
3
7
|
|
|
4
8
|
const del = require('del')
|
|
5
|
-
const
|
|
6
|
-
const pathType = require('path-type')
|
|
9
|
+
const { gte, parse } = require('semver')
|
|
7
10
|
|
|
8
|
-
const
|
|
9
|
-
const readFileAsync = promisify(fs.readFile)
|
|
10
|
-
const writeFileAsync = promisify(fs.writeFile)
|
|
11
|
-
const rmFileAsync = promisify(fs.unlink)
|
|
12
|
-
const copyFileAsync = promisify(fs.copyFile)
|
|
13
|
-
const accessAsync = promisify(fs.access)
|
|
14
|
-
const mkdtempAsync = promisify(fs.mkdtemp)
|
|
15
|
-
const appendFileAsync = promisify(fs.appendFile)
|
|
11
|
+
const NODE_VERSION = parse(version)
|
|
16
12
|
|
|
17
|
-
|
|
13
|
+
/**
|
|
14
|
+
* reads a file async and catches potential errors
|
|
15
|
+
* @param {string} filePath
|
|
16
|
+
*/
|
|
17
|
+
const readFileAsyncCatchError = async (filePath) => {
|
|
18
18
|
try {
|
|
19
|
-
return { content: await
|
|
19
|
+
return { content: await readFile(filePath, 'utf-8') }
|
|
20
20
|
} catch (error) {
|
|
21
21
|
return { error }
|
|
22
22
|
}
|
|
@@ -24,42 +24,60 @@ const readFileAsyncCatchError = async (filepath) => {
|
|
|
24
24
|
|
|
25
25
|
const fileExistsAsync = async (filePath) => {
|
|
26
26
|
try {
|
|
27
|
-
await
|
|
27
|
+
await access(filePath, constants.F_OK)
|
|
28
28
|
return true
|
|
29
29
|
} catch {
|
|
30
30
|
return false
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Removes a directory recursively and async
|
|
36
|
+
* @param {string} path
|
|
37
|
+
* @returns {Promise<void>}
|
|
38
|
+
*/
|
|
39
|
+
const rmdirRecursiveAsync = async (path) => {
|
|
40
|
+
if (gte(NODE_VERSION, '14.14.0')) {
|
|
41
|
+
return await rm(path, { force: true, recursive: true })
|
|
42
|
+
}
|
|
43
|
+
await del(path, { force: true })
|
|
44
|
+
}
|
|
39
45
|
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
/**
|
|
47
|
+
* calls stat async with a function and catches potential errors
|
|
48
|
+
* @param {string} filePath
|
|
49
|
+
* @param {keyof import('fs').StatsBase<number>} type For example `isDirectory` or `isFile`
|
|
50
|
+
*/
|
|
51
|
+
const isType = async (filePath, type) => {
|
|
42
52
|
try {
|
|
43
|
-
await
|
|
44
|
-
|
|
45
|
-
|
|
53
|
+
const stats = await stat(filePath)
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
return typeof stats[type] === 'function' ? stats[type]() : stats[type]
|
|
56
|
+
} catch (error_) {
|
|
57
|
+
if (error_.code === 'ENOENT') {
|
|
58
|
+
return false
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
throw error_
|
|
46
62
|
}
|
|
47
63
|
}
|
|
48
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Checks if the provided filePath is a file
|
|
67
|
+
* @param {string} filePath
|
|
68
|
+
*/
|
|
69
|
+
const isFileAsync = (filePath) => isType(filePath, 'isFile')
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Checks if the provided filePath is a directory
|
|
73
|
+
* @param {string} filePath
|
|
74
|
+
*/
|
|
75
|
+
const isDirectoryAsync = (filePath) => isType(filePath, 'isDirectory')
|
|
76
|
+
|
|
49
77
|
module.exports = {
|
|
50
|
-
statAsync,
|
|
51
|
-
readFileAsync,
|
|
52
|
-
readFileAsyncCatchError,
|
|
53
|
-
writeFileAsync,
|
|
54
|
-
rmFileAsync,
|
|
55
|
-
copyFileAsync,
|
|
56
78
|
fileExistsAsync,
|
|
57
79
|
isDirectoryAsync,
|
|
58
80
|
isFileAsync,
|
|
59
|
-
|
|
60
|
-
mkdirRecursiveAsync,
|
|
81
|
+
readFileAsyncCatchError,
|
|
61
82
|
rmdirRecursiveAsync,
|
|
62
|
-
safelyRmdirRecursiveAsync,
|
|
63
|
-
mkdtempAsync,
|
|
64
|
-
appendFileAsync,
|
|
65
83
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
const { Readable } = require('stream')
|
|
2
3
|
|
|
3
4
|
const { parse: parseContentType } = require('content-type')
|
|
4
5
|
const multiparty = require('multiparty')
|
|
5
6
|
const getRawBody = require('raw-body')
|
|
6
7
|
|
|
8
|
+
const { BACKGROUND } = require('../../utils')
|
|
7
9
|
const { warn } = require('../../utils/command-helpers')
|
|
8
|
-
const { BACKGROUND } = require('../../utils/get-functions')
|
|
9
10
|
const { capitalize } = require('../string')
|
|
10
11
|
|
|
11
12
|
const createFormSubmissionHandler = function ({ functionsRegistry, siteUrl }) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
const { stdout } = require('process')
|
|
2
3
|
|
|
3
4
|
const { getBinaryPath: getFunctionsProxyPath } = require('@netlify/local-functions-proxy')
|
|
4
5
|
|
|
5
|
-
const execa = require('../../utils
|
|
6
|
+
const { execa } = require('../../utils')
|
|
6
7
|
|
|
7
8
|
const runFunctionsProxy = ({ binaryPath, context, directory, event, name, timeout }) => {
|
|
8
9
|
const functionsProxyPath = getFunctionsProxyPath()
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
const { error: errorExit } = require('../../utils/command-helpers')
|
|
2
|
-
const { difference } = require('../../utils/difference')
|
|
3
3
|
|
|
4
4
|
const BACKGROUND_SUFFIX = '-background'
|
|
5
5
|
|
|
6
|
+
// Returns a new set with all elements of `setA` that don't exist in `setB`.
|
|
7
|
+
const difference = (setA, setB) => new Set([...setA].filter((item) => !setB.has(item)))
|
|
8
|
+
|
|
6
9
|
class NetlifyFunction {
|
|
7
10
|
constructor({ config, directory, mainFile, name, projectRoot, runtime, timeoutBackground, timeoutSynchronous }) {
|
|
8
11
|
this.config = config
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
const { mkdir } = require('fs').promises
|
|
1
3
|
const { env } = require('process')
|
|
2
4
|
|
|
3
|
-
const chalk = require('
|
|
4
|
-
|
|
5
|
-
const { log, warn } = require('../../utils/command-helpers')
|
|
6
|
-
const { NETLIFYDEVERR, NETLIFYDEVLOG } = require('../../utils/logo')
|
|
7
|
-
const { mkdirRecursiveAsync } = require('../fs')
|
|
5
|
+
const { NETLIFYDEVERR, NETLIFYDEVLOG, chalk, log, warn } = require('../../utils')
|
|
8
6
|
const { getLogMessage } = require('../log')
|
|
9
7
|
|
|
10
8
|
const { NetlifyFunction } = require('./netlify-function')
|
|
@@ -45,7 +43,7 @@ class FunctionsRegistry {
|
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
static async prepareDirectoryScan(directory) {
|
|
48
|
-
await
|
|
46
|
+
await mkdir(directory, { recursive: true })
|
|
49
47
|
|
|
50
48
|
// We give runtimes the opportunity to react to a directory scan and run
|
|
51
49
|
// additional logic before the directory is read. So if they implement a
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
const { dirname, extname } = require('path')
|
|
2
3
|
const { platform } = require('process')
|
|
3
4
|
|
|
@@ -5,7 +6,7 @@ const tempy = require('tempy')
|
|
|
5
6
|
|
|
6
7
|
const isWindows = platform === 'win32'
|
|
7
8
|
|
|
8
|
-
const execa = require('../../../../utils
|
|
9
|
+
const { execa } = require('../../../../utils')
|
|
9
10
|
const { runFunctionsProxy } = require('../../local-proxy')
|
|
10
11
|
|
|
11
12
|
const build = async ({ binaryPath, functionDirectory }) => {
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
const { readFile } = require('fs').promises
|
|
1
3
|
const { resolve } = require('path')
|
|
2
4
|
|
|
3
|
-
const execa = require('execa')
|
|
4
5
|
const minimist = require('minimist')
|
|
5
6
|
|
|
6
|
-
const {
|
|
7
|
+
const { execa } = require('../../../../../utils')
|
|
8
|
+
const { fileExistsAsync } = require('../../../../fs')
|
|
7
9
|
const { memoizedBuild } = require('../../../memoized-build')
|
|
8
10
|
|
|
9
11
|
const detectNetlifyLambda = async function ({ packageJson } = {}) {
|
|
@@ -59,8 +61,8 @@ module.exports = async function handler() {
|
|
|
59
61
|
return false
|
|
60
62
|
}
|
|
61
63
|
|
|
62
|
-
const content = await
|
|
63
|
-
const packageJson = JSON.parse(content
|
|
64
|
+
const content = await readFile('package.json', 'utf-8')
|
|
65
|
+
const packageJson = JSON.parse(content)
|
|
64
66
|
return detectNetlifyLambda({ packageJson })
|
|
65
67
|
}
|
|
66
68
|
module.exports.detectNetlifyLambda = detectNetlifyLambda
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const { writeFile } = require('fs').promises
|
|
1
2
|
const path = require('path')
|
|
2
3
|
|
|
3
4
|
const { zipFunction } = require('@netlify/zip-it-and-ship-it')
|
|
@@ -6,8 +7,7 @@ const makeDir = require('make-dir')
|
|
|
6
7
|
const readPkgUp = require('read-pkg-up')
|
|
7
8
|
const sourceMapSupport = require('source-map-support')
|
|
8
9
|
|
|
9
|
-
const { NETLIFYDEVERR } = require('../../../../../utils
|
|
10
|
-
const { writeFileAsync } = require('../../../../fs')
|
|
10
|
+
const { NETLIFYDEVERR } = require('../../../../../utils')
|
|
11
11
|
const { getPathInProject } = require('../../../../settings')
|
|
12
12
|
const { normalizeFunctionsConfig } = require('../../../config')
|
|
13
13
|
const { memoizedBuild } = require('../../../memoized-build')
|
|
@@ -47,7 +47,7 @@ const buildFunction = async ({ cache, config, directory, func, hasTypeModule, pr
|
|
|
47
47
|
// some projects include a package.json with "type=module", forcing Node to interpret every descending file
|
|
48
48
|
// as ESM. ZISI outputs CJS, so we emit an overriding directive into the output directory.
|
|
49
49
|
if (hasTypeModule) {
|
|
50
|
-
await
|
|
50
|
+
await writeFile(
|
|
51
51
|
path.join(functionPath, `package.json`),
|
|
52
52
|
JSON.stringify({
|
|
53
53
|
type: 'commonjs',
|
|
@@ -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/settings.js
CHANGED
|
@@ -6,17 +6,32 @@ const envPaths = require('env-paths')
|
|
|
6
6
|
const OSBasedPaths = envPaths('netlify', { suffix: '' })
|
|
7
7
|
const NETLIFY_HOME = '.netlify'
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Deprecated method to get netlify's home config - ~/.netlify/...
|
|
11
|
+
* @deprecated
|
|
12
|
+
* @param {string[]} paths
|
|
13
|
+
* @returns {string}
|
|
14
|
+
*/
|
|
10
15
|
const getLegacyPathInHome = (paths) => {
|
|
11
16
|
const pathInHome = path.join(os.homedir(), NETLIFY_HOME, ...paths)
|
|
12
17
|
return pathInHome
|
|
13
18
|
}
|
|
14
19
|
|
|
20
|
+
/**
|
|
21
|
+
* get a global path on the os base path
|
|
22
|
+
* @param {string[]} paths
|
|
23
|
+
* @returns {string}
|
|
24
|
+
*/
|
|
15
25
|
const getPathInHome = (paths) => {
|
|
16
26
|
const pathInHome = path.join(OSBasedPaths.config, ...paths)
|
|
17
27
|
return pathInHome
|
|
18
28
|
}
|
|
19
29
|
|
|
30
|
+
/**
|
|
31
|
+
* get a path inside the project folder
|
|
32
|
+
* @param {string[]} paths
|
|
33
|
+
* @returns {string}
|
|
34
|
+
*/
|
|
20
35
|
const getPathInProject = (paths) => {
|
|
21
36
|
const pathInProject = path.join(NETLIFY_HOME, ...paths)
|
|
22
37
|
return pathInProject
|
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 {ora.Ora} config.spinner
|
|
20
|
+
* @param {object} [config.error]
|
|
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 }),
|