-
-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
1,511 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {aborted} from 'node:util'; | ||
import {createNonCommandError} from './validate.js'; | ||
|
||
export const unpipeOnAbort = (signal, ...args) => signal === undefined | ||
? [] | ||
: [unpipeOnSignalAbort(signal, ...args)]; | ||
|
||
const unpipeOnSignalAbort = async (signal, sourceStream, mergedStream, {stdioStreamsGroups, options}) => { | ||
await aborted(signal, sourceStream); | ||
await mergedStream.remove(sourceStream); | ||
const error = new Error('Pipe cancelled by `signal` option.'); | ||
throw createNonCommandError({error, stdioStreamsGroups, options}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Like Bash, we await both processes. This is unlike some other shells which only await the destination process. | ||
// Like Bash with the `pipefail` option, if either process fails, the whole pipe fails. | ||
// Like Bash, if both processes fail, we return the failure of the destination. | ||
// This ensures both processes' errors are present, using `error.pipedFrom`. | ||
export const waitForBothProcesses = async (source, destination) => { | ||
const [ | ||
{status: sourceStatus, reason: sourceReason, value: sourceResult = sourceReason}, | ||
{status: destinationStatus, reason: destinationReason, value: destinationResult = destinationReason}, | ||
] = await Promise.allSettled([source, destination]); | ||
|
||
if (!destinationResult.pipedFrom.includes(sourceResult)) { | ||
destinationResult.pipedFrom.push(sourceResult); | ||
} | ||
|
||
if (destinationStatus === 'rejected') { | ||
throw destinationResult; | ||
} | ||
|
||
if (sourceStatus === 'rejected') { | ||
throw sourceResult; | ||
} | ||
|
||
return destinationResult; | ||
}; |
Oops, something went wrong.