@@ -62,28 +62,35 @@ function downloadFile (inputUri, callback) {
62
62
}
63
63
64
64
// returns package information (package.json) given a package name
65
- function getPackageInformation ( packageName ) {
65
+ function getPackageInformation ( packageName , parentPackagePath ) {
66
66
67
67
try {
68
- 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 , '..' ) ;
68
+ if ( ! parentPackagePath ) {
69
+ parentPackagePath = path . dirname ( require . main . filename ) ;
74
70
}
75
71
72
+ var modulePath = parentPackagePath ;
73
+
76
74
if ( packageName ) {
77
- packagePath = path . join ( modulesPath , packageName ) ;
75
+ modulePath = modulePath . endsWith ( node_modules ) ? modulePath : path . join ( modulePath , node_modules ) ;
76
+ modulePath = path . join ( modulePath , packageName ) ;
78
77
}
78
+ modulePath = path . join ( modulePath , packageJson ) ;
79
79
80
- packagePath = path . join ( packagePath , packageJson ) ;
81
-
82
- return require ( packagePath ) ;
80
+ return require ( modulePath ) ;
83
81
}
84
82
catch ( err ) {
85
- throw new Error ( 'Error retrieving information for module: \'' + ( packageName || 'main' ) + '\'.' ) ;
83
+ if ( err . code !== 'MODULE_NOT_FOUND' ) {
84
+ throw err ;
85
+ }
86
+
87
+ var next = path . resolve ( parentPackagePath , '..' ) ;
88
+ if ( parentPackagePath !== next ) {
89
+ return getPackageInformation ( packageName , next ) ;
90
+ }
86
91
}
92
+
93
+ throw new Error ( 'Error retrieving information for module: \'' + ( packageName || 'main' ) + '\'.' ) ;
87
94
}
88
95
89
96
// returns package information (package.json) given a file or directory
0 commit comments