Skip to content

Commit

Permalink
use spawn instead of exec for outdated check
Browse files Browse the repository at this point in the history
  • Loading branch information
whitelisab committed Aug 7, 2024
1 parent 2dc40df commit 07aa636
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions .github/workflows/new-app-review/validators/dependencies.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,49 @@
const { exec } = require('child_process');
const util = require('util');

const execPromise = util.promisify(exec);
const { spawn } = require('child_process');

module.exports = {
validate: async ({ github, context, core }, newAppDir, files) => {
let warning = '';
let result = true;
let message = 'Dependency check finished';

try {
const { stdout, stderr } = await execPromise(`cd ${newAppDir} && npm outdated --json`);
console.log({ stdout, stderr });
const stdout = await new Promise((resolve, reject) => {
const command = `npm outdated --json`;
const child = spawn(command, { shell: true, cwd: newAppDir });

let output = '';
let errorOutput = '';

child.stdout.on('data', (data) => {
output += data.toString();
});

child.stderr.on('data', (data) => {
errorOutput += data.toString();
});

// if (stderr) {
// result = false;
// message = 'Unable to check for outdated dependencies';
// console.error(`stderr: ${stderr}`);
// }
child.on('close', (code) => {
if (code !== 0) {
console.log({ output, errorOutput });
reject(new Error(`Child process exited with code ${code}`));
} else if (errorOutput) {
reject(new Error(errorOutput));
} else {
resolve(output);
}
});
});

// console.log({stdout);
const outdatedDependencies = JSON.parse(stdout);

if (Object.keys(outdatedDependencies).length > 0) {
warning += 'The following dependencies are outdated:\n';
warning += outdatedDependencies;
warning += JSON.stringify(outdatedDependencies, null, 2);
console.log(warning);
}
} catch (error) {
message = 'Failed to check for outdated dependencies';
console.error(`exec error: ${error.stderr.toString()}`);
console.error(`exec error: ${error.message}`);
result = false;
}

Expand Down

0 comments on commit 07aa636

Please sign in to comment.