Skip to content

Commit

Permalink
Restrict script-shell to yarn run
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunyu Lin committed Dec 28, 2017
1 parent 790c4ae commit 8e19ab6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/cli/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg
for (const [stage, cmd] of cmds) {
// only tack on trailing arguments for default script, ignore for pre and post - #1595
const cmdWithArgs = stage === action ? sh`${unquoted(cmd)} ${args}` : cmd;
await execCommand(stage, config, cmdWithArgs, config.cwd);
const customShell = config.getOption('script-shell');
await execCommand(stage, config, cmdWithArgs, config.cwd, customShell ? String(customShell) : undefined);
}
} else if (action === 'env') {
reporter.log(JSON.stringify(await makeEnv('env', config.cwd, config), null, 2), {force: true});
Expand Down
12 changes: 9 additions & 3 deletions src/util/execute-lifecycle-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export async function executeLifecycleScript(
cwd: string,
cmd: string,
spinner?: ReporterSpinner,
customShell?: string,
): LifecycleReturn {
// if we don't have a spinner then pipe everything to the terminal
const stdio = spinner ? undefined : 'inherit';
Expand All @@ -183,7 +184,6 @@ export async function executeLifecycleScript(
let sh = 'sh';
let shFlag = '-c';

const customShell = config.getOption('script-shell');
let windowsVerbatimArguments = undefined;

if (customShell) {
Expand Down Expand Up @@ -271,11 +271,17 @@ export async function execFromManifest(config: Config, commandName: string, cwd:
}
}

export async function execCommand(stage: string, config: Config, cmd: string, cwd: string): Promise<void> {
export async function execCommand(
stage: string,
config: Config,
cmd: string,
cwd: string,
customShell?: string,
): Promise<void> {
const {reporter} = config;
try {
reporter.command(cmd);
await executeLifecycleScript(stage, config, cwd, cmd);
await executeLifecycleScript(stage, config, cwd, cmd, undefined, customShell);
return Promise.resolve();
} catch (err) {
if (err instanceof ProcessTermError) {
Expand Down

0 comments on commit 8e19ab6

Please sign in to comment.