snyk-php-plugin
Version:
Snyk CLI PHP plugin
56 lines • 1.9 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.localComposer = exports.globalComposer = void 0;
exports.cmdReturnsOk = cmdReturnsOk;
exports.execWithResult = execWithResult;
const path = require("path");
const childProcess = require("child_process");
function versionCmd() {
return {
command: this.command,
args: [...this.args, '--version'],
};
}
function listPlatformDepsCmd() {
return {
command: this.command,
args: [...this.args, 'show', '-p', '--format=json'],
};
}
exports.globalComposer = {
command: 'composer',
args: [],
version: versionCmd,
listPlatformDeps: listPlatformDepsCmd,
};
exports.localComposer = {
command: 'php',
args: [`${path.resolve(path.resolve() + '/composer.phar')}`],
version: versionCmd,
listPlatformDeps: listPlatformDepsCmd,
};
function cleanUpComposerWarnings(composerOutput) {
// Remove all lines preceding the JSON data; including "Deprecated" messages and blank lines.
const lines = composerOutput.split('\n');
const jsonStartIndex = lines.findIndex((line) => line.startsWith('{'));
return lines.slice(jsonStartIndex).join('\n');
}
function cmdReturnsOk(cmd) {
const spawnOptions = { shell: false };
return (!!cmd &&
childProcess.spawnSync(cmd.command, cmd.args, spawnOptions).status === 0);
}
// run a cmd in a specific folder and it's result should be there
function execWithResult(cmd, basePath) {
const spawnOptions = {
cwd: basePath,
shell: false,
};
const execResult = childProcess.spawnSync(cmd.command, cmd.args, spawnOptions);
// Throw the whole Result object in case of error, similarly to `execSync`.
if (execResult.status !== 0) {
throw execResult;
}
return cleanUpComposerWarnings(execResult.stdout.toString());
}
//# sourceMappingURL=composer-cmds.js.map
;