@@ -664,15 +664,8 @@ type ProcessDto = {
664
664
store : TSpawnStore
665
665
}
666
666
667
- type ProcessOutputDto = ProcessDto & {
668
- stdout : string
669
- stderr : string
670
- stdall : string
671
- message : string
672
- }
673
-
674
667
export class ProcessOutput extends Error {
675
- private readonly _dto : ProcessOutputDto
668
+ private readonly _dto : ProcessDto
676
669
constructor ( dto : ProcessDto )
677
670
constructor (
678
671
code : number | null ,
@@ -683,44 +676,63 @@ export class ProcessOutput extends Error {
683
676
message : string ,
684
677
duration ?: number
685
678
)
679
+ // prettier-ignore
686
680
constructor (
687
681
code : number | null | ProcessDto ,
688
682
signal : NodeJS . Signals | null = null ,
689
683
stdout : string = '' ,
690
684
stderr : string = '' ,
691
685
stdall : string = '' ,
692
686
message : string = '' ,
693
- duration : number = 0
687
+ duration : number = 0 ,
688
+ error : any = null ,
689
+ from : string = '' ,
690
+ store : TSpawnStore = { stdout : [ stdout ] , stderr : [ stderr ] , stdall : [ stdall ] , }
694
691
) {
695
692
super ( message )
696
- Reflect . deleteProperty ( this , 'message' )
697
- this . _dto =
698
- code !== null && typeof code === 'object'
699
- ? ProcessOutput . createLazyDto ( code )
700
- : {
701
- code,
702
- signal,
703
- duration,
704
- stdout,
705
- stderr,
706
- stdall,
707
- error : null ,
708
- from : '' ,
709
- message,
710
- store : { stdout : [ ] , stderr : [ ] , stdall : [ ] } ,
711
- }
693
+ const dto = this . _dto = code !== null && typeof code === 'object'
694
+ ? code
695
+ : { code, signal, duration, error, from, store }
696
+
697
+ Object . defineProperties ( this , {
698
+ stdout : { get : once ( ( ) => bufArrJoin ( dto . store . stdout ) ) } ,
699
+ stderr : { get : once ( ( ) => bufArrJoin ( dto . store . stderr ) ) } ,
700
+ stdall : { get : once ( ( ) => bufArrJoin ( dto . store . stdall ) ) } ,
701
+ message : { get : once ( ( ) =>
702
+ message || dto . error
703
+ ? ProcessOutput . getErrorMessage ( dto . error , dto . from )
704
+ : ProcessOutput . getExitMessage ( dto . code , dto . signal , this . stderr , dto . from )
705
+ ) ,
706
+ } ,
707
+ } )
708
+ }
709
+ message ! : string
710
+ stdout ! : string
711
+ stderr ! : string
712
+ stdall ! : string
713
+
714
+ get exitCode ( ) : number | null {
715
+ return this . _dto . code
716
+ }
717
+
718
+ get signal ( ) : NodeJS . Signals | null {
719
+ return this . _dto . signal
720
+ }
721
+
722
+ get duration ( ) : number {
723
+ return this . _dto . duration
712
724
}
713
725
714
726
toString ( ) : string {
715
- return this . _dto . stdall
727
+ return this . stdall
716
728
}
717
729
718
730
json < T = any > ( ) : T {
719
- return JSON . parse ( this . _dto . stdall )
731
+ return JSON . parse ( this . stdall )
720
732
}
721
733
722
734
buffer ( ) : Buffer {
723
- return Buffer . from ( this . _dto . stdall )
735
+ return Buffer . from ( this . stdall )
724
736
}
725
737
726
738
blob ( type = 'text/plain' ) : Blob {
@@ -742,63 +754,7 @@ export class ProcessOutput extends Error {
742
754
}
743
755
744
756
valueOf ( ) : string {
745
- return this . _dto . stdall . trim ( )
746
- }
747
-
748
- get stdout ( ) : string {
749
- return this . _dto . stdout
750
- }
751
-
752
- get stderr ( ) : string {
753
- return this . _dto . stderr
754
- }
755
-
756
- get exitCode ( ) : number | null {
757
- return this . _dto . code
758
- }
759
-
760
- get signal ( ) : NodeJS . Signals | null {
761
- return this . _dto . signal
762
- }
763
-
764
- get duration ( ) : number {
765
- return this . _dto . duration
766
- }
767
-
768
- get message ( ) : string {
769
- return this . _dto . message
770
- }
771
-
772
- private static createLazyDto ( {
773
- code,
774
- signal,
775
- duration,
776
- store : { stdout, stderr, stdall } ,
777
- from,
778
- error,
779
- } : ProcessDto ) : ProcessOutputDto {
780
- const dto = Object . defineProperties (
781
- {
782
- code,
783
- signal,
784
- duration,
785
- } ,
786
- {
787
- stdout : { get : once ( ( ) => bufArrJoin ( stdout ) ) } ,
788
- stderr : { get : once ( ( ) => bufArrJoin ( stderr ) ) } ,
789
- stdall : { get : once ( ( ) => bufArrJoin ( stdall ) ) } ,
790
- message : {
791
- get : once ( ( ) =>
792
- ProcessOutput . getExitMessage ( code , signal , dto . stderr , from )
793
- ) ,
794
- } ,
795
- ...( error && {
796
- message : { get : ( ) => ProcessOutput . getErrorMessage ( error , from ) } ,
797
- } ) ,
798
- }
799
- ) as ProcessOutputDto
800
-
801
- return dto
757
+ return this . stdall . trim ( )
802
758
}
803
759
804
760
static getExitMessage = formatExitMessage
0 commit comments