@@ -163,6 +163,7 @@ func main() {
163
163
sendPings := false
164
164
isWatch := false
165
165
isWatchForever := false
166
+ isServe := false
166
167
167
168
// Do an initial scan over the argument list
168
169
argsEnd := 0
@@ -226,7 +227,13 @@ func main() {
226
227
isWatch = true
227
228
} else if arg == "--watch=forever" {
228
229
arg = "--watch"
230
+ isWatch = true
229
231
isWatchForever = true
232
+ } else if arg == "--serve" ||
233
+ strings .HasPrefix (arg , "--serve=" ) ||
234
+ strings .HasPrefix (arg , "--servedir=" ) ||
235
+ strings .HasPrefix (arg , "--serve-fallback=" ) {
236
+ isServe = true
230
237
}
231
238
232
239
// Strip any arguments that were handled above
@@ -295,31 +302,30 @@ func main() {
295
302
exitCode = cli .Run (osArgs )
296
303
}
297
304
} else {
298
- isServeOrWatch := false
299
- nonFlagCount := 0
300
- for _ , arg := range osArgs {
301
- if ! strings .HasPrefix (arg , "-" ) {
302
- nonFlagCount ++
303
- } else if arg == "--watch" ||
304
- arg == "--watch=true" ||
305
- arg == "--serve" ||
306
- strings .HasPrefix (arg , "--serve=" ) ||
307
- strings .HasPrefix (arg , "--servedir=" ) ||
308
- strings .HasPrefix (arg , "--serve-fallback=" ) {
309
- isServeOrWatch = true
310
- }
311
- }
312
-
313
- if ! isServeOrWatch {
305
+ if ! isWatch && ! isServe {
314
306
// If this is not a long-running process and there is at most a single
315
307
// entry point, then disable the GC since we're just going to allocate
316
308
// a bunch of memory and then exit anyway. This speedup is not
317
309
// insignificant. We don't do this when there are multiple entry points
318
310
// since otherwise esbuild could unnecessarily use much more memory
319
311
// than it might otherwise need to process many entry points.
312
+ nonFlagCount := 0
313
+ for _ , arg := range osArgs {
314
+ if ! strings .HasPrefix (arg , "-" ) {
315
+ nonFlagCount ++
316
+ }
317
+ }
320
318
if nonFlagCount <= 1 {
321
319
debug .SetGCPercent (- 1 )
322
320
}
321
+ } else if isServe && isServeUnsupported () {
322
+ // The development server isn't supported on WebAssembly, so we will
323
+ // immediately call "os.Exit(1)" below, which will call "process.exit(1)"
324
+ // in node. However, node has a bug/feature where any pending calls to
325
+ // "fs.read(process.stdin.fd)" hold up "process.exit()" without seemingly
326
+ // any way to stop this from happening. So to avoid this bug/feature,
327
+ // we explicitly avoid listening to stdin in this case (when we know
328
+ // that we are about to exit due to an invalid flag).
323
329
} else if ! isStdinTTY && ! isWatchForever {
324
330
// If stdin isn't a TTY, watch stdin and abort in case it is closed.
325
331
// This is necessary when the esbuild binary executable is invoked via
@@ -344,7 +350,7 @@ func main() {
344
350
logger .PrintTextWithColor (os .Stderr , options .Color , func (colors logger.Colors ) string {
345
351
return fmt .Sprintf ("%s[watch] stopped automatically because stdin was closed (use \" --watch=forever\" to keep watching even after stdin is closed)%s\n " , colors .Dim , colors .Reset )
346
352
})
347
- } else if isServeOrWatch {
353
+ } else if isServe {
348
354
logger .PrintTextWithColor (os .Stderr , options .Color , func (colors logger.Colors ) string {
349
355
return fmt .Sprintf ("%s[serve] stopped automatically because stdin was closed (keep stdin open to continue serving)%s\n " , colors .Dim , colors .Reset )
350
356
})
0 commit comments