netlify-cli 17.3.1 → 17.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -139
- package/npm-shrinkwrap.json +82 -82
- package/package.json +16 -15
- package/src/commands/addons/addons-auth.mjs +27 -30
- package/src/commands/addons/addons-config.mjs +145 -154
- package/src/commands/addons/addons-create.mjs +94 -108
- package/src/commands/addons/addons-delete.mjs +36 -41
- package/src/commands/addons/addons-list.mjs +38 -42
- package/src/commands/addons/addons.mjs +26 -28
- package/src/commands/addons/index.mjs +1 -1
- package/src/commands/api/api.mjs +45 -53
- package/src/commands/api/index.mjs +1 -1
- package/src/commands/base-command.mjs +597 -684
- package/src/commands/blobs/blobs-delete.mjs +35 -0
- package/src/commands/blobs/blobs-get.mjs +44 -0
- package/src/commands/blobs/blobs-list.mjs +48 -0
- package/src/commands/blobs/blobs-set.mjs +54 -0
- package/src/commands/blobs/blobs.mjs +32 -0
- package/src/commands/blobs/index.mjs +1 -0
- package/src/commands/build/build.mjs +55 -67
- package/src/commands/build/index.mjs +1 -1
- package/src/commands/completion/completion.mjs +41 -46
- package/src/commands/completion/index.mjs +1 -1
- package/src/commands/deploy/deploy.mjs +675 -710
- package/src/commands/deploy/index.mjs +1 -1
- package/src/commands/dev/dev-exec.mjs +20 -32
- package/src/commands/dev/dev.mjs +217 -302
- package/src/commands/dev/index.mjs +1 -1
- package/src/commands/dev/types.d.ts +30 -0
- package/src/commands/env/env-clone.mjs +157 -184
- package/src/commands/env/env-get.mjs +49 -68
- package/src/commands/env/env-import.mjs +100 -119
- package/src/commands/env/env-list.mjs +104 -129
- package/src/commands/env/env-set.mjs +160 -185
- package/src/commands/env/env-unset.mjs +104 -122
- package/src/commands/env/env.mjs +28 -30
- package/src/commands/env/index.mjs +1 -1
- package/src/commands/functions/functions-build.mjs +29 -41
- package/src/commands/functions/functions-create.mjs +533 -601
- package/src/commands/functions/functions-invoke.mjs +193 -216
- package/src/commands/functions/functions-list.mjs +45 -55
- package/src/commands/functions/functions-serve.mjs +51 -61
- package/src/commands/functions/functions.mjs +26 -32
- package/src/commands/functions/index.mjs +1 -1
- package/src/commands/index.mjs +2 -2
- package/src/commands/init/index.mjs +1 -1
- package/src/commands/init/init.mjs +138 -167
- package/src/commands/integration/deploy.mjs +337 -399
- package/src/commands/integration/index.mjs +12 -13
- package/src/commands/link/index.mjs +1 -1
- package/src/commands/link/link.mjs +298 -317
- package/src/commands/lm/index.mjs +1 -1
- package/src/commands/lm/lm-info.mjs +23 -31
- package/src/commands/lm/lm-install.mjs +13 -17
- package/src/commands/lm/lm-setup.mjs +80 -84
- package/src/commands/lm/lm-uninstall.mjs +7 -12
- package/src/commands/lm/lm.mjs +18 -22
- package/src/commands/login/index.mjs +1 -1
- package/src/commands/login/login.mjs +35 -41
- package/src/commands/logout/index.mjs +1 -1
- package/src/commands/logout/logout.mjs +25 -31
- package/src/commands/main.mjs +166 -201
- package/src/commands/open/index.mjs +1 -1
- package/src/commands/open/open-admin.mjs +15 -18
- package/src/commands/open/open-site.mjs +16 -19
- package/src/commands/open/open.mjs +24 -27
- package/src/commands/recipes/common.mjs +23 -34
- package/src/commands/recipes/index.mjs +1 -1
- package/src/commands/recipes/recipes-list.mjs +13 -20
- package/src/commands/recipes/recipes.mjs +59 -72
- package/src/commands/serve/index.mjs +1 -1
- package/src/commands/serve/serve.mjs +142 -189
- package/src/commands/sites/index.mjs +2 -2
- package/src/commands/sites/sites-create-template.mjs +214 -236
- package/src/commands/sites/sites-create.mjs +145 -157
- package/src/commands/sites/sites-delete.mjs +75 -81
- package/src/commands/sites/sites-list.mjs +63 -66
- package/src/commands/sites/sites.mjs +18 -20
- package/src/commands/status/index.mjs +1 -1
- package/src/commands/status/status-hooks.mjs +32 -34
- package/src/commands/status/status.mjs +99 -106
- package/src/commands/switch/index.mjs +1 -1
- package/src/commands/switch/switch.mjs +32 -37
- package/src/commands/types.d.ts +31 -0
- package/src/commands/unlink/index.mjs +1 -1
- package/src/commands/unlink/unlink.mjs +23 -29
- package/src/commands/watch/index.mjs +1 -1
- package/src/commands/watch/watch.mjs +91 -105
- package/src/functions-templates/javascript/hello/{{name}}.js +2 -3
- package/src/lib/account.mjs +4 -5
- package/src/lib/api.mjs +22 -20
- package/src/lib/blobs/blobs.mjs +36 -45
- package/src/lib/build.mjs +82 -85
- package/src/lib/completion/constants.mjs +2 -4
- package/src/lib/completion/generate-autocompletion.mjs +33 -36
- package/src/lib/completion/get-autocompletion.mjs +31 -35
- package/src/lib/completion/index.mjs +1 -1
- package/src/lib/completion/script.mjs +12 -19
- package/src/lib/edge-functions/bootstrap.mjs +3 -5
- package/src/lib/edge-functions/consts.mjs +9 -10
- package/src/lib/edge-functions/deploy.mjs +28 -34
- package/src/lib/edge-functions/editor-helper.mjs +29 -42
- package/src/lib/edge-functions/headers.mjs +24 -26
- package/src/lib/edge-functions/internal.mjs +38 -44
- package/src/lib/edge-functions/proxy.mjs +229 -228
- package/src/lib/edge-functions/registry.mjs +473 -574
- package/src/lib/exec-fetcher.mjs +115 -122
- package/src/lib/fs.mjs +28 -27
- package/src/lib/functions/background.mjs +16 -20
- package/src/lib/functions/config.mjs +12 -9
- package/src/lib/functions/form-submissions-handler.mjs +143 -149
- package/src/lib/functions/local-proxy.mjs +40 -44
- package/src/lib/functions/memoized-build.mjs +19 -21
- package/src/lib/functions/netlify-function.mjs +269 -249
- package/src/lib/functions/registry.mjs +509 -568
- package/src/lib/functions/runtimes/go/index.mjs +62 -71
- package/src/lib/functions/runtimes/index.mjs +8 -15
- package/src/lib/functions/runtimes/js/builders/netlify-lambda.mjs +55 -64
- package/src/lib/functions/runtimes/js/builders/zisi.mjs +135 -154
- package/src/lib/functions/runtimes/js/constants.mjs +1 -1
- package/src/lib/functions/runtimes/js/index.mjs +92 -109
- package/src/lib/functions/runtimes/js/worker.mjs +43 -45
- package/src/lib/functions/runtimes/rust/index.mjs +64 -73
- package/src/lib/functions/scheduled.mjs +70 -88
- package/src/lib/functions/server.mjs +269 -327
- package/src/lib/functions/synchronous.mjs +118 -147
- package/src/lib/functions/utils.mjs +38 -46
- package/src/lib/geo-location.mjs +69 -81
- package/src/lib/http-agent.mjs +87 -90
- package/src/lib/images/proxy.mjs +97 -89
- package/src/lib/log.mjs +6 -9
- package/src/lib/path.mjs +2 -1
- package/src/lib/render-error-template.mjs +19 -20
- package/src/lib/settings.mjs +17 -19
- package/src/lib/spinner.mjs +21 -23
- package/src/lib/string.mjs +4 -2
- package/src/recipes/vscode/index.mjs +69 -85
- package/src/recipes/vscode/settings.mjs +53 -58
- package/src/utils/addons/compare.mjs +31 -32
- package/src/utils/addons/diffs/index.mjs +16 -17
- package/src/utils/addons/diffs/options.mjs +99 -101
- package/src/utils/addons/prepare.mjs +100 -97
- package/src/utils/addons/prompts.mjs +73 -76
- package/src/utils/addons/render.mjs +33 -36
- package/src/utils/addons/validation.mjs +19 -15
- package/src/utils/banner.mjs +11 -16
- package/src/utils/build-info.mjs +65 -66
- package/src/utils/command-helpers.mjs +185 -199
- package/src/utils/create-deferred.mjs +9 -12
- package/src/utils/create-stream-promise.mjs +54 -47
- package/src/utils/deploy/constants.mjs +9 -11
- package/src/utils/deploy/deploy-site.mjs +162 -182
- package/src/utils/deploy/hash-config.mjs +21 -21
- package/src/utils/deploy/hash-files.mjs +34 -38
- package/src/utils/deploy/hash-fns.mjs +149 -154
- package/src/utils/deploy/hasher-segments.mjs +58 -52
- package/src/utils/deploy/upload-files.mjs +99 -113
- package/src/utils/deploy/util.mjs +85 -91
- package/src/utils/detect-server-settings.mjs +236 -268
- package/src/utils/dev.mjs +163 -178
- package/src/utils/dot-env.mjs +37 -42
- package/src/utils/env/index.mjs +148 -148
- package/src/utils/execa.mjs +9 -13
- package/src/utils/feature-flags.mjs +6 -5
- package/src/utils/framework-server.mjs +43 -52
- package/src/utils/functions/constants.mjs +1 -1
- package/src/utils/functions/functions.mjs +30 -40
- package/src/utils/functions/get-functions.mjs +28 -29
- package/src/utils/functions/index.mjs +3 -3
- package/src/utils/get-global-config.mjs +33 -36
- package/src/utils/get-package-json.mjs +14 -15
- package/src/utils/get-repo-data.mjs +54 -64
- package/src/utils/get-site.mjs +14 -14
- package/src/utils/gh-auth.mjs +79 -100
- package/src/utils/gitignore.mjs +37 -40
- package/src/utils/headers.mjs +33 -35
- package/src/utils/hooks/requires-site-info.mjs +26 -22
- package/src/utils/init/config-github.mjs +207 -219
- package/src/utils/init/config-manual.mjs +83 -100
- package/src/utils/init/config.mjs +25 -26
- package/src/utils/init/node-version.mjs +23 -30
- package/src/utils/init/plugins.mjs +12 -8
- package/src/utils/init/utils.mjs +152 -172
- package/src/utils/live-tunnel.mjs +118 -141
- package/src/utils/lm/install.mjs +220 -259
- package/src/utils/lm/requirements.mjs +54 -63
- package/src/utils/lm/steps.mjs +31 -31
- package/src/utils/lm/ui.mjs +13 -20
- package/src/utils/open-browser.mjs +31 -32
- package/src/utils/parse-raw-flags.mjs +39 -35
- package/src/utils/proxy-server.mjs +84 -71
- package/src/utils/proxy.mjs +696 -750
- package/src/utils/read-repo-url.mjs +48 -47
- package/src/utils/redirects.mjs +49 -49
- package/src/utils/request-id.mjs +2 -4
- package/src/utils/rules-proxy.mjs +96 -100
- package/src/utils/run-build.mjs +109 -132
- package/src/utils/shell.mjs +99 -106
- package/src/utils/sign-redirect.mjs +14 -14
- package/src/utils/sites/utils.mjs +48 -55
- package/src/utils/state-config.mjs +101 -101
- package/src/utils/static-server.mjs +28 -34
- package/src/utils/telemetry/index.mjs +2 -2
- package/src/utils/telemetry/report-error.mjs +45 -49
- package/src/utils/telemetry/request.mjs +36 -43
- package/src/utils/telemetry/telemetry.mjs +90 -105
- package/src/utils/telemetry/utils.mjs +5 -6
- package/src/utils/telemetry/validation.mjs +55 -53
- package/src/utils/types.d.ts +46 -0
- package/src/utils/validation.mjs +10 -13
package/src/utils/build-info.mjs
CHANGED
|
@@ -1,43 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import inquirer from 'inquirer'
|
|
5
|
-
|
|
6
|
-
import { chalk, log } from './command-helpers.mjs'
|
|
7
|
-
|
|
1
|
+
import fuzzy from 'fuzzy';
|
|
2
|
+
import inquirer from 'inquirer';
|
|
3
|
+
import { chalk, log } from './command-helpers.mjs';
|
|
8
4
|
/**
|
|
9
5
|
* Filters the inquirer settings based on the input
|
|
10
6
|
* @param {ReturnType<typeof formatSettingsArrForInquirer>} scriptInquirerOptions
|
|
11
7
|
* @param {string} input
|
|
12
8
|
*/
|
|
9
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'scriptInquirerOptions' implicitly has a... Remove this comment to see the full error message
|
|
13
10
|
const filterSettings = function (scriptInquirerOptions, input) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
filteredSettings.map((filteredSetting) => (input ? filteredSetting.string : filteredSetting))
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
11
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'scriptInquirerOption' implicitly has an... Remove this comment to see the full error message
|
|
12
|
+
const filterOptions = scriptInquirerOptions.map((scriptInquirerOption) => scriptInquirerOption.name);
|
|
13
|
+
// TODO: remove once https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1394 is fixed
|
|
14
|
+
// eslint-disable-next-line unicorn/no-array-method-this-argument
|
|
15
|
+
const filteredSettings = fuzzy.filter(input, filterOptions);
|
|
16
|
+
const filteredSettingNames = new Set(filteredSettings.map((filteredSetting) => (input ? filteredSetting.string : filteredSetting)));
|
|
17
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 't' implicitly has an 'any' type.
|
|
18
|
+
return scriptInquirerOptions.filter((t) => filteredSettingNames.has(t.name));
|
|
19
|
+
};
|
|
24
20
|
/** @typedef {import('@netlify/build-info').Settings} Settings */
|
|
25
|
-
|
|
26
21
|
/**
|
|
27
22
|
* @param {Settings[]} settings
|
|
28
23
|
* @param {'dev' | 'build'} type The type of command (dev or build)
|
|
29
24
|
*/
|
|
25
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'settings' implicitly has an 'any' type.
|
|
30
26
|
const formatSettingsArrForInquirer = function (settings, type = 'dev') {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
27
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'setting' implicitly has an 'any' type.
|
|
28
|
+
return settings.map((setting) => {
|
|
29
|
+
const cmd = type === 'dev' ? setting.devCommand : setting.buildCommand;
|
|
30
|
+
return {
|
|
31
|
+
name: `[${chalk.yellow(setting.framework.name)}] '${cmd}'`,
|
|
32
|
+
value: { ...setting, commands: [cmd] },
|
|
33
|
+
short: `${setting.name}-${cmd}`,
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
};
|
|
41
37
|
/**
|
|
42
38
|
* Uses @netlify/build-info to detect the dev settings and port based on the framework
|
|
43
39
|
* and the build system that is used.
|
|
@@ -45,29 +41,31 @@ const formatSettingsArrForInquirer = function (settings, type = 'dev') {
|
|
|
45
41
|
* @param {'dev' | 'build'} type The type of command (dev or build)
|
|
46
42
|
* @returns {Promise<Settings | undefined>}
|
|
47
43
|
*/
|
|
44
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'command' implicitly has an 'any' type.
|
|
48
45
|
export const detectFrameworkSettings = async (command, type = 'dev') => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
46
|
+
const { relConfigFilePath } = command.netlify;
|
|
47
|
+
const settings = await detectBuildSettings(command);
|
|
48
|
+
if (settings.length === 1) {
|
|
49
|
+
return settings[0];
|
|
50
|
+
}
|
|
51
|
+
if (settings.length > 1) {
|
|
52
|
+
/** multiple matching detectors, make the user choose */
|
|
53
|
+
const scriptInquirerOptions = formatSettingsArrForInquirer(settings, type);
|
|
54
|
+
/** @type {{chosenSettings: Settings}} */
|
|
55
|
+
const { chosenSettings } = await inquirer.prompt({
|
|
56
|
+
name: 'chosenSettings',
|
|
57
|
+
message: `Multiple possible ${type} commands found`,
|
|
58
|
+
// @ts-expect-error TS(2769) FIXME: No overload matches this call.
|
|
59
|
+
type: 'autocomplete',
|
|
60
|
+
// @ts-expect-error TS(7006) FIXME: Parameter '_' implicitly has an 'any' type.
|
|
61
|
+
source(/** @type {string} */ _, input = '') {
|
|
62
|
+
if (!input)
|
|
63
|
+
return scriptInquirerOptions;
|
|
64
|
+
// only show filtered results
|
|
65
|
+
return filterSettings(scriptInquirerOptions, input);
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
log(`
|
|
71
69
|
Update your ${relConfigFilePath} to avoid this selection prompt next time:
|
|
72
70
|
|
|
73
71
|
[build]
|
|
@@ -76,25 +74,26 @@ publish = "${chosenSettings.dist}"
|
|
|
76
74
|
|
|
77
75
|
[dev]
|
|
78
76
|
command = "${chosenSettings.devCommand}"
|
|
79
|
-
`)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
77
|
+
`);
|
|
78
|
+
return chosenSettings;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
84
81
|
/**
|
|
85
82
|
* Detects and filters the build setting for a project and a command
|
|
86
83
|
* @param {import('../commands/base-command.mjs').default} command
|
|
87
84
|
*/
|
|
85
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'command' implicitly has an 'any' type.
|
|
88
86
|
export const detectBuildSettings = async (command) => {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
87
|
+
const { project, workspacePackage } = command;
|
|
88
|
+
const buildSettings = await project.getBuildSettings(project.workspace ? workspacePackage : '');
|
|
89
|
+
return buildSettings
|
|
90
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'setting' implicitly has an 'any' type.
|
|
91
|
+
.filter((setting) => {
|
|
92
|
+
if (project.workspace && project.relativeBaseDirectory && setting.packagePath) {
|
|
93
|
+
return project.relativeBaseDirectory.startsWith(setting.packagePath);
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
98
96
|
})
|
|
99
|
-
|
|
100
|
-
|
|
97
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'setting' implicitly has an 'any' type.
|
|
98
|
+
.filter((setting) => setting.devCommand);
|
|
99
|
+
};
|
|
@@ -1,41 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { format, inspect } from 'util'
|
|
6
|
-
|
|
1
|
+
import { once } from 'events';
|
|
2
|
+
import os from 'os';
|
|
3
|
+
import process from 'process';
|
|
4
|
+
import { format, inspect } from 'util';
|
|
7
5
|
// eslint-disable-next-line no-restricted-imports
|
|
8
|
-
import { Chalk } from 'chalk'
|
|
9
|
-
import chokidar from 'chokidar'
|
|
10
|
-
import decache from 'decache'
|
|
11
|
-
import WSL from 'is-wsl'
|
|
12
|
-
import debounce from 'lodash/debounce.js'
|
|
13
|
-
import terminalLink from 'terminal-link'
|
|
14
|
-
|
|
15
|
-
import
|
|
16
|
-
|
|
17
|
-
import
|
|
18
|
-
import getPackageJson from './get-package-json.mjs'
|
|
19
|
-
import { reportError } from './telemetry/report-error.mjs'
|
|
20
|
-
|
|
6
|
+
import { Chalk } from 'chalk';
|
|
7
|
+
import chokidar from 'chokidar';
|
|
8
|
+
import decache from 'decache';
|
|
9
|
+
import WSL from 'is-wsl';
|
|
10
|
+
import debounce from 'lodash/debounce.js';
|
|
11
|
+
import terminalLink from 'terminal-link';
|
|
12
|
+
import { clearSpinner, startSpinner } from '../lib/spinner.mjs';
|
|
13
|
+
import getGlobalConfig from './get-global-config.mjs';
|
|
14
|
+
import getPackageJson from './get-package-json.mjs';
|
|
15
|
+
import { reportError } from './telemetry/report-error.mjs';
|
|
21
16
|
/** The parsed process argv without the binary only arguments and flags */
|
|
22
|
-
const argv = process.argv.slice(2)
|
|
17
|
+
const argv = process.argv.slice(2);
|
|
23
18
|
/**
|
|
24
19
|
* Chalk instance for CLI that can be initialized with no colors mode
|
|
25
20
|
* needed for json outputs where we don't want to have colors
|
|
26
21
|
* @param {boolean} noColors - disable chalk colors
|
|
27
22
|
* @return {import('chalk').ChalkInstance} - default or custom chalk instance
|
|
28
23
|
*/
|
|
24
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'noColors' implicitly has an 'any' type.
|
|
29
25
|
const safeChalk = function (noColors) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export const chalk = safeChalk(argv.includes('--json'))
|
|
38
|
-
|
|
26
|
+
if (noColors) {
|
|
27
|
+
const colorlessChalk = new Chalk({ level: 0 });
|
|
28
|
+
return colorlessChalk;
|
|
29
|
+
}
|
|
30
|
+
return new Chalk();
|
|
31
|
+
};
|
|
32
|
+
export const chalk = safeChalk(argv.includes('--json'));
|
|
39
33
|
/**
|
|
40
34
|
* Adds the filler to the start of the string
|
|
41
35
|
* @param {string} str
|
|
@@ -43,27 +37,20 @@ export const chalk = safeChalk(argv.includes('--json'))
|
|
|
43
37
|
* @param {string} [filler]
|
|
44
38
|
* @returns {string}
|
|
45
39
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const platform = WSL ? 'wsl' : os.platform()
|
|
49
|
-
const arch = os.arch() === 'ia32' ? 'x86' : os.arch()
|
|
50
|
-
|
|
51
|
-
const {
|
|
52
|
-
|
|
53
|
-
export const USER_AGENT = `${name}/${version} ${platform}-${arch} node-${process.version}`
|
|
54
|
-
|
|
40
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'str' implicitly has an 'any' type.
|
|
41
|
+
export const padLeft = (str, count, filler = ' ') => str.padStart(str.length + count, filler);
|
|
42
|
+
const platform = WSL ? 'wsl' : os.platform();
|
|
43
|
+
const arch = os.arch() === 'ia32' ? 'x86' : os.arch();
|
|
44
|
+
const { name, version } = await getPackageJson();
|
|
45
|
+
export const USER_AGENT = `${name}/${version} ${platform}-${arch} node-${process.version}`;
|
|
55
46
|
/** A list of base command flags that needs to be sorted down on documentation and on help pages */
|
|
56
|
-
const BASE_FLAGS = new Set(['--debug', '--httpProxy', '--httpProxyCertificateFilename'])
|
|
57
|
-
|
|
58
|
-
export const
|
|
59
|
-
|
|
60
|
-
export const
|
|
61
|
-
export const
|
|
62
|
-
export const
|
|
63
|
-
export const NETLIFYDEVERR = `${chalk.redBright('◈')}`
|
|
64
|
-
|
|
65
|
-
export const BANG = process.platform === 'win32' ? '»' : '›'
|
|
66
|
-
|
|
47
|
+
const BASE_FLAGS = new Set(['--debug', '--httpProxy', '--httpProxyCertificateFilename']);
|
|
48
|
+
export const NETLIFY_CYAN = chalk.rgb(40, 180, 170);
|
|
49
|
+
export const NETLIFYDEV = `${chalk.greenBright('◈')} ${NETLIFY_CYAN('Netlify Dev')} ${chalk.greenBright('◈')}`;
|
|
50
|
+
export const NETLIFYDEVLOG = `${chalk.greenBright('◈')}`;
|
|
51
|
+
export const NETLIFYDEVWARN = `${chalk.yellowBright('◈')}`;
|
|
52
|
+
export const NETLIFYDEVERR = `${chalk.redBright('◈')}`;
|
|
53
|
+
export const BANG = process.platform === 'win32' ? '»' : '›';
|
|
67
54
|
/**
|
|
68
55
|
* Sorts two options so that the base flags are at the bottom of the list
|
|
69
56
|
* @param {import('commander').Option} optionA
|
|
@@ -72,17 +59,16 @@ export const BANG = process.platform === 'win32' ? '»' : '›'
|
|
|
72
59
|
* @example
|
|
73
60
|
* options.sort(sortOptions)
|
|
74
61
|
*/
|
|
62
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'optionA' implicitly has an 'any' type.
|
|
75
63
|
export const sortOptions = (optionA, optionB) => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
64
|
+
// base flags should be always at the bottom
|
|
65
|
+
if (BASE_FLAGS.has(optionA.long) || BASE_FLAGS.has(optionB.long)) {
|
|
66
|
+
return -1;
|
|
67
|
+
}
|
|
68
|
+
return optionA.long.localeCompare(optionB.long);
|
|
69
|
+
};
|
|
83
70
|
// Poll Token timeout 5 Minutes
|
|
84
|
-
const TOKEN_TIMEOUT = 3e5
|
|
85
|
-
|
|
71
|
+
const TOKEN_TIMEOUT = 3e5;
|
|
86
72
|
/**
|
|
87
73
|
*
|
|
88
74
|
* @param {object} config
|
|
@@ -90,94 +76,89 @@ const TOKEN_TIMEOUT = 3e5
|
|
|
90
76
|
* @param {object} config.ticket
|
|
91
77
|
* @returns
|
|
92
78
|
*/
|
|
79
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'api' implicitly has an 'any' type... Remove this comment to see the full error message
|
|
93
80
|
export const pollForToken = async ({ api, ticket }) => {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
81
|
+
const spinner = startSpinner({ text: 'Waiting for authorization...' });
|
|
82
|
+
try {
|
|
83
|
+
const accessToken = await api.getAccessToken(ticket, { timeout: TOKEN_TIMEOUT });
|
|
84
|
+
if (!accessToken) {
|
|
85
|
+
error('Could not retrieve access token');
|
|
86
|
+
}
|
|
87
|
+
return accessToken;
|
|
88
|
+
}
|
|
89
|
+
catch (error_) {
|
|
90
|
+
// @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
|
|
91
|
+
if (error_.name === 'TimeoutError') {
|
|
92
|
+
error(`Timed out waiting for authorization. If you do not have a ${chalk.bold.greenBright('Netlify')} account, please create one at ${chalk.magenta('https://app.netlify.com/signup')}, then run ${chalk.cyanBright('netlify login')} again.`);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// @ts-expect-error TS(2345) FIXME: Argument of type 'unknown' is not assignable to pa... Remove this comment to see the full error message
|
|
96
|
+
error(error_);
|
|
97
|
+
}
|
|
99
98
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (error_.name === 'TimeoutError') {
|
|
103
|
-
error(
|
|
104
|
-
`Timed out waiting for authorization. If you do not have a ${chalk.bold.greenBright(
|
|
105
|
-
'Netlify',
|
|
106
|
-
)} account, please create one at ${chalk.magenta(
|
|
107
|
-
'https://app.netlify.com/signup',
|
|
108
|
-
)}, then run ${chalk.cyanBright('netlify login')} again.`,
|
|
109
|
-
)
|
|
110
|
-
} else {
|
|
111
|
-
error(error_)
|
|
99
|
+
finally {
|
|
100
|
+
clearSpinner({ spinner });
|
|
112
101
|
}
|
|
113
|
-
|
|
114
|
-
clearSpinner({ spinner })
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
102
|
+
};
|
|
118
103
|
/**
|
|
119
104
|
* Get a netlify token
|
|
120
105
|
* @param {string} [tokenFromOptions] optional token from the provided --auth options
|
|
121
106
|
* @returns {Promise<[null|string, 'flag' | 'env' |'config' |'not found']>}
|
|
122
107
|
*/
|
|
108
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'tokenFromOptions' implicitly has an 'an... Remove this comment to see the full error message
|
|
123
109
|
export const getToken = async (tokenFromOptions) => {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
|
|
110
|
+
// 1. First honor command flag --auth
|
|
111
|
+
if (tokenFromOptions) {
|
|
112
|
+
return [tokenFromOptions, 'flag'];
|
|
113
|
+
}
|
|
114
|
+
// 2. then Check ENV var
|
|
115
|
+
const { NETLIFY_AUTH_TOKEN } = process.env;
|
|
116
|
+
if (NETLIFY_AUTH_TOKEN && NETLIFY_AUTH_TOKEN !== 'null') {
|
|
117
|
+
return [NETLIFY_AUTH_TOKEN, 'env'];
|
|
118
|
+
}
|
|
119
|
+
// 3. If no env var use global user setting
|
|
120
|
+
const globalConfig = await getGlobalConfig();
|
|
121
|
+
const userId = globalConfig.get('userId');
|
|
122
|
+
const tokenFromConfig = globalConfig.get(`users.${userId}.auth.token`);
|
|
123
|
+
if (tokenFromConfig) {
|
|
124
|
+
return [tokenFromConfig, 'config'];
|
|
125
|
+
}
|
|
126
|
+
return [null, 'not found'];
|
|
127
|
+
};
|
|
143
128
|
// 'api' command uses JSON output by default
|
|
144
129
|
// 'functions:invoke' need to return the data from the function as is
|
|
145
|
-
const isDefaultJson = () => argv[0] === 'functions:invoke' || (argv[0] === 'api' && !argv.includes('--list'))
|
|
146
|
-
|
|
130
|
+
const isDefaultJson = () => argv[0] === 'functions:invoke' || (argv[0] === 'api' && !argv.includes('--list'));
|
|
147
131
|
/**
|
|
148
132
|
* logs a json message
|
|
149
|
-
* @param {string|object} message
|
|
150
133
|
*/
|
|
151
134
|
export const logJson = (message = '') => {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
135
|
+
if (argv.includes('--json') || isDefaultJson()) {
|
|
136
|
+
process.stdout.write(JSON.stringify(message, null, 2));
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
// @ts-expect-error TS(7019) FIXME: Rest parameter 'args' implicitly has an 'any[]' ty... Remove this comment to see the full error message
|
|
157
140
|
export const log = (message = '', ...args) => {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
|
|
141
|
+
// If --silent or --json flag passed disable logger
|
|
142
|
+
if (argv.includes('--json') || argv.includes('--silent') || isDefaultJson()) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
message = typeof message === 'string' ? message : inspect(message);
|
|
146
|
+
process.stdout.write(`${format(message, ...args)}\n`);
|
|
147
|
+
};
|
|
148
|
+
// @ts-expect-error TS(7019) FIXME: Rest parameter 'args' implicitly has an 'any[]' ty... Remove this comment to see the full error message
|
|
166
149
|
export const logPadded = (message = '', ...args) => {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
|
|
150
|
+
log('');
|
|
151
|
+
log(message, ...args);
|
|
152
|
+
log('');
|
|
153
|
+
};
|
|
172
154
|
/**
|
|
173
155
|
* logs a warning message
|
|
174
156
|
* @param {string} message
|
|
175
157
|
*/
|
|
176
158
|
export const warn = (message = '') => {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
|
|
159
|
+
const bang = chalk.yellow(BANG);
|
|
160
|
+
log(` ${bang} Warning: ${message}`);
|
|
161
|
+
};
|
|
181
162
|
/**
|
|
182
163
|
* throws an error or log it
|
|
183
164
|
* @param {unknown} message
|
|
@@ -185,31 +166,32 @@ export const warn = (message = '') => {
|
|
|
185
166
|
* @param {boolean} [options.exit]
|
|
186
167
|
*/
|
|
187
168
|
export const error = (message = '', options = {}) => {
|
|
188
|
-
|
|
169
|
+
const err =
|
|
170
|
+
// @ts-expect-error TS(2358) FIXME: The left-hand side of an 'instanceof' expression m... Remove this comment to see the full error message
|
|
189
171
|
message instanceof Error
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
172
|
+
? message
|
|
173
|
+
: // eslint-disable-next-line unicorn/no-nested-ternary
|
|
174
|
+
typeof message === 'string'
|
|
175
|
+
? new Error(message)
|
|
176
|
+
: /** @type {Error} */ { message, stack: undefined, name: 'Error' };
|
|
177
|
+
// @ts-expect-error TS(2339) FIXME: Property 'exit' does not exist on type '{}'.
|
|
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} `)}\n`);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
process.stderr.write(` ${bang} ${chalk.red(`${err.name}:`)} ${err.message}\n`);
|
|
185
|
+
}
|
|
202
186
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
|
|
187
|
+
else {
|
|
188
|
+
reportError(err, { severity: 'error' });
|
|
189
|
+
throw err;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
209
192
|
export const exit = (code = 0) => {
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
|
|
193
|
+
process.exit(code);
|
|
194
|
+
};
|
|
213
195
|
/**
|
|
214
196
|
* When `build.publish` is not set by the user, the CLI behavior differs in
|
|
215
197
|
* several ways. It detects it by checking if `build.publish` is `undefined`.
|
|
@@ -217,16 +199,14 @@ export const exit = (code = 0) => {
|
|
|
217
199
|
* This removes 'publish' and 'publishOrigin' in this case.
|
|
218
200
|
* @param {*} config
|
|
219
201
|
*/
|
|
202
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'config' implicitly has an 'any' type.
|
|
220
203
|
export const normalizeConfig = (config) => {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
const DEBOUNCE_WAIT = 100
|
|
229
|
-
|
|
204
|
+
// Unused var here is in order to omit 'publish' from build config
|
|
205
|
+
// eslint-disable-next-line no-unused-vars
|
|
206
|
+
const { publish, publishOrigin, ...build } = config.build;
|
|
207
|
+
return publishOrigin === 'default' ? { ...config, build } : config;
|
|
208
|
+
};
|
|
209
|
+
const DEBOUNCE_WAIT = 100;
|
|
230
210
|
/**
|
|
231
211
|
* Adds a file watcher to a path or set of paths and debounces the events.
|
|
232
212
|
*
|
|
@@ -239,49 +219,55 @@ const DEBOUNCE_WAIT = 100
|
|
|
239
219
|
* @param {(paths: string[]) => any} [opts.onUnlink]
|
|
240
220
|
*/
|
|
241
221
|
export const watchDebounced = async (
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
)
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
debouncedOnUnlink()
|
|
222
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'target' implicitly has an 'any' type.
|
|
223
|
+
target,
|
|
224
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'depth' implicitly has an 'any' ty... Remove this comment to see the full error message
|
|
225
|
+
{ depth, ignored = [], onAdd = () => { }, onChange = () => { }, onUnlink = () => { } }) => {
|
|
226
|
+
const baseIgnores = [/\/(node_modules|.git)\//];
|
|
227
|
+
const watcher = chokidar.watch(target, { depth, ignored: [...baseIgnores, ...ignored], ignoreInitial: true });
|
|
228
|
+
await once(watcher, 'ready');
|
|
229
|
+
// @ts-expect-error TS(7034) FIXME: Variable 'onChangeQueue' implicitly has type 'any[... Remove this comment to see the full error message
|
|
230
|
+
let onChangeQueue = [];
|
|
231
|
+
// @ts-expect-error TS(7034) FIXME: Variable 'onAddQueue' implicitly has type 'any[]' ... Remove this comment to see the full error message
|
|
232
|
+
let onAddQueue = [];
|
|
233
|
+
// @ts-expect-error TS(7034) FIXME: Variable 'onUnlinkQueue' implicitly has type 'any[... Remove this comment to see the full error message
|
|
234
|
+
let onUnlinkQueue = [];
|
|
235
|
+
const debouncedOnChange = debounce(() => {
|
|
236
|
+
// @ts-expect-error TS(2554) FIXME: Expected 0 arguments, but got 1.
|
|
237
|
+
onChange(onChangeQueue);
|
|
238
|
+
onChangeQueue = [];
|
|
239
|
+
}, DEBOUNCE_WAIT);
|
|
240
|
+
const debouncedOnAdd = debounce(() => {
|
|
241
|
+
// @ts-expect-error TS(2554) FIXME: Expected 0 arguments, but got 1.
|
|
242
|
+
onAdd(onAddQueue);
|
|
243
|
+
onAddQueue = [];
|
|
244
|
+
}, DEBOUNCE_WAIT);
|
|
245
|
+
const debouncedOnUnlink = debounce(() => {
|
|
246
|
+
// @ts-expect-error TS(2554) FIXME: Expected 0 arguments, but got 1.
|
|
247
|
+
onUnlink(onUnlinkQueue);
|
|
248
|
+
onUnlinkQueue = [];
|
|
249
|
+
}, DEBOUNCE_WAIT);
|
|
250
|
+
watcher
|
|
251
|
+
.on('change', (path) => {
|
|
252
|
+
// @ts-expect-error
|
|
253
|
+
decache(path);
|
|
254
|
+
onChangeQueue.push(path);
|
|
255
|
+
debouncedOnChange();
|
|
277
256
|
})
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
257
|
+
.on('unlink', (path) => {
|
|
258
|
+
// @ts-expect-error
|
|
259
|
+
decache(path);
|
|
260
|
+
onUnlinkQueue.push(path);
|
|
261
|
+
debouncedOnUnlink();
|
|
282
262
|
})
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
263
|
+
.on('add', (path) => {
|
|
264
|
+
// @ts-expect-error
|
|
265
|
+
decache(path);
|
|
266
|
+
onAddQueue.push(path);
|
|
267
|
+
debouncedOnAdd();
|
|
268
|
+
});
|
|
269
|
+
return watcher;
|
|
270
|
+
};
|
|
271
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'text' implicitly has an 'any' type.
|
|
272
|
+
export const getTerminalLink = (text, url) => terminalLink(text, url, { fallback: () => `${text} (${url})` });
|
|
273
|
+
export const isNodeError = (err) => error instanceof Error;
|