Merge pull request #13529 from webpack/fix-npx-usage

fix: usage `npx webpack`
This commit is contained in:
Tobias Koppers 2021-06-07 18:01:46 +02:00 committed by GitHub
commit ff1b314d30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 5 deletions

View File

@ -32,13 +32,28 @@ const runCommand = (command, args) => {
* @returns {boolean} is the package installed? * @returns {boolean} is the package installed?
*/ */
const isInstalled = packageName => { const isInstalled = packageName => {
try { if (process.versions.pnp) {
require.resolve(packageName);
return true; return true;
} catch (err) {
return false;
} }
const path = require("path");
const fs = require("graceful-fs");
let dir = __dirname;
do {
try {
if (
fs.statSync(path.join(dir, "node_modules", packageName)).isDirectory()
) {
return true;
}
} catch (_error) {
// Nothing
}
} while (dir !== (dir = path.dirname(dir)));
return false;
}; };
/** /**