File tree Expand file tree Collapse file tree 2 files changed +6
-13
lines changed Expand file tree Collapse file tree 2 files changed +6
-13
lines changed Original file line number Diff line number Diff line change @@ -26,9 +26,6 @@ export interface IOptions {
26
26
/* 过滤器,调用 reload 时过滤需要 reload 的模块 */
27
27
filter ?: ( file : string ) => boolean ;
28
28
29
- /* 过滤器,调用 reloadAll 时过滤需要 reload 的模块 */
30
- filterAll ?: ( file : string ) => boolean ;
31
-
32
29
commonRootPath ?: string ;
33
30
}
34
31
@@ -43,7 +40,6 @@ export default class Reloader {
43
40
fileMap : IFileMap = { } ;
44
41
filter : ( file : string ) => boolean ;
45
42
commonRootPath : string ;
46
- filterAll : ( file : string ) => boolean ;
47
43
48
44
files : string [ ] = [ ] ;
49
45
@@ -56,18 +52,14 @@ export default class Reloader {
56
52
if ( options . filter ) {
57
53
this . filter = options . filter ;
58
54
}
59
- this . filterAll = ( ( ) => false ) ;
60
- if ( options . filterAll ) {
61
- this . filterAll = options . filterAll ;
62
- }
63
55
this . commonRootPath = options . commonRootPath || '' ;
64
56
this . updateFiles ( ) ;
65
57
}
66
58
67
- reloadAll ( ) {
59
+ reloadAll ( filter : ( file : string ) => boolean ) {
68
60
const reloadModules = new Set < string > ( ) ;
69
61
for ( const moduleId of Object . keys ( require . cache ) ) {
70
- if ( this . filterAll ( moduleId ) ) {
62
+ if ( filter ( moduleId ) ) {
71
63
reloadModules . add ( moduleId ) ;
72
64
}
73
65
}
Original file line number Diff line number Diff line change @@ -67,8 +67,7 @@ describe('Reloader test', () => {
67
67
68
68
const reloader = new Reloader ( {
69
69
context : resolve ( __dirname , './fixtures' ) ,
70
- commonRootPath : resolve ( __dirname , './fixtures/mainModule.js' ) ,
71
- filterAll : ( id ) => id . endsWith ( 'fixtures/mod1.js' )
70
+ commonRootPath : resolve ( __dirname , './fixtures/mainModule.js' )
72
71
} ) ;
73
72
74
73
require ( './fixtures/mod1' ) . num ++ ;
@@ -77,7 +76,9 @@ describe('Reloader test', () => {
77
76
expect ( require ( './fixtures/mod1' ) . num ) . to . be . equal ( 2 ) ;
78
77
expect ( require ( './fixtures/mod2' ) . num ) . to . be . equal ( 3 ) ;
79
78
80
- let { errors, reloadModules} = reloader . reloadAll ( ) ;
79
+ let { errors, reloadModules} = reloader . reloadAll (
80
+ id => id . endsWith ( 'fixtures/mod1.js' )
81
+ ) ;
81
82
82
83
expect ( errors . length ) . to . be . equal ( 0 ) ;
83
84
expect ( reloadModules . length ) . to . be . equal ( 1 ) ;
You can’t perform that action at this time.
0 commit comments