Skip to content

Commit

Permalink
fix: root path
Browse files Browse the repository at this point in the history
  • Loading branch information
cxtom committed Jul 28, 2020
1 parent 438b638 commit af08cd6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
9 changes: 4 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit af08cd6

Please sign in to comment.