Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to check package on exists, because if it was failed we will exit with 2 code above

}

process.exit(2);
Expand Down