Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function parse(a: string): string {
if (a.startsWith('"')) {
a = a.replace(/\\n/g, '\n')
} else if (a.startsWith("'")) {
a = a.replace(/\\\\/g, '\\')
}
let parsed = shell.parse(a)
if (parsed.length > 1) throw new Error(`Invalid token: ${a}`)
return parsed[0]
// return parsed[0].replace(/\\\\n/g, '\n')
}
Runner.prototype.execFn = function(cmd) {
var self = this;
var args = require('shell-quote').parse(cmd);
var bin = args.shift(0);
return function(fn) {
// Allow .run('') without attempting
if (cmd === '') { fn(undefined); return; }
var child = spawn(bin, args, self.world);
var stdout = '';
var stderr = '';
var err;
if (self.standardInput != null) {
child.stdin.end(self.standardInput);
}
if (self.world.timeout) {
.map(input => {
try {
return evalChain(data, parseArgs(parse(input)));
} catch(e) { /* */ }
});
function guessEditor() {
// Explicit config always wins
if (process.env.REACT_EDITOR) {
return shellQuote.parse(process.env.REACT_EDITOR);
}
// We can find out which editor is currently running by:
// `ps x` on macOS and Linux
// `Get-Process` on Windows
try {
if (process.platform === 'darwin') {
const output = child_process.execSync('ps x').toString();
const processNames = Object.keys(COMMON_EDITORS_OSX);
for (let i = 0; i < processNames.length; i++) {
const processName = processNames[i];
if (output.indexOf(processName) !== -1) {
return [COMMON_EDITORS_OSX[processName]];
}
}
} else if (process.platform === 'win32') {
return patterns.map(pattern => pattern.replace(ARGS_PATTERN, (whole, indirectionMark, id, options) => {
if (indirectionMark != null) {
throw Error(`Invalid Placeholder: ${whole}`)
}
if (id === "@") {
return shellQuote.quote(args)
}
if (id === "*") {
return shellQuote.quote([args.join(" ")])
}
const position = parseInt(id, 10)
if (position >= 1 && position <= args.length) {
return shellQuote.quote([args[position - 1]])
}
// Address default values
if (options != null) {
const prefix = options.slice(0, 2)
if (prefix === ":=") {
defaults[id] = shellQuote.quote([options.slice(2)])
async function exec (cmd, args = [], opts = {}) {
// get a quoted representation of the command for error strings
const rep = quote([cmd, ...args]);
// extend default options; we're basically re-implementing exec's options
// for use here with spawn under the hood
opts = Object.assign({
timeout: null,
encoding: 'utf8',
killSignal: 'SIGTERM',
cwd: undefined,
env: process.env,
ignoreOutput: false,
stdio: 'inherit',
isBuffer: false,
shell: undefined,
logger: undefined,
maxStdoutBufferSize: MAX_BUFFER_SIZE,
maxStderrBufferSize: MAX_BUFFER_SIZE,
.forEach(function (c) {
var cmd = parseShell(c);
b.transform(function (file) {
var env = Object.keys(process.env).reduce(function (acc, key) {
acc[key] = process.env[key];
return acc;
}, {});
env.FILENAME = file;
var ps = spawn(cmd[0], cmd.slice(1), { env: env });
var error = '';
ps.stderr.on('data', function (buf) { error += buf });
ps.on('exit', function (code) {
if (code === 0) return;
console.error([
'error running source transform command: ' + c,
error.split('\n').join('\n '),
''
tag({ name = this.options.tagName, annotation = this.options.tagAnnotation, args = this.options.tagArgs } = {}) {
const quotedMessage = quote([format(annotation, this.getContext())]);
return this.exec(`git tag --annotate --message=${quotedMessage} ${args || ''} ${name}`)
.then(() => this.setContext({ isTagged: true }))
.catch(err => {
const { latestTagName, tagName } = this.getContext();
if (/tag '.+' already exists/.test(err) && latestTagName === tagName) {
this.log.warn(`Tag "${tagName}" already exists`);
} else {
throw err;
}
});
}
function expandVariable(variable: string | undefined): string[] {
if (variable) {
outputChannel.appendLine("Using JAVA options set in JAVA_OPTS");
return parse(variable).filter(
(entry): entry is string => {
if (typeof entry === "string") {
return true;
} else {
outputChannel.appendLine(
`Ignoring unexpected JAVA_OPTS token: ${entry}`
);
return false;
}
}
);
} else {
return [];
}
}
const javaOpts = expandVariable(process.env.JAVA_OPTS);
async $invoke(_expression, {owner} = {}) {
const expressions = this.$expressions || [];
let result;
for (let expression of expressions) {
const args = parse(expression, variable => '$' + variable);
expression = parseCommandLineArguments(args);
result = await this._invokeExpression(expression, {owner});
}
return result;
}