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 @@ -42,6 +42,16 @@ module.exports = function (x, options) {
4242 throw err ;
4343
4444 function loadAsFileSync ( x ) {
45+ var pkg = loadpkg ( path . dirname ( x ) )
46+
47+ if ( pkg && pkg . dir && pkg . pkg && opts . pathFilter ) {
48+ var rfile = path . relative ( pkg . dir , x ) ;
49+ var r = opts . pathFilter ( pkg . pkg , x , rfile ) ;
50+ if ( r ) {
51+ x = path . resolve ( pkg . dir , r ) ;
52+ }
53+ }
54+
4555 if ( isFile ( x ) ) {
4656 return x ;
4757 }
@@ -54,6 +64,30 @@ module.exports = function (x, options) {
5464 }
5565 }
5666
67+ function loadpkg ( dir ) {
68+ if ( dir === '' || dir === '/' || / [ / \\ ] n o d e _ m o d u l e s [ / \\ ] * $ / . test ( dir ) ) {
69+ return null ;
70+ }
71+
72+ var pkgfile = path . join ( dir , 'package.json' ) ;
73+
74+ if ( ! isFile ( pkgfile ) ) {
75+ return loadpkg ( path . dirname ( dir ) ) ;
76+ }
77+
78+ var body = readFileSync ( pkgfile ) ;
79+
80+ try {
81+ var pkg = JSON . parse ( body ) ;
82+ } catch ( jsonErr ) { }
83+
84+ if ( pkg && opts . packageFilter ) {
85+ pkg = opts . packageFilter ( pkg , pkgfile ) ;
86+ }
87+
88+ return { pkg : pkg , dir : dir } ;
89+ }
90+
5791 function loadAsDirectorySync ( x ) {
5892 var pkgfile = path . join ( x , '/package.json' ) ;
5993 if ( isFile ( pkgfile ) ) {
You can’t perform that action at this time.
0 commit comments