Skip to content

Commit 121dd26

Browse files
committed
Fix: Skip micromatch when ignore file is empty (#1043)
1 parent e2e902c commit 121dd26

2 files changed

Lines changed: 40 additions & 6 deletions

File tree

src/core/files.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'path';
22
import chalk from 'chalk';
3-
import chokidar from 'chokidar';
3+
import chokidar, {Matcher} from 'chokidar';
44
import Debug from 'debug';
55
import {fdir} from 'fdir';
66
import fs from 'fs/promises';
@@ -39,8 +39,14 @@ async function getLocalFiles(rootDir: string, ignorePatterns: string[], recursiv
3939
fdirBuilder = fdirBuilder.withMaxDepth(0);
4040
}
4141
const files = await fdirBuilder.crawl(rootDir).withPromise();
42-
const filteredFiles = micromatch.not(files, ignorePatterns, {dot: true});
43-
debug('Filtered %d files from ignore rules', files.length - filteredFiles.length);
42+
let filteredFiles: string[];
43+
if (ignorePatterns && ignorePatterns.length) {
44+
filteredFiles = micromatch.not(files, ignorePatterns, {dot: true});
45+
debug('Filtered %d files from ignore rules', files.length - filteredFiles.length);
46+
} else {
47+
debug('Ignore rules are empty, using all files.');
48+
filteredFiles = files;
49+
}
4450
filteredFiles.sort((a, b) => a.localeCompare(b));
4551
return filteredFiles[Symbol.iterator]();
4652
}
@@ -222,13 +228,17 @@ export class Files {
222228
const onChange = async (path: string) => {
223229
collector(path);
224230
};
231+
let matcher: Matcher | undefined;
232+
if (ignorePatterns && ignorePatterns.length) {
233+
matcher = file => {
234+
return micromatch.not([file], ignorePatterns, {dot: true}).length === 0;
235+
};
236+
}
225237
const watcher = chokidar.watch(this.options.files.contentDir, {
226238
persistent: true,
227239
ignoreInitial: true,
228240
cwd: this.options.files.contentDir,
229-
ignored: file => {
230-
return micromatch.not([file], ignorePatterns, {dot: true}).length === 0;
231-
},
241+
ignored: matcher,
232242
});
233243
watcher.on('ready', onReady); // Push on start
234244
watcher.on('add', onChange);

test/core/files.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,4 +526,28 @@ describe('File operations', function () {
526526
expect(pulledFiles[2].localPath).to.equal('Page.htmlx');
527527
});
528528
});
529+
530+
describe('with valid project, empty ignore file', function () {
531+
beforeEach(function () {
532+
mockfs({
533+
'appsscript.json': mockfs.load(path.resolve(__dirname, '../fixtures/appsscript-no-services.json')),
534+
'Code.js': mockfs.load(path.resolve(__dirname, '../fixtures/Code.js')),
535+
'subdir/Code.js': mockfs.load(path.resolve(__dirname, '../fixtures/Code.js')),
536+
'page.html': mockfs.load(path.resolve(__dirname, '../fixtures/page.html')),
537+
'.clasp.json': mockfs.load(path.resolve(__dirname, '../fixtures/dot-clasp-no-settings.json')),
538+
'.claspignore': '',
539+
[path.resolve(os.homedir(), '.clasprc.json')]: mockfs.load(
540+
path.resolve(__dirname, '../fixtures/dot-clasprc-authenticated.json'),
541+
),
542+
});
543+
});
544+
545+
it('should collect local files', async function () {
546+
const clasp = await initClaspInstance({
547+
credentials: mockCredentials(),
548+
});
549+
const foundFiles = await clasp.files.collectLocalFiles();
550+
expect(foundFiles).to.have.length(4);
551+
});
552+
});
529553
});

0 commit comments

Comments
 (0)