Skip to content

Commit

Permalink
fix: not found module after ask installation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Jun 4, 2021
1 parent 8f4077a commit 61bc24e
Show file tree
Hide file tree
Showing 2 changed files with 21 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;
3 changes: 2 additions & 1 deletion packages/webpack-cli/lib/utils/prompt-installation.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ async function promptInstallation(packageName, preMessage) {
const commandToBeRun = `${packageManager} ${[
packageManager === "yarn" ? "add" : "install",
"-D",
"--ignore-workspace-root-check",
packageName,
].join(" ")}`;
const { colors } = utils;
Expand Down Expand Up @@ -51,7 +52,7 @@ async function promptInstallation(packageName, preMessage) {
process.exit(2);
}

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

process.exit(2);
Expand Down

0 comments on commit 61bc24e

Please sign in to comment.