33 * @author cxtom(cxtom2008@gmail.com)
44 */
55
6- import { join } from 'path' ;
6+ import { join , sep } from 'path' ;
77import batchdelcache from 'batchdelcache' ;
88
99interface IFileMap {
@@ -65,26 +65,31 @@ export default class Reloader {
6565 const md5 = this . getKey ( item ) ;
6666 if ( hasKey && this . getKey ( this . fileMap [ name ] ) !== md5 && this . filter . call ( this , name ) ) {
6767 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 ) ) ) ;
7071 }
7172 reloadModules . add ( join ( this . context , name ) ) ;
7273 }
7374 }
7475
75- // 删除缓存
76- batchdelcache (
77- Array . from ( reloadModules ) ,
78- true , this . commonRootPath
79- ) ;
76+ const modulesToReload = Array . from ( reloadModules ) ;
8077
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+ }
8489 }
8590
8691 const errors : IError [ ] = [ ] ;
87- for ( const mod of reloadModules ) {
92+ for ( const mod of modulesToReload ) {
8893 try {
8994 // eslint-disable-next-line @typescript-eslint/no-require-imports
9095 require ( mod ) ;
@@ -100,7 +105,7 @@ export default class Reloader {
100105 this . updateFileMap ( Object . assign ( this . fileMap , newFileMap ) ) ;
101106
102107 return {
103- reloadModules : Array . from ( reloadModules ) ,
108+ reloadModules : modulesToReload . map ( a => a . replace ( this . context + sep , '' ) ) ,
104109 errors,
105110 } ;
106111 }
0 commit comments