File tree 1 file changed +34
-0
lines changed 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) {
44
44
throw err ;
45
45
46
46
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
+
47
57
if ( isFile ( x ) ) {
48
58
return x ;
49
59
}
@@ -56,6 +66,30 @@ module.exports = function (x, options) {
56
66
}
57
67
}
58
68
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
+
59
93
function loadAsDirectorySync ( x ) {
60
94
var pkgfile = path . join ( x , '/package.json' ) ;
61
95
if ( isFile ( pkgfile ) ) {
You can’t perform that action at this time.
0 commit comments