Skip to content

Commit 2a15e15

Browse files
committed
chore: add fallback for windows
1 parent 9d7ae87 commit 2a15e15

1 file changed

Lines changed: 8 additions & 16 deletions

File tree

packages/webpack-cli/lib/utils/package-exists.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
async function packageExists(packageName) {
22
try {
3-
const execa = require('execa');
4-
const path = require('path');
5-
const command = `
6-
try {
7-
console.log(require.resolve('${packageName}'));
8-
} catch (err) {
9-
console.log('Not Found');
10-
}`;
3+
const { execSync } = require('child_process');
4+
const command = `try { console.log(require.resolve('${packageName}')); } catch (err) { console.log('Not Found');}`;
5+
const rootPath = execSync(`node -e "${command}"`, { encoding: 'utf8' }).trimEnd();
116

12-
const { stdout: rootPath } = await execa('node', ['-e', command], {
13-
cwd: path.resolve(process.cwd()),
14-
reject: false,
15-
stdio: 'inherit',
16-
maxBuffer: Infinity,
17-
});
7+
if (!rootPath || rootPath === 'Not Found') {
8+
// Fallback to require resolve
9+
return require.resolve(packageName);
10+
}
1811

19-
console.log(rootPath);
20-
return rootPath && rootPath !== 'Not Found';
12+
return true;
2113
} catch (err) {
2214
return false;
2315
}

0 commit comments

Comments
 (0)