Skip to content

Commit

Permalink
fix: not found module after ask installation (#2761)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Jun 5, 2021
1 parent c8fef37 commit 557ad05
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions packages/webpack-cli/lib/utils/package-exists.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
const fs = require("fs");
const path = require("path");

function packageExists(packageName) {
try {
return require.resolve(packageName);
} catch (error) {
return false;
if (process.versions.pnp) {
return true;
}

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;
}

module.exports = packageExists;
2 changes: 1 addition & 1 deletion packages/webpack-cli/lib/utils/prompt-installation.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async function promptInstallation(packageName, preMessage) {
process.exit(2);
}

return utils.packageExists(packageName);
return packageName;
}

process.exit(2);
Expand Down

0 comments on commit 557ad05

Please sign in to comment.