|
1 |
| -import * as os from 'os'; |
2 |
| -import { SystemPackages } from '@snyk/composer-lockfile-parser'; |
| 1 | +import {SystemPackages} from '@snyk/composer-lockfile-parser'; |
3 | 2 |
|
4 | 3 | import * as cmds from './composer-cmds';
|
5 |
| -import { PhpOptions } from './types'; |
| 4 | +import {PhpOptions} from './types'; |
6 | 5 |
|
7 |
| -function isSet(variable): boolean { |
| 6 | +function isSet(variable: boolean | undefined): boolean { |
8 | 7 | return typeof variable !== 'undefined';
|
9 | 8 | }
|
10 | 9 |
|
11 | 10 | export function systemDeps(basePath: string, options: PhpOptions): SystemPackages {
|
12 | 11 | const composerOk = isSet(options.composerIsFine) ?
|
13 |
| - options.composerIsFine : cmds.cmdReturnsOk(cmds.composerVersionCmd.command, cmds.composerVersionCmd.args); |
| 12 | + options.composerIsFine : cmds.cmdReturnsOk(cmds.composerCmd.command, [...cmds.composerCmd.args, ...cmds.versionArgs.args]); |
14 | 13 | const composerPharOk = isSet(options.composerPharIsFine) ?
|
15 |
| - options.composerPharIsFine : cmds.cmdReturnsOk(cmds.pharVersionCmd.command, cmds.pharVersionCmd.args); |
| 14 | + options.composerPharIsFine : cmds.cmdReturnsOk(cmds.composerPharCmd.command, [...cmds.composerPharCmd.args, ...cmds.versionArgs.args]); |
16 | 15 |
|
17 | 16 | let finalVersionsObj = {};
|
18 | 17 |
|
19 | 18 | if (options.systemVersions && (Object.keys(options.systemVersions).length > 0)) {
|
20 | 19 | // give first preference to a stub
|
21 | 20 | finalVersionsObj = options.systemVersions;
|
22 |
| - } else if (composerOk) { |
23 |
| - const lines = cmds.execWithResult(cmds.composerShowCmd.command, basePath, cmds.composerShowCmd.args).split(os.EOL); |
24 |
| - lines.forEach((line) => { |
25 |
| - const [part1, part2] = line.split(/\s+/); |
26 |
| - if (part2) { |
27 |
| - finalVersionsObj[part1] = part2; |
28 |
| - } |
29 |
| - }); |
30 |
| - } else if (composerPharOk) { |
31 |
| - const output = cmds.execWithResult(cmds.pharShowCmd.command, basePath, cmds.pharShowCmd.args); |
| 21 | + } else if (composerOk || composerPharOk) { |
| 22 | + const composer = composerOk ? cmds.composerCmd : cmds.composerPharCmd; |
| 23 | + |
| 24 | + const output = cmds.execWithResult(composer.command, basePath, [...composer.args, ...cmds.showArgs.args]); |
32 | 25 | const versionsObj = JSON.parse(output).platform;
|
33 | 26 |
|
34 | 27 | versionsObj.forEach(({name, version}) => {
|
|
0 commit comments