diff --git a/package-lock.json b/package-lock.json index c05ed4a..26a54e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "reload-modules", - "version": "0.1.0", + "version": "0.3.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index a1e13c9..8633e4f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "reload-modules", - "version": "0.1.0", + "version": "0.3.2", "description": "reload nodejs modules with delcache", "keywords": [], "main": "dist/reload-modules.umd.js", diff --git a/src/index.ts b/src/index.ts index 7d1941d..de72ebc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -63,20 +63,19 @@ export default class Reloader { for (const [name, item] of Object.entries(newFileMap)) { const hasKey = name in this.fileMap; const md5 = this.getKey(item); - if (hasKey && this.getKey(this.fileMap[name]) !== md5 && this.filter(name)) { + if (hasKey && this.getKey(this.fileMap[name]) !== md5 && this.filter.call(this, name)) { const parents = this.getParents(item); if (parents.length > 0) { parents.forEach(filename => reloadModules.add(join(this.context, filename))); } - else { - reloadModules.add(join(this.context, name)); - } + reloadModules.add(join(this.context, name)); } } // 删除缓存 batchdelcache( - Array.from(reloadModules) + Array.from(reloadModules), + true, this.commonRootPath ); /* istanbul ignore next */ diff --git a/test/index.test.ts b/test/index.test.ts index 657f6be..0ce792f 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -62,7 +62,7 @@ describe('Reloader test', () => { expect(require('./fixtures/mod2').num).to.be.equal(2); }); - it('reload success', () => { + it('reload success with parents', () => { require('./fixtures/mainModule'); const reloader = new Reloader({ @@ -94,7 +94,7 @@ describe('Reloader test', () => { }); expect(errors.length).to.be.equal(0); - expect(reloadModules.length).to.be.equal(1); + expect(reloadModules.length).to.be.equal(2); expect(reloadModules.includes(resolve(__dirname, './fixtures/mod2.js'))).to.be.equal(true); expect(require('./fixtures/mod2').num).to.be.equal(2); expect(require('./fixtures/mod3').num).to.be.equal(3);