File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,16 @@ module.exports = function (x, options) {
4444 throw err ;
4545
4646 function loadAsFileSync ( x ) {
47+ var pkg = loadpkg ( path . dirname ( x ) ) ;
48+
49+ if ( pkg && pkg . dir && pkg . pkg && opts . pathFilter ) {
50+ var rfile = path . relative ( pkg . dir , x ) ;
51+ var r = opts . pathFilter ( pkg . pkg , x , rfile ) ;
52+ if ( r ) {
53+ x = path . resolve ( pkg . dir , r ) ;
54+ }
55+ }
56+
4757 if ( isFile ( x ) ) {
4858 return x ;
4959 }
@@ -56,6 +66,30 @@ module.exports = function (x, options) {
5666 }
5767 }
5868
69+ function loadpkg ( dir ) {
70+ if ( dir === '' || dir === '/' || ( / [ / \\ ] n o d e _ m o d u l e s [ / \\ ] * $ / ) . test ( dir ) ) {
71+ return null ;
72+ }
73+
74+ var pkgfile = path . join ( dir , 'package.json' ) ;
75+
76+ if ( ! isFile ( pkgfile ) ) {
77+ return loadpkg ( path . dirname ( dir ) ) ;
78+ }
79+
80+ var body = readFileSync ( pkgfile ) ;
81+
82+ try {
83+ var pkg = JSON . parse ( body ) ;
84+ } catch ( jsonErr ) { }
85+
86+ if ( pkg && opts . packageFilter ) {
87+ pkg = opts . packageFilter ( pkg , pkgfile ) ;
88+ }
89+
90+ return { pkg : pkg , dir : dir } ;
91+ }
92+
5993 function loadAsDirectorySync ( x ) {
6094 var pkgfile = path . join ( x , '/package.json' ) ;
6195 if ( isFile ( pkgfile ) ) {
You can’t perform that action at this time.
0 commit comments