spawn-rx 4.0.0 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CODE_OF_CONDUCT.md +119 -36
- package/COPYING +1 -1
- package/lib/src/index.d.ts +104 -16
- package/lib/src/index.js +74 -31
- package/lib/src/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +281 -73
- package/test/spawn.ts +26 -0
    
        package/CODE_OF_CONDUCT.md
    CHANGED
    
    | @@ -1,50 +1,133 @@ | |
| 1 | 
            -
            # Contributor Code of Conduct
         | 
| 2 1 |  | 
| 3 | 
            -
             | 
| 4 | 
            -
            fostering an open and welcoming community, we pledge to respect all people who
         | 
| 5 | 
            -
            contribute through reporting issues, posting feature requests, updating
         | 
| 6 | 
            -
            documentation, submitting pull requests or patches, and other activities.
         | 
| 2 | 
            +
            # Contributor Covenant Code of Conduct
         | 
| 7 3 |  | 
| 8 | 
            -
             | 
| 9 | 
            -
            experience for everyone, regardless of level of experience, gender, gender
         | 
| 10 | 
            -
            identity and expression, sexual orientation, disability, personal appearance,
         | 
| 11 | 
            -
            body size, race, ethnicity, age, religion, or nationality.
         | 
| 4 | 
            +
            ## Our Pledge
         | 
| 12 5 |  | 
| 13 | 
            -
             | 
| 6 | 
            +
            We as members, contributors, and leaders pledge to make participation in our
         | 
| 7 | 
            +
            community a harassment-free experience for everyone, regardless of age, body
         | 
| 8 | 
            +
            size, visible or invisible disability, ethnicity, sex characteristics, gender
         | 
| 9 | 
            +
            identity and expression, level of experience, education, socio-economic status,
         | 
| 10 | 
            +
            nationality, personal appearance, race, caste, color, religion, or sexual
         | 
| 11 | 
            +
            identity and orientation.
         | 
| 14 12 |  | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 13 | 
            +
            We pledge to act and interact in ways that contribute to an open, welcoming,
         | 
| 14 | 
            +
            diverse, inclusive, and healthy community.
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            ## Our Standards
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            Examples of behavior that contributes to a positive environment for our
         | 
| 19 | 
            +
            community include:
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            * Demonstrating empathy and kindness toward other people
         | 
| 22 | 
            +
            * Being respectful of differing opinions, viewpoints, and experiences
         | 
| 23 | 
            +
            * Giving and gracefully accepting constructive feedback
         | 
| 24 | 
            +
            * Accepting responsibility and apologizing to those affected by our mistakes,
         | 
| 25 | 
            +
              and learning from the experience
         | 
| 26 | 
            +
            * Focusing on what is best not just for us as individuals, but for the overall
         | 
| 27 | 
            +
              community
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            Examples of unacceptable behavior include:
         | 
| 30 | 
            +
             | 
| 31 | 
            +
            * The use of sexualized language or imagery, and sexual attention or advances of
         | 
| 32 | 
            +
              any kind
         | 
| 33 | 
            +
            * Trolling, insulting or derogatory comments, and personal or political attacks
         | 
| 18 34 | 
             
            * Public or private harassment
         | 
| 19 | 
            -
            * Publishing  | 
| 20 | 
            -
               | 
| 21 | 
            -
            * Other  | 
| 35 | 
            +
            * Publishing others' private information, such as a physical or email address,
         | 
| 36 | 
            +
              without their explicit permission
         | 
| 37 | 
            +
            * Other conduct which could reasonably be considered inappropriate in a
         | 
| 38 | 
            +
              professional setting
         | 
| 39 | 
            +
             | 
| 40 | 
            +
            ## Enforcement Responsibilities
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            Community leaders are responsible for clarifying and enforcing our standards of
         | 
| 43 | 
            +
            acceptable behavior and will take appropriate and fair corrective action in
         | 
| 44 | 
            +
            response to any behavior that they deem inappropriate, threatening, offensive,
         | 
| 45 | 
            +
            or harmful.
         | 
| 22 46 |  | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
            threatening, offensive, or harmful.
         | 
| 47 | 
            +
            Community leaders have the right and responsibility to remove, edit, or reject
         | 
| 48 | 
            +
            comments, commits, code, wiki edits, issues, and other contributions that are
         | 
| 49 | 
            +
            not aligned to this Code of Conduct, and will communicate reasons for moderation
         | 
| 50 | 
            +
            decisions when appropriate.
         | 
| 28 51 |  | 
| 29 | 
            -
             | 
| 30 | 
            -
            fairly and consistently applying these principles to every aspect of managing
         | 
| 31 | 
            -
            this project. Project maintainers who do not follow or enforce the Code of
         | 
| 32 | 
            -
            Conduct may be permanently removed from the project team.
         | 
| 52 | 
            +
            ## Scope
         | 
| 33 53 |  | 
| 34 | 
            -
            This Code of Conduct applies  | 
| 35 | 
            -
             | 
| 54 | 
            +
            This Code of Conduct applies within all community spaces, and also applies when
         | 
| 55 | 
            +
            an individual is officially representing the community in public spaces.
         | 
| 56 | 
            +
            Examples of representing our community include using an official email address,
         | 
| 57 | 
            +
            posting via an official social media account, or acting as an appointed
         | 
| 58 | 
            +
            representative at an online or offline event.
         | 
| 59 | 
            +
             | 
| 60 | 
            +
            ## Enforcement
         | 
| 36 61 |  | 
| 37 62 | 
             
            Instances of abusive, harassing, or otherwise unacceptable behavior may be
         | 
| 38 | 
            -
            reported  | 
| 39 | 
            -
            complaints will be reviewed and investigated  | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 63 | 
            +
            reported to the community leaders responsible for enforcement at
         | 
| 64 | 
            +
            anais@anaisbetts.org.  All complaints will be reviewed and investigated promptly
         | 
| 65 | 
            +
            and fairly.
         | 
| 66 | 
            +
             | 
| 67 | 
            +
            All community leaders are obligated to respect the privacy and security of the
         | 
| 68 | 
            +
            reporter of any incident.
         | 
| 69 | 
            +
             | 
| 70 | 
            +
            ## Enforcement Guidelines
         | 
| 71 | 
            +
             | 
| 72 | 
            +
            Community leaders will follow these Community Impact Guidelines in determining
         | 
| 73 | 
            +
            the consequences for any action they deem in violation of this Code of Conduct:
         | 
| 74 | 
            +
             | 
| 75 | 
            +
            ### 1. Correction
         | 
| 76 | 
            +
             | 
| 77 | 
            +
            **Community Impact**: Use of inappropriate language or other behavior deemed
         | 
| 78 | 
            +
            unprofessional or unwelcome in the community.
         | 
| 43 79 |  | 
| 80 | 
            +
            **Consequence**: A private, written warning from community leaders, providing
         | 
| 81 | 
            +
            clarity around the nature of the violation and an explanation of why the
         | 
| 82 | 
            +
            behavior was inappropriate. A public apology may be requested.
         | 
| 83 | 
            +
             | 
| 84 | 
            +
            ### 2. Warning
         | 
| 85 | 
            +
             | 
| 86 | 
            +
            **Community Impact**: A violation through a single incident or series of
         | 
| 87 | 
            +
            actions.
         | 
| 88 | 
            +
             | 
| 89 | 
            +
            **Consequence**: A warning with consequences for continued behavior. No
         | 
| 90 | 
            +
            interaction with the people involved, including unsolicited interaction with
         | 
| 91 | 
            +
            those enforcing the Code of Conduct, for a specified period of time. This
         | 
| 92 | 
            +
            includes avoiding interactions in community spaces as well as external channels
         | 
| 93 | 
            +
            like social media. Violating these terms may lead to a temporary or permanent
         | 
| 94 | 
            +
            ban.
         | 
| 95 | 
            +
             | 
| 96 | 
            +
            ### 3. Temporary Ban
         | 
| 97 | 
            +
             | 
| 98 | 
            +
            **Community Impact**: A serious violation of community standards, including
         | 
| 99 | 
            +
            sustained inappropriate behavior.
         | 
| 100 | 
            +
             | 
| 101 | 
            +
            **Consequence**: A temporary ban from any sort of interaction or public
         | 
| 102 | 
            +
            communication with the community for a specified period of time. No public or
         | 
| 103 | 
            +
            private interaction with the people involved, including unsolicited interaction
         | 
| 104 | 
            +
            with those enforcing the Code of Conduct, is allowed during this period.
         | 
| 105 | 
            +
            Violating these terms may lead to a permanent ban.
         | 
| 106 | 
            +
             | 
| 107 | 
            +
            ### 4. Permanent Ban
         | 
| 108 | 
            +
             | 
| 109 | 
            +
            **Community Impact**: Demonstrating a pattern of violation of community
         | 
| 110 | 
            +
            standards, including sustained inappropriate behavior, harassment of an
         | 
| 111 | 
            +
            individual, or aggression toward or disparagement of classes of individuals.
         | 
| 112 | 
            +
             | 
| 113 | 
            +
            **Consequence**: A permanent ban from any sort of public interaction within the
         | 
| 114 | 
            +
            community.
         | 
| 115 | 
            +
             | 
| 116 | 
            +
            ## Attribution
         | 
| 44 117 |  | 
| 45 118 | 
             
            This Code of Conduct is adapted from the [Contributor Covenant][homepage],
         | 
| 46 | 
            -
            version 1 | 
| 47 | 
            -
            [ | 
| 119 | 
            +
            version 2.1, available at
         | 
| 120 | 
            +
            [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
         | 
| 121 | 
            +
             | 
| 122 | 
            +
            Community Impact Guidelines were inspired by
         | 
| 123 | 
            +
            [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
         | 
| 124 | 
            +
             | 
| 125 | 
            +
            For answers to common questions about this code of conduct, see the FAQ at
         | 
| 126 | 
            +
            [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
         | 
| 127 | 
            +
            [https://www.contributor-covenant.org/translations][translations].
         | 
| 48 128 |  | 
| 49 | 
            -
            [homepage]:  | 
| 50 | 
            -
            [ | 
| 129 | 
            +
            [homepage]: https://www.contributor-covenant.org
         | 
| 130 | 
            +
            [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
         | 
| 131 | 
            +
            [Mozilla CoC]: https://github.com/mozilla/diversity
         | 
| 132 | 
            +
            [FAQ]: https://www.contributor-covenant.org/faq
         | 
| 133 | 
            +
            [translations]: https://www.contributor-covenant.org/translations
         | 
    
        package/COPYING
    CHANGED
    
    | @@ -1,4 +1,4 @@ | |
| 1 | 
            -
            Copyright (c) 2016  | 
| 1 | 
            +
            Copyright (c) 2016 Anaïs Betts
         | 
| 2 2 |  | 
| 3 3 | 
             
            Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
         | 
| 4 4 |  | 
    
        package/lib/src/index.d.ts
    CHANGED
    
    | @@ -1,4 +1,5 @@ | |
| 1 1 | 
             
            import { Observable } from "rxjs";
         | 
| 2 | 
            +
            import { SpawnOptions } from "child_process";
         | 
| 2 3 | 
             
            /**
         | 
| 3 4 | 
             
             * Finds the actual executable and parameters to run on Windows. This method
         | 
| 4 5 | 
             
             * mimics the POSIX behavior of being able to run scripts as executables by
         | 
| @@ -9,15 +10,25 @@ import { Observable } from "rxjs"; | |
| 9 10 | 
             
             * also doesn't do, unlike on POSIX.
         | 
| 10 11 | 
             
             *
         | 
| 11 12 | 
             
             * @param  {string} exe           The executable to run
         | 
| 12 | 
            -
             * @param  { | 
| 13 | 
            +
             * @param  {string[]} args   The arguments to run
         | 
| 13 14 | 
             
             *
         | 
| 14 15 | 
             
             * @return {Object}               The cmd and args to run
         | 
| 15 16 | 
             
             * @property {string} cmd         The command to pass to spawn
         | 
| 16 | 
            -
             * @property { | 
| 17 | 
            +
             * @property {string[]} args The arguments to pass to spawn
         | 
| 17 18 | 
             
             */
         | 
| 18 | 
            -
            export declare function findActualExecutable(exe: string, args:  | 
| 19 | 
            +
            export declare function findActualExecutable(exe: string, args: string[]): {
         | 
| 19 20 | 
             
                cmd: string;
         | 
| 20 | 
            -
                args:  | 
| 21 | 
            +
                args: string[];
         | 
| 22 | 
            +
            };
         | 
| 23 | 
            +
            export type SpawnRxExtras = {
         | 
| 24 | 
            +
                stdin?: Observable<string>;
         | 
| 25 | 
            +
                split?: boolean;
         | 
| 26 | 
            +
                jobber?: boolean;
         | 
| 27 | 
            +
                encoding?: BufferEncoding;
         | 
| 28 | 
            +
            };
         | 
| 29 | 
            +
            export type OutputLine = {
         | 
| 30 | 
            +
                source: "stdout" | "stderr";
         | 
| 31 | 
            +
                text: string;
         | 
| 21 32 | 
             
            };
         | 
| 22 33 | 
             
            /**
         | 
| 23 34 | 
             
             * Spawns a process but detached from the current process. The process is put
         | 
| @@ -25,8 +36,28 @@ export declare function findActualExecutable(exe: string, args: Array<string>): | |
| 25 36 | 
             
             * return Observable.
         | 
| 26 37 | 
             
             *
         | 
| 27 38 | 
             
             * @param  {string} exe               The executable to run
         | 
| 28 | 
            -
             * @param  { | 
| 29 | 
            -
             * @param  { | 
| 39 | 
            +
             * @param  {string[]} params     The parameters to pass to the child
         | 
| 40 | 
            +
             * @param  {SpawnOptions & SpawnRxExtras} opts              Options to pass to spawn.
         | 
| 41 | 
            +
             *
         | 
| 42 | 
            +
             * @return {Observable<OutputLine>}       Returns an Observable that when subscribed
         | 
| 43 | 
            +
             *                                    to, will create a detached process. The
         | 
| 44 | 
            +
             *                                    process output will be streamed to this
         | 
| 45 | 
            +
             *                                    Observable, and if unsubscribed from, the
         | 
| 46 | 
            +
             *                                    process will be terminated early. If the
         | 
| 47 | 
            +
             *                                    process terminates with a non-zero value,
         | 
| 48 | 
            +
             *                                    the Observable will terminate with onError.
         | 
| 49 | 
            +
             */
         | 
| 50 | 
            +
            export declare function spawnDetached(exe: string, params: string[], opts: SpawnOptions & SpawnRxExtras & {
         | 
| 51 | 
            +
                split: true;
         | 
| 52 | 
            +
            }): Observable<OutputLine>;
         | 
| 53 | 
            +
            /**
         | 
| 54 | 
            +
             * Spawns a process but detached from the current process. The process is put
         | 
| 55 | 
            +
             * into its own Process Group that can be killed by unsubscribing from the
         | 
| 56 | 
            +
             * return Observable.
         | 
| 57 | 
            +
             *
         | 
| 58 | 
            +
             * @param  {string} exe               The executable to run
         | 
| 59 | 
            +
             * @param  {string[]} params     The parameters to pass to the child
         | 
| 60 | 
            +
             * @param  {SpawnOptions & SpawnRxExtras} opts              Options to pass to spawn.
         | 
| 30 61 | 
             
             *
         | 
| 31 62 | 
             
             * @return {Observable<string>}       Returns an Observable that when subscribed
         | 
| 32 63 | 
             
             *                                    to, will create a detached process. The
         | 
| @@ -36,13 +67,33 @@ export declare function findActualExecutable(exe: string, args: Array<string>): | |
| 36 67 | 
             
             *                                    process terminates with a non-zero value,
         | 
| 37 68 | 
             
             *                                    the Observable will terminate with onError.
         | 
| 38 69 | 
             
             */
         | 
| 39 | 
            -
            export declare function spawnDetached(exe: string, params:  | 
| 70 | 
            +
            export declare function spawnDetached(exe: string, params: string[], opts?: SpawnOptions & SpawnRxExtras & {
         | 
| 71 | 
            +
                split: false | undefined;
         | 
| 72 | 
            +
            }): Observable<string>;
         | 
| 40 73 | 
             
            /**
         | 
| 41 74 | 
             
             * Spawns a process attached as a child of the current process.
         | 
| 42 75 | 
             
             *
         | 
| 43 76 | 
             
             * @param  {string} exe               The executable to run
         | 
| 44 | 
            -
             * @param  { | 
| 45 | 
            -
             * @param  { | 
| 77 | 
            +
             * @param  {string[]} params     The parameters to pass to the child
         | 
| 78 | 
            +
             * @param  {SpawnOptions & SpawnRxExtras} opts              Options to pass to spawn.
         | 
| 79 | 
            +
             *
         | 
| 80 | 
            +
             * @return {Observable<OutputLine>}       Returns an Observable that when subscribed
         | 
| 81 | 
            +
             *                                    to, will create a child process. The
         | 
| 82 | 
            +
             *                                    process output will be streamed to this
         | 
| 83 | 
            +
             *                                    Observable, and if unsubscribed from, the
         | 
| 84 | 
            +
             *                                    process will be terminated early. If the
         | 
| 85 | 
            +
             *                                    process terminates with a non-zero value,
         | 
| 86 | 
            +
             *                                    the Observable will terminate with onError.
         | 
| 87 | 
            +
             */
         | 
| 88 | 
            +
            export declare function spawn(exe: string, params: string[], opts: SpawnOptions & SpawnRxExtras & {
         | 
| 89 | 
            +
                split: true;
         | 
| 90 | 
            +
            }): Observable<OutputLine>;
         | 
| 91 | 
            +
            /**
         | 
| 92 | 
            +
             * Spawns a process attached as a child of the current process.
         | 
| 93 | 
            +
             *
         | 
| 94 | 
            +
             * @param  {string} exe               The executable to run
         | 
| 95 | 
            +
             * @param  {string[]} params     The parameters to pass to the child
         | 
| 96 | 
            +
             * @param  {SpawnOptions & SpawnRxExtras} opts              Options to pass to spawn.
         | 
| 46 97 | 
             
             *
         | 
| 47 98 | 
             
             * @return {Observable<string>}       Returns an Observable that when subscribed
         | 
| 48 99 | 
             
             *                                    to, will create a child process. The
         | 
| @@ -52,14 +103,33 @@ export declare function spawnDetached(exe: string, params: Array<string>, opts?: | |
| 52 103 | 
             
             *                                    process terminates with a non-zero value,
         | 
| 53 104 | 
             
             *                                    the Observable will terminate with onError.
         | 
| 54 105 | 
             
             */
         | 
| 55 | 
            -
            export declare function spawn | 
| 106 | 
            +
            export declare function spawn(exe: string, params: string[], opts?: SpawnOptions & SpawnRxExtras & {
         | 
| 107 | 
            +
                split: false | undefined;
         | 
| 108 | 
            +
            }): Observable<string>;
         | 
| 109 | 
            +
            /**
         | 
| 110 | 
            +
             * Spawns a process but detached from the current process. The process is put
         | 
| 111 | 
            +
             * into its own Process Group.
         | 
| 112 | 
            +
             *
         | 
| 113 | 
            +
             * @param  {string} exe               The executable to run
         | 
| 114 | 
            +
             * @param  {string[]} params     The parameters to pass to the child
         | 
| 115 | 
            +
             * @param  {SpawnOptions & SpawnRxExtras} opts              Options to pass to spawn.
         | 
| 116 | 
            +
             *
         | 
| 117 | 
            +
             * @return {Promise<[string, string]>}       Returns an Promise that represents a detached
         | 
| 118 | 
            +
             *                                 process. The value returned is the process
         | 
| 119 | 
            +
             *                                 output. If the process terminates with a
         | 
| 120 | 
            +
             *                                 non-zero value, the Promise will resolve with
         | 
| 121 | 
            +
             *                                 an Error.
         | 
| 122 | 
            +
             */
         | 
| 123 | 
            +
            export declare function spawnDetachedPromise(exe: string, params: string[], opts: SpawnOptions & SpawnRxExtras & {
         | 
| 124 | 
            +
                split: true;
         | 
| 125 | 
            +
            }): Promise<[string, string]>;
         | 
| 56 126 | 
             
            /**
         | 
| 57 127 | 
             
             * Spawns a process but detached from the current process. The process is put
         | 
| 58 128 | 
             
             * into its own Process Group.
         | 
| 59 129 | 
             
             *
         | 
| 60 130 | 
             
             * @param  {string} exe               The executable to run
         | 
| 61 | 
            -
             * @param  { | 
| 62 | 
            -
             * @param  { | 
| 131 | 
            +
             * @param  {string[]} params     The parameters to pass to the child
         | 
| 132 | 
            +
             * @param  {SpawnOptions & SpawnRxExtras} opts              Options to pass to spawn.
         | 
| 63 133 | 
             
             *
         | 
| 64 134 | 
             
             * @return {Promise<string>}       Returns an Promise that represents a detached
         | 
| 65 135 | 
             
             *                                 process. The value returned is the process
         | 
| @@ -67,13 +137,31 @@ export declare function spawn<T = string>(exe: string, params?: Array<string>, o | |
| 67 137 | 
             
             *                                 non-zero value, the Promise will resolve with
         | 
| 68 138 | 
             
             *                                 an Error.
         | 
| 69 139 | 
             
             */
         | 
| 70 | 
            -
            export declare function spawnDetachedPromise(exe: string, params:  | 
| 140 | 
            +
            export declare function spawnDetachedPromise(exe: string, params: string[], opts?: SpawnOptions & SpawnRxExtras & {
         | 
| 141 | 
            +
                split: false | undefined;
         | 
| 142 | 
            +
            }): Promise<string>;
         | 
| 143 | 
            +
            /**
         | 
| 144 | 
            +
             * Spawns a process as a child process.
         | 
| 145 | 
            +
             *
         | 
| 146 | 
            +
             * @param  {string} exe               The executable to run
         | 
| 147 | 
            +
             * @param  {string[]} params     The parameters to pass to the child
         | 
| 148 | 
            +
             * @param  {SpawnOptions & SpawnRxExtras} opts              Options to pass to spawn.
         | 
| 149 | 
            +
             *
         | 
| 150 | 
            +
             * @return {Promise<[string, string]>}       Returns an Promise that represents a child
         | 
| 151 | 
            +
             *                                 process. The value returned is the process
         | 
| 152 | 
            +
             *                                 output. If the process terminates with a
         | 
| 153 | 
            +
             *                                 non-zero value, the Promise will resolve with
         | 
| 154 | 
            +
             *                                 an Error.
         | 
| 155 | 
            +
             */
         | 
| 156 | 
            +
            export declare function spawnPromise(exe: string, params: string[], opts: SpawnOptions & SpawnRxExtras & {
         | 
| 157 | 
            +
                split: true;
         | 
| 158 | 
            +
            }): Promise<[string, string]>;
         | 
| 71 159 | 
             
            /**
         | 
| 72 160 | 
             
             * Spawns a process as a child process.
         | 
| 73 161 | 
             
             *
         | 
| 74 162 | 
             
             * @param  {string} exe               The executable to run
         | 
| 75 | 
            -
             * @param  { | 
| 76 | 
            -
             * @param  { | 
| 163 | 
            +
             * @param  {string[]} params     The parameters to pass to the child
         | 
| 164 | 
            +
             * @param  {SpawnOptions & SpawnRxExtras} opts              Options to pass to spawn.
         | 
| 77 165 | 
             
             *
         | 
| 78 166 | 
             
             * @return {Promise<string>}       Returns an Promise that represents a child
         | 
| 79 167 | 
             
             *                                 process. The value returned is the process
         | 
| @@ -81,4 +169,4 @@ export declare function spawnDetachedPromise(exe: string, params: Array<string>, | |
| 81 169 | 
             
             *                                 non-zero value, the Promise will resolve with
         | 
| 82 170 | 
             
             *                                 an Error.
         | 
| 83 171 | 
             
             */
         | 
| 84 | 
            -
            export declare function spawnPromise(exe: string, params:  | 
| 172 | 
            +
            export declare function spawnPromise(exe: string, params: string[], opts?: SpawnOptions & SpawnRxExtras): Promise<string>;
         | 
    
        package/lib/src/index.js
    CHANGED
    
    | @@ -1,4 +1,15 @@ | |
| 1 1 | 
             
            "use strict";
         | 
| 2 | 
            +
            var __assign = (this && this.__assign) || function () {
         | 
| 3 | 
            +
                __assign = Object.assign || function(t) {
         | 
| 4 | 
            +
                    for (var s, i = 1, n = arguments.length; i < n; i++) {
         | 
| 5 | 
            +
                        s = arguments[i];
         | 
| 6 | 
            +
                        for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
         | 
| 7 | 
            +
                            t[p] = s[p];
         | 
| 8 | 
            +
                    }
         | 
| 9 | 
            +
                    return t;
         | 
| 10 | 
            +
                };
         | 
| 11 | 
            +
                return __assign.apply(this, arguments);
         | 
| 12 | 
            +
            };
         | 
| 2 13 | 
             
            var __rest = (this && this.__rest) || function (s, e) {
         | 
| 3 14 | 
             
                var t = {};
         | 
| 4 15 | 
             
                for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
         | 
| @@ -95,11 +106,11 @@ function runDownPath(exe) { | |
| 95 106 | 
             
             * also doesn't do, unlike on POSIX.
         | 
| 96 107 | 
             
             *
         | 
| 97 108 | 
             
             * @param  {string} exe           The executable to run
         | 
| 98 | 
            -
             * @param  { | 
| 109 | 
            +
             * @param  {string[]} args   The arguments to run
         | 
| 99 110 | 
             
             *
         | 
| 100 111 | 
             
             * @return {Object}               The cmd and args to run
         | 
| 101 112 | 
             
             * @property {string} cmd         The command to pass to spawn
         | 
| 102 | 
            -
             * @property { | 
| 113 | 
            +
             * @property {string[]} args The arguments to pass to spawn
         | 
| 103 114 | 
             
             */
         | 
| 104 115 | 
             
            function findActualExecutable(exe, args) {
         | 
| 105 116 | 
             
                // POSIX can just execute scripts directly, no need for silly goosery
         | 
| @@ -150,8 +161,8 @@ function findActualExecutable(exe, args) { | |
| 150 161 | 
             
             * return Observable.
         | 
| 151 162 | 
             
             *
         | 
| 152 163 | 
             
             * @param  {string} exe               The executable to run
         | 
| 153 | 
            -
             * @param  { | 
| 154 | 
            -
             * @param  { | 
| 164 | 
            +
             * @param  {string[]} params     The parameters to pass to the child
         | 
| 165 | 
            +
             * @param  {SpawnOptions & SpawnRxExtras} opts              Options to pass to spawn.
         | 
| 155 166 | 
             
             *
         | 
| 156 167 | 
             
             * @return {Observable<string>}       Returns an Observable that when subscribed
         | 
| 157 168 | 
             
             *                                    to, will create a detached process. The
         | 
| @@ -162,8 +173,7 @@ function findActualExecutable(exe, args) { | |
| 162 173 | 
             
             *                                    the Observable will terminate with onError.
         | 
| 163 174 | 
             
             */
         | 
| 164 175 | 
             
            function spawnDetached(exe, params, opts) {
         | 
| 165 | 
            -
                 | 
| 166 | 
            -
                var _a = findActualExecutable(exe, params), cmd = _a.cmd, args = _a.args;
         | 
| 176 | 
            +
                var _a = findActualExecutable(exe, params !== null && params !== void 0 ? params : []), cmd = _a.cmd, args = _a.args;
         | 
| 167 177 | 
             
                if (!isWindows) {
         | 
| 168 178 | 
             
                    return spawn(cmd, args, assign({}, opts || {}, { detached: true }));
         | 
| 169 179 | 
             
                }
         | 
| @@ -177,8 +187,8 @@ function spawnDetached(exe, params, opts) { | |
| 177 187 | 
             
             * Spawns a process attached as a child of the current process.
         | 
| 178 188 | 
             
             *
         | 
| 179 189 | 
             
             * @param  {string} exe               The executable to run
         | 
| 180 | 
            -
             * @param  { | 
| 181 | 
            -
             * @param  { | 
| 190 | 
            +
             * @param  {string[]} params     The parameters to pass to the child
         | 
| 191 | 
            +
             * @param  {SpawnOptions & SpawnRxExtras} opts              Options to pass to spawn.
         | 
| 182 192 | 
             
             *
         | 
| 183 193 | 
             
             * @return {Observable<string>}       Returns an Observable that when subscribed
         | 
| 184 194 | 
             
             *                                    to, will create a child process. The
         | 
| @@ -189,22 +199,13 @@ function spawnDetached(exe, params, opts) { | |
| 189 199 | 
             
             *                                    the Observable will terminate with onError.
         | 
| 190 200 | 
             
             */
         | 
| 191 201 | 
             
            function spawn(exe, params, opts) {
         | 
| 192 | 
            -
                 | 
| 193 | 
            -
                 | 
| 194 | 
            -
                opts = opts || {};
         | 
| 195 | 
            -
                var spawnObs = rxjs_1.Observable.create(function (subj) {
         | 
| 202 | 
            +
                opts = opts !== null && opts !== void 0 ? opts : {};
         | 
| 203 | 
            +
                var spawnObs = new rxjs_1.Observable(function (subj) {
         | 
| 196 204 | 
             
                    // eslint-disable-next-line @typescript-eslint/no-unused-vars
         | 
| 197 | 
            -
                    var  | 
| 205 | 
            +
                    var stdin = opts.stdin, jobber = opts.jobber, split = opts.split, encoding = opts.encoding, spawnOpts = __rest(opts, ["stdin", "jobber", "split", "encoding"]);
         | 
| 198 206 | 
             
                    var _a = findActualExecutable(exe, params), cmd = _a.cmd, args = _a.args;
         | 
| 199 | 
            -
                    d("spawning process: ".concat(cmd, " ").concat(args.join(), ", ").concat(JSON.stringify( | 
| 200 | 
            -
                    var  | 
| 201 | 
            -
                    if ("jobber" in origOpts) {
         | 
| 202 | 
            -
                        delete origOpts.jobber;
         | 
| 203 | 
            -
                    }
         | 
| 204 | 
            -
                    if ("split" in origOpts) {
         | 
| 205 | 
            -
                        delete origOpts.split;
         | 
| 206 | 
            -
                    }
         | 
| 207 | 
            -
                    var proc = (0, child_process_1.spawn)(cmd, args, origOpts);
         | 
| 207 | 
            +
                    d("spawning process: ".concat(cmd, " ").concat(args.join(), ", ").concat(JSON.stringify(spawnOpts)));
         | 
| 208 | 
            +
                    var proc = (0, child_process_1.spawn)(cmd, args, spawnOpts);
         | 
| 208 209 | 
             
                    var bufHandler = function (source) { return function (b) {
         | 
| 209 210 | 
             
                        if (b.length < 1) {
         | 
| 210 211 | 
             
                            return;
         | 
| @@ -215,7 +216,7 @@ function spawn(exe, params, opts) { | |
| 215 216 | 
             
                                chunk = b.toString();
         | 
| 216 217 | 
             
                            }
         | 
| 217 218 | 
             
                            else {
         | 
| 218 | 
            -
                                chunk = b.toString( | 
| 219 | 
            +
                                chunk = b.toString(encoding || "utf8");
         | 
| 219 220 | 
             
                            }
         | 
| 220 221 | 
             
                        }
         | 
| 221 222 | 
             
                        catch (_a) {
         | 
| @@ -226,7 +227,11 @@ function spawn(exe, params, opts) { | |
| 226 227 | 
             
                    var ret = new rxjs_1.Subscription();
         | 
| 227 228 | 
             
                    if (opts.stdin) {
         | 
| 228 229 | 
             
                        if (proc.stdin) {
         | 
| 229 | 
            -
                            ret.add(opts.stdin.subscribe( | 
| 230 | 
            +
                            ret.add(opts.stdin.subscribe({
         | 
| 231 | 
            +
                                next: function (x) { return proc.stdin.write(x); },
         | 
| 232 | 
            +
                                error: subj.error.bind(subj),
         | 
| 233 | 
            +
                                complete: function () { return proc.stdin.end(); },
         | 
| 234 | 
            +
                            }));
         | 
| 230 235 | 
             
                        }
         | 
| 231 236 | 
             
                        else {
         | 
| 232 237 | 
             
                            subj.error(new Error("opts.stdio conflicts with provided spawn opts.stdin observable, 'pipe' is required"));
         | 
| @@ -271,6 +276,7 @@ function spawn(exe, params, opts) { | |
| 271 276 | 
             
                            pipesClosed.subscribe(function () {
         | 
| 272 277 | 
             
                                var e = new Error("Failed with exit code: ".concat(code));
         | 
| 273 278 | 
             
                                e.exitCode = code;
         | 
| 279 | 
            +
                                e.code = code;
         | 
| 274 280 | 
             
                                subj.error(e);
         | 
| 275 281 | 
             
                            });
         | 
| 276 282 | 
             
                        }
         | 
| @@ -296,7 +302,36 @@ function spawn(exe, params, opts) { | |
| 296 302 | 
             
            function wrapObservableInPromise(obs) {
         | 
| 297 303 | 
             
                return new Promise(function (res, rej) {
         | 
| 298 304 | 
             
                    var out = "";
         | 
| 299 | 
            -
                    obs.subscribe( | 
| 305 | 
            +
                    obs.subscribe({
         | 
| 306 | 
            +
                        next: function (x) { return (out += x); },
         | 
| 307 | 
            +
                        error: function (e) {
         | 
| 308 | 
            +
                            var err = new Error("".concat(out, "\n").concat(e.message));
         | 
| 309 | 
            +
                            if ("exitCode" in e) {
         | 
| 310 | 
            +
                                err.exitCode = e.exitCode;
         | 
| 311 | 
            +
                                err.code = e.exitCode;
         | 
| 312 | 
            +
                            }
         | 
| 313 | 
            +
                            rej(err);
         | 
| 314 | 
            +
                        },
         | 
| 315 | 
            +
                        complete: function () { return res(out); },
         | 
| 316 | 
            +
                    });
         | 
| 317 | 
            +
                });
         | 
| 318 | 
            +
            }
         | 
| 319 | 
            +
            function wrapObservableInSplitPromise(obs) {
         | 
| 320 | 
            +
                return new Promise(function (res, rej) {
         | 
| 321 | 
            +
                    var out = "";
         | 
| 322 | 
            +
                    var err = "";
         | 
| 323 | 
            +
                    obs.subscribe({
         | 
| 324 | 
            +
                        next: function (x) { return (x.source === "stdout" ? (out += x.text) : (err += x.text)); },
         | 
| 325 | 
            +
                        error: function (e) {
         | 
| 326 | 
            +
                            var err = new Error("".concat(out, "\n").concat(e.message));
         | 
| 327 | 
            +
                            if ("exitCode" in e) {
         | 
| 328 | 
            +
                                err.exitCode = e.exitCode;
         | 
| 329 | 
            +
                                err.code = e.exitCode;
         | 
| 330 | 
            +
                            }
         | 
| 331 | 
            +
                            rej(err);
         | 
| 332 | 
            +
                        },
         | 
| 333 | 
            +
                        complete: function () { return res([out, err]); },
         | 
| 334 | 
            +
                    });
         | 
| 300 335 | 
             
                });
         | 
| 301 336 | 
             
            }
         | 
| 302 337 | 
             
            /**
         | 
| @@ -304,7 +339,7 @@ function wrapObservableInPromise(obs) { | |
| 304 339 | 
             
             * into its own Process Group.
         | 
| 305 340 | 
             
             *
         | 
| 306 341 | 
             
             * @param  {string} exe               The executable to run
         | 
| 307 | 
            -
             * @param  { | 
| 342 | 
            +
             * @param  {string[]} params     The parameters to pass to the child
         | 
| 308 343 | 
             
             * @param  {Object} opts              Options to pass to spawn.
         | 
| 309 344 | 
             
             *
         | 
| 310 345 | 
             
             * @return {Promise<string>}       Returns an Promise that represents a detached
         | 
| @@ -314,14 +349,18 @@ function wrapObservableInPromise(obs) { | |
| 314 349 | 
             
             *                                 an Error.
         | 
| 315 350 | 
             
             */
         | 
| 316 351 | 
             
            function spawnDetachedPromise(exe, params, opts) {
         | 
| 317 | 
            -
                if (opts === void 0 | 
| 318 | 
            -
             | 
| 352 | 
            +
                if (opts === null || opts === void 0 ? void 0 : opts.split) {
         | 
| 353 | 
            +
                    return wrapObservableInSplitPromise(spawnDetached(exe, params, __assign(__assign({}, (opts !== null && opts !== void 0 ? opts : {})), { split: true })));
         | 
| 354 | 
            +
                }
         | 
| 355 | 
            +
                else {
         | 
| 356 | 
            +
                    return wrapObservableInPromise(spawnDetached(exe, params, __assign(__assign({}, (opts !== null && opts !== void 0 ? opts : {})), { split: false })));
         | 
| 357 | 
            +
                }
         | 
| 319 358 | 
             
            }
         | 
| 320 359 | 
             
            /**
         | 
| 321 360 | 
             
             * Spawns a process as a child process.
         | 
| 322 361 | 
             
             *
         | 
| 323 362 | 
             
             * @param  {string} exe               The executable to run
         | 
| 324 | 
            -
             * @param  { | 
| 363 | 
            +
             * @param  {string[]} params     The parameters to pass to the child
         | 
| 325 364 | 
             
             * @param  {Object} opts              Options to pass to spawn.
         | 
| 326 365 | 
             
             *
         | 
| 327 366 | 
             
             * @return {Promise<string>}       Returns an Promise that represents a child
         | 
| @@ -331,7 +370,11 @@ function spawnDetachedPromise(exe, params, opts) { | |
| 331 370 | 
             
             *                                 an Error.
         | 
| 332 371 | 
             
             */
         | 
| 333 372 | 
             
            function spawnPromise(exe, params, opts) {
         | 
| 334 | 
            -
                if (opts === void 0 | 
| 335 | 
            -
             | 
| 373 | 
            +
                if (opts === null || opts === void 0 ? void 0 : opts.split) {
         | 
| 374 | 
            +
                    return wrapObservableInSplitPromise(spawn(exe, params, __assign(__assign({}, (opts !== null && opts !== void 0 ? opts : {})), { split: true })));
         | 
| 375 | 
            +
                }
         | 
| 376 | 
            +
                else {
         | 
| 377 | 
            +
                    return wrapObservableInPromise(spawn(exe, params, __assign(__assign({}, (opts !== null && opts !== void 0 ? opts : {})), { split: false })));
         | 
| 378 | 
            +
                }
         | 
| 336 379 | 
             
            }
         | 
| 337 380 | 
             
            //# sourceMappingURL=index.js.map
         | 
    
        package/lib/src/index.js.map
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":" | 
| 1 | 
            +
            {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqFA,oDA8DC;AA6ED,sCAyBC;AA2DD,sBAgIC;AA+FD,oDAcC;AAqDD,oCAcC;AApmBD,uDAAuD;AACvD,2BAA6B;AAC7B,yBAA2B;AAC3B,wBAA0B;AAC1B,sCAAwC;AAGxC,6BAAyE;AACzE,4CAA6C;AAC7C,+CAA+D;AAC/D,+BAA0B;AAE1B,IAAM,SAAS,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC;AAE/C,IAAM,CAAC,GAAG,IAAA,eAAK,EAAC,UAAU,CAAC,CAAC,CAAC,sCAAsC;AAEnE;;;;;;;GAOG;AACH,SAAS,mBAAmB,CAAC,IAAY;IACvC,IAAI,CAAC;QACH,OAAO,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,WAAW,CAAC,GAAW;IAC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f,CAAe;SAChC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AA0CD;;;;;;;;;;;;;GAaG;AACH,SAAgB,oBAAoB,CAClC,GAAW,EACX,MAAgB,EAChB,IAAmC;IAEnC,IAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,EAAE,CAAC;QAChB,OAAO,4BAA4B,CACjC,aAAa,CAAC,GAAG,EAAE,MAAM,wBAAO,CAAC,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,EAAE,CAAC,KAAE,KAAK,EAAE,IAAI,IAAG,CAC7D,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,OAAO,uBAAuB,CAC5B,aAAa,CAAC,GAAG,EAAE,MAAM,wBAAO,CAAC,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,EAAE,CAAC,KAAE,KAAK,EAAE,KAAK,IAAG,CAC9D,CAAC;IACJ,CAAC;AACH,CAAC;AAwCD;;;;;;;;;;;;GAYG;AACH,SAAgB,YAAY,CAC1B,GAAW,EACX,MAAgB,EAChB,IAAmC;IAEnC,IAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,EAAE,CAAC;QAChB,OAAO,4BAA4B,CACjC,KAAK,CAAC,GAAG,EAAE,MAAM,wBAAO,CAAC,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,EAAE,CAAC,KAAE,KAAK,EAAE,IAAI,IAAG,CACrD,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,OAAO,uBAAuB,CAC5B,KAAK,CAAC,GAAG,EAAE,MAAM,wBAAO,CAAC,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,EAAE,CAAC,KAAE,KAAK,EAAE,KAAK,IAAG,CACtD,CAAC;IACJ,CAAC;AACH,CAAC"}
         | 
    
        package/package.json
    CHANGED
    
    | @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            {
         | 
| 2 2 | 
             
              "name": "spawn-rx",
         | 
| 3 | 
            -
              "version": " | 
| 3 | 
            +
              "version": "5.0.1",
         | 
| 4 4 | 
             
              "description": "An Rx-version of child_process.spawn",
         | 
| 5 5 | 
             
              "scripts": {
         | 
| 6 6 | 
             
                "doc": "echo \"esdoc may not work correctly\" && esdoc -c ./esdoc.json",
         | 
| @@ -57,4 +57,4 @@ | |
| 57 57 | 
             
                "typescript-eslint": "^8.14.0",
         | 
| 58 58 | 
             
                "uuid": "3.0.1"
         | 
| 59 59 | 
             
              }
         | 
| 60 | 
            -
            }
         | 
| 60 | 
            +
            }
         | 
    
        package/src/index.ts
    CHANGED
    
    | @@ -7,7 +7,7 @@ import * as assign from "lodash.assign"; | |
| 7 7 | 
             
            import type { Observer, Subject } from "rxjs";
         | 
| 8 8 | 
             
            import { Observable, Subscription, AsyncSubject, of, merge } from "rxjs";
         | 
| 9 9 | 
             
            import { map, reduce } from "rxjs/operators";
         | 
| 10 | 
            -
            import { spawn as spawnOg } from "child_process";
         | 
| 10 | 
            +
            import { spawn as spawnOg, SpawnOptions } from "child_process";
         | 
| 11 11 | 
             
            import Debug from "debug";
         | 
| 12 12 |  | 
| 13 13 | 
             
            const isWindows = process.platform === "win32";
         | 
| @@ -77,18 +77,18 @@ function runDownPath(exe: string): string { | |
| 77 77 | 
             
             * also doesn't do, unlike on POSIX.
         | 
| 78 78 | 
             
             *
         | 
| 79 79 | 
             
             * @param  {string} exe           The executable to run
         | 
| 80 | 
            -
             * @param  { | 
| 80 | 
            +
             * @param  {string[]} args   The arguments to run
         | 
| 81 81 | 
             
             *
         | 
| 82 82 | 
             
             * @return {Object}               The cmd and args to run
         | 
| 83 83 | 
             
             * @property {string} cmd         The command to pass to spawn
         | 
| 84 | 
            -
             * @property { | 
| 84 | 
            +
             * @property {string[]} args The arguments to pass to spawn
         | 
| 85 85 | 
             
             */
         | 
| 86 86 | 
             
            export function findActualExecutable(
         | 
| 87 87 | 
             
              exe: string,
         | 
| 88 | 
            -
              args:  | 
| 88 | 
            +
              args: string[],
         | 
| 89 89 | 
             
            ): {
         | 
| 90 90 | 
             
              cmd: string;
         | 
| 91 | 
            -
              args:  | 
| 91 | 
            +
              args: string[];
         | 
| 92 92 | 
             
            } {
         | 
| 93 93 | 
             
              // POSIX can just execute scripts directly, no need for silly goosery
         | 
| 94 94 | 
             
              if (process.platform !== "win32") {
         | 
| @@ -147,14 +147,72 @@ export function findActualExecutable( | |
| 147 147 | 
             
              return { cmd: exe, args: args };
         | 
| 148 148 | 
             
            }
         | 
| 149 149 |  | 
| 150 | 
            +
            export type SpawnRxExtras = {
         | 
| 151 | 
            +
              stdin?: Observable<string>;
         | 
| 152 | 
            +
              split?: boolean;
         | 
| 153 | 
            +
              jobber?: boolean;
         | 
| 154 | 
            +
              encoding?: BufferEncoding;
         | 
| 155 | 
            +
            };
         | 
| 156 | 
            +
             | 
| 157 | 
            +
            export type OutputLine = {
         | 
| 158 | 
            +
              source: "stdout" | "stderr";
         | 
| 159 | 
            +
              text: string;
         | 
| 160 | 
            +
            };
         | 
| 161 | 
            +
             | 
| 150 162 | 
             
            /**
         | 
| 151 163 | 
             
             * Spawns a process but detached from the current process. The process is put
         | 
| 152 164 | 
             
             * into its own Process Group that can be killed by unsubscribing from the
         | 
| 153 165 | 
             
             * return Observable.
         | 
| 154 166 | 
             
             *
         | 
| 155 167 | 
             
             * @param  {string} exe               The executable to run
         | 
| 156 | 
            -
             * @param  { | 
| 157 | 
            -
             * @param  { | 
| 168 | 
            +
             * @param  {string[]} params     The parameters to pass to the child
         | 
| 169 | 
            +
             * @param  {SpawnOptions & SpawnRxExtras} opts              Options to pass to spawn.
         | 
| 170 | 
            +
             *
         | 
| 171 | 
            +
             * @return {Observable<OutputLine>}       Returns an Observable that when subscribed
         | 
| 172 | 
            +
             *                                    to, will create a detached process. The
         | 
| 173 | 
            +
             *                                    process output will be streamed to this
         | 
| 174 | 
            +
             *                                    Observable, and if unsubscribed from, the
         | 
| 175 | 
            +
             *                                    process will be terminated early. If the
         | 
| 176 | 
            +
             *                                    process terminates with a non-zero value,
         | 
| 177 | 
            +
             *                                    the Observable will terminate with onError.
         | 
| 178 | 
            +
             */
         | 
| 179 | 
            +
            export function spawnDetached(
         | 
| 180 | 
            +
              exe: string,
         | 
| 181 | 
            +
              params: string[],
         | 
| 182 | 
            +
              opts: SpawnOptions & SpawnRxExtras & { split: true },
         | 
| 183 | 
            +
            ): Observable<OutputLine>;
         | 
| 184 | 
            +
             | 
| 185 | 
            +
            /**
         | 
| 186 | 
            +
             * Spawns a process but detached from the current process. The process is put
         | 
| 187 | 
            +
             * into its own Process Group that can be killed by unsubscribing from the
         | 
| 188 | 
            +
             * return Observable.
         | 
| 189 | 
            +
             *
         | 
| 190 | 
            +
             * @param  {string} exe               The executable to run
         | 
| 191 | 
            +
             * @param  {string[]} params     The parameters to pass to the child
         | 
| 192 | 
            +
             * @param  {SpawnOptions & SpawnRxExtras} opts              Options to pass to spawn.
         | 
| 193 | 
            +
             *
         | 
| 194 | 
            +
             * @return {Observable<string>}       Returns an Observable that when subscribed
         | 
| 195 | 
            +
             *                                    to, will create a detached process. The
         | 
| 196 | 
            +
             *                                    process output will be streamed to this
         | 
| 197 | 
            +
             *                                    Observable, and if unsubscribed from, the
         | 
| 198 | 
            +
             *                                    process will be terminated early. If the
         | 
| 199 | 
            +
             *                                    process terminates with a non-zero value,
         | 
| 200 | 
            +
             *                                    the Observable will terminate with onError.
         | 
| 201 | 
            +
             */
         | 
| 202 | 
            +
            export function spawnDetached(
         | 
| 203 | 
            +
              exe: string,
         | 
| 204 | 
            +
              params: string[],
         | 
| 205 | 
            +
              opts?: SpawnOptions & SpawnRxExtras & { split: false | undefined },
         | 
| 206 | 
            +
            ): Observable<string>;
         | 
| 207 | 
            +
             | 
| 208 | 
            +
            /**
         | 
| 209 | 
            +
             * Spawns a process but detached from the current process. The process is put
         | 
| 210 | 
            +
             * into its own Process Group that can be killed by unsubscribing from the
         | 
| 211 | 
            +
             * return Observable.
         | 
| 212 | 
            +
             *
         | 
| 213 | 
            +
             * @param  {string} exe               The executable to run
         | 
| 214 | 
            +
             * @param  {string[]} params     The parameters to pass to the child
         | 
| 215 | 
            +
             * @param  {SpawnOptions & SpawnRxExtras} opts              Options to pass to spawn.
         | 
| 158 216 | 
             
             *
         | 
| 159 217 | 
             
             * @return {Observable<string>}       Returns an Observable that when subscribed
         | 
| 160 218 | 
             
             *                                    to, will create a detached process. The
         | 
| @@ -166,10 +224,10 @@ export function findActualExecutable( | |
| 166 224 | 
             
             */
         | 
| 167 225 | 
             
            export function spawnDetached(
         | 
| 168 226 | 
             
              exe: string,
         | 
| 169 | 
            -
              params:  | 
| 170 | 
            -
              opts | 
| 171 | 
            -
            ): Observable<string> {
         | 
| 172 | 
            -
              const { cmd, args } = findActualExecutable(exe, params);
         | 
| 227 | 
            +
              params: string[],
         | 
| 228 | 
            +
              opts?: SpawnOptions & SpawnRxExtras,
         | 
| 229 | 
            +
            ): Observable<string> | Observable<OutputLine> {
         | 
| 230 | 
            +
              const { cmd, args } = findActualExecutable(exe, params ?? []);
         | 
| 173 231 |  | 
| 174 232 | 
             
              if (!isWindows) {
         | 
| 175 233 | 
             
                return spawn(cmd, args, assign({}, opts || {}, { detached: true }));
         | 
| @@ -195,8 +253,29 @@ export function spawnDetached( | |
| 195 253 | 
             
             * Spawns a process attached as a child of the current process.
         | 
| 196 254 | 
             
             *
         | 
| 197 255 | 
             
             * @param  {string} exe               The executable to run
         | 
| 198 | 
            -
             * @param  { | 
| 199 | 
            -
             * @param  { | 
| 256 | 
            +
             * @param  {string[]} params     The parameters to pass to the child
         | 
| 257 | 
            +
             * @param  {SpawnOptions & SpawnRxExtras} opts              Options to pass to spawn.
         | 
| 258 | 
            +
             *
         | 
| 259 | 
            +
             * @return {Observable<OutputLine>}       Returns an Observable that when subscribed
         | 
| 260 | 
            +
             *                                    to, will create a child process. The
         | 
| 261 | 
            +
             *                                    process output will be streamed to this
         | 
| 262 | 
            +
             *                                    Observable, and if unsubscribed from, the
         | 
| 263 | 
            +
             *                                    process will be terminated early. If the
         | 
| 264 | 
            +
             *                                    process terminates with a non-zero value,
         | 
| 265 | 
            +
             *                                    the Observable will terminate with onError.
         | 
| 266 | 
            +
             */
         | 
| 267 | 
            +
            export function spawn(
         | 
| 268 | 
            +
              exe: string,
         | 
| 269 | 
            +
              params: string[],
         | 
| 270 | 
            +
              opts: SpawnOptions & SpawnRxExtras & { split: true },
         | 
| 271 | 
            +
            ): Observable<OutputLine>;
         | 
| 272 | 
            +
             | 
| 273 | 
            +
            /**
         | 
| 274 | 
            +
             * Spawns a process attached as a child of the current process.
         | 
| 275 | 
            +
             *
         | 
| 276 | 
            +
             * @param  {string} exe               The executable to run
         | 
| 277 | 
            +
             * @param  {string[]} params     The parameters to pass to the child
         | 
| 278 | 
            +
             * @param  {SpawnOptions & SpawnRxExtras} opts              Options to pass to spawn.
         | 
| 200 279 | 
             
             *
         | 
| 201 280 | 
             
             * @return {Observable<string>}       Returns an Observable that when subscribed
         | 
| 202 281 | 
             
             *                                    to, will create a child process. The
         | 
| @@ -206,66 +285,73 @@ export function spawnDetached( | |
| 206 285 | 
             
             *                                    process terminates with a non-zero value,
         | 
| 207 286 | 
             
             *                                    the Observable will terminate with onError.
         | 
| 208 287 | 
             
             */
         | 
| 288 | 
            +
            export function spawn(
         | 
| 289 | 
            +
              exe: string,
         | 
| 290 | 
            +
              params: string[],
         | 
| 291 | 
            +
              opts?: SpawnOptions & SpawnRxExtras & { split: false | undefined },
         | 
| 292 | 
            +
            ): Observable<string>;
         | 
| 209 293 |  | 
| 210 | 
            -
             | 
| 294 | 
            +
            /**
         | 
| 295 | 
            +
             * Spawns a process attached as a child of the current process.
         | 
| 296 | 
            +
             *
         | 
| 297 | 
            +
             * @param  {string} exe               The executable to run
         | 
| 298 | 
            +
             * @param  {string[]} params     The parameters to pass to the child
         | 
| 299 | 
            +
             * @param  {SpawnOptions & SpawnRxExtras} opts              Options to pass to spawn.
         | 
| 300 | 
            +
             *
         | 
| 301 | 
            +
             * @return {Observable<string>}       Returns an Observable that when subscribed
         | 
| 302 | 
            +
             *                                    to, will create a child process. The
         | 
| 303 | 
            +
             *                                    process output will be streamed to this
         | 
| 304 | 
            +
             *                                    Observable, and if unsubscribed from, the
         | 
| 305 | 
            +
             *                                    process will be terminated early. If the
         | 
| 306 | 
            +
             *                                    process terminates with a non-zero value,
         | 
| 307 | 
            +
             *                                    the Observable will terminate with onError.
         | 
| 308 | 
            +
             */
         | 
| 309 | 
            +
            export function spawn(
         | 
| 211 310 | 
             
              exe: string,
         | 
| 212 | 
            -
              params:  | 
| 213 | 
            -
              opts | 
| 214 | 
            -
            ): Observable< | 
| 215 | 
            -
              opts = opts  | 
| 216 | 
            -
              const spawnObs = Observable | 
| 217 | 
            -
                (
         | 
| 218 | 
            -
                  subj: Observer<{
         | 
| 219 | 
            -
                    source: any;
         | 
| 220 | 
            -
                    text: any;
         | 
| 221 | 
            -
                  }>,
         | 
| 222 | 
            -
                ) => {
         | 
| 311 | 
            +
              params: string[],
         | 
| 312 | 
            +
              opts?: SpawnOptions & SpawnRxExtras,
         | 
| 313 | 
            +
            ): Observable<string> | Observable<OutputLine> {
         | 
| 314 | 
            +
              opts = opts ?? {};
         | 
| 315 | 
            +
              const spawnObs: Observable<OutputLine> = new Observable(
         | 
| 316 | 
            +
                (subj: Observer<OutputLine>) => {
         | 
| 223 317 | 
             
                  // eslint-disable-next-line @typescript-eslint/no-unused-vars
         | 
| 224 | 
            -
                  const {  | 
| 318 | 
            +
                  const { stdin, jobber, split, encoding, ...spawnOpts } = opts;
         | 
| 225 319 | 
             
                  const { cmd, args } = findActualExecutable(exe, params);
         | 
| 226 320 | 
             
                  d(
         | 
| 227 | 
            -
                    `spawning process: ${cmd} ${args.join()}, ${JSON.stringify(
         | 
| 228 | 
            -
                      optsWithoutStdIn,
         | 
| 229 | 
            -
                    )}`,
         | 
| 321 | 
            +
                    `spawning process: ${cmd} ${args.join()}, ${JSON.stringify(spawnOpts)}`,
         | 
| 230 322 | 
             
                  );
         | 
| 231 | 
            -
                  const origOpts = assign({}, optsWithoutStdIn);
         | 
| 232 | 
            -
                  if ("jobber" in origOpts) {
         | 
| 233 | 
            -
                    delete origOpts.jobber;
         | 
| 234 | 
            -
                  }
         | 
| 235 | 
            -
                  if ("split" in origOpts) {
         | 
| 236 | 
            -
                    delete origOpts.split;
         | 
| 237 | 
            -
                  }
         | 
| 238 323 |  | 
| 239 | 
            -
                  const proc = spawnOg(cmd, args,  | 
| 324 | 
            +
                  const proc = spawnOg(cmd, args, spawnOpts);
         | 
| 240 325 |  | 
| 241 | 
            -
                  const bufHandler = | 
| 242 | 
            -
                     | 
| 243 | 
            -
                       | 
| 244 | 
            -
             | 
| 245 | 
            -
             | 
| 246 | 
            -
             | 
| 247 | 
            -
                       | 
| 248 | 
            -
                         | 
| 249 | 
            -
             | 
| 250 | 
            -
                         | 
| 326 | 
            +
                  const bufHandler =
         | 
| 327 | 
            +
                    (source: "stdout" | "stderr") => (b: string | Buffer) => {
         | 
| 328 | 
            +
                      if (b.length < 1) {
         | 
| 329 | 
            +
                        return;
         | 
| 330 | 
            +
                      }
         | 
| 331 | 
            +
                      let chunk = "<< String sent back was too long >>";
         | 
| 332 | 
            +
                      try {
         | 
| 333 | 
            +
                        if (typeof b === "string") {
         | 
| 334 | 
            +
                          chunk = b.toString();
         | 
| 335 | 
            +
                        } else {
         | 
| 336 | 
            +
                          chunk = b.toString(encoding || "utf8");
         | 
| 337 | 
            +
                        }
         | 
| 338 | 
            +
                      } catch {
         | 
| 339 | 
            +
                        chunk = `<< Lost chunk of process output for ${exe} - length was ${b.length}>>`;
         | 
| 251 340 | 
             
                      }
         | 
| 252 | 
            -
                    } catch {
         | 
| 253 | 
            -
                      chunk = `<< Lost chunk of process output for ${exe} - length was ${b.length}>>`;
         | 
| 254 | 
            -
                    }
         | 
| 255 341 |  | 
| 256 | 
            -
             | 
| 257 | 
            -
             | 
| 342 | 
            +
                      subj.next({ source: source, text: chunk });
         | 
| 343 | 
            +
                    };
         | 
| 258 344 |  | 
| 259 345 | 
             
                  const ret = new Subscription();
         | 
| 260 346 |  | 
| 261 347 | 
             
                  if (opts.stdin) {
         | 
| 262 348 | 
             
                    if (proc.stdin) {
         | 
| 263 349 | 
             
                      ret.add(
         | 
| 264 | 
            -
                        opts.stdin.subscribe(
         | 
| 265 | 
            -
                          (x: any) => proc.stdin.write(x),
         | 
| 266 | 
            -
                          subj.error.bind(subj),
         | 
| 267 | 
            -
                          () => proc.stdin.end(),
         | 
| 268 | 
            -
                        ),
         | 
| 350 | 
            +
                        opts.stdin.subscribe({
         | 
| 351 | 
            +
                          next: (x: any) => proc.stdin.write(x),
         | 
| 352 | 
            +
                          error: subj.error.bind(subj),
         | 
| 353 | 
            +
                          complete: () => proc.stdin.end(),
         | 
| 354 | 
            +
                        }),
         | 
| 269 355 | 
             
                      );
         | 
| 270 356 | 
             
                    } else {
         | 
| 271 357 | 
             
                      subj.error(
         | 
| @@ -319,6 +405,7 @@ export function spawn<T = string>( | |
| 319 405 | 
             
                      pipesClosed.subscribe(() => {
         | 
| 320 406 | 
             
                        const e: any = new Error(`Failed with exit code: ${code}`);
         | 
| 321 407 | 
             
                        e.exitCode = code;
         | 
| 408 | 
            +
                        e.code = code;
         | 
| 322 409 |  | 
| 323 410 | 
             
                        subj.error(e);
         | 
| 324 411 | 
             
                      });
         | 
| @@ -349,15 +436,42 @@ export function spawn<T = string>( | |
| 349 436 | 
             
              return opts.split ? spawnObs : spawnObs.pipe(map((x: any) => x?.text));
         | 
| 350 437 | 
             
            }
         | 
| 351 438 |  | 
| 352 | 
            -
            function wrapObservableInPromise | 
| 439 | 
            +
            function wrapObservableInPromise(obs: Observable<string>) {
         | 
| 353 440 | 
             
              return new Promise<string>((res, rej) => {
         | 
| 354 441 | 
             
                let out = "";
         | 
| 355 442 |  | 
| 356 | 
            -
                obs.subscribe(
         | 
| 357 | 
            -
                  (x) => (out += x),
         | 
| 358 | 
            -
                  (e) =>  | 
| 359 | 
            -
             | 
| 360 | 
            -
             | 
| 443 | 
            +
                obs.subscribe({
         | 
| 444 | 
            +
                  next: (x) => (out += x),
         | 
| 445 | 
            +
                  error: (e) => {
         | 
| 446 | 
            +
                    const err: any = new Error(`${out}\n${e.message}`);
         | 
| 447 | 
            +
                    if ("exitCode" in e) {
         | 
| 448 | 
            +
                      err.exitCode = e.exitCode;
         | 
| 449 | 
            +
                      err.code = e.exitCode;
         | 
| 450 | 
            +
                    }
         | 
| 451 | 
            +
                    rej(err);
         | 
| 452 | 
            +
                  },
         | 
| 453 | 
            +
                  complete: () => res(out),
         | 
| 454 | 
            +
                });
         | 
| 455 | 
            +
              });
         | 
| 456 | 
            +
            }
         | 
| 457 | 
            +
             | 
| 458 | 
            +
            function wrapObservableInSplitPromise(obs: Observable<OutputLine>) {
         | 
| 459 | 
            +
              return new Promise<[string, string]>((res, rej) => {
         | 
| 460 | 
            +
                let out = "";
         | 
| 461 | 
            +
                let err = "";
         | 
| 462 | 
            +
             | 
| 463 | 
            +
                obs.subscribe({
         | 
| 464 | 
            +
                  next: (x) => (x.source === "stdout" ? (out += x.text) : (err += x.text)),
         | 
| 465 | 
            +
                  error: (e) => {
         | 
| 466 | 
            +
                    const err: any = new Error(`${out}\n${e.message}`);
         | 
| 467 | 
            +
                    if ("exitCode" in e) {
         | 
| 468 | 
            +
                      err.exitCode = e.exitCode;
         | 
| 469 | 
            +
                      err.code = e.exitCode;
         | 
| 470 | 
            +
                    }
         | 
| 471 | 
            +
                    rej(err);
         | 
| 472 | 
            +
                  },
         | 
| 473 | 
            +
                  complete: () => res([out, err]),
         | 
| 474 | 
            +
                });
         | 
| 361 475 | 
             
              });
         | 
| 362 476 | 
             
            }
         | 
| 363 477 |  | 
| @@ -366,7 +480,47 @@ function wrapObservableInPromise<T>(obs: Observable<T>) { | |
| 366 480 | 
             
             * into its own Process Group.
         | 
| 367 481 | 
             
             *
         | 
| 368 482 | 
             
             * @param  {string} exe               The executable to run
         | 
| 369 | 
            -
             * @param  { | 
| 483 | 
            +
             * @param  {string[]} params     The parameters to pass to the child
         | 
| 484 | 
            +
             * @param  {SpawnOptions & SpawnRxExtras} opts              Options to pass to spawn.
         | 
| 485 | 
            +
             *
         | 
| 486 | 
            +
             * @return {Promise<[string, string]>}       Returns an Promise that represents a detached
         | 
| 487 | 
            +
             *                                 process. The value returned is the process
         | 
| 488 | 
            +
             *                                 output. If the process terminates with a
         | 
| 489 | 
            +
             *                                 non-zero value, the Promise will resolve with
         | 
| 490 | 
            +
             *                                 an Error.
         | 
| 491 | 
            +
             */
         | 
| 492 | 
            +
            export function spawnDetachedPromise(
         | 
| 493 | 
            +
              exe: string,
         | 
| 494 | 
            +
              params: string[],
         | 
| 495 | 
            +
              opts: SpawnOptions & SpawnRxExtras & { split: true },
         | 
| 496 | 
            +
            ): Promise<[string, string]>;
         | 
| 497 | 
            +
             | 
| 498 | 
            +
            /**
         | 
| 499 | 
            +
             * Spawns a process but detached from the current process. The process is put
         | 
| 500 | 
            +
             * into its own Process Group.
         | 
| 501 | 
            +
             *
         | 
| 502 | 
            +
             * @param  {string} exe               The executable to run
         | 
| 503 | 
            +
             * @param  {string[]} params     The parameters to pass to the child
         | 
| 504 | 
            +
             * @param  {SpawnOptions & SpawnRxExtras} opts              Options to pass to spawn.
         | 
| 505 | 
            +
             *
         | 
| 506 | 
            +
             * @return {Promise<string>}       Returns an Promise that represents a detached
         | 
| 507 | 
            +
             *                                 process. The value returned is the process
         | 
| 508 | 
            +
             *                                 output. If the process terminates with a
         | 
| 509 | 
            +
             *                                 non-zero value, the Promise will resolve with
         | 
| 510 | 
            +
             *                                 an Error.
         | 
| 511 | 
            +
             */
         | 
| 512 | 
            +
            export function spawnDetachedPromise(
         | 
| 513 | 
            +
              exe: string,
         | 
| 514 | 
            +
              params: string[],
         | 
| 515 | 
            +
              opts?: SpawnOptions & SpawnRxExtras & { split: false | undefined },
         | 
| 516 | 
            +
            ): Promise<string>;
         | 
| 517 | 
            +
             | 
| 518 | 
            +
            /**
         | 
| 519 | 
            +
             * Spawns a process but detached from the current process. The process is put
         | 
| 520 | 
            +
             * into its own Process Group.
         | 
| 521 | 
            +
             *
         | 
| 522 | 
            +
             * @param  {string} exe               The executable to run
         | 
| 523 | 
            +
             * @param  {string[]} params     The parameters to pass to the child
         | 
| 370 524 | 
             
             * @param  {Object} opts              Options to pass to spawn.
         | 
| 371 525 | 
             
             *
         | 
| 372 526 | 
             
             * @return {Promise<string>}       Returns an Promise that represents a detached
         | 
| @@ -377,17 +531,63 @@ function wrapObservableInPromise<T>(obs: Observable<T>) { | |
| 377 531 | 
             
             */
         | 
| 378 532 | 
             
            export function spawnDetachedPromise(
         | 
| 379 533 | 
             
              exe: string,
         | 
| 380 | 
            -
              params:  | 
| 381 | 
            -
              opts | 
| 382 | 
            -
            ): Promise<string> {
         | 
| 383 | 
            -
               | 
| 534 | 
            +
              params: string[],
         | 
| 535 | 
            +
              opts?: SpawnOptions & SpawnRxExtras,
         | 
| 536 | 
            +
            ): Promise<string> | Promise<[string, string]> {
         | 
| 537 | 
            +
              if (opts?.split) {
         | 
| 538 | 
            +
                return wrapObservableInSplitPromise(
         | 
| 539 | 
            +
                  spawnDetached(exe, params, { ...(opts ?? {}), split: true }),
         | 
| 540 | 
            +
                );
         | 
| 541 | 
            +
              } else {
         | 
| 542 | 
            +
                return wrapObservableInPromise(
         | 
| 543 | 
            +
                  spawnDetached(exe, params, { ...(opts ?? {}), split: false }),
         | 
| 544 | 
            +
                );
         | 
| 545 | 
            +
              }
         | 
| 384 546 | 
             
            }
         | 
| 385 547 |  | 
| 386 548 | 
             
            /**
         | 
| 387 549 | 
             
             * Spawns a process as a child process.
         | 
| 388 550 | 
             
             *
         | 
| 389 551 | 
             
             * @param  {string} exe               The executable to run
         | 
| 390 | 
            -
             * @param  { | 
| 552 | 
            +
             * @param  {string[]} params     The parameters to pass to the child
         | 
| 553 | 
            +
             * @param  {SpawnOptions & SpawnRxExtras} opts              Options to pass to spawn.
         | 
| 554 | 
            +
             *
         | 
| 555 | 
            +
             * @return {Promise<[string, string]>}       Returns an Promise that represents a child
         | 
| 556 | 
            +
             *                                 process. The value returned is the process
         | 
| 557 | 
            +
             *                                 output. If the process terminates with a
         | 
| 558 | 
            +
             *                                 non-zero value, the Promise will resolve with
         | 
| 559 | 
            +
             *                                 an Error.
         | 
| 560 | 
            +
             */
         | 
| 561 | 
            +
            export function spawnPromise(
         | 
| 562 | 
            +
              exe: string,
         | 
| 563 | 
            +
              params: string[],
         | 
| 564 | 
            +
              opts: SpawnOptions & SpawnRxExtras & { split: true },
         | 
| 565 | 
            +
            ): Promise<[string, string]>;
         | 
| 566 | 
            +
             | 
| 567 | 
            +
            /**
         | 
| 568 | 
            +
             * Spawns a process as a child process.
         | 
| 569 | 
            +
             *
         | 
| 570 | 
            +
             * @param  {string} exe               The executable to run
         | 
| 571 | 
            +
             * @param  {string[]} params     The parameters to pass to the child
         | 
| 572 | 
            +
             * @param  {SpawnOptions & SpawnRxExtras} opts              Options to pass to spawn.
         | 
| 573 | 
            +
             *
         | 
| 574 | 
            +
             * @return {Promise<string>}       Returns an Promise that represents a child
         | 
| 575 | 
            +
             *                                 process. The value returned is the process
         | 
| 576 | 
            +
             *                                 output. If the process terminates with a
         | 
| 577 | 
            +
             *                                 non-zero value, the Promise will resolve with
         | 
| 578 | 
            +
             *                                 an Error.
         | 
| 579 | 
            +
             */
         | 
| 580 | 
            +
            export function spawnPromise(
         | 
| 581 | 
            +
              exe: string,
         | 
| 582 | 
            +
              params: string[],
         | 
| 583 | 
            +
              opts?: SpawnOptions & SpawnRxExtras,
         | 
| 584 | 
            +
            ): Promise<string>;
         | 
| 585 | 
            +
             | 
| 586 | 
            +
            /**
         | 
| 587 | 
            +
             * Spawns a process as a child process.
         | 
| 588 | 
            +
             *
         | 
| 589 | 
            +
             * @param  {string} exe               The executable to run
         | 
| 590 | 
            +
             * @param  {string[]} params     The parameters to pass to the child
         | 
| 391 591 | 
             
             * @param  {Object} opts              Options to pass to spawn.
         | 
| 392 592 | 
             
             *
         | 
| 393 593 | 
             
             * @return {Promise<string>}       Returns an Promise that represents a child
         | 
| @@ -398,8 +598,16 @@ export function spawnDetachedPromise( | |
| 398 598 | 
             
             */
         | 
| 399 599 | 
             
            export function spawnPromise(
         | 
| 400 600 | 
             
              exe: string,
         | 
| 401 | 
            -
              params:  | 
| 402 | 
            -
              opts | 
| 403 | 
            -
            ): Promise<string> {
         | 
| 404 | 
            -
               | 
| 601 | 
            +
              params: string[],
         | 
| 602 | 
            +
              opts?: SpawnOptions & SpawnRxExtras,
         | 
| 603 | 
            +
            ): Promise<string> | Promise<[string, string]> {
         | 
| 604 | 
            +
              if (opts?.split) {
         | 
| 605 | 
            +
                return wrapObservableInSplitPromise(
         | 
| 606 | 
            +
                  spawn(exe, params, { ...(opts ?? {}), split: true }),
         | 
| 607 | 
            +
                );
         | 
| 608 | 
            +
              } else {
         | 
| 609 | 
            +
                return wrapObservableInPromise(
         | 
| 610 | 
            +
                  spawn(exe, params, { ...(opts ?? {}), split: false }),
         | 
| 611 | 
            +
                );
         | 
| 612 | 
            +
              }
         | 
| 405 613 | 
             
            }
         | 
    
        package/test/spawn.ts
    CHANGED
    
    | @@ -18,6 +18,32 @@ describe("The spawnPromise method", function () { | |
| 18 18 | 
             
                const result = await spawnPromise("uuid", []);
         | 
| 19 19 | 
             
                expect(result.match(uuidRegex)).to.be.ok;
         | 
| 20 20 | 
             
              });
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              it("should split stdout and stderr when we call uuid", async function () {
         | 
| 23 | 
            +
                // NB: Since we get run via npm run test, we know that npm bins are in our
         | 
| 24 | 
            +
                // PATH.
         | 
| 25 | 
            +
                const result = await spawnPromise("uuid", [], { split: true });
         | 
| 26 | 
            +
                expect(result[0].match(uuidRegex)).to.be.ok;
         | 
| 27 | 
            +
                expect(result[1].match(uuidRegex)).to.not.be.ok;
         | 
| 28 | 
            +
              });
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              it("should retur nthe exit code", async function () {
         | 
| 31 | 
            +
                // NB: Since we get run via npm run test, we know that npm bins are in our
         | 
| 32 | 
            +
                // PATH.
         | 
| 33 | 
            +
                try {
         | 
| 34 | 
            +
                  await spawnPromise("false", [], { split: true });
         | 
| 35 | 
            +
                  expect(false).to.be.true;
         | 
| 36 | 
            +
                } catch (e) {
         | 
| 37 | 
            +
                  expect(e.code).to.be.equal(1);
         | 
| 38 | 
            +
                }
         | 
| 39 | 
            +
              });
         | 
| 40 | 
            +
             | 
| 41 | 
            +
              it("should not stdout and stderr when we call uuid with split false", async function () {
         | 
| 42 | 
            +
                // NB: Since we get run via npm run test, we know that npm bins are in our
         | 
| 43 | 
            +
                // PATH.
         | 
| 44 | 
            +
                const result = await spawnPromise("uuid", [], { split: false });
         | 
| 45 | 
            +
                expect(result.match(uuidRegex)).to.be.ok;
         | 
| 46 | 
            +
              });
         | 
| 21 47 | 
             
            });
         | 
| 22 48 |  | 
| 23 49 | 
             
            describe("The spawnDetachedPromise method", function () {
         |