Skip to content
Myr

Allow `shell` option to be a file URL (#635)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by GitHub · parent 640ae39 · Browse files · 6 files+18 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+18 added−10 removed

  • tests:+8 added−3 removed
  • other:+10 added−7 removed

6 files+18 added−10 removed

modified:test/test.js+8 added-3 removed
2 unmodified lines
3import {fileURLToPath, pathToFileURL} from 'node:url';4import test from 'ava';5import isRunning from 'is-running';6import getNode from 'get-node';7import which from 'which';8import {execa, execaSync, execaNode, $} from '../index.js';9import {setFixtureDir, PATH_KEY, FIXTURES_DIR_URL} from './helpers/fixtures-dir.js';1011setFixtureDir();
233 unmodified lines
245 const {stdout} = await execa('node test/fixtures/noop.js foo', {shell: true});246 t.is(stdout, 'foo');247});248248test('can use `options.shell: string`', async t => {249 const shell = process.platform === 'win32' ? 'cmd.exe' : '/bin/bash';249const testShellPath = async (t, mapPath) => {250 const shellPath = process.platform === 'win32' ? 'cmd.exe' : 'bash';251 const shell = mapPath(await which(shellPath));252 const {stdout} = await execa('node test/fixtures/noop.js foo', {shell});253 t.is(stdout, 'foo');252});254};255256test('can use `options.shell: string`', testShellPath, identity);257test('can use `options.shell: file URL`', testShellPath, pathToFileURL);258259test('use extend environment with `extendEnv: true` and `shell: true`', async t => {260 process.env.TEST = 'test';261 const command = process.platform === 'win32' ? 'echo %TEST%' : 'echo $TEST';262 const {stdout} = await execa(command, {shell: true, env: {}, extendEnv: true});
43 unmodified lines
modified:index.d.ts+1 added-1 removed
254 unmodified lines
255 - unsafe, potentially allowing command injection.256257 @default false258 */259 readonly shell?: boolean | string;259 readonly shell?: boolean | string | URL;260261 /**262 Specify the character encoding used to decode the `stdout` and `stderr` output. If set to `'buffer'`, then `stdout` and `stderr` will be a `Uint8Array` instead of a string.263
806 unmodified lines
modified:index.js+6 added-5 removed
28 unmodified lines
2930 return env;31};3233const normalizeFileUrl = file => file instanceof URL ? fileURLToPath(file) : file;3435const getFilePath = file => {34 if (file instanceof URL) {35 return fileURLToPath(file);36 }36 const fileString = normalizeFileUrl(file);3738 if (typeof file !== 'string') {38 if (typeof fileString !== 'string') {39 throw new TypeError('First argument must be a string or a file URL.');40 }4142 return file;42 return fileString;43};4445const handleArguments = (file, args, options = {}) => {46 const parsed = crossSpawn._parse(file, args, options);
15 unmodified lines
62 all: false,63 windowsHide: true,64 verbose: verboseDefault,65 ...options,66 shell: normalizeFileUrl(options.shell),67 };6869 options.env = getEnv(options);70
263 unmodified lines
modified:index.test-d.ts+1 added
262 unmodified lines
263execa('unicorns', {uid: 0});264execa('unicorns', {gid: 0});265execa('unicorns', {shell: true});266execa('unicorns', {shell: '/bin/sh'});267execa('unicorns', {shell: fileUrl});268execa('unicorns', {timeout: 1000});269execa('unicorns', {maxBuffer: 1000});270execa('unicorns', {killSignal: 'SIGTERM'});271execa('unicorns', {killSignal: 9});
139 unmodified lines
modified:package.json+1 added
modified:readme.md+1 added-1 removed
716 unmodified lines
717Sets the group identity of the process.718719#### shell720721Type: `boolean | string`\721Type: `boolean | string | URL`\722Default: `false`723724If `true`, runs `file` inside of a shell. Uses `/bin/sh` on UNIX and `cmd.exe` on Windows. A different shell can be specified as a string. The shell should understand the `-c` switch on UNIX or `/d /s /c` on Windows.725
136 unmodified lines