@@ -26,6 +26,32 @@ function getModulePath(filePath, compiler) {
26
26
return path . isAbsolute ( filePath ) ? filePath : path . join ( compiler . context , filePath ) ;
27
27
}
28
28
29
+ function createVirtualStats ( len ) {
30
+ const time = new Date ( ) ;
31
+ const timeMs = time . getTime ( ) ;
32
+
33
+ return new VirtualStats ( {
34
+ dev : 8675309 ,
35
+ ino : inode ++ ,
36
+ mode : 16877 ,
37
+ nlink : 0 ,
38
+ uid : 1000 ,
39
+ gid : 1000 ,
40
+ rdev : 0 ,
41
+ size : len ,
42
+ blksize : 4096 ,
43
+ blocks : Math . floor ( len / 4096 ) ,
44
+ atimeMs : timeMs ,
45
+ mtimeMs : timeMs ,
46
+ ctimeMs : timeMs ,
47
+ birthtimeMs : timeMs ,
48
+ atime : time ,
49
+ mtime : time ,
50
+ ctime : time ,
51
+ birthtime : time
52
+ } ) ;
53
+ }
54
+
29
55
/**
30
56
* @param {Compiler } compiler - the webpack compiler
31
57
*/
@@ -64,28 +90,7 @@ function VirtualModulesPlugin(compiler) {
64
90
try {
65
91
compiler . inputFileSystem . readdirSync ( dir ) ;
66
92
} catch ( e ) {
67
- const time = new Date ( ) ;
68
- const timeMs = time . getTime ( ) ;
69
- const dirStats = new VirtualStats ( {
70
- dev : 8675309 ,
71
- nlink : 0 ,
72
- uid : 1000 ,
73
- gid : 1000 ,
74
- rdev : 0 ,
75
- blksize : 4096 ,
76
- ino : inode ++ ,
77
- mode : 16877 ,
78
- size : stats . size ,
79
- blocks : Math . floor ( stats . size / 4096 ) ,
80
- atimeMs : timeMs ,
81
- mtimeMs : timeMs ,
82
- ctimeMs : timeMs ,
83
- birthtimeMs : timeMs ,
84
- atime : time ,
85
- mtime : time ,
86
- ctime : time ,
87
- birthtime : time
88
- } ) ;
93
+ const dirStats = createVirtualStats ( stats . size ) ;
89
94
setData ( readDirStorage , dir , createWebpackData ( [ ] ) ) ;
90
95
setData ( statStorage , dir , createWebpackData ( dirStats ) ) ;
91
96
}
@@ -118,29 +123,7 @@ function VirtualModulesPlugin(compiler) {
118
123
119
124
VirtualModulesPlugin . prototype . writeModule = function ( filePath , contents ) {
120
125
const len = contents ? contents . length : 0 ;
121
- const time = new Date ( ) ;
122
- const timeMs = time . getTime ( ) ;
123
-
124
- const stats = new VirtualStats ( {
125
- dev : 8675309 ,
126
- ino : inode ++ ,
127
- mode : 16877 ,
128
- nlink : 0 ,
129
- uid : 1000 ,
130
- gid : 1000 ,
131
- rdev : 0 ,
132
- size : len ,
133
- blksize : 4096 ,
134
- blocks : Math . floor ( len / 4096 ) ,
135
- atimeMs : timeMs ,
136
- mtimeMs : timeMs ,
137
- ctimeMs : timeMs ,
138
- birthtimeMs : timeMs ,
139
- atime : time ,
140
- mtime : time ,
141
- ctime : time ,
142
- birthtime : time
143
- } ) ;
126
+ const stats = createVirtualStats ( len ) ;
144
127
const modulePath = getModulePath ( filePath , this . compiler ) ;
145
128
146
129
// When using the WatchIgnorePlugin (https://github.com/webpack/webpack/blob/52184b897f40c75560b3630e43ca642fcac7e2cf/lib/WatchIgnorePlugin.js),
@@ -164,12 +147,12 @@ VirtualModulesPlugin.prototype.writeModule = function(filePath, contents) {
164
147
delete fileWatcher . directoryWatcher . _cachedTimeInfoEntries ;
165
148
fileWatcher . directoryWatcher . setFileTime (
166
149
filePath ,
167
- time ,
150
+ stats . birthtime ,
168
151
false ,
169
152
false ,
170
153
null
171
154
) ;
172
- fileWatcher . emit ( "change" , time , null ) ;
155
+ fileWatcher . emit ( "change" , stats . birthtime , null ) ;
173
156
}
174
157
} ) ;
175
158
}
0 commit comments