Skip to content

Commit 2146a03

Browse files
seaoakSukkaW
authored andcommitted
fix(hexojs#3873): enable using "ignore:" option for individual files (hexojs#3878)
1 parent 7786279 commit 2146a03

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

lib/box/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,17 @@ Box.prototype._readDir = function(base, fn, prefix = '') {
120120
const { ignore } = this;
121121

122122
if (base && ignore && ignore.length && micromatch.isMatch(base, ignore)) {
123-
return Promise.resolve('Ignoring dir.');
123+
return Promise.resolve([]);
124124
}
125125

126126
return fs.readdir(base).map(path => fs.stat(join(base, path)).then(stats => {
127+
const fullpath = join(base, path);
127128
if (stats.isDirectory()) {
128-
return this._readDir(join(base, path), fn, `${prefix + path}/`);
129+
return this._readDir(fullpath, fn, `${prefix + path}/`);
130+
}
131+
132+
if (ignore && ignore.length && micromatch.isMatch(fullpath, ignore)) {
133+
return Promise.resolve([]);
129134
}
130135

131136
return this._checkFileStatus(prefix + path).then(file => fn(file).thenReturn(file));

test/scripts/box/box.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ describe('Box', () => {
265265
});
266266

267267
it('process() - skip files if they match any of the glob expressions in ignore', () => {
268-
const box = newBox('test', {ignore: ['**/ignore_me', '**/ignore_me_too']});
268+
const box = newBox('test', {ignore: ['**/ignore_me', '**/ignore_me_too.txt']});
269269
const data = {};
270270

271271
box.addProcessor(file => {
@@ -274,7 +274,8 @@ describe('Box', () => {
274274

275275
return Promise.all([
276276
fs.writeFile(pathFn.join(box.base, 'foo.txt'), 'foo'),
277-
fs.writeFile(pathFn.join(box.base, 'ignore_me', 'bar.txt'), 'ignore_me')
277+
fs.writeFile(pathFn.join(box.base, 'ignore_me', 'bar.txt'), 'ignore_me'),
278+
fs.writeFile(pathFn.join(box.base, 'ignore_me_too.txt'), 'ignore_me_too')
278279
]).then(() => box.process()).then(() => {
279280
const keys = Object.keys(data);
280281

@@ -474,13 +475,16 @@ describe('Box', () => {
474475
});
475476

476477
it('watch() - update with complex "ignore" option', () => {
477-
const box = newBox('test', {ignore: ['**/ignore_me', '**/ignore_me_too']});
478+
const box = newBox('test', {ignore: ['**/ignore_me', '**/ignore_me_too.txt']});
478479
const path1 = 'a.txt';
479480
const path2 = 'b.txt';
481+
const path3 = 'ignore_me_too.txt';
480482
const src1 = pathFn.join(box.base, path1);
481483
const src2 = pathFn.join(box.base, 'ignore_me', path2);
484+
const src3 = pathFn.join(box.base, path3);
482485
const cacheId1 = 'test/' + path1;
483486
const cacheId2 = 'test/ignore_me/' + path2;
487+
const cacheId3 = 'test/' + path3;
484488
const Cache = box.Cache;
485489
const processor = sinon.spy();
486490

@@ -493,6 +497,9 @@ describe('Box', () => {
493497
]).then(() => Promise.all([
494498
fs.writeFile(src2, 'b'),
495499
Cache.insert({_id: cacheId2})
500+
])).then(() => Promise.all([
501+
fs.writeFile(src3, 'c'),
502+
Cache.insert({_id: cacheId3})
496503
])).then(() => box.watch()).then(() => fs.appendFile(src1, 'aaa')).delay(500).then(() => {
497504
file = processor.lastCall.args[0];
498505

@@ -503,6 +510,9 @@ describe('Box', () => {
503510
}).then(() => fs.appendFile(src2, 'bbb')).delay(500).then(() => {
504511
const file2 = processor.lastCall.args[0];
505512
file2.should.eql(file); // not changed
513+
}).then(() => fs.appendFile(src3, 'ccc')).delay(500).then(() => {
514+
const file3 = processor.lastCall.args[0];
515+
file3.should.eql(file); // not changed
506516
}).finally(() => {
507517
box.unwatch();
508518
return fs.rmdir(box.base);

0 commit comments

Comments
 (0)