Skip to content

Commit 820ab23

Browse files
committed
headlamp-plugin: bin: Replace execSync with execFileSync
1 parent 29b0ba6 commit 820ab23

File tree

1 file changed

+34
-27
lines changed

1 file changed

+34
-27
lines changed

plugins/headlamp-plugin/bin/headlamp-plugin.js

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function create(name, link, noInstall) {
108108
} else {
109109
console.log('Installing dependencies...');
110110
try {
111-
child_process.execSync('npm ci', {
111+
child_process.execFileSync('npm', ['ci'], {
112112
stdio: 'inherit',
113113
cwd: dstFolder,
114114
encoding: 'utf8',
@@ -603,7 +603,7 @@ function runScriptOnPackages(packageFolder, scriptName, cmdLine, env) {
603603
console.log(`No node_modules in "${folder}" found. Running npm install...`);
604604

605605
try {
606-
child_process.execSync('npm install', {
606+
child_process.execFileSync('npm', ['install'], {
607607
stdio: 'inherit',
608608
encoding: 'utf8',
609609
});
@@ -861,17 +861,16 @@ function format(packageFolder, check) {
861861
* ```
862862
*/
863863
function getNpmOutdated() {
864-
let result = null;
865-
866864
try {
867-
result = child_process.execSync('npm outdated --json', {
868-
encoding: 'utf8',
869-
});
865+
return JSON.parse(
866+
child_process.execFileSync('npm', ['outdated', '--json'], {
867+
encoding: 'utf8',
868+
})
869+
);
870870
} catch (error) {
871-
// npm outdated exit codes 1 when something is not up to date.
872-
result = error.stdout.toString();
871+
const output = error && error.stdout ? error.stdout.toString() : '';
872+
return JSON.parse(output);
873873
}
874-
return JSON.parse(result);
875874
}
876875

877876
/**
@@ -1024,15 +1023,23 @@ function upgrade(packageFolder, skipPackageUpdates, headlampPluginVersion) {
10241023
*/
10251024
function runCmd(cmd, folder) {
10261025
console.log(`Running cmd:"${cmd}" inside of ${folder} abs: "${resolve(folder)}"`);
1027-
try {
1028-
child_process.execSync(cmd, {
1029-
stdio: 'inherit',
1030-
encoding: 'utf8',
1031-
});
1032-
} catch (e) {
1026+
const result = child_process.spawnSync(cmd, {
1027+
shell: true,
1028+
stdio: 'inherit',
1029+
encoding: 'utf8',
1030+
cwd: folder,
1031+
});
1032+
1033+
if (result.error) {
10331034
console.error(`Problem running ${cmd}`);
1034-
return e.status;
1035+
return result.status;
10351036
}
1037+
1038+
if (result.status !== 0) {
1039+
console.error(`Problem running ${cmd}`);
1040+
return result.status;
1041+
}
1042+
10361043
return 0;
10371044
}
10381045

@@ -1260,16 +1267,16 @@ function tsc(packageFolder) {
12601267
* @returns {0 | 1} Exit code, where 0 is success, 1 is failure.
12611268
*/
12621269
function storybook(packageFolder) {
1263-
try {
1264-
child_process.execSync(
1265-
'./node_modules/.bin/storybook dev -p 6007 -c node_modules/@kinvolk/headlamp-plugin/config/.storybook',
1266-
{
1267-
stdio: 'inherit',
1268-
cwd: packageFolder,
1269-
encoding: 'utf8',
1270-
}
1271-
);
1272-
} catch (e) {
1270+
const command =
1271+
'./node_modules/.bin/storybook dev -p 6007 -c node_modules/@kinvolk/headlamp-plugin/config/.storybook';
1272+
const result = child_process.spawnSync(command, {
1273+
stdio: 'inherit',
1274+
cwd: packageFolder,
1275+
encoding: 'utf8',
1276+
shell: true,
1277+
});
1278+
1279+
if (result.error || result.status !== 0) {
12731280
console.error(
12741281
`Problem running storybook dev inside of "${packageFolder}" abs: "${resolve(packageFolder)}"`
12751282
);

0 commit comments

Comments
 (0)