@@ -108,18 +108,32 @@ FileManager.prototype.loadFile = function(filename, currentDirectory, options, e
108
108
}
109
109
}
110
110
111
+ var modified = false ;
112
+
111
113
if ( self . contents [ fullFilename ] ) {
112
- fulfill ( { contents : self . contents [ fullFilename ] , filename : fullFilename } ) ;
114
+ try {
115
+ var stat = fs . statSync . apply ( this , [ fullFilename ] ) ;
116
+ if ( stat . mtime . getTime ( ) === self . contents [ fullFilename ] . mtime . getTime ( ) ) {
117
+ fulfill ( { contents : self . contents [ fullFilename ] . data , filename : fullFilename } ) ;
118
+ }
119
+ else {
120
+ modified = true ;
121
+ }
122
+ }
123
+ catch ( e ) {
124
+ modified = true ;
125
+ }
113
126
}
114
- else {
127
+ if ( modified || ! self . contents [ fullFilename ] ) {
115
128
var readFileArgs = [ fullFilename ] ;
116
129
if ( ! options . rawBuffer ) {
117
130
readFileArgs . push ( 'utf-8' ) ;
118
131
}
119
132
if ( options . syncImport ) {
120
133
try {
121
134
var data = fs . readFileSync . apply ( this , readFileArgs ) ;
122
- self . contents [ fullFilename ] = data ;
135
+ var stat = fs . statSync . apply ( this , [ fullFilename ] ) ;
136
+ self . contents [ fullFilename ] = { data : data , mtime : stat . mtime } ;
123
137
fulfill ( { contents : data , filename : fullFilename } ) ;
124
138
}
125
139
catch ( e ) {
@@ -133,7 +147,8 @@ FileManager.prototype.loadFile = function(filename, currentDirectory, options, e
133
147
filenamesTried . push ( isNodeModule ? npmPrefix + fullFilename : fullFilename ) ;
134
148
return tryPrefix ( j + 1 ) ;
135
149
}
136
- self . contents [ fullFilename ] = data ;
150
+ var stat = fs . statSync . apply ( this , [ fullFilename ] ) ;
151
+ self . contents [ fullFilename ] = { data : data , mtime : stat . mtime } ;
137
152
fulfill ( { contents : data , filename : fullFilename } ) ;
138
153
} ) ;
139
154
fs . readFile . apply ( this , readFileArgs ) ;
0 commit comments