Skip to content

Commit c738bfa

Browse files
committed
Fixes #1824
Signed-off-by: Prabhu Subramanian <[email protected]>
1 parent 7c01278 commit c738bfa

File tree

14 files changed

+126
-100
lines changed

14 files changed

+126
-100
lines changed

lib/cli/index.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Buffer } from "node:buffer";
2-
import { spawnSync } from "node:child_process";
32
import {
43
constants,
54
accessSync,
@@ -163,6 +162,7 @@ import {
163162
recomputeScope,
164163
safeExistsSync,
165164
safeMkdirSync,
165+
safeSpawnSync,
166166
shouldFetchLicense,
167167
splitOutputByGradleProjects,
168168
} from "../helpers/utils.js";
@@ -1660,7 +1660,7 @@ export async function createJavaBom(path, options) {
16601660
`Executing '${mavenCmd} ${mvnArgs.join(" ")}' in`,
16611661
basePath,
16621662
);
1663-
result = spawnSync(mavenCmd, mvnArgs, {
1663+
result = safeSpawnSync(mavenCmd, mvnArgs, {
16641664
cwd: basePath,
16651665
shell: true,
16661666
encoding: "utf-8",
@@ -1709,7 +1709,7 @@ export async function createJavaBom(path, options) {
17091709
thoughtLog(
17101710
"What is the parent component here? Let's use maven command to find out.",
17111711
);
1712-
result = spawnSync(
1712+
result = safeSpawnSync(
17131713
"mvn",
17141714
["dependency:tree", "-N", `-DoutputFile=${tempMvnParentTree}`],
17151715
{
@@ -1748,7 +1748,7 @@ export async function createJavaBom(path, options) {
17481748
);
17491749
}
17501750
// Prefer the built-in maven
1751-
result = spawnSync(
1751+
result = safeSpawnSync(
17521752
PREFER_MAVEN_DEPS_TREE ? "mvn" : mavenCmd,
17531753
mvnTreeArgs,
17541754
{
@@ -2147,7 +2147,7 @@ export async function createJavaBom(path, options) {
21472147
thoughtLog(
21482148
`Let's invoke '${basename(gradleCmd)}' with the arguments '${gradleArg.join(" ").substring(0, 100)} ...'.`,
21492149
);
2150-
const sresult = spawnSync(gradleCmd, gradleArg, {
2150+
const sresult = safeSpawnSync(gradleCmd, gradleArg, {
21512151
cwd: gradleRootPath,
21522152
encoding: "utf-8",
21532153
shell: isWin,
@@ -2232,7 +2232,7 @@ export async function createJavaBom(path, options) {
22322232
if (DEBUG_MODE) {
22332233
console.log("Stopping gradle daemon...");
22342234
}
2235-
const sresult = spawnSync(gradleCmd, ["--stop"], {
2235+
const sresult = safeSpawnSync(gradleCmd, ["--stop"], {
22362236
cwd: gradleRootPath,
22372237
encoding: "utf-8",
22382238
shell: isWin,
@@ -2293,7 +2293,7 @@ export async function createJavaBom(path, options) {
22932293
bArgs = ["--bazelrc=.bazelrc", "build", bazelTarget];
22942294
}
22952295
console.log("Executing", BAZEL_CMD, bArgs.join(" "), "in", basePath);
2296-
let result = spawnSync(BAZEL_CMD, bArgs, {
2296+
let result = safeSpawnSync(BAZEL_CMD, bArgs, {
22972297
cwd: basePath,
22982298
shell: true,
22992299
encoding: "utf-8",
@@ -2331,7 +2331,7 @@ export async function createJavaBom(path, options) {
23312331
bazelParser = parseBazelSkyframe;
23322332
}
23332333
console.log("Executing", BAZEL_CMD, `${query.join(" ")} in`, basePath);
2334-
result = spawnSync(BAZEL_CMD, query, {
2334+
result = safeSpawnSync(BAZEL_CMD, query, {
23352335
cwd: basePath,
23362336
encoding: "utf-8",
23372337
timeout: TIMEOUT_MS,
@@ -2509,7 +2509,7 @@ export async function createJavaBom(path, options) {
25092509
tempSbtgDir,
25102510
);
25112511
// Note that the command has to be invoked with `shell: true` to properly execut sbt
2512-
const result = spawnSync(SBT_CMD, sbtArgs, {
2512+
const result = safeSpawnSync(SBT_CMD, sbtArgs, {
25132513
cwd: basePath,
25142514
shell: true,
25152515
encoding: "utf-8",
@@ -2628,7 +2628,7 @@ export async function createJavaBom(path, options) {
26282628
if (DEBUG_MODE) {
26292629
console.log("Executing", millCmd, millArgs.join(" "), "in", millRootPath);
26302630
}
2631-
let sresult = spawnSync(millCmd, millArgs, {
2631+
let sresult = safeSpawnSync(millCmd, millArgs, {
26322632
cwd: millRootPath,
26332633
encoding: "utf-8",
26342634
shell: isWin,
@@ -2651,7 +2651,7 @@ export async function createJavaBom(path, options) {
26512651
millRootPath,
26522652
);
26532653
}
2654-
sresult = spawnSync(millCmd, millResolveArgs, {
2654+
sresult = safeSpawnSync(millCmd, millResolveArgs, {
26552655
cwd: millRootPath,
26562656
encoding: "utf-8",
26572657
shell: isWin,
@@ -2717,7 +2717,7 @@ export async function createJavaBom(path, options) {
27172717
if (DEBUG_MODE) {
27182718
console.log("Shutting down mill server...");
27192719
}
2720-
const sresult = spawnSync(millCmd, ["shutdown"], {
2720+
const sresult = safeSpawnSync(millCmd, ["shutdown"], {
27212721
cwd: millRootPath,
27222722
encoding: "utf-8",
27232723
shell: isWin,
@@ -2943,7 +2943,7 @@ export async function createNodejsBom(path, options) {
29432943
`Executing '${pkgMgr} ${installArgs.join(" ")}' in`,
29442944
basePath,
29452945
);
2946-
const result = spawnSync(pkgMgr, installArgs, {
2946+
const result = safeSpawnSync(pkgMgr, installArgs, {
29472947
cwd: basePath,
29482948
encoding: "utf-8",
29492949
timeout: TIMEOUT_MS,
@@ -3270,7 +3270,7 @@ export async function createNodejsBom(path, options) {
32703270
// Do rush install if we don't have node_modules directory
32713271
if (!safeExistsSync(nmDir)) {
32723272
console.log("Executing 'rush install --no-link'", path);
3273-
const result = spawnSync(
3273+
const result = safeSpawnSync(
32743274
"rush",
32753275
["install", "--no-link", "--bypass-policy"],
32763276
{
@@ -3806,7 +3806,7 @@ export async function createPythonBom(path, options) {
38063806
if (requirementsMode || pipenvMode) {
38073807
if (pipenvMode) {
38083808
// TODO: Support for nested directories
3809-
spawnSync("pipenv", ["install"], { cwd: path, encoding: "utf-8" });
3809+
safeSpawnSync("pipenv", ["install"], { cwd: path, encoding: "utf-8" });
38103810
const piplockFile = join(path, "Pipfile.lock");
38113811
if (safeExistsSync(piplockFile)) {
38123812
const lockData = JSON.parse(readFileSync(piplockFile));
@@ -4148,7 +4148,7 @@ export async function createGoBom(path, options) {
41484148
if (DEBUG_MODE) {
41494149
console.log(`go mod why -m -vendor ${pkgFullName}`);
41504150
}
4151-
const mresult = spawnSync(
4151+
const mresult = safeSpawnSync(
41524152
"go",
41534153
["mod", "why", "-m", "-vendor", pkgFullName],
41544154
{
@@ -4250,7 +4250,7 @@ export async function createGoBom(path, options) {
42504250
if (DEBUG_MODE) {
42514251
console.log("Executing go list -deps in", basePath);
42524252
}
4253-
let result = spawnSync(
4253+
let result = safeSpawnSync(
42544254
"go",
42554255
[
42564256
"list",
@@ -4298,7 +4298,7 @@ export async function createGoBom(path, options) {
42984298
console.log("Executing go mod graph in", basePath);
42994299
}
43004300
// Next we use the go mod graph command to construct the dependency tree
4301-
result = spawnSync("go", ["mod", "graph"], {
4301+
result = safeSpawnSync("go", ["mod", "graph"], {
43024302
cwd: basePath,
43034303
encoding: "utf-8",
43044304
timeout: TIMEOUT_MS,
@@ -4351,7 +4351,7 @@ export async function createGoBom(path, options) {
43514351
console.log("Executing go mod graph in", basePath);
43524352
}
43534353
// Next we use the go mod graph command to construct the dependency tree
4354-
result = spawnSync("go", ["mod", "graph"], {
4354+
result = safeSpawnSync("go", ["mod", "graph"], {
43554355
cwd: basePath,
43564356
encoding: "utf-8",
43574357
timeout: TIMEOUT_MS,
@@ -4541,7 +4541,7 @@ export async function createRustBom(path, options) {
45414541
basePath,
45424542
);
45434543
}
4544-
const cargoInstallResult = spawnSync(CARGO_CMD, cargoArgs, {
4544+
const cargoInstallResult = safeSpawnSync(CARGO_CMD, cargoArgs, {
45454545
cwd: basePath,
45464546
encoding: "utf-8",
45474547
shell: isWin,
@@ -4907,7 +4907,7 @@ export function createClojureBom(path, options) {
49074907
}
49084908
const basePath = dirname(f);
49094909
console.log("Executing", LEIN_CMD, LEIN_ARGS.join(" "), "in", basePath);
4910-
const result = spawnSync(LEIN_CMD, LEIN_ARGS, {
4910+
const result = safeSpawnSync(LEIN_CMD, LEIN_ARGS, {
49114911
cwd: basePath,
49124912
encoding: "utf-8",
49134913
timeout: TIMEOUT_MS,
@@ -4956,7 +4956,7 @@ export function createClojureBom(path, options) {
49564956
for (const f of ednFiles) {
49574957
const basePath = dirname(f);
49584958
console.log("Executing", CLJ_CMD, CLJ_ARGS.join(" "), "in", basePath);
4959-
const result = spawnSync(CLJ_CMD, CLJ_ARGS, {
4959+
const result = safeSpawnSync(CLJ_CMD, CLJ_ARGS, {
49604960
cwd: basePath,
49614961
encoding: "utf-8",
49624962
timeout: TIMEOUT_MS,
@@ -5339,7 +5339,7 @@ export async function createSwiftBom(path, options) {
53395339
`Executing '${swiftCommand} ${packageArgs.join(" ")}' in ${basePath}. Please wait ...`,
53405340
);
53415341
}
5342-
const result = spawnSync(swiftCommand, packageArgs, {
5342+
const result = safeSpawnSync(swiftCommand, packageArgs, {
53435343
cwd: basePath,
53445344
encoding: "utf-8",
53455345
timeout: TIMEOUT_MS,
@@ -5923,7 +5923,7 @@ export function createPHPBom(path, options) {
59235923
if (DEBUG_MODE) {
59245924
console.log("About to invoke composer --version");
59255925
}
5926-
const versionResult = spawnSync("composer", ["--version"], {
5926+
const versionResult = safeSpawnSync("composer", ["--version"], {
59275927
encoding: "utf-8",
59285928
});
59295929
if (versionResult.status !== 0 || versionResult.error) {
@@ -5956,7 +5956,7 @@ export function createPHPBom(path, options) {
59565956
console.log("Executing 'composer install' in", basePath);
59575957
args = ["install", "--ignore-platform-reqs"];
59585958
}
5959-
const result = spawnSync("composer", args, {
5959+
const result = safeSpawnSync("composer", args, {
59605960
cwd: basePath,
59615961
encoding: "utf-8",
59625962
});
@@ -6108,7 +6108,7 @@ export async function createRubyBom(path, options) {
61086108
for (const f of gemFiles) {
61096109
const basePath = dirname(f);
61106110
console.log("Executing 'bundle install' in", basePath);
6111-
const result = spawnSync("bundle", ["install"], {
6111+
const result = safeSpawnSync("bundle", ["install"], {
61126112
cwd: basePath,
61136113
encoding: "utf-8",
61146114
});
@@ -6368,7 +6368,7 @@ export async function createCsharpBom(path, options) {
63686368
`Executing '${buildCmd} ${buildArgs.join(" ")}' in ${basePath}`,
63696369
);
63706370
}
6371-
const result = spawnSync(buildCmd, buildArgs, {
6371+
const result = safeSpawnSync(buildCmd, buildArgs, {
63726372
cwd: path,
63736373
encoding: "utf-8",
63746374
env: { ...process.env, DOTNET_ROLL_FORWARD: "Major" },

lib/helpers/envcontext.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Buffer } from "node:buffer";
2-
import { spawnSync } from "node:child_process";
32
import { arch, homedir } from "node:os";
43
import { delimiter, dirname, join } from "node:path";
54
import process from "node:process";
@@ -23,6 +22,7 @@ import {
2322
isMac,
2423
isWin,
2524
safeExistsSync,
25+
safeSpawnSync,
2626
} from "./utils.js";
2727

2828
export const GIT_COMMAND = process.env.GIT_CMD || "git";
@@ -399,7 +399,7 @@ const getCommandOutput = (cmd, dir, args) => {
399399
if (DEBUG_MODE) {
400400
console.log(`Executing ${commandToUse} ${args.join(" ")} in ${dir}`);
401401
}
402-
const result = spawnSync(commandToUse, args, {
402+
const result = safeSpawnSync(commandToUse, args, {
403403
cwd: dir,
404404
encoding: "utf-8",
405405
shell: isWin,
@@ -440,7 +440,7 @@ export function isSdkmanAvailable() {
440440
* Method to check if nvm is available.
441441
*/
442442
export function isNvmAvailable() {
443-
const result = spawnSync(
443+
const result = safeSpawnSync(
444444
process.env.SHELL || "bash",
445445
["-i", "-c", process.env.NVM_CMD || "nvm"],
446446
{
@@ -502,7 +502,7 @@ export function installSdkmanTool(toolType, toolName) {
502502
installDir = join(process.env.SDKMAN_CANDIDATES_DIR, toolType);
503503
}
504504
console.log("About to install", toolType, toolName, installDir);
505-
result = spawnSync(
505+
result = safeSpawnSync(
506506
process.env.SHELL || "bash",
507507
[
508508
"-i",
@@ -597,7 +597,7 @@ export function installSdkmanTool(toolType, toolName) {
597597
* @returns {String} path of nvm if present, otherwise false
598598
*/
599599
export function getNvmToolDirectory(toolName) {
600-
const resultWhichNode = spawnSync(
600+
const resultWhichNode = safeSpawnSync(
601601
process.env.SHELL || "bash",
602602
["-i", "-c", `"nvm which ${toolName}"`],
603603
{
@@ -632,7 +632,7 @@ export function getOrInstallNvmTool(toolVersion) {
632632
const nvmNodePath = getNvmToolDirectory(toolVersion);
633633
if (!nvmNodePath) {
634634
// nvm couldn't directly use toolName so maybe needs to be installed
635-
const resultInstall = spawnSync(
635+
const resultInstall = safeSpawnSync(
636636
process.env.SHELL || "bash",
637637
["-i", "-c", `"nvm install ${toolVersion}"`],
638638
{
@@ -678,7 +678,7 @@ function getSdkmanToolFullname(toolName) {
678678
* @returns {Boolean} true if rbenv is available. false otherwise.
679679
*/
680680
export function isRbenvAvailable() {
681-
let result = spawnSync(
681+
let result = safeSpawnSync(
682682
process.env.SHELL || "bash",
683683
["-i", "-c", process.env.RBENV_CMD || "rbenv", "--version"],
684684
{
@@ -688,7 +688,7 @@ export function isRbenvAvailable() {
688688
},
689689
);
690690
if (result.status !== 0) {
691-
result = spawnSync(process.env.RBENV_CMD || "rbenv", ["--version"], {
691+
result = safeSpawnSync(process.env.RBENV_CMD || "rbenv", ["--version"], {
692692
shell: isWin,
693693
encoding: "utf-8",
694694
});
@@ -732,7 +732,7 @@ export function bundleInstallWithDocker(rubyVersion, cdxgenGemHome, filePath) {
732732
"install",
733733
];
734734
console.log(`Performing bundle install with: ${ociCmd} ${ociArgs.join(" ")}`);
735-
const result = spawnSync(ociCmd, ociArgs, {
735+
const result = safeSpawnSync(ociCmd, ociArgs, {
736736
encoding: "utf-8",
737737
shell: isWin,
738738
timeout: TIMEOUT_MS,
@@ -765,7 +765,7 @@ export function installRubyVersion(rubyVersion, filePath) {
765765
}
766766
const fullToolBinDir = rubyVersionDir(rubyVersion);
767767
if (safeExistsSync(fullToolBinDir)) {
768-
const result = spawnSync(
768+
const result = safeSpawnSync(
769769
process.env.RBENV_CMD || "rbenv",
770770
["local", rubyVersion],
771771
{
@@ -809,7 +809,7 @@ export function installRubyVersion(rubyVersion, filePath) {
809809
`To speed up this step, use bind mounts. Example: "--mount type=bind,src=/tmp/rbenv,dst=/root/.rbenv/versions/${rubyVersion}"`,
810810
);
811811
}
812-
const result = spawnSync(
812+
const result = safeSpawnSync(
813813
process.env.RBENV_CMD || "rbenv",
814814
["install", rubyVersion],
815815
{
@@ -879,7 +879,7 @@ export function installRubyBundler(rubyVersion, bundlerVersion) {
879879
);
880880
}
881881
}
882-
const result = spawnSync(join(fullToolBinDir, "gem"), gemInstallArgs, {
882+
const result = safeSpawnSync(join(fullToolBinDir, "gem"), gemInstallArgs, {
883883
encoding: "utf-8",
884884
shell: isWin,
885885
timeout: TIMEOUT_MS,
@@ -946,7 +946,7 @@ export function performBundleInstall(
946946
console.log(
947947
`Invoking ${bundleCommand} ${installArgs.join(" ")} from ${basePath} with GEM_HOME ${cdxgenGemHome}. Please wait ...`,
948948
);
949-
let result = spawnSync(bundleCommand, installArgs, {
949+
let result = safeSpawnSync(bundleCommand, installArgs, {
950950
encoding: "utf-8",
951951
shell: isWin,
952952
timeout: TIMEOUT_MS,
@@ -1003,7 +1003,7 @@ export function performBundleInstall(
10031003
);
10041004
}
10051005
console.log(`${bundleCommand} ${updateArgs.join(" ")}`);
1006-
result = spawnSync(bundleCommand, updateArgs, {
1006+
result = safeSpawnSync(bundleCommand, updateArgs, {
10071007
encoding: "utf-8",
10081008
shell: isWin,
10091009
timeout: TIMEOUT_MS,

0 commit comments

Comments
 (0)