Skip to content

Commit 2e8a649

Browse files
fix: npx usage (#3400)
1 parent 70ed7dc commit 2e8a649

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

bin/webpack-dev-server.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,29 @@ const runCommand = (command, args) => {
3636
* @returns {boolean} is the package installed?
3737
*/
3838
const isInstalled = (packageName) => {
39-
try {
40-
require.resolve(packageName);
41-
39+
if (process.versions.pnp) {
4240
return true;
43-
} catch (err) {
44-
return false;
4541
}
42+
43+
const path = require('path');
44+
const fs = require('graceful-fs');
45+
46+
let dir = __dirname;
47+
48+
do {
49+
try {
50+
if (
51+
fs.statSync(path.join(dir, 'node_modules', packageName)).isDirectory()
52+
) {
53+
return true;
54+
}
55+
} catch (_error) {
56+
// Nothing
57+
}
58+
// eslint-disable-next-line no-cond-assign
59+
} while (dir !== (dir = path.dirname(dir)));
60+
61+
return false;
4662
};
4763

4864
/**

0 commit comments

Comments
 (0)