make sure to shell escape the arguments for the preset tasks

This commit is contained in:
Ken 2018-12-17 15:16:54 -08:00
Родитель 598313fd77
Коммит d58d5321de
4 изменённых файлов: 23 добавлений и 9 удалений

Просмотреть файл

@ -15,6 +15,19 @@ export function exec(cmd: string, opts: ExecOptions & { stdout?: NodeJS.Writable
});
}
// Taken from https://github.com/xxorax/node-shell-escape/blob/master/shell-escape.js
// However, we needed to use double quotes because that's the norm in more platforms
export function encodeArgs(cmdArgs: string[]) {
return cmdArgs.map(arg => {
if (/[^A-Za-z0-9_\/:=-]/.test(arg)) {
arg = '"' + arg.replace(/"/g, '"\\"') + '"';
arg = arg.replace(/^(?:"")+/g, '').replace(/\\"""/g, '\\"');
}
return arg;
});
}
export function spawn(
cmd: string,
args: ReadonlyArray<string> = [],

Просмотреть файл

@ -1,5 +1,5 @@
import { resolve, logger, resolveCwd } from 'just-task';
import { exec } from './exec';
import { exec, encodeArgs } from './exec';
import { fstat, existsSync } from 'fs';
export interface IJestTaskOptions {
@ -18,7 +18,7 @@ export function jestTask(options: IJestTaskOptions = {}) {
const jestCmd = resolve('jest/bin/jest.js');
const configFile = options.config || jestConfigFile;
if (configFile && existsSync(configFile)) {
if (configFile && jestCmd && existsSync(configFile)) {
logger.info(`Running Jest`);
const args = [
`--config ${configFile}`,
@ -32,7 +32,7 @@ export function jestTask(options: IJestTaskOptions = {}) {
.filter(arg => !!arg)
.join(' ');
const cmd = [process.execPath, jestCmd, args].join(' ');
const cmd = encodeArgs([process.execPath, jestCmd, args]).join(' ');
logger.info(cmd);
return exec(cmd, { stdout: process.stdout, stderr: process.stderr });
} else {

Просмотреть файл

@ -1,6 +1,6 @@
import * as ts from 'typescript';
import { resolve, logger, resolveCwd } from 'just-task';
import { exec } from './exec';
import { exec, encodeArgs } from './exec';
import path from 'path';
import fs from 'fs';
@ -35,7 +35,7 @@ export function tscTask(options: CompilerOptions) {
[tscCmd]
);
const cmd = [process.execPath, ...args].join(' ');
const cmd = encodeArgs([process.execPath, ...args]).join(' ');
logger.info(`Executing: ${cmd}`);
return exec(cmd);
} else {

Просмотреть файл

@ -1,5 +1,5 @@
import { resolve, logger, resolveCwd } from 'just-task';
import { exec } from './exec';
import { exec, encodeArgs } from './exec';
import path from 'path';
import fs from 'fs';
@ -11,13 +11,14 @@ export function tslintTask(options: ITsLintTaskOptions = {}) {
const projectFile = resolveCwd('./tsconfig.json');
return function tslint() {
if (projectFile && fs.existsSync(projectFile)) {
const tslintCmd = resolve('tslint/lib/tslintCli.js');
if (projectFile && tslintCmd && fs.existsSync(projectFile)) {
logger.info(`Running tslint`);
const tslintCmd = resolve('tslint/lib/tslintCli.js');
const args = ['--project', projectFile, '-t', 'stylish', '-r', path.dirname(resolve('tslint-microsoft-contrib') || '')];
const cmd = [process.execPath, tslintCmd, ...args].join(' ');
const cmd = encodeArgs([process.execPath, tslintCmd, ...args]).join(' ');
logger.info(cmd);
return exec(cmd, { stdout: process.stdout, stderr: process.stderr });
} else {