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.
Files changed (210) hide show
  1. package/README.md +3 -139
  2. package/npm-shrinkwrap.json +82 -82
  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 -89
  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 +1 @@
1
- export { createDeployCommand } from './deploy.mjs'
1
+ export { createDeployCommand } from './deploy.mjs';
@@ -1,47 +1,35 @@
1
- import execa from 'execa'
2
-
3
- import { getDotEnvVariables, injectEnvVariables } from '../../utils/dev.mjs'
4
- import { getEnvelopeEnv, normalizeContext } from '../../utils/env/index.mjs'
5
-
1
+ import execa from 'execa';
2
+ import { getDotEnvVariables, injectEnvVariables } from '../../utils/dev.mjs';
3
+ import { getEnvelopeEnv, normalizeContext } from '../../utils/env/index.mjs';
6
4
  /**
7
5
  * The dev:exec command
8
6
  * @param {import('commander').OptionValues} options
9
7
  * @param {import('../base-command.mjs').default} command
10
8
  */
9
+ // @ts-expect-error TS(7006) FIXME: Parameter 'cmd' implicitly has an 'any' type.
11
10
  const devExec = async (cmd, options, command) => {
12
- const { api, cachedConfig, config, site, siteInfo } = command.netlify
13
-
14
- let { env } = cachedConfig
15
- if (siteInfo.use_envelope) {
16
- env = await getEnvelopeEnv({ api, context: options.context, env, siteInfo })
17
- }
18
-
19
- env = await getDotEnvVariables({ devConfig: { ...config.dev }, env, site })
20
- injectEnvVariables(env)
21
-
22
- await execa(cmd, command.args.slice(1), {
23
- stdio: 'inherit',
24
- })
25
- }
26
-
11
+ const { api, cachedConfig, config, site, siteInfo } = command.netlify;
12
+ let { env } = cachedConfig;
13
+ if (siteInfo.use_envelope) {
14
+ env = await getEnvelopeEnv({ api, context: options.context, env, siteInfo });
15
+ }
16
+ env = await getDotEnvVariables({ devConfig: { ...config.dev }, env, site });
17
+ injectEnvVariables(env);
18
+ await execa(cmd, command.args.slice(1), {
19
+ stdio: 'inherit',
20
+ });
21
+ };
27
22
  /**
28
23
  * Creates the `netlify dev:exec` command
29
24
  * @param {import('../base-command.mjs').default} program
30
25
  * @returns
31
26
  */
32
- export const createDevExecCommand = (program) =>
33
- program
27
+ // @ts-expect-error TS(7006) FIXME: Parameter 'program' implicitly has an 'any' type.
28
+ export const createDevExecCommand = (program) => program
34
29
  .command('dev:exec')
35
30
  .argument('<...cmd>', `the command that should be executed`)
36
- .option(
37
- '--context <context>',
38
- 'Specify a deploy context or branch for environment variables (contexts: "production", "deploy-preview", "branch-deploy", "dev")',
39
- normalizeContext,
40
- 'dev',
41
- )
42
- .description(
43
- 'Exec command\nRuns a command within the netlify dev environment, e.g. with env variables from any installed addons',
44
- )
31
+ .option('--context <context>', 'Specify a deploy context or branch for environment variables (contexts: "production", "deploy-preview", "branch-deploy", "dev")', normalizeContext, 'dev')
32
+ .description('Exec command\nRuns a command within the netlify dev environment, e.g. with env variables from any installed addons')
45
33
  .allowExcessArguments(true)
46
34
  .addExamples(['netlify dev:exec npm run bootstrap'])
47
- .action(devExec)
35
+ .action(devExec);
@@ -1,35 +1,21 @@
1
- // @ts-check
2
- import process from 'process'
3
-
4
- import { Option } from 'commander'
5
-
6
- import { getBlobsContext } from '../../lib/blobs/blobs.mjs'
7
- import { promptEditorHelper } from '../../lib/edge-functions/editor-helper.mjs'
8
- import { startFunctionsServer } from '../../lib/functions/server.mjs'
9
- import { printBanner } from '../../utils/banner.mjs'
10
- import {
11
- BANG,
12
- chalk,
13
- log,
14
- NETLIFYDEV,
15
- NETLIFYDEVERR,
16
- NETLIFYDEVLOG,
17
- NETLIFYDEVWARN,
18
- normalizeConfig,
19
- } from '../../utils/command-helpers.mjs'
20
- import detectServerSettings, { getConfigWithPlugins } from '../../utils/detect-server-settings.mjs'
21
- import { getDotEnvVariables, getSiteInformation, injectEnvVariables } from '../../utils/dev.mjs'
22
- import { getEnvelopeEnv, normalizeContext } from '../../utils/env/index.mjs'
23
- import { ensureNetlifyIgnore } from '../../utils/gitignore.mjs'
24
- import { getLiveTunnelSlug, startLiveTunnel } from '../../utils/live-tunnel.mjs'
25
- import openBrowser from '../../utils/open-browser.mjs'
26
- import { generateInspectSettings, startProxyServer } from '../../utils/proxy-server.mjs'
27
- import { getProxyUrl } from '../../utils/proxy.mjs'
28
- import { runDevTimeline } from '../../utils/run-build.mjs'
29
- import { getGeoCountryArgParser } from '../../utils/validation.mjs'
30
-
31
- import { createDevExecCommand } from './dev-exec.mjs'
32
-
1
+ import process from 'process';
2
+ import { Option } from 'commander';
3
+ import { getBlobsContext } from '../../lib/blobs/blobs.mjs';
4
+ import { promptEditorHelper } from '../../lib/edge-functions/editor-helper.mjs';
5
+ import { startFunctionsServer } from '../../lib/functions/server.mjs';
6
+ import { printBanner } from '../../utils/banner.mjs';
7
+ import { BANG, chalk, log, NETLIFYDEV, NETLIFYDEVERR, NETLIFYDEVLOG, NETLIFYDEVWARN, normalizeConfig, } from '../../utils/command-helpers.mjs';
8
+ import detectServerSettings, { getConfigWithPlugins } from '../../utils/detect-server-settings.mjs';
9
+ import { getDotEnvVariables, getSiteInformation, injectEnvVariables } from '../../utils/dev.mjs';
10
+ import { getEnvelopeEnv, normalizeContext } from '../../utils/env/index.mjs';
11
+ import { ensureNetlifyIgnore } from '../../utils/gitignore.mjs';
12
+ import { getLiveTunnelSlug, startLiveTunnel } from '../../utils/live-tunnel.mjs';
13
+ import openBrowser from '../../utils/open-browser.mjs';
14
+ import { generateInspectSettings, startProxyServer } from '../../utils/proxy-server.mjs';
15
+ import { getProxyUrl } from '../../utils/proxy.mjs';
16
+ import { runDevTimeline } from '../../utils/run-build.mjs';
17
+ import { getGeoCountryArgParser } from '../../utils/validation.mjs';
18
+ import { createDevExecCommand } from './dev-exec.mjs';
33
19
  /**
34
20
  *
35
21
  * @param {object} config
@@ -40,309 +26,238 @@ import { createDevExecCommand } from './dev-exec.mjs'
40
26
  * @param {*} config.state
41
27
  * @returns
42
28
  */
29
+ // @ts-expect-error TS(7031) FIXME: Binding element 'api' implicitly has an 'any' type... Remove this comment to see the full error message
43
30
  const handleLiveTunnel = async ({ api, options, settings, site, state }) => {
44
- const { live } = options
45
-
46
- if (live) {
47
- const customSlug = typeof live === 'string' && live.length !== 0 ? live : undefined
48
- const slug = getLiveTunnelSlug(state, customSlug)
49
-
50
- let message = `${NETLIFYDEVWARN} Creating live URL with ID ${chalk.yellow(slug)}`
51
-
52
- if (!customSlug) {
53
- message += ` (to generate a custom URL, use ${chalk.magenta('--live=<subdomain>')})`
31
+ const { live } = options;
32
+ if (live) {
33
+ const customSlug = typeof live === 'string' && live.length !== 0 ? live : undefined;
34
+ const slug = getLiveTunnelSlug(state, customSlug);
35
+ let message = `${NETLIFYDEVWARN} Creating live URL with ID ${chalk.yellow(slug)}`;
36
+ if (!customSlug) {
37
+ message += ` (to generate a custom URL, use ${chalk.magenta('--live=<subdomain>')})`;
38
+ }
39
+ log(message);
40
+ const sessionUrl = await startLiveTunnel({
41
+ siteId: site.id,
42
+ netlifyApiToken: api.accessToken,
43
+ localPort: settings.port,
44
+ slug,
45
+ });
46
+ process.env.BASE_URL = sessionUrl;
47
+ return sessionUrl;
54
48
  }
55
-
56
- log(message)
57
-
58
- const sessionUrl = await startLiveTunnel({
59
- siteId: site.id,
60
- netlifyApiToken: api.accessToken,
61
- localPort: settings.port,
62
- slug,
63
- })
64
-
65
- process.env.BASE_URL = sessionUrl
66
-
67
- return sessionUrl
68
- }
69
- }
70
-
49
+ };
71
50
  /**
72
51
  * @param {string} args
73
52
  */
53
+ // @ts-expect-error TS(7006) FIXME: Parameter 'args' implicitly has an 'any' type.
74
54
  const validateShortFlagArgs = (args) => {
75
- if (args.startsWith('=')) {
76
- throw new Error(
77
- `Short flag options like -e or -E don't support the '=' sign
55
+ if (args.startsWith('=')) {
56
+ throw new Error(`Short flag options like -e or -E don't support the '=' sign
78
57
  ${chalk.red(BANG)} Supported formats:
79
58
  netlify dev -e
80
59
  netlify dev -e 127.0.0.1:9229
81
60
  netlify dev -e127.0.0.1:9229
82
61
  netlify dev -E
83
62
  netlify dev -E 127.0.0.1:9229
84
- netlify dev -E127.0.0.1:9229`,
85
- )
86
- }
87
- return args
88
- }
89
-
63
+ netlify dev -E127.0.0.1:9229`);
64
+ }
65
+ return args;
66
+ };
90
67
  /**
91
68
  * The dev command
92
69
  * @param {import('commander').OptionValues} options
93
70
  * @param {import('../base-command.mjs').default} command
94
71
  */
72
+ // @ts-expect-error TS(7006) FIXME: Parameter 'options' implicitly has an 'any' type.
95
73
  const dev = async (options, command) => {
96
- log(`${NETLIFYDEV}`)
97
- const { api, cachedConfig, config, repositoryRoot, site, siteInfo, state } = command.netlify
98
- config.dev = { ...config.dev }
99
- config.build = { ...config.build }
100
- /** @type {import('./types.js').DevConfig} */
101
- const devConfig = {
102
- framework: '#auto',
103
- autoLaunch: Boolean(options.open),
104
- ...(config.functionsDirectory && { functions: config.functionsDirectory }),
105
- ...(config.build.publish && { publish: config.build.publish }),
106
- ...(config.build.base && { base: config.build.base }),
107
- ...config.dev,
108
- ...options,
109
- }
110
-
111
- let { env } = cachedConfig
112
-
113
- env.NETLIFY_DEV = { sources: ['internal'], value: 'true' }
114
-
115
- if (!options.offline && siteInfo.use_envelope) {
116
- env = await getEnvelopeEnv({ api, context: options.context, env, siteInfo })
117
- log(`${NETLIFYDEVLOG} Injecting environment variable values for ${chalk.yellow('all scopes')}`)
118
- }
119
-
120
- env = await getDotEnvVariables({ devConfig, env, site })
121
- injectEnvVariables(env)
122
- await promptEditorHelper({ chalk, config, log, NETLIFYDEVLOG, repositoryRoot, state })
123
-
124
- const { accountId, addonsUrls, capabilities, siteUrl, timeouts } = await getSiteInformation({
125
- // inherited from base command --offline
126
- offline: options.offline,
127
- api,
128
- site,
129
- siteInfo,
130
- })
131
-
132
- /** @type {import('../../utils/types.js').ServerSettings} */
133
- let settings
134
- try {
135
- settings = await detectServerSettings(devConfig, options, command)
136
-
137
- cachedConfig.config = getConfigWithPlugins(cachedConfig.config, settings)
138
- } catch (error_) {
139
- if (error_ && typeof error_ === 'object' && 'message' in error_) {
140
- log(NETLIFYDEVERR, error_.message)
74
+ log(`${NETLIFYDEV}`);
75
+ const { api, cachedConfig, config, repositoryRoot, site, siteInfo, state } = command.netlify;
76
+ config.dev = { ...config.dev };
77
+ config.build = { ...config.build };
78
+ /** @type {import('./types.js').DevConfig} */
79
+ const devConfig = {
80
+ framework: '#auto',
81
+ autoLaunch: Boolean(options.open),
82
+ ...(config.functionsDirectory && { functions: config.functionsDirectory }),
83
+ ...(config.build.publish && { publish: config.build.publish }),
84
+ ...(config.build.base && { base: config.build.base }),
85
+ ...config.dev,
86
+ ...options,
87
+ };
88
+ let { env } = cachedConfig;
89
+ env.NETLIFY_DEV = { sources: ['internal'], value: 'true' };
90
+ if (!options.offline && siteInfo.use_envelope) {
91
+ env = await getEnvelopeEnv({ api, context: options.context, env, siteInfo });
92
+ log(`${NETLIFYDEVLOG} Injecting environment variable values for ${chalk.yellow('all scopes')}`);
93
+ }
94
+ env = await getDotEnvVariables({ devConfig, env, site });
95
+ injectEnvVariables(env);
96
+ await promptEditorHelper({ chalk, config, log, NETLIFYDEVLOG, repositoryRoot, state });
97
+ const { accountId, addonsUrls, capabilities, siteUrl, timeouts } = await getSiteInformation({
98
+ // inherited from base command --offline
99
+ offline: options.offline,
100
+ api,
101
+ site,
102
+ siteInfo,
103
+ });
104
+ /** @type {import('../../utils/types.js').ServerSettings} */
105
+ let settings;
106
+ try {
107
+ settings = await detectServerSettings(devConfig, options, command);
108
+ cachedConfig.config = getConfigWithPlugins(cachedConfig.config, settings);
109
+ }
110
+ catch (error_) {
111
+ if (error_ && typeof error_ === 'object' && 'message' in error_) {
112
+ log(NETLIFYDEVERR, error_.message);
113
+ }
114
+ process.exit(1);
115
+ }
116
+ command.setAnalyticsPayload({ live: options.live });
117
+ const liveTunnelUrl = await handleLiveTunnel({ options, site, api, settings, state });
118
+ const url = liveTunnelUrl || getProxyUrl(settings);
119
+ process.env.URL = url;
120
+ process.env.DEPLOY_URL = url;
121
+ log(`${NETLIFYDEVWARN} Setting up local development server`);
122
+ const { configPath: configPathOverride } = await runDevTimeline({
123
+ command,
124
+ options,
125
+ settings,
126
+ env: {
127
+ URL: url,
128
+ DEPLOY_URL: url,
129
+ },
130
+ });
131
+ const blobsContext = await getBlobsContext({
132
+ debug: options.debug,
133
+ projectRoot: command.workingDir,
134
+ siteID: site.id ?? 'unknown-site-id',
135
+ });
136
+ const functionsRegistry = await startFunctionsServer({
137
+ api,
138
+ blobsContext,
139
+ command,
140
+ config,
141
+ debug: options.debug,
142
+ settings,
143
+ site,
144
+ siteInfo,
145
+ siteUrl,
146
+ capabilities,
147
+ timeouts,
148
+ geolocationMode: options.geo,
149
+ geoCountry: options.country,
150
+ offline: options.offline,
151
+ state,
152
+ accountId,
153
+ });
154
+ // Try to add `.netlify` to `.gitignore`.
155
+ try {
156
+ await ensureNetlifyIgnore(repositoryRoot);
157
+ }
158
+ catch {
159
+ // no-op
160
+ }
161
+ // TODO: We should consolidate this with the existing config watcher.
162
+ const getUpdatedConfig = async () => {
163
+ const { config: newConfig } = await command.getConfig({
164
+ cwd: command.workingDir,
165
+ offline: true,
166
+ state,
167
+ });
168
+ const normalizedNewConfig = normalizeConfig(newConfig);
169
+ return normalizedNewConfig;
170
+ };
171
+ const inspectSettings = generateInspectSettings(options.edgeInspect, options.edgeInspectBrk);
172
+ await startProxyServer({
173
+ addonsUrls,
174
+ blobsContext,
175
+ config,
176
+ configPath: configPathOverride,
177
+ debug: options.debug,
178
+ projectDir: command.workingDir,
179
+ env,
180
+ getUpdatedConfig,
181
+ inspectSettings,
182
+ offline: options.offline,
183
+ settings,
184
+ site,
185
+ siteInfo,
186
+ state,
187
+ geolocationMode: options.geo,
188
+ geoCountry: options.country,
189
+ accountId,
190
+ functionsRegistry,
191
+ repositoryRoot,
192
+ });
193
+ if (devConfig.autoLaunch !== false) {
194
+ await openBrowser({ url, silentBrowserNoneError: true });
141
195
  }
142
- process.exit(1)
143
- }
144
-
145
- command.setAnalyticsPayload({ live: options.live })
146
-
147
- const liveTunnelUrl = await handleLiveTunnel({ options, site, api, settings, state })
148
- const url = liveTunnelUrl || getProxyUrl(settings)
149
-
150
- process.env.URL = url
151
- process.env.DEPLOY_URL = url
152
-
153
- log(`${NETLIFYDEVWARN} Setting up local development server`)
154
-
155
- const { configPath: configPathOverride } = await runDevTimeline({
156
- command,
157
- options,
158
- settings,
159
- env: {
160
- URL: url,
161
- DEPLOY_URL: url,
162
- },
163
- })
164
-
165
- const blobsContext = await getBlobsContext({
166
- debug: options.debug,
167
- projectRoot: command.workingDir,
168
- siteID: site.id ?? 'unknown-site-id',
169
- })
170
-
171
- const functionsRegistry = await startFunctionsServer({
172
- api,
173
- blobsContext,
174
- command,
175
- config,
176
- debug: options.debug,
177
- settings,
178
- site,
179
- siteInfo,
180
- siteUrl,
181
- capabilities,
182
- timeouts,
183
- geolocationMode: options.geo,
184
- geoCountry: options.country,
185
- offline: options.offline,
186
- state,
187
- accountId,
188
- })
189
-
190
- // Try to add `.netlify` to `.gitignore`.
191
- try {
192
- await ensureNetlifyIgnore(repositoryRoot)
193
- } catch {
194
- // no-op
195
- }
196
-
197
- // TODO: We should consolidate this with the existing config watcher.
198
- const getUpdatedConfig = async () => {
199
- const { config: newConfig } = await command.getConfig({
200
- cwd: command.workingDir,
201
- offline: true,
202
- state,
203
- })
204
- const normalizedNewConfig = normalizeConfig(newConfig)
205
-
206
- return normalizedNewConfig
207
- }
208
-
209
- const inspectSettings = generateInspectSettings(options.edgeInspect, options.edgeInspectBrk)
210
-
211
- await startProxyServer({
212
- addonsUrls,
213
- blobsContext,
214
- config,
215
- configPath: configPathOverride,
216
- debug: options.debug,
217
- projectDir: command.workingDir,
218
- env,
219
- getUpdatedConfig,
220
- inspectSettings,
221
- offline: options.offline,
222
- settings,
223
- site,
224
- siteInfo,
225
- state,
226
- geolocationMode: options.geo,
227
- geoCountry: options.country,
228
- accountId,
229
- functionsRegistry,
230
- repositoryRoot,
231
- })
232
-
233
- if (devConfig.autoLaunch !== false) {
234
- await openBrowser({ url, silentBrowserNoneError: true })
235
- }
236
-
237
- printBanner({ url })
238
- }
239
-
196
+ printBanner({ url });
197
+ };
240
198
  /**
241
199
  * Creates the `netlify dev` command
242
200
  * @param {import('../base-command.mjs').default} program
243
201
  * @returns
244
202
  */
203
+ // @ts-expect-error TS(7006) FIXME: Parameter 'program' implicitly has an 'any' type.
245
204
  export const createDevCommand = (program) => {
246
- createDevExecCommand(program)
247
-
248
- return program
249
- .command('dev')
250
- .alias('develop')
251
- .description(
252
- `Local dev server\nThe dev command will run a local dev server with Netlify's proxy and redirect rules`,
253
- )
254
- .option('-c ,--command <command>', 'command to run')
255
- .option(
256
- '--context <context>',
257
- 'Specify a deploy context or branch for environment variables (contexts: "production", "deploy-preview", "branch-deploy", "dev")',
258
- normalizeContext,
259
- )
260
- .option('-p ,--port <port>', 'port of netlify dev', (value) => Number.parseInt(value))
261
- .addOption(
262
- new Option('--targetPort <port>', 'Old, prefer --target-port. Port of target app server')
205
+ createDevExecCommand(program);
206
+ return program
207
+ .command('dev')
208
+ .alias('develop')
209
+ .description(`Local dev server\nThe dev command will run a local dev server with Netlify's proxy and redirect rules`)
210
+ .option('-c ,--command <command>', 'command to run')
211
+ .option('--context <context>', 'Specify a deploy context or branch for environment variables (contexts: "production", "deploy-preview", "branch-deploy", "dev")', normalizeContext)
212
+ // @ts-expect-error TS(7006) FIXME: Parameter 'value' implicitly has an 'any' type.
213
+ .option('-p ,--port <port>', 'port of netlify dev', (value) => Number.parseInt(value))
214
+ .addOption(new Option('--targetPort <port>', 'Old, prefer --target-port. Port of target app server')
263
215
  .argParser((value) => Number.parseInt(value))
264
- .hideHelp(true),
265
- )
266
- .addOption(new Option('--no-open', 'disables the automatic opening of a browser window'))
267
- .option('--target-port <port>', 'port of target app server', (value) => Number.parseInt(value))
268
- .option('--framework <name>', 'framework to use. Defaults to #auto which automatically detects a framework')
269
- .option('-d ,--dir <path>', 'dir with static files')
270
- .option('-f ,--functions <folder>', 'specify a functions folder to serve')
271
- .option('-o ,--offline', 'disables any features that require network access')
272
- .option(
273
- '-l, --live [subdomain]',
274
- 'start a public live session; optionally, supply a subdomain to generate a custom URL',
275
- false,
276
- )
277
- .addOption(
278
- new Option('--functionsPort <port>', 'Old, prefer --functions-port. Port of functions server')
216
+ .hideHelp(true))
217
+ .addOption(new Option('--no-open', 'disables the automatic opening of a browser window'))
218
+ // @ts-expect-error TS(7006) FIXME: Parameter 'value' implicitly has an 'any' type.
219
+ .option('--target-port <port>', 'port of target app server', (value) => Number.parseInt(value))
220
+ .option('--framework <name>', 'framework to use. Defaults to #auto which automatically detects a framework')
221
+ .option('-d ,--dir <path>', 'dir with static files')
222
+ .option('-f ,--functions <folder>', 'specify a functions folder to serve')
223
+ .option('-o ,--offline', 'disables any features that require network access')
224
+ .option('-l, --live [subdomain]', 'start a public live session; optionally, supply a subdomain to generate a custom URL', false)
225
+ .addOption(new Option('--functionsPort <port>', 'Old, prefer --functions-port. Port of functions server')
279
226
  .argParser((value) => Number.parseInt(value))
280
- .hideHelp(true),
281
- )
282
- .option('--functions-port <port>', 'port of functions server', (value) => Number.parseInt(value))
283
- .addOption(
284
- new Option(
285
- '--geo <mode>',
286
- 'force geolocation data to be updated, use cached data from the last 24h if found, or use a mock location',
287
- )
227
+ .hideHelp(true))
228
+ // @ts-expect-error TS(7006) FIXME: Parameter 'value' implicitly has an 'any' type.
229
+ .option('--functions-port <port>', 'port of functions server', (value) => Number.parseInt(value))
230
+ .addOption(new Option('--geo <mode>', 'force geolocation data to be updated, use cached data from the last 24h if found, or use a mock location')
288
231
  .choices(['cache', 'mock', 'update'])
289
- .default('cache'),
290
- )
291
- .addOption(
292
- new Option(
293
- '--country <geoCountry>',
294
- 'Two-letter country code (https://ntl.fyi/country-codes) to use as mock geolocation (enables --geo=mock automatically)',
295
- ).argParser(getGeoCountryArgParser('netlify dev --geo=mock --country=FR')),
296
- )
297
- .addOption(
298
- new Option('--staticServerPort <port>', 'port of the static app server used when no framework is detected')
232
+ .default('cache'))
233
+ .addOption(new Option('--country <geoCountry>', 'Two-letter country code (https://ntl.fyi/country-codes) to use as mock geolocation (enables --geo=mock automatically)').argParser(getGeoCountryArgParser('netlify dev --geo=mock --country=FR')))
234
+ .addOption(new Option('--staticServerPort <port>', 'port of the static app server used when no framework is detected')
299
235
  .argParser((value) => Number.parseInt(value))
300
- .hideHelp(),
301
- )
302
- .addOption(
303
- new Option(
304
- '-e, --edgeInspect [address]',
305
- 'Old, prefer --edge-inspect. Enable the V8 Inspector Protocol for Edge Functions, with an optional address in the host:port format',
306
- )
236
+ .hideHelp())
237
+ .addOption(new Option('-e, --edgeInspect [address]', 'Old, prefer --edge-inspect. Enable the V8 Inspector Protocol for Edge Functions, with an optional address in the host:port format')
307
238
  .conflicts('edgeInspectBrk')
308
239
  .argParser(validateShortFlagArgs)
309
- .hideHelp(true),
310
- )
311
- .addOption(
312
- new Option(
313
- '-e, --edge-inspect [address]',
314
- 'enable the V8 Inspector Protocol for Edge Functions, with an optional address in the host:port format',
315
- )
240
+ .hideHelp(true))
241
+ .addOption(new Option('-e, --edge-inspect [address]', 'enable the V8 Inspector Protocol for Edge Functions, with an optional address in the host:port format')
316
242
  .conflicts('edgeInspectBrk')
317
- .argParser(validateShortFlagArgs),
318
- )
319
- .addOption(
320
- new Option(
321
- '-E, --edgeInspectBrk [address]',
322
- 'Old, prefer --edge-inspect-brk. Enable the V8 Inspector Protocol for Edge Functions and pause execution on the first line of code, with an optional address in the host:port format',
323
- )
243
+ .argParser(validateShortFlagArgs))
244
+ .addOption(new Option('-E, --edgeInspectBrk [address]', 'Old, prefer --edge-inspect-brk. Enable the V8 Inspector Protocol for Edge Functions and pause execution on the first line of code, with an optional address in the host:port format')
324
245
  .conflicts('edgeInspect')
325
246
  .hideHelp(true)
326
- .argParser(validateShortFlagArgs),
327
- )
328
- .addOption(
329
- new Option(
330
- '-E, --edge-inspect-brk [address]',
331
- 'enable the V8 Inspector Protocol for Edge Functions and pause execution on the first line of code, with an optional address in the host:port format',
332
- )
247
+ .argParser(validateShortFlagArgs))
248
+ .addOption(new Option('-E, --edge-inspect-brk [address]', 'enable the V8 Inspector Protocol for Edge Functions and pause execution on the first line of code, with an optional address in the host:port format')
333
249
  .conflicts('edgeInspect')
334
- .argParser(validateShortFlagArgs),
335
- )
336
- .addExamples([
337
- 'netlify dev',
338
- 'netlify dev -d public',
339
- 'netlify dev -c "hugo server -w" --target-port 1313',
340
- 'netlify dev --context production',
341
- 'netlify dev --edge-inspect',
342
- 'netlify dev --edge-inspect=127.0.0.1:9229',
343
- 'netlify dev --edge-inspect-brk',
344
- 'netlify dev --edge-inspect-brk=127.0.0.1:9229',
345
- 'BROWSER=none netlify dev # disable browser auto opening',
250
+ .argParser(validateShortFlagArgs))
251
+ .addExamples([
252
+ 'netlify dev',
253
+ 'netlify dev -d public',
254
+ 'netlify dev -c "hugo server -w" --target-port 1313',
255
+ 'netlify dev --context production',
256
+ 'netlify dev --edge-inspect',
257
+ 'netlify dev --edge-inspect=127.0.0.1:9229',
258
+ 'netlify dev --edge-inspect-brk',
259
+ 'netlify dev --edge-inspect-brk=127.0.0.1:9229',
260
+ 'BROWSER=none netlify dev # disable browser auto opening',
346
261
  ])
347
- .action(dev)
348
- }
262
+ .action(dev);
263
+ };
@@ -1 +1 @@
1
- export { createDevCommand } from './dev.mjs'
1
+ export { createDevCommand } from './dev.mjs';