Skip to content
This repository was archived by the owner on Jan 14, 2022. It is now read-only.

Commit 90f7b3a

Browse files
committed
Allow manifoldjs CLI to retrieve package info when used as a module (not CLI) - Closes #13 , Closes #pwa-builder/PWABuilder-CLI#213
1 parent 29ef8af commit 90f7b3a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/packageTools.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,22 @@ function downloadFile (inputUri, callback) {
6363

6464
// returns package information (package.json) given a package name
6565
function getPackageInformation (packageName) {
66-
66+
6767
try {
6868
var packagePath = path.dirname(require.main.filename);
69+
var modulesPath = path.join(packagePath, node_modules);
70+
71+
try { fs.statSync(modulesPath).isDirectory() }
72+
catch (er) {
73+
modulesPath = path.resolve(packagePath, '..');
74+
}
75+
6976
if (packageName) {
70-
packagePath = path.join(packagePath, node_modules, packageName);
77+
packagePath = path.join(modulesPath, packageName);
7178
}
72-
79+
7380
packagePath = path.join(packagePath, packageJson);
81+
7482
return require(packagePath);
7583
}
7684
catch (err) {

0 commit comments

Comments
 (0)