Files
bun.sh/test/js/bun/shell/util.ts
Zack Radisic 2605722891 shell: Allow duplicating output fds (e.g. 2>&1) (#9004)
* Open with proper perms when redirecting file to stdin

* Add test for redirecting file to stdin

* Extract redirect flags -> bun.Mode logic to function

* Remove dead code

* Support duplicating output file descriptors

* Clean up

* fix merge fuck up

* Add comment documenting weird hack to get around ordering of posix spawn actions

* Update docs

* Delete dead code

* Update docs
2024-02-21 18:45:44 -08:00

41 lines
1.1 KiB
TypeScript

import { describe, test, afterAll, beforeAll, expect } from "bun:test";
import { ShellOutput } from "bun";
import { ShellPromise } from "bun";
import { tempDirWithFiles } from "harness";
import { join } from "node:path";
import * as fs from "node:fs";
import { TestBuilder } from "./test_builder";
export { TestBuilder };
declare module "bun" {
// Define the additional methods
interface Shell {
parse: (strings: TemplateStringsArray, ...expressions: any[]) => string; // Define the return type for parse
lex: (strings: TemplateStringsArray, ...expressions: any[]) => string; // Define the return type for lex
}
}
const defaultRedirect = {
__unused: 0,
append: false,
stderr: false,
stdin: false,
stdout: false,
duplicate_out: false,
};
export const redirect = (opts?: Partial<typeof defaultRedirect>): typeof defaultRedirect =>
opts === undefined
? defaultRedirect
: {
...defaultRedirect,
...opts,
};
export const sortedShellOutput = (output: string): string[] =>
output
.split("\n")
.filter(s => s.length > 0)
.sort();