Skip to content

Commit 9ec1788

Browse files
committed
refactor: switch to using shell.cmd()
This swaps the internal implementation to use the new shell.cmd() API. This avoids the need for wrapping with double quotes which should also mean better compatibility on Windows.
1 parent a26f8a5 commit 9ec1788

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

index.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,20 @@ const proxyifyCmd = (t, ...cmdStart) => {
99
newArgs.push(cmdStart[0]);
1010

1111
// Wrap all subsequent arguments in quotes
12-
newArgs = newArgs.concat(cmdStart.slice(1)
13-
.concat(args)
14-
.map((x) => JSON.stringify(x)));
15-
// Run this command in the shell
16-
return origShell.exec.call(this.stdout, newArgs.join(' '));
12+
newArgs = newArgs
13+
.concat(cmdStart.slice(1))
14+
.concat(args);
15+
// Run this command in the shell with globbing temporarily disabled.
16+
// 'noglob' is part of ShellJS internals, but hopefully this will stay
17+
// around. We cannot achieve the same with `set('-f')` because we need to
18+
// know the previous state in order to reset globbing back the way it was.
19+
const oldGlob = origShell.config.noglob;
20+
try {
21+
origShell.config.noglob = true;
22+
return origShell.cmd.call(this.stdout, newArgs);
23+
} finally {
24+
origShell.config.noglob = oldGlob;
25+
}
1726
};
1827
// Store the list of commands, in case we have a subcommand chain
1928
t[cmdArrayAttr] = cmdStart;

test/test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,26 @@ describe('proxy', function describeproxy() {
289289
done();
290290
});
291291

292+
it('other shelljs commands can still glob', (done) => {
293+
const fa = 'a.txt';
294+
const fglob = '*.txt';
295+
shell.exec('echo hello world').to(fa);
296+
shell.exec('echo hello world').to(fglob);
297+
298+
if (unix()) {
299+
shell.__native.rm(fglob);
300+
} else {
301+
shell.del(fglob);
302+
}
303+
fs.existsSync(fglob).should.equal(false);
304+
fs.existsSync(fa).should.equal(true);
305+
306+
shell.rm('*.txt');
307+
fs.existsSync(fglob).should.equal(false);
308+
fs.existsSync(fa).should.equal(false);
309+
done();
310+
});
311+
292312
it('escapes quotes', (done) => {
293313
if (!unix()) {
294314
// Windows doesn't support `"` as a character in a filename, see

0 commit comments

Comments
 (0)