netlify-cli 17.3.2 → 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.
Files changed (210) hide show
  1. package/README.md +2 -138
  2. package/npm-shrinkwrap.json +76 -76
  3. package/package.json +16 -15
  4. package/src/commands/addons/addons-auth.mjs +27 -30
  5. package/src/commands/addons/addons-config.mjs +145 -154
  6. package/src/commands/addons/addons-create.mjs +94 -108
  7. package/src/commands/addons/addons-delete.mjs +36 -41
  8. package/src/commands/addons/addons-list.mjs +38 -42
  9. package/src/commands/addons/addons.mjs +26 -28
  10. package/src/commands/addons/index.mjs +1 -1
  11. package/src/commands/api/api.mjs +45 -53
  12. package/src/commands/api/index.mjs +1 -1
  13. package/src/commands/base-command.mjs +597 -684
  14. package/src/commands/blobs/blobs-delete.mjs +35 -0
  15. package/src/commands/blobs/blobs-get.mjs +44 -0
  16. package/src/commands/blobs/blobs-list.mjs +48 -0
  17. package/src/commands/blobs/blobs-set.mjs +54 -0
  18. package/src/commands/blobs/blobs.mjs +32 -0
  19. package/src/commands/blobs/index.mjs +1 -0
  20. package/src/commands/build/build.mjs +55 -67
  21. package/src/commands/build/index.mjs +1 -1
  22. package/src/commands/completion/completion.mjs +41 -46
  23. package/src/commands/completion/index.mjs +1 -1
  24. package/src/commands/deploy/deploy.mjs +675 -710
  25. package/src/commands/deploy/index.mjs +1 -1
  26. package/src/commands/dev/dev-exec.mjs +20 -32
  27. package/src/commands/dev/dev.mjs +217 -302
  28. package/src/commands/dev/index.mjs +1 -1
  29. package/src/commands/dev/types.d.ts +30 -0
  30. package/src/commands/env/env-clone.mjs +157 -184
  31. package/src/commands/env/env-get.mjs +49 -68
  32. package/src/commands/env/env-import.mjs +100 -119
  33. package/src/commands/env/env-list.mjs +104 -129
  34. package/src/commands/env/env-set.mjs +160 -185
  35. package/src/commands/env/env-unset.mjs +104 -122
  36. package/src/commands/env/env.mjs +28 -30
  37. package/src/commands/env/index.mjs +1 -1
  38. package/src/commands/functions/functions-build.mjs +29 -41
  39. package/src/commands/functions/functions-create.mjs +533 -601
  40. package/src/commands/functions/functions-invoke.mjs +193 -216
  41. package/src/commands/functions/functions-list.mjs +45 -55
  42. package/src/commands/functions/functions-serve.mjs +51 -61
  43. package/src/commands/functions/functions.mjs +26 -32
  44. package/src/commands/functions/index.mjs +1 -1
  45. package/src/commands/index.mjs +2 -2
  46. package/src/commands/init/index.mjs +1 -1
  47. package/src/commands/init/init.mjs +138 -167
  48. package/src/commands/integration/deploy.mjs +337 -399
  49. package/src/commands/integration/index.mjs +12 -13
  50. package/src/commands/link/index.mjs +1 -1
  51. package/src/commands/link/link.mjs +298 -317
  52. package/src/commands/lm/index.mjs +1 -1
  53. package/src/commands/lm/lm-info.mjs +23 -31
  54. package/src/commands/lm/lm-install.mjs +13 -17
  55. package/src/commands/lm/lm-setup.mjs +80 -84
  56. package/src/commands/lm/lm-uninstall.mjs +7 -12
  57. package/src/commands/lm/lm.mjs +18 -22
  58. package/src/commands/login/index.mjs +1 -1
  59. package/src/commands/login/login.mjs +35 -41
  60. package/src/commands/logout/index.mjs +1 -1
  61. package/src/commands/logout/logout.mjs +25 -31
  62. package/src/commands/main.mjs +166 -201
  63. package/src/commands/open/index.mjs +1 -1
  64. package/src/commands/open/open-admin.mjs +15 -18
  65. package/src/commands/open/open-site.mjs +16 -19
  66. package/src/commands/open/open.mjs +24 -27
  67. package/src/commands/recipes/common.mjs +23 -34
  68. package/src/commands/recipes/index.mjs +1 -1
  69. package/src/commands/recipes/recipes-list.mjs +13 -20
  70. package/src/commands/recipes/recipes.mjs +59 -72
  71. package/src/commands/serve/index.mjs +1 -1
  72. package/src/commands/serve/serve.mjs +142 -189
  73. package/src/commands/sites/index.mjs +2 -2
  74. package/src/commands/sites/sites-create-template.mjs +214 -236
  75. package/src/commands/sites/sites-create.mjs +145 -157
  76. package/src/commands/sites/sites-delete.mjs +75 -81
  77. package/src/commands/sites/sites-list.mjs +63 -66
  78. package/src/commands/sites/sites.mjs +18 -20
  79. package/src/commands/status/index.mjs +1 -1
  80. package/src/commands/status/status-hooks.mjs +32 -34
  81. package/src/commands/status/status.mjs +99 -106
  82. package/src/commands/switch/index.mjs +1 -1
  83. package/src/commands/switch/switch.mjs +32 -37
  84. package/src/commands/types.d.ts +31 -0
  85. package/src/commands/unlink/index.mjs +1 -1
  86. package/src/commands/unlink/unlink.mjs +23 -29
  87. package/src/commands/watch/index.mjs +1 -1
  88. package/src/commands/watch/watch.mjs +91 -105
  89. package/src/functions-templates/javascript/hello/{{name}}.js +2 -3
  90. package/src/lib/account.mjs +4 -5
  91. package/src/lib/api.mjs +22 -20
  92. package/src/lib/blobs/blobs.mjs +36 -45
  93. package/src/lib/build.mjs +82 -85
  94. package/src/lib/completion/constants.mjs +2 -4
  95. package/src/lib/completion/generate-autocompletion.mjs +33 -36
  96. package/src/lib/completion/get-autocompletion.mjs +31 -35
  97. package/src/lib/completion/index.mjs +1 -1
  98. package/src/lib/completion/script.mjs +12 -19
  99. package/src/lib/edge-functions/bootstrap.mjs +3 -5
  100. package/src/lib/edge-functions/consts.mjs +9 -10
  101. package/src/lib/edge-functions/deploy.mjs +28 -34
  102. package/src/lib/edge-functions/editor-helper.mjs +29 -42
  103. package/src/lib/edge-functions/headers.mjs +24 -26
  104. package/src/lib/edge-functions/internal.mjs +38 -44
  105. package/src/lib/edge-functions/proxy.mjs +229 -228
  106. package/src/lib/edge-functions/registry.mjs +473 -574
  107. package/src/lib/exec-fetcher.mjs +115 -122
  108. package/src/lib/fs.mjs +28 -27
  109. package/src/lib/functions/background.mjs +16 -20
  110. package/src/lib/functions/config.mjs +12 -9
  111. package/src/lib/functions/form-submissions-handler.mjs +143 -149
  112. package/src/lib/functions/local-proxy.mjs +40 -44
  113. package/src/lib/functions/memoized-build.mjs +19 -21
  114. package/src/lib/functions/netlify-function.mjs +269 -249
  115. package/src/lib/functions/registry.mjs +509 -568
  116. package/src/lib/functions/runtimes/go/index.mjs +62 -71
  117. package/src/lib/functions/runtimes/index.mjs +8 -15
  118. package/src/lib/functions/runtimes/js/builders/netlify-lambda.mjs +55 -64
  119. package/src/lib/functions/runtimes/js/builders/zisi.mjs +135 -154
  120. package/src/lib/functions/runtimes/js/constants.mjs +1 -1
  121. package/src/lib/functions/runtimes/js/index.mjs +92 -109
  122. package/src/lib/functions/runtimes/js/worker.mjs +43 -45
  123. package/src/lib/functions/runtimes/rust/index.mjs +64 -73
  124. package/src/lib/functions/scheduled.mjs +70 -88
  125. package/src/lib/functions/server.mjs +269 -327
  126. package/src/lib/functions/synchronous.mjs +118 -147
  127. package/src/lib/functions/utils.mjs +38 -46
  128. package/src/lib/geo-location.mjs +69 -81
  129. package/src/lib/http-agent.mjs +87 -90
  130. package/src/lib/images/proxy.mjs +97 -99
  131. package/src/lib/log.mjs +6 -9
  132. package/src/lib/path.mjs +2 -1
  133. package/src/lib/render-error-template.mjs +19 -20
  134. package/src/lib/settings.mjs +17 -19
  135. package/src/lib/spinner.mjs +21 -23
  136. package/src/lib/string.mjs +4 -2
  137. package/src/recipes/vscode/index.mjs +69 -85
  138. package/src/recipes/vscode/settings.mjs +53 -58
  139. package/src/utils/addons/compare.mjs +31 -32
  140. package/src/utils/addons/diffs/index.mjs +16 -17
  141. package/src/utils/addons/diffs/options.mjs +99 -101
  142. package/src/utils/addons/prepare.mjs +100 -97
  143. package/src/utils/addons/prompts.mjs +73 -76
  144. package/src/utils/addons/render.mjs +33 -36
  145. package/src/utils/addons/validation.mjs +19 -15
  146. package/src/utils/banner.mjs +11 -16
  147. package/src/utils/build-info.mjs +65 -66
  148. package/src/utils/command-helpers.mjs +185 -199
  149. package/src/utils/create-deferred.mjs +9 -12
  150. package/src/utils/create-stream-promise.mjs +54 -47
  151. package/src/utils/deploy/constants.mjs +9 -11
  152. package/src/utils/deploy/deploy-site.mjs +162 -182
  153. package/src/utils/deploy/hash-config.mjs +21 -21
  154. package/src/utils/deploy/hash-files.mjs +34 -38
  155. package/src/utils/deploy/hash-fns.mjs +149 -154
  156. package/src/utils/deploy/hasher-segments.mjs +58 -52
  157. package/src/utils/deploy/upload-files.mjs +99 -113
  158. package/src/utils/deploy/util.mjs +85 -91
  159. package/src/utils/detect-server-settings.mjs +236 -268
  160. package/src/utils/dev.mjs +163 -178
  161. package/src/utils/dot-env.mjs +37 -42
  162. package/src/utils/env/index.mjs +148 -148
  163. package/src/utils/execa.mjs +9 -13
  164. package/src/utils/feature-flags.mjs +6 -5
  165. package/src/utils/framework-server.mjs +43 -52
  166. package/src/utils/functions/constants.mjs +1 -1
  167. package/src/utils/functions/functions.mjs +30 -40
  168. package/src/utils/functions/get-functions.mjs +28 -29
  169. package/src/utils/functions/index.mjs +3 -3
  170. package/src/utils/get-global-config.mjs +33 -36
  171. package/src/utils/get-package-json.mjs +14 -15
  172. package/src/utils/get-repo-data.mjs +54 -64
  173. package/src/utils/get-site.mjs +14 -14
  174. package/src/utils/gh-auth.mjs +79 -100
  175. package/src/utils/gitignore.mjs +37 -40
  176. package/src/utils/headers.mjs +33 -35
  177. package/src/utils/hooks/requires-site-info.mjs +26 -22
  178. package/src/utils/init/config-github.mjs +207 -219
  179. package/src/utils/init/config-manual.mjs +83 -100
  180. package/src/utils/init/config.mjs +25 -26
  181. package/src/utils/init/node-version.mjs +23 -30
  182. package/src/utils/init/plugins.mjs +12 -8
  183. package/src/utils/init/utils.mjs +152 -172
  184. package/src/utils/live-tunnel.mjs +118 -141
  185. package/src/utils/lm/install.mjs +220 -259
  186. package/src/utils/lm/requirements.mjs +54 -63
  187. package/src/utils/lm/steps.mjs +31 -31
  188. package/src/utils/lm/ui.mjs +13 -20
  189. package/src/utils/open-browser.mjs +31 -32
  190. package/src/utils/parse-raw-flags.mjs +39 -35
  191. package/src/utils/proxy-server.mjs +84 -71
  192. package/src/utils/proxy.mjs +696 -750
  193. package/src/utils/read-repo-url.mjs +48 -47
  194. package/src/utils/redirects.mjs +49 -49
  195. package/src/utils/request-id.mjs +2 -4
  196. package/src/utils/rules-proxy.mjs +96 -100
  197. package/src/utils/run-build.mjs +109 -132
  198. package/src/utils/shell.mjs +99 -106
  199. package/src/utils/sign-redirect.mjs +14 -14
  200. package/src/utils/sites/utils.mjs +48 -55
  201. package/src/utils/state-config.mjs +101 -101
  202. package/src/utils/static-server.mjs +28 -34
  203. package/src/utils/telemetry/index.mjs +2 -2
  204. package/src/utils/telemetry/report-error.mjs +45 -49
  205. package/src/utils/telemetry/request.mjs +36 -43
  206. package/src/utils/telemetry/telemetry.mjs +90 -105
  207. package/src/utils/telemetry/utils.mjs +5 -6
  208. package/src/utils/telemetry/validation.mjs +55 -53
  209. package/src/utils/types.d.ts +46 -0
  210. package/src/utils/validation.mjs +10 -13
@@ -1,43 +1,39 @@
1
- // @ts-check
2
-
3
- import fuzzy from 'fuzzy'
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
- const filterOptions = scriptInquirerOptions.map((scriptInquirerOption) => scriptInquirerOption.name)
15
- // TODO: remove once https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1394 is fixed
16
- // eslint-disable-next-line unicorn/no-array-method-this-argument
17
- const filteredSettings = fuzzy.filter(input, filterOptions)
18
- const filteredSettingNames = new Set(
19
- filteredSettings.map((filteredSetting) => (input ? filteredSetting.string : filteredSetting)),
20
- )
21
- return scriptInquirerOptions.filter((t) => filteredSettingNames.has(t.name))
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
- return settings.map((setting) => {
32
- const cmd = type === 'dev' ? setting.devCommand : setting.buildCommand
33
- return {
34
- name: `[${chalk.yellow(setting.framework.name)}] '${cmd}'`,
35
- value: { ...setting, commands: [cmd] },
36
- short: `${setting.name}-${cmd}`,
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
- const { relConfigFilePath } = command.netlify
50
- const settings = await detectBuildSettings(command)
51
- if (settings.length === 1) {
52
- return settings[0]
53
- }
54
-
55
- if (settings.length > 1) {
56
- /** multiple matching detectors, make the user choose */
57
- const scriptInquirerOptions = formatSettingsArrForInquirer(settings, type)
58
- /** @type {{chosenSettings: Settings}} */
59
- const { chosenSettings } = await inquirer.prompt({
60
- name: 'chosenSettings',
61
- message: `Multiple possible ${type} commands found`,
62
- type: 'autocomplete',
63
- source(/** @type {string} */ _, input = '') {
64
- if (!input) return scriptInquirerOptions
65
- // only show filtered results
66
- return filterSettings(scriptInquirerOptions, input)
67
- },
68
- })
69
-
70
- log(`
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
- return chosenSettings
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
- const { project, workspacePackage } = command
90
- const buildSettings = await project.getBuildSettings(project.workspace ? workspacePackage : '')
91
- return buildSettings
92
- .filter((setting) => {
93
- if (project.workspace && project.relativeBaseDirectory && setting.packagePath) {
94
- return project.relativeBaseDirectory.startsWith(setting.packagePath)
95
- }
96
-
97
- return true
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
- .filter((setting) => setting.devCommand)
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
- // @ts-check
2
- import { once } from 'events'
3
- import os from 'os'
4
- import process from 'process'
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 { clearSpinner, startSpinner } from '../lib/spinner.mjs'
16
-
17
- import getGlobalConfig from './get-global-config.mjs'
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
- if (noColors) {
31
- const colorlessChalk = new Chalk({ level: 0 })
32
- return colorlessChalk
33
- }
34
- return new Chalk()
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
- export const padLeft = (str, count, filler = ' ') => str.padStart(str.length + count, filler)
47
-
48
- const platform = WSL ? 'wsl' : os.platform()
49
- const arch = os.arch() === 'ia32' ? 'x86' : os.arch()
50
-
51
- const { name, version } = await getPackageJson()
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 NETLIFY_CYAN = chalk.rgb(40, 180, 170)
59
-
60
- export const NETLIFYDEV = `${chalk.greenBright('◈')} ${NETLIFY_CYAN('Netlify Dev')} ${chalk.greenBright('◈')}`
61
- export const NETLIFYDEVLOG = `${chalk.greenBright('◈')}`
62
- export const NETLIFYDEVWARN = `${chalk.yellowBright('')}`
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
- // base flags should be always at the bottom
77
- if (BASE_FLAGS.has(optionA.long) || BASE_FLAGS.has(optionB.long)) {
78
- return -1
79
- }
80
- return optionA.long.localeCompare(optionB.long)
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
- const spinner = startSpinner({ text: 'Waiting for authorization...' })
95
- try {
96
- const accessToken = await api.getAccessToken(ticket, { timeout: TOKEN_TIMEOUT })
97
- if (!accessToken) {
98
- error('Could not retrieve access token')
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
- return accessToken
101
- } catch (error_) {
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
- } finally {
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
- // 1. First honor command flag --auth
125
- if (tokenFromOptions) {
126
- return [tokenFromOptions, 'flag']
127
- }
128
- // 2. then Check ENV var
129
- const { NETLIFY_AUTH_TOKEN } = process.env
130
- if (NETLIFY_AUTH_TOKEN && NETLIFY_AUTH_TOKEN !== 'null') {
131
- return [NETLIFY_AUTH_TOKEN, 'env']
132
- }
133
- // 3. If no env var use global user setting
134
- const globalConfig = await getGlobalConfig()
135
- const userId = globalConfig.get('userId')
136
- const tokenFromConfig = globalConfig.get(`users.${userId}.auth.token`)
137
- if (tokenFromConfig) {
138
- return [tokenFromConfig, 'config']
139
- }
140
- return [null, 'not found']
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
- if (argv.includes('--json') || isDefaultJson()) {
153
- process.stdout.write(JSON.stringify(message, null, 2))
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
- // If --silent or --json flag passed disable logger
159
- if (argv.includes('--json') || argv.includes('--silent') || isDefaultJson()) {
160
- return
161
- }
162
- message = typeof message === 'string' ? message : inspect(message)
163
- process.stdout.write(`${format(message, ...args)}\n`)
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
- log('')
168
- log(message, ...args)
169
- log('')
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
- const bang = chalk.yellow(BANG)
178
- log(` ${bang} Warning: ${message}`)
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
- const err =
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
- ? message
191
- : // eslint-disable-next-line unicorn/no-nested-ternary
192
- typeof message === 'string'
193
- ? new Error(message)
194
- : /** @type {Error} */ ({ message, stack: undefined, name: 'Error' })
195
-
196
- if (options.exit === false) {
197
- const bang = chalk.red(BANG)
198
- if (process.env.DEBUG) {
199
- process.stderr.write(` ${bang} Warning: ${err.stack?.split('\n').join(`\n ${bang} `)}\n`)
200
- } else {
201
- process.stderr.write(` ${bang} ${chalk.red(`${err.name}:`)} ${err.message}\n`)
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
- } else {
204
- reportError(err, { severity: 'error' })
205
- throw err
206
- }
207
- }
208
-
187
+ else {
188
+ reportError(err, { severity: 'error' });
189
+ throw err;
190
+ }
191
+ };
209
192
  export const exit = (code = 0) => {
210
- process.exit(code)
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
- // Unused var here is in order to omit 'publish' from build config
222
- // eslint-disable-next-line no-unused-vars
223
- const { publish, publishOrigin, ...build } = config.build
224
-
225
- return publishOrigin === 'default' ? { ...config, build } : config
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
- target,
243
- { depth, ignored = [], onAdd = () => {}, onChange = () => {}, onUnlink = () => {} },
244
- ) => {
245
- const baseIgnores = [/\/(node_modules|.git)\//]
246
- const watcher = chokidar.watch(target, { depth, ignored: [...baseIgnores, ...ignored], ignoreInitial: true })
247
-
248
- await once(watcher, 'ready')
249
-
250
- let onChangeQueue = []
251
- let onAddQueue = []
252
- let onUnlinkQueue = []
253
-
254
- const debouncedOnChange = debounce(() => {
255
- onChange(onChangeQueue)
256
- onChangeQueue = []
257
- }, DEBOUNCE_WAIT)
258
- const debouncedOnAdd = debounce(() => {
259
- onAdd(onAddQueue)
260
- onAddQueue = []
261
- }, DEBOUNCE_WAIT)
262
- const debouncedOnUnlink = debounce(() => {
263
- onUnlink(onUnlinkQueue)
264
- onUnlinkQueue = []
265
- }, DEBOUNCE_WAIT)
266
-
267
- watcher
268
- .on('change', (path) => {
269
- decache(path)
270
- onChangeQueue.push(path)
271
- debouncedOnChange()
272
- })
273
- .on('unlink', (path) => {
274
- decache(path)
275
- onUnlinkQueue.push(path)
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
- .on('add', (path) => {
279
- decache(path)
280
- onAddQueue.push(path)
281
- debouncedOnAdd()
257
+ .on('unlink', (path) => {
258
+ // @ts-expect-error
259
+ decache(path);
260
+ onUnlinkQueue.push(path);
261
+ debouncedOnUnlink();
282
262
  })
283
-
284
- return watcher
285
- }
286
-
287
- export const getTerminalLink = (text, url) => terminalLink(text, url, { fallback: () => `${text} (${url})` })
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;