File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,9 +26,6 @@ export interface IOptions {
2626 /* 过滤器,调用 reload 时过滤需要 reload 的模块 */
2727 filter ?: ( file : string ) => boolean ;
2828
29- /* 过滤器,调用 reloadAll 时过滤需要 reload 的模块 */
30- filterAll ?: ( file : string ) => boolean ;
31-
3229 commonRootPath ?: string ;
3330}
3431
@@ -43,7 +40,6 @@ export default class Reloader {
4340 fileMap : IFileMap = { } ;
4441 filter : ( file : string ) => boolean ;
4542 commonRootPath : string ;
46- filterAll : ( file : string ) => boolean ;
4743
4844 files : string [ ] = [ ] ;
4945
@@ -56,18 +52,14 @@ export default class Reloader {
5652 if ( options . filter ) {
5753 this . filter = options . filter ;
5854 }
59- this . filterAll = ( ( ) => false ) ;
60- if ( options . filterAll ) {
61- this . filterAll = options . filterAll ;
62- }
6355 this . commonRootPath = options . commonRootPath || '' ;
6456 this . updateFiles ( ) ;
6557 }
6658
67- reloadAll ( ) {
59+ reloadAll ( filter : ( file : string ) => boolean ) {
6860 const reloadModules = new Set < string > ( ) ;
6961 for ( const moduleId of Object . keys ( require . cache ) ) {
70- if ( this . filterAll ( moduleId ) ) {
62+ if ( filter ( moduleId ) ) {
7163 reloadModules . add ( moduleId ) ;
7264 }
7365 }
Original file line number Diff line number Diff line change @@ -67,8 +67,7 @@ describe('Reloader test', () => {
6767
6868 const reloader = new Reloader ( {
6969 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' )
7271 } ) ;
7372
7473 require ( './fixtures/mod1' ) . num ++ ;
@@ -77,7 +76,9 @@ describe('Reloader test', () => {
7776 expect ( require ( './fixtures/mod1' ) . num ) . to . be . equal ( 2 ) ;
7877 expect ( require ( './fixtures/mod2' ) . num ) . to . be . equal ( 3 ) ;
7978
80- let { errors, reloadModules} = reloader . reloadAll ( ) ;
79+ let { errors, reloadModules} = reloader . reloadAll (
80+ id => id . endsWith ( 'fixtures/mod1.js' )
81+ ) ;
8182
8283 expect ( errors . length ) . to . be . equal ( 0 ) ;
8384 expect ( reloadModules . length ) . to . be . equal ( 1 ) ;
You can’t perform that action at this time.
0 commit comments