3
3
* @author cxtom([email protected] )
4
4
*/
5
5
6
- import { join } from 'path' ;
6
+ import { join , sep } from 'path' ;
7
7
import batchdelcache from 'batchdelcache' ;
8
8
9
9
interface IFileMap {
@@ -65,26 +65,31 @@ export default class Reloader {
65
65
const md5 = this . getKey ( item ) ;
66
66
if ( hasKey && this . getKey ( this . fileMap [ name ] ) !== md5 && this . filter . call ( this , name ) ) {
67
67
const parents = this . getParents ( item ) ;
68
- if ( parents . length > 0 ) {
69
- parents . forEach ( filename => reloadModules . add ( join ( this . context , filename ) ) ) ;
68
+ const prevParents = this . getParents ( this . fileMap [ name ] ) ;
69
+ if ( parents . length > 0 || prevParents . length > 0 ) {
70
+ [ ...parents , ...prevParents ] . forEach ( filename => reloadModules . add ( join ( this . context , filename ) ) ) ;
70
71
}
71
72
reloadModules . add ( join ( this . context , name ) ) ;
72
73
}
73
74
}
74
75
75
- // 删除缓存
76
- batchdelcache (
77
- Array . from ( reloadModules ) ,
78
- true , this . commonRootPath
79
- ) ;
76
+ const modulesToReload = Array . from ( reloadModules ) ;
80
77
81
- /* istanbul ignore next */
82
- if ( typeof global . gc === 'function' ) {
83
- global . gc ( ) ;
78
+ if ( modulesToReload . length > 0 ) {
79
+ // 删除缓存
80
+ batchdelcache (
81
+ modulesToReload ,
82
+ true , this . commonRootPath
83
+ ) ;
84
+
85
+ /* istanbul ignore next */
86
+ if ( typeof global . gc === 'function' ) {
87
+ global . gc ( ) ;
88
+ }
84
89
}
85
90
86
91
const errors : IError [ ] = [ ] ;
87
- for ( const mod of reloadModules ) {
92
+ for ( const mod of modulesToReload ) {
88
93
try {
89
94
// eslint-disable-next-line @typescript-eslint/no-require-imports
90
95
require ( mod ) ;
@@ -100,7 +105,7 @@ export default class Reloader {
100
105
this . updateFileMap ( Object . assign ( this . fileMap , newFileMap ) ) ;
101
106
102
107
return {
103
- reloadModules : Array . from ( reloadModules ) ,
108
+ reloadModules : modulesToReload . map ( a => a . replace ( this . context + sep , '' ) ) ,
104
109
errors,
105
110
} ;
106
111
}
0 commit comments