Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: let shell be false #32

Merged
merged 1 commit into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/ts/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export interface TSpawnCtxNormalized {
on: Partial<TSpawnListeners>
ac: AbortController
signal: AbortController['signal']
shell: string | true | undefined
shell: string | boolean | undefined
spawn: typeof cp.spawn
spawnSync: typeof cp.spawnSync
spawnOpts: Record<string, any>
Expand Down
3 changes: 2 additions & 1 deletion src/main/ts/x.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ export const $: TShell = function(this: any, pieces?: any, ...args: any): any {
}

const ignite = (preset: any, pieces: TemplateStringsArray, ...args: any[]) => {
const cmd = buildCmd(preset.quote || quote, pieces as TemplateStringsArray, args)
const _quote = preset.quote || (preset.shell === false ? (arg: string) => arg : quote)
const cmd = buildCmd(_quote, pieces as TemplateStringsArray, args)
const input = parseInput(preset.input)
const run = cmd instanceof Promise
? (cb: TVoidCallback, ctx: TShellCtx) => cmd.then((cmd) => { ctx.cmd = cmd; cb() })
Expand Down
11 changes: 11 additions & 0 deletions src/test/ts/x.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ describe('$()', () => {
console.error(error)
assert.ok((error as Error).message.includes('exit code: 2 (Misuse of shell builtins)'))
}

const err = await $`exit 2`.catch((error) => error)
assert.ok(err.message.includes('exit code: 2 (Misuse of shell builtins)'))
})

it('supports sync flow', () => {
Expand Down Expand Up @@ -74,6 +77,14 @@ describe('$()', () => {
$({stdio: 'ignore', sync: true})`ls`
})

it('works without shell', async () => {
const o1 = await $({shell: true})`exit 2 | exit 0`
const o2 = await $({shell: false, nothrow: true})`exit 1 | exit 0`

assert.equal(o1.status, 0)
assert.equal(o2.status, -2)
})

it('supports presets', () => {
const $$ = $({sync: true, cmd: 'echo foo'})
const $$$ = $$({cmd: 'echo bar'})
Expand Down
3 changes: 2 additions & 1 deletion target/cjs/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ var $ = function(pieces, ...args) {
return (...args2) => $.apply(self ? (0, import_util4.assign)(self, pieces) : pieces, args2);
};
var ignite = (preset, pieces, ...args) => {
const cmd = (0, import_util4.buildCmd)(preset.quote || import_util4.quote, pieces, args);
const _quote = preset.quote || (preset.shell === false ? (arg) => arg : import_util4.quote);
const cmd = (0, import_util4.buildCmd)(_quote, pieces, args);
const input = (0, import_util4.parseInput)(preset.input);
const run = cmd instanceof Promise ? (cb, ctx) => cmd.then((cmd2) => {
ctx.cmd = cmd2;
Expand Down
4 changes: 2 additions & 2 deletions target/dts/spawn.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export interface TSpawnCtxNormalized {
on: Partial<TSpawnListeners>;
ac: AbortController;
signal: AbortController['signal'];
shell: string | true | undefined;
shell: string | boolean | undefined;
spawn: typeof cp.spawn;
spawnSync: typeof cp.spawnSync;
spawnOpts: Record<string, any>;
Expand All @@ -81,7 +81,7 @@ export declare const buildSpawnOpts: ({ spawnOpts, stdio, cwd, shell, input, env
env: Record<string, string | undefined>;
cwd: string;
stdio: cp.StdioOptions;
shell: string | true | undefined;
shell: string | boolean | undefined;
input: string | Buffer;
windowsHide: boolean;
detached: boolean;
Expand Down
3 changes: 2 additions & 1 deletion target/esm/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ var $ = function(pieces, ...args) {
return (...args2) => $.apply(self ? assign4(self, pieces) : pieces, args2);
};
var ignite = (preset, pieces, ...args) => {
const cmd = buildCmd(preset.quote || quote, pieces, args);
const _quote = preset.quote || (preset.shell === false ? (arg) => arg : quote);
const cmd = buildCmd(_quote, pieces, args);
const input = parseInput(preset.input);
const run = cmd instanceof Promise ? (cb, ctx) => cmd.then((cmd2) => {
ctx.cmd = cmd2;
Expand Down
Loading