Skip to content

Commit

Permalink
Simplify the spawn logic
Browse files Browse the repository at this point in the history
There was some platform-specific code aimed at very old Node.js versions
we no longer care about.
  • Loading branch information
mgol committed Nov 15, 2023
1 parent fc04cc8 commit 4917ab0
Showing 1 changed file with 7 additions and 27 deletions.
34 changes: 7 additions & 27 deletions lib/check-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ const findup = fileName => {
};

const checkDependenciesHelper = (syncOrAsync, config) => {

Check warning on line 26 in lib/check-dependencies.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.x)

Arrow function has a complexity of 13. Maximum allowed is 10

Check warning on line 26 in lib/check-dependencies.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 20.x)

Arrow function has a complexity of 13. Maximum allowed is 10

Check warning on line 26 in lib/check-dependencies.js

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 21.x)

Arrow function has a complexity of 13. Maximum allowed is 10

Check warning on line 26 in lib/check-dependencies.js

View workflow job for this annotation

GitHub Actions / build (windows-latest, 18.x)

Arrow function has a complexity of 13. Maximum allowed is 10

Check warning on line 26 in lib/check-dependencies.js

View workflow job for this annotation

GitHub Actions / build (windows-latest, 20.x)

Arrow function has a complexity of 13. Maximum allowed is 10

Check warning on line 26 in lib/check-dependencies.js

View workflow job for this annotation

GitHub Actions / build (windows-latest, 21.x)

Arrow function has a complexity of 13. Maximum allowed is 10
const spawnShellSupported = semver.satisfies(process.version, '>=4.8.0');
const win32 = process.platform === 'win32';
const output = { log: [], error: [] };

let packageJson, pkgManagerPath;
let packageJson;

let installPromise = Promise.resolve();
let success = true;
Expand Down Expand Up @@ -279,32 +277,14 @@ const checkDependenciesHelper = (syncOrAsync, config) => {

// If we're using a direct path, on Windows we need to invoke it via `node path`, not
// `cmd /c path`. In UNIX systems we can execute the command directly so no need to wrap.
let msg, spawnReturn;
let msg;
const method = syncOrAsync === 'sync' ? spawnSync : spawn;

if (spawnShellSupported) {
spawnReturn = method(`${options.packageManager} install`, {
cwd: options.packageDir,
stdio: 'inherit',
shell: true,
});
} else if (win32) {
spawnReturn = method(
pkgManagerPath ? 'node' : 'cmd',
pkgManagerPath
? [pkgManagerPath, 'install']
: ['/c', options.packageManager, 'install'],
{
cwd: options.packageDir,
stdio: 'inherit',
},
);
} else {
spawnReturn = method(options.packageManager, ['install'], {
cwd: options.packageDir,
stdio: 'inherit',
});
}
const spawnReturn = method(`${options.packageManager} install`, {
cwd: options.packageDir,
stdio: 'inherit',
shell: true,
});

if (syncOrAsync === 'sync') {
if (spawnReturn.status !== 0) {
Expand Down

0 comments on commit 4917ab0

Please sign in to comment.