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');
66const chalk = require ( 'chalk' ) ;
77const EventEmitter = require ( 'events' ) . EventEmitter ;
88const 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' ) ;
1013
1114/**
1215 * @name log
@@ -159,7 +162,7 @@ const fetchPackage = packageName =>
159162const checkAndInstallPackage = packageName =>
160163 wrapAsync ( function * ( ) {
161164 try {
162- require . resolve ( packageName ) ;
165+ resolvePackageFolder ( packageName ) ;
163166 return true ;
164167 } catch ( err ) {
165168 debug (
Original file line number Diff line number Diff line change 22
33const path = require ( 'path' ) ;
44
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+
519/**
620 * @func resolveFileInPackage
721 * Resolves a file inside a package
822 */
923const 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+ }
1131} ;
1232
1333/**
You can’t perform that action at this time.
0 commit comments