Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Issue #97 - Ignore add/change messages from Chokidar on files that don't match the pattern. #301

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"glob": "^10.3.10",
"icss-replace-symbols": "^1.1.0",
"is-there": "^4.4.2",
"minimatch": "^9.0.3",
"mkdirp": "^3.0.0",
"postcss": "^8.0.0",
"postcss-modules-extract-imports": "^3.0.0",
Expand Down
22 changes: 22 additions & 0 deletions src/run.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import chalk from 'chalk';
import chokidar from 'chokidar';
import { glob } from 'glob';
import { minimatch } from 'minimatch';

import { DtsCreator } from './dts-creator';
import { DtsContent } from './dts-content';

Expand Down Expand Up @@ -41,6 +43,21 @@ export async function run(searchDir: string, options: RunOptions = {}): Promise<

const writeFile = async (f: string): Promise<void> => {
try {
// If we're watching recheck the file against the pattern since
// chokidar does not filter files inside symlinks and we don't
// know (without checking every parent) if the file is inside a
// symlink.
//
// Chokidar issue:
//
// https://github.com/paulmillr/chokidar/issues/967
//
// When that's fixed this can be removed (from deleteFile too),
// but the issue is 2 years old already (reported 2020).
if (!!options.watch && !minimatch(f, filesPattern)) {
return;
}

const content: DtsContent = await creator.create(f, undefined, !!options.watch);
await content.writeFile();

Expand All @@ -54,6 +71,11 @@ export async function run(searchDir: string, options: RunOptions = {}): Promise<

const deleteFile = async (f: string): Promise<void> => {
try {
// Recheck patterh, see writeFile for explanation.
if (!!options.watch && !minimatch(f, filesPattern)) {
return;
}

const content: DtsContent = await creator.create(f, undefined, !!options.watch, true);

await content.deleteFile();
Expand Down