@@ -163,6 +163,7 @@ func main() {
163163 sendPings := false
164164 isWatch := false
165165 isWatchForever := false
166+ isServe := false
166167
167168 // Do an initial scan over the argument list
168169 argsEnd := 0
@@ -226,7 +227,13 @@ func main() {
226227 isWatch = true
227228 } else if arg == "--watch=forever" {
228229 arg = "--watch"
230+ isWatch = true
229231 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
230237 }
231238
232239 // Strip any arguments that were handled above
@@ -295,31 +302,30 @@ func main() {
295302 exitCode = cli .Run (osArgs )
296303 }
297304 } 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 {
314306 // If this is not a long-running process and there is at most a single
315307 // entry point, then disable the GC since we're just going to allocate
316308 // a bunch of memory and then exit anyway. This speedup is not
317309 // insignificant. We don't do this when there are multiple entry points
318310 // since otherwise esbuild could unnecessarily use much more memory
319311 // 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+ }
320318 if nonFlagCount <= 1 {
321319 debug .SetGCPercent (- 1 )
322320 }
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).
323329 } else if ! isStdinTTY && ! isWatchForever {
324330 // If stdin isn't a TTY, watch stdin and abort in case it is closed.
325331 // This is necessary when the esbuild binary executable is invoked via
@@ -344,7 +350,7 @@ func main() {
344350 logger .PrintTextWithColor (os .Stderr , options .Color , func (colors logger.Colors ) string {
345351 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 )
346352 })
347- } else if isServeOrWatch {
353+ } else if isServe {
348354 logger .PrintTextWithColor (os .Stderr , options .Color , func (colors logger.Colors ) string {
349355 return fmt .Sprintf ("%s[serve] stopped automatically because stdin was closed (keep stdin open to continue serving)%s\n " , colors .Dim , colors .Reset )
350356 })
0 commit comments