Skip to content

Commit 5b4ebdb

Browse files
committed
feat: let shell be false
1 parent 50ab896 commit 5b4ebdb

File tree

6 files changed

+20
-6
lines changed

6 files changed

+20
-6
lines changed

src/main/ts/spawn.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export interface TSpawnCtxNormalized {
6464
on: Partial<TSpawnListeners>
6565
ac: AbortController
6666
signal: AbortController['signal']
67-
shell: string | true | undefined
67+
shell: string | boolean | undefined
6868
spawn: typeof cp.spawn
6969
spawnSync: typeof cp.spawnSync
7070
spawnOpts: Record<string, any>

src/main/ts/x.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ export const $: TShell = function(this: any, pieces?: any, ...args: any): any {
101101
}
102102

103103
const ignite = (preset: any, pieces: TemplateStringsArray, ...args: any[]) => {
104-
const cmd = buildCmd(preset.quote || quote, pieces as TemplateStringsArray, args)
104+
const _quote = preset.quote || (preset.shell === false ? (arg: string) => arg : quote)
105+
const cmd = buildCmd(_quote, pieces as TemplateStringsArray, args)
105106
const input = parseInput(preset.input)
106107
const run = cmd instanceof Promise
107108
? (cb: TVoidCallback, ctx: TShellCtx) => cmd.then((cmd) => { ctx.cmd = cmd; cb() })

src/test/ts/x.test.ts

+11
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ describe('$()', () => {
2828
console.error(error)
2929
assert.ok((error as Error).message.includes('exit code: 2 (Misuse of shell builtins)'))
3030
}
31+
32+
const err = await $`exit 2`.catch((error) => error)
33+
assert.ok(err.message.includes('exit code: 2 (Misuse of shell builtins)'))
3134
})
3235

3336
it('supports sync flow', () => {
@@ -74,6 +77,14 @@ describe('$()', () => {
7477
$({stdio: 'ignore', sync: true})`ls`
7578
})
7679

80+
it('works without shell', async () => {
81+
const o1 = await $({shell: true})`exit 2 | exit 0`
82+
const o2 = await $({shell: false, nothrow: true})`exit 1 | exit 0`
83+
84+
assert.equal(o1.status, 0)
85+
assert.equal(o2.status, -2)
86+
})
87+
7788
it('supports presets', () => {
7889
const $$ = $({sync: true, cmd: 'echo foo'})
7990
const $$$ = $$({cmd: 'echo bar'})

target/cjs/index.cjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ var $ = function(pieces, ...args) {
141141
return (...args2) => $.apply(self ? (0, import_util4.assign)(self, pieces) : pieces, args2);
142142
};
143143
var ignite = (preset, pieces, ...args) => {
144-
const cmd = (0, import_util4.buildCmd)(preset.quote || import_util4.quote, pieces, args);
144+
const _quote = preset.quote || (preset.shell === false ? (arg) => arg : import_util4.quote);
145+
const cmd = (0, import_util4.buildCmd)(_quote, pieces, args);
145146
const input = (0, import_util4.parseInput)(preset.input);
146147
const run = cmd instanceof Promise ? (cb, ctx) => cmd.then((cmd2) => {
147148
ctx.cmd = cmd2;

target/dts/spawn.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export interface TSpawnCtxNormalized {
5656
on: Partial<TSpawnListeners>;
5757
ac: AbortController;
5858
signal: AbortController['signal'];
59-
shell: string | true | undefined;
59+
shell: string | boolean | undefined;
6060
spawn: typeof cp.spawn;
6161
spawnSync: typeof cp.spawnSync;
6262
spawnOpts: Record<string, any>;
@@ -81,7 +81,7 @@ export declare const buildSpawnOpts: ({ spawnOpts, stdio, cwd, shell, input, env
8181
env: Record<string, string | undefined>;
8282
cwd: string;
8383
stdio: cp.StdioOptions;
84-
shell: string | true | undefined;
84+
shell: string | boolean | undefined;
8585
input: string | Buffer;
8686
windowsHide: boolean;
8787
detached: boolean;

target/esm/index.mjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ var $ = function(pieces, ...args) {
136136
return (...args2) => $.apply(self ? assign4(self, pieces) : pieces, args2);
137137
};
138138
var ignite = (preset, pieces, ...args) => {
139-
const cmd = buildCmd(preset.quote || quote, pieces, args);
139+
const _quote = preset.quote || (preset.shell === false ? (arg) => arg : quote);
140+
const cmd = buildCmd(_quote, pieces, args);
140141
const input = parseInput(preset.input);
141142
const run = cmd instanceof Promise ? (cb, ctx) => cmd.then((cmd2) => {
142143
ctx.cmd = cmd2;

0 commit comments

Comments
 (0)