-
-
Notifications
You must be signed in to change notification settings - Fork 611
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: not found module after ask installation
- Loading branch information
1 parent
8f4077a
commit 61bc24e
Showing
2 changed files
with
21 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters