Skip to content

Commit 9189f09

Browse files
committed
feat: pass command and args into spawn separately
1 parent 0d64ae5 commit 9189f09

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

lib/composer-cmds.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import * as path from 'path';
22
import * as childProcess from 'child_process';
3+
export const composerCmd = {command: 'composer', args: ['--version']};
4+
export const composerShowCmd = {command: 'composer', args: ['show', '-p']};
5+
export const pharCmd = {command: `php`, args:[`${path.resolve(path.resolve() + '/composer.phar')}`, 'show', '-p', '--format=json']
6+
};
37

4-
export const composerCmd = 'composer --version';
5-
export const composerShowCmd = 'composer show -p';
6-
export const pharCmd = `php ${path.resolve(path.resolve() + '/composer.phar')} show -p --format=json`;
7-
8-
export function cmdReturnsOk(cmd): boolean {
9-
return cmd && childProcess.spawnSync(cmd, { shell: false }).status === 0;
8+
export function cmdReturnsOk(cmd, args: string[] = []): boolean {
9+
const spawnOptions: childProcess.SpawnOptions = { shell: false };
10+
return cmd && childProcess.spawnSync(cmd, args,spawnOptions).status === 0;
1011
}
1112

1213
// run a cmd in a specific folder and it's result should be there
13-
export function execWithResult(cmd, basePath): string {
14-
return childProcess.spawnSync(cmd, { cwd: basePath, shell: false }).toString();
14+
export function execWithResult(cmd, basePath, args: string[] = []): string {
15+
const spawnOptions: childProcess.SpawnOptions ={ cwd: basePath, shell: false }
16+
return childProcess.spawnSync(cmd, args, spawnOptions).toString();
1517
}

lib/system-deps.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,25 @@ function isSet(variable): boolean {
99
}
1010

1111
export function systemDeps(basePath: string, options: PhpOptions): SystemPackages {
12-
const composerOk = isSet(options.composerIsFine) ? options.composerIsFine : cmds.cmdReturnsOk(cmds.composerCmd);
12+
const composerOk = isSet(options.composerIsFine) ? options.composerIsFine : cmds.cmdReturnsOk(cmds.composerCmd.command,cmds.composerCmd.args);
1313
const composerPharOk = isSet(options.composerPharIsFine) ?
14-
options.composerPharIsFine : cmds.cmdReturnsOk(cmds.pharCmd);
14+
options.composerPharIsFine : cmds.cmdReturnsOk(cmds.pharCmd.command, cmds.pharCmd.args);
1515

1616
let finalVersionsObj = {};
1717

1818
if (options.systemVersions && (Object.keys(options.systemVersions).length > 0)) {
1919
// give first preference to a stub
2020
finalVersionsObj = options.systemVersions;
2121
} else if (composerOk) {
22-
const lines = cmds.execWithResult(cmds.composerShowCmd, basePath).split(os.EOL);
22+
const lines = cmds.execWithResult(cmds.composerShowCmd.command, basePath, cmds.composerShowCmd.args).split(os.EOL);
2323
lines.forEach((line) => {
2424
const [part1, part2] = line.split(/\s+/);
2525
if (part2) {
2626
finalVersionsObj[part1] = part2;
2727
}
2828
});
2929
} else if (composerPharOk) {
30-
const output = cmds.execWithResult(cmds.pharCmd, basePath);
30+
const output = cmds.execWithResult(cmds.pharCmd.command, basePath, cmds.pharCmd.args);
3131
const versionsObj = JSON.parse(output).platform;
3232
versionsObj.forEach(({name, version}) => {
3333
finalVersionsObj[name] = version;

0 commit comments

Comments
 (0)