File tree Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,10 @@ const path = require('path');
6
6
const chalk = require ( 'chalk' ) ;
7
7
const EventEmitter = require ( 'events' ) . EventEmitter ;
8
8
const hasYarn = require ( 'has-yarn' ) ;
9
- const { resolveFileInPackage } = require ( '@pattern-lab/core/src/lib/resolver' ) ;
9
+ const {
10
+ resolvePackageFolder,
11
+ resolveFileInPackage,
12
+ } = require ( '@pattern-lab/core/src/lib/resolver' ) ;
10
13
11
14
/**
12
15
* @name log
@@ -159,7 +162,7 @@ const fetchPackage = packageName =>
159
162
const checkAndInstallPackage = packageName =>
160
163
wrapAsync ( function * ( ) {
161
164
try {
162
- require . resolve ( packageName ) ;
165
+ resolvePackageFolder ( packageName ) ;
163
166
return true ;
164
167
} catch ( err ) {
165
168
debug (
Original file line number Diff line number Diff line change 2
2
3
3
const path = require ( 'path' ) ;
4
4
5
+ /**
6
+ * @func resolvePackageLocations
7
+ * Resolves all possible package locations
8
+ */
9
+ const resolvePackageLocations = ( ) => {
10
+ let lookupPath = path . resolve ( process . env . projectDir ) ;
11
+ const paths = [ lookupPath ] ;
12
+ while ( path . dirname ( lookupPath ) !== lookupPath ) {
13
+ lookupPath = path . join ( lookupPath , '../' ) ;
14
+ paths . push ( lookupPath ) ;
15
+ }
16
+ return paths ;
17
+ } ;
18
+
5
19
/**
6
20
* @func resolveFileInPackage
7
21
* Resolves a file inside a package
8
22
*/
9
23
const resolveFileInPackage = ( packageName , ...pathElements ) => {
10
- return require . resolve ( path . join ( packageName , ...pathElements ) ) ;
24
+ if ( process . env . projectDir ) {
25
+ return require . resolve ( path . join ( packageName , ...pathElements ) , {
26
+ paths : resolvePackageLocations ( ) ,
27
+ } ) ;
28
+ } else {
29
+ return require . resolve ( path . join ( packageName , ...pathElements ) ) ;
30
+ }
11
31
} ;
12
32
13
33
/**
You can’t perform that action at this time.
0 commit comments