@@ -2,14 +2,13 @@ import process from 'process'
2
2
3
3
import type { NetlifyAPI } from 'netlify'
4
4
import { applyMutations } from '@netlify/config'
5
- import { Option , OptionValues } from 'commander'
5
+ import { OptionValues } from 'commander'
6
6
7
7
import { BLOBS_CONTEXT_VARIABLE , encodeBlobsContext , getBlobsContextWithEdgeAccess } from '../../lib/blobs/blobs.js'
8
8
import { promptEditorHelper } from '../../lib/edge-functions/editor-helper.js'
9
9
import { startFunctionsServer } from '../../lib/functions/server.js'
10
10
import { printBanner } from '../../utils/banner.js'
11
11
import {
12
- BANG ,
13
12
NETLIFYDEV ,
14
13
NETLIFYDEVERR ,
15
14
NETLIFYDEVLOG ,
@@ -21,19 +20,17 @@ import {
21
20
} from '../../utils/command-helpers.js'
22
21
import detectServerSettings , { getConfigWithPlugins } from '../../utils/detect-server-settings.js'
23
22
import { UNLINKED_SITE_MOCK_ID , getDotEnvVariables , getSiteInformation , injectEnvVariables } from '../../utils/dev.js'
24
- import { getEnvelopeEnv , normalizeContext } from '../../utils/env/index.js'
23
+ import { getEnvelopeEnv } from '../../utils/env/index.js'
25
24
import { ensureNetlifyIgnore } from '../../utils/gitignore.js'
26
25
import { getLiveTunnelSlug , startLiveTunnel } from '../../utils/live-tunnel.js'
27
26
import openBrowser from '../../utils/open-browser.js'
28
27
import { generateInspectSettings , startProxyServer } from '../../utils/proxy-server.js'
29
28
import { getProxyUrl } from '../../utils/proxy.js'
30
29
import { runDevTimeline } from '../../utils/run-build.js'
31
30
import type { CLIState , ServerSettings } from '../../utils/types.js'
32
- import { getGeoCountryArgParser } from '../../utils/validation.js'
33
31
import type BaseCommand from '../base-command.js'
34
32
import type { NetlifySite } from '../types.js'
35
33
36
- import { createDevExecCommand } from './dev-exec.js'
37
34
import type { DevConfig } from './types.js'
38
35
39
36
const handleLiveTunnel = async ( {
@@ -76,22 +73,6 @@ const handleLiveTunnel = async ({
76
73
}
77
74
}
78
75
79
- const validateShortFlagArgs = ( args : string ) => {
80
- if ( args . startsWith ( '=' ) ) {
81
- throw new Error (
82
- `Short flag options like -e or -E don't support the '=' sign
83
- ${ chalk . red ( BANG ) } Supported formats:
84
- netlify dev -e
85
- netlify dev -e 127.0.0.1:9229
86
- netlify dev -e127.0.0.1:9229
87
- netlify dev -E
88
- netlify dev -E 127.0.0.1:9229
89
- netlify dev -E127.0.0.1:9229` ,
90
- )
91
- }
92
- return args
93
- }
94
-
95
76
export const dev = async ( options : OptionValues , command : BaseCommand ) => {
96
77
log ( NETLIFYDEV )
97
78
const { api, cachedConfig, config, repositoryRoot, site, siteInfo, state } = command . netlify
@@ -134,6 +115,7 @@ export const dev = async (options: OptionValues, command: BaseCommand) => {
134
115
135
116
const { accountId, addonsUrls, capabilities, siteUrl, timeouts } = await getSiteInformation ( {
136
117
// inherited from base command --offline
118
+
137
119
offline : options . offline ,
138
120
api,
139
121
site,
@@ -161,12 +143,14 @@ export const dev = async (options: OptionValues, command: BaseCommand) => {
161
143
if ( error instanceof Error ) {
162
144
log ( NETLIFYDEVERR , error . message )
163
145
}
146
+
164
147
process . exit ( 1 )
165
148
}
166
149
167
150
command . setAnalyticsPayload ( { live : options . live } )
168
151
169
152
const liveTunnelUrl = await handleLiveTunnel ( { options, site, api, settings, state } )
153
+
170
154
const url = liveTunnelUrl || getProxyUrl ( settings )
171
155
172
156
process . env . URL = url
@@ -185,12 +169,14 @@ export const dev = async (options: OptionValues, command: BaseCommand) => {
185
169
} )
186
170
187
171
// FIXME(serhalp): `applyMutations` is `(any, any) => any)`. Add types in `@netlify/config`.
172
+
188
173
const mutatedConfig : typeof config = applyMutations ( config , configMutations )
189
174
190
175
const functionsRegistry = await startFunctionsServer ( {
191
176
blobsContext,
192
177
command,
193
178
config : mutatedConfig ,
179
+
194
180
debug : options . debug ,
195
181
settings,
196
182
site,
@@ -254,90 +240,3 @@ export const dev = async (options: OptionValues, command: BaseCommand) => {
254
240
255
241
printBanner ( { url } )
256
242
}
257
-
258
- export const createDevCommand = ( program : BaseCommand ) => {
259
- createDevExecCommand ( program )
260
-
261
- return program
262
- . command ( 'dev' )
263
- . alias ( 'develop' )
264
- . description (
265
- `Local dev server\nThe dev command will run a local dev server with Netlify's proxy and redirect rules` ,
266
- )
267
- . option ( '-c ,--command <command>' , 'command to run' )
268
- . option (
269
- '--context <context>' ,
270
- 'Specify a deploy context or branch for environment variables (contexts: "production", "deploy-preview", "branch-deploy", "dev")' ,
271
- normalizeContext ,
272
- )
273
- . option ( '-p ,--port <port>' , 'port of netlify dev' , ( value ) => Number . parseInt ( value ) )
274
- . addOption ( new Option ( '--skip-wait-port' , 'disables waiting for target port to become available' ) . hideHelp ( true ) )
275
- . addOption ( new Option ( '--no-open' , 'disables the automatic opening of a browser window' ) )
276
- . option ( '--target-port <port>' , 'port of target app server' , ( value ) => Number . parseInt ( value ) )
277
- . option ( '--framework <name>' , 'framework to use. Defaults to #auto which automatically detects a framework' )
278
- . option ( '-d ,--dir <path>' , 'dir with static files' )
279
- . option ( '-f ,--functions <folder>' , 'specify a functions folder to serve' )
280
- . option ( '-o, --offline' , 'Disables any features that require network access' )
281
- . addOption (
282
- new Option ( '--offline-env' , 'disables fetching environment variables from the Netlify API' ) . hideHelp ( true ) ,
283
- )
284
- . addOption (
285
- new Option (
286
- '--internal-disable-edge-functions' ,
287
- "disables edge functions. use this if your environment doesn't support Deno. This option is internal and should not be used by end users." ,
288
- ) . hideHelp ( true ) ,
289
- )
290
- . option (
291
- '-l, --live [subdomain]' ,
292
- 'start a public live session; optionally, supply a subdomain to generate a custom URL' ,
293
- false ,
294
- )
295
- . option ( '--functions-port <port>' , 'port of functions server' , ( value ) => Number . parseInt ( value ) )
296
- . addOption (
297
- new Option (
298
- '--geo <mode>' ,
299
- 'force geolocation data to be updated, use cached data from the last 24h if found, or use a mock location' ,
300
- )
301
- . choices ( [ 'cache' , 'mock' , 'update' ] )
302
- . default ( 'cache' ) ,
303
- )
304
- . addOption (
305
- new Option (
306
- '--country <geoCountry>' ,
307
- 'Two-letter country code (https://ntl.fyi/country-codes) to use as mock geolocation (enables --geo=mock automatically)' ,
308
- ) . argParser ( getGeoCountryArgParser ( 'netlify dev --geo=mock --country=FR' ) ) ,
309
- )
310
- . addOption (
311
- new Option ( '--staticServerPort <port>' , 'port of the static app server used when no framework is detected' )
312
- . argParser ( ( value ) => Number . parseInt ( value ) )
313
- . hideHelp ( ) ,
314
- )
315
- . addOption (
316
- new Option (
317
- '-e, --edge-inspect [address]' ,
318
- 'enable the V8 Inspector Protocol for Edge Functions, with an optional address in the host:port format' ,
319
- )
320
- . conflicts ( 'edgeInspectBrk' )
321
- . argParser ( validateShortFlagArgs ) ,
322
- )
323
- . addOption (
324
- new Option (
325
- '-E, --edge-inspect-brk [address]' ,
326
- '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' ,
327
- )
328
- . conflicts ( 'edgeInspect' )
329
- . argParser ( validateShortFlagArgs ) ,
330
- )
331
- . addExamples ( [
332
- 'netlify dev' ,
333
- 'netlify dev -d public' ,
334
- 'netlify dev -c "hugo server -w" --target-port 1313' ,
335
- 'netlify dev --context production' ,
336
- 'netlify dev --edge-inspect' ,
337
- 'netlify dev --edge-inspect=127.0.0.1:9229' ,
338
- 'netlify dev --edge-inspect-brk' ,
339
- 'netlify dev --edge-inspect-brk=127.0.0.1:9229' ,
340
- 'BROWSER=none netlify dev # disable browser auto opening' ,
341
- ] )
342
- . action ( dev )
343
- }
0 commit comments