11"use strict" ;
22const {
33 __spreadValues,
4+ __spreadProps,
45 __export,
56 __toESM,
67 __toCommonJS,
@@ -432,8 +433,14 @@ var defaults = resolveDefaults({
432433 killSignal : SIGTERM ,
433434 timeoutSignal : SIGTERM
434435} ) ;
435- var boundCtxs = [ ] ;
436+ var snapshots = [ ] ;
436437var delimiters = [ ] ;
438+ var getSnapshot = ( snapshot , from , cmd ) => __spreadProps ( __spreadValues ( { } , snapshot ) , {
439+ ac : snapshot . ac || new AbortController ( ) ,
440+ ee : new import_node_events . EventEmitter ( ) ,
441+ from,
442+ cmd
443+ } ) ;
437444var $ = new Proxy (
438445 function ( pieces , ...args ) {
439446 const snapshot = getStore ( ) ;
@@ -445,7 +452,7 @@ var $ = new Proxy(
445452 } ;
446453 }
447454 const from = getCallerLocation ( ) ;
448- if ( pieces . some ( ( p ) => p == void 0 ) )
455+ if ( pieces . some ( ( p ) => p == null ) )
449456 throw new Error ( `Malformed command at ${ from } ` ) ;
450457 checkShell ( ) ;
451458 checkQuote ( ) ;
@@ -454,10 +461,10 @@ var $ = new Proxy(
454461 pieces ,
455462 args
456463 ) ;
457- boundCtxs . push ( [ cmd , from , snapshot ] ) ;
458- const process3 = new ProcessPromise ( import_util . noop ) ;
459- if ( ! process3 . isHalted ( ) ) process3 . run ( ) ;
460- return process3 . output || process3 ;
464+ snapshots . push ( getSnapshot ( snapshot , from , cmd ) ) ;
465+ const pp = new ProcessPromise ( import_util . noop ) ;
466+ if ( ! pp . isHalted ( ) ) pp . run ( ) ;
467+ return pp . sync ? pp . output : pp ;
461468 } ,
462469 {
463470 set ( _ , key , value ) {
@@ -483,68 +490,58 @@ var _ProcessPromise = class _ProcessPromise extends Promise {
483490 } ) ;
484491 this . _stage = "initial" ;
485492 this . _id = ( 0 , import_util . randomId ) ( ) ;
486- this . _cmd = "" ;
487- this . _from = "" ;
488- this . _snapshot = getStore ( ) ;
489493 this . _piped = false ;
490- this . _ee = new import_node_events . EventEmitter ( ) ;
491- this . _ac = new AbortController ( ) ;
492494 this . _stdin = new import_vendor_core2 . VoidStream ( ) ;
493495 this . _zurk = null ;
494496 this . _output = null ;
495497 this . _reject = import_util . noop ;
496498 this . _resolve = import_util . noop ;
497499 // Stream-like API
498500 this . writable = true ;
499- if ( boundCtxs . length ) {
500- const [ cmd , from , snapshot ] = boundCtxs . pop ( ) ;
501- this . _cmd = cmd ;
502- this . _from = from ;
503- this . _snapshot = __spreadValues ( { } , snapshot ) ;
501+ if ( snapshots . length ) {
502+ this . _snapshot = snapshots . pop ( ) ;
504503 this . _resolve = resolve ;
505504 this . _reject = ( v ) => {
506505 reject ( v ) ;
507- if ( this . isSync ( ) ) throw v ;
506+ if ( this . sync ) throw v ;
508507 } ;
509- if ( snapshot . halt ) this . _stage = "halted" ;
508+ if ( this . _snapshot . halt ) this . _stage = "halted" ;
510509 } else _ProcessPromise . disarm ( this ) ;
511510 }
512511 run ( ) {
513- var _a , _b , _c , _d , _e , _f , _g ;
512+ var _a , _b , _c , _d ;
514513 if ( this . isRunning ( ) || this . isSettled ( ) ) return this ;
515514 this . _stage = "running" ;
516515 ( _a = this . _pipedFrom ) == null ? void 0 : _a . run ( ) ;
517516 const self = this ;
518517 const $2 = self . _snapshot ;
519518 const id = self . id ;
520- const timeout = ( _b = self . _timeout ) != null ? _b : $2 . timeout ;
521- const timeoutSignal = ( _c = self . _timeoutSignal ) != null ? _c : $2 . timeoutSignal ;
522519 if ( $2 . preferLocal ) {
523520 const dirs = $2 . preferLocal === true ? [ $2 . cwd , $2 [ CWD ] ] : [ $2 . preferLocal ] . flat ( ) ;
524521 $2 . env = ( 0 , import_util . preferLocalBin ) ( $2 . env , ...dirs ) ;
525522 }
526523 this . _zurk = ( 0 , import_vendor_core2 . exec ) ( {
527- id,
528- sync : self . isSync ( ) ,
529524 cmd : self . fullCmd ,
530- cwd : ( _d = $2 . cwd ) != null ? _d : $2 [ CWD ] ,
531- input : ( _f = ( _e = $2 . input ) == null ? void 0 : _e . stdout ) != null ? _f : $2 . input ,
525+ cwd : ( _b = $2 . cwd ) != null ? _b : $2 [ CWD ] ,
526+ input : ( _d = ( _c = $2 . input ) == null ? void 0 : _c . stdout ) != null ? _d : $2 . input ,
527+ stdin : self . _stdin ,
528+ sync : self . sync ,
532529 signal : self . signal ,
533530 shell : ( 0 , import_util . isString ) ( $2 . shell ) ? $2 . shell : true ,
531+ id,
534532 env : $2 . env ,
535533 spawn : $2 . spawn ,
536534 spawnSync : $2 . spawnSync ,
537535 store : $2 . store ,
538- stdin : self . _stdin ,
539- stdio : ( _g = self . _stdio ) != null ? _g : $2 . stdio ,
536+ stdio : $2 . stdio ,
540537 detached : $2 . detached ,
541- ee : self . _ee ,
538+ ee : $2 . ee ,
542539 run ( cb , ctx ) {
543540 var _a2 , _b2 ;
544541 ( ( _b2 = ( _a2 = self . cmd ) . then ) == null ? void 0 : _b2 . call (
545542 _a2 ,
546- ( _cmd ) => {
547- self . _cmd = _cmd ;
543+ ( cmd ) => {
544+ $2 . cmd = cmd ;
548545 ctx . cmd = self . fullCmd ;
549546 cb ( ) ;
550547 } ,
@@ -554,7 +551,7 @@ var _ProcessPromise = class _ProcessPromise extends Promise {
554551 on : {
555552 start : ( ) => {
556553 $2 . log ( { kind : "cmd" , cmd : self . cmd , verbose : self . isVerbose ( ) , id } ) ;
557- self . timeout ( timeout , timeoutSignal ) ;
554+ self . timeout ( $2 . timeout , $2 . timeoutSignal ) ;
558555 } ,
559556 stdout : ( data ) => {
560557 if ( self . _piped ) return ;
@@ -572,7 +569,7 @@ var _ProcessPromise = class _ProcessPromise extends Promise {
572569 error,
573570 duration,
574571 store,
575- from : self . _from
572+ from : $2 . from
576573 } ) ;
577574 $2 . log ( { kind : "end" , signal, exitCode : status , duration, error, verbose : self . isVerbose ( ) , id } ) ;
578575 if ( stdout . length && ( 0 , import_util . getLast ) ( ( 0 , import_util . getLast ) ( stdout ) ) !== BR_CC ) c . on . stdout ( EOL , c ) ;
@@ -598,7 +595,7 @@ var _ProcessPromise = class _ProcessPromise extends Promise {
598595 } ) ( dest , ...args )
599596 ) ;
600597 this . _piped = true ;
601- const ee = this . _ee ;
598+ const { ee } = this . _snapshot ;
602599 const from = new import_vendor_core2 . VoidStream ( ) ;
603600 const fill = ( ) => {
604601 for ( const chunk of this . _zurk . store [ source ] ) from . write ( chunk ) ;
@@ -661,10 +658,11 @@ var _ProcessPromise = class _ProcessPromise extends Promise {
661658 return ( _a = this . child ) == null ? void 0 : _a . pid ;
662659 }
663660 get cmd ( ) {
664- return this . _cmd ;
661+ return this . _snapshot . cmd ;
665662 }
666663 get fullCmd ( ) {
667- return ( this . _snapshot . prefix || "" ) + this . cmd + ( this . _snapshot . postfix || "" ) ;
664+ const { prefix = "" , postfix = "" , cmd } = this . _snapshot ;
665+ return prefix + cmd + postfix ;
668666 }
669667 get child ( ) {
670668 var _a ;
@@ -692,14 +690,17 @@ var _ProcessPromise = class _ProcessPromise extends Promise {
692690 return this . _snapshot . signal || this . ac . signal ;
693691 }
694692 get ac ( ) {
695- return this . _snapshot . ac || this . _ac ;
693+ return this . _snapshot . ac ;
696694 }
697695 get output ( ) {
698696 return this . _output ;
699697 }
700698 get stage ( ) {
701699 return this . _stage ;
702700 }
701+ get sync ( ) {
702+ return this . _snapshot [ SYNC ] ;
703+ }
703704 get [ Symbol . toStringTag ] ( ) {
704705 return "ProcessPromise" ;
705706 }
@@ -708,31 +709,29 @@ var _ProcessPromise = class _ProcessPromise extends Promise {
708709 }
709710 // Configurators
710711 stdio ( stdin , stdout = "pipe" , stderr = "pipe" ) {
711- this . _stdio = [ stdin , stdout , stderr ] ;
712+ this . _snapshot . stdio = [ stdin , stdout , stderr ] ;
712713 return this ;
713714 }
714715 nothrow ( v = true ) {
715- this . _nothrow = v ;
716+ this . _snapshot . nothrow = v ;
716717 return this ;
717718 }
718719 quiet ( v = true ) {
719- this . _quiet = v ;
720+ this . _snapshot . quiet = v ;
720721 return this ;
721722 }
722723 verbose ( v = true ) {
723- this . _verbose = v ;
724+ this . _snapshot . verbose = v ;
724725 return this ;
725726 }
726- timeout ( d = 0 , signal = this . _timeoutSignal || $ . timeoutSignal ) {
727+ timeout ( d = 0 , signal = $ . timeoutSignal ) {
727728 if ( this . isSettled ( ) ) return this ;
728- this . _timeout = ( 0 , import_util . parseDuration ) ( d ) ;
729- this . _timeoutSignal = signal ;
729+ const $2 = this . _snapshot ;
730+ $2 . timeout = ( 0 , import_util . parseDuration ) ( d ) ;
731+ $2 . timeoutSignal = signal ;
730732 if ( this . _timeoutId ) clearTimeout ( this . _timeoutId ) ;
731- if ( this . _timeout && this . isRunning ( ) ) {
732- this . _timeoutId = setTimeout (
733- ( ) => this . kill ( this . _timeoutSignal ) ,
734- this . _timeout
735- ) ;
733+ if ( $2 . timeout && this . isRunning ( ) ) {
734+ this . _timeoutId = setTimeout ( ( ) => this . kill ( $2 . timeoutSignal ) , $2 . timeout ) ;
736735 this . finally ( ( ) => clearTimeout ( this . _timeoutId ) ) . catch ( import_util . noop ) ;
737736 }
738737 return this ;
@@ -755,22 +754,16 @@ var _ProcessPromise = class _ProcessPromise extends Promise {
755754 }
756755 // Status checkers
757756 isQuiet ( ) {
758- var _a ;
759- return ( _a = this . _quiet ) != null ? _a : this . _snapshot . quiet ;
757+ return this . _snapshot . quiet ;
760758 }
761759 isVerbose ( ) {
762- var _a ;
763- return ( ( _a = this . _verbose ) != null ? _a : this . _snapshot . verbose ) && ! this . isQuiet ( ) ;
760+ return this . _snapshot . verbose && ! this . isQuiet ( ) ;
764761 }
765762 isNothrow ( ) {
766- var _a ;
767- return ( _a = this . _nothrow ) != null ? _a : this . _snapshot . nothrow ;
763+ return this . _snapshot . nothrow ;
768764 }
769765 isHalted ( ) {
770- return this . stage === "halted" && ! this . isSync ( ) ;
771- }
772- isSync ( ) {
773- return this . _snapshot [ SYNC ] ;
766+ return this . stage === "halted" && ! this . sync ;
774767 }
775768 isSettled ( ) {
776769 return ! ! this . output ;
0 commit comments