Skip to content

Commit c6ca6d6

Browse files
committed
Chokidar doesn't do globs anymore
1 parent bfd1f73 commit c6ca6d6

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

dist/utils/file-watcher.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ exports.CssWatcher = void 0;
77
const fs_1 = __importDefault(require("fs"));
88
const chokidar_1 = __importDefault(require("chokidar"));
99
const css_extractor_1 = require("./css-extractor");
10+
const micromatch_1 = __importDefault(require("micromatch"));
1011
class CssWatcher {
1112
constructor(patterns = ['**/*.css'], ignore = ['**/node_modules/**', '**/dist/**', '**/out/**', '**/build/**']) {
1213
this.state = {
@@ -15,21 +16,20 @@ class CssWatcher {
1516
};
1617
this.watcher = null;
1718
this.patterns = patterns;
18-
this.ignorePatterns = ignore;
19+
// Ignore hidden files by default
20+
this.ignorePatterns = ['**/.*', ...ignore];
1921
this.setupWatcher();
2022
}
2123
setupWatcher() {
22-
// Initial scan and watch setup
23-
const watchPatterns = this.patterns.map((pattern) => {
24-
// Convert Windows-style paths if necessary
25-
return pattern.replace(/\\/g, '/');
26-
});
2724
// Set up chokidar with appropriate options
28-
this.watcher = chokidar_1.default.watch(watchPatterns, {
25+
const cwd = process.cwd();
26+
this.watcher = chokidar_1.default.watch(cwd, {
2927
persistent: true,
3028
ignoreInitial: false, // This ensures we get the initial scan
31-
ignored: [...this.ignorePatterns, /(^|[/\\])\../], // Ignore dotfiles and user-specified patterns
32-
cwd: '.', // Use current working directory as base
29+
ignored: (path, stats) => {
30+
return (micromatch_1.default.isMatch(path, this.ignorePatterns) ||
31+
!!((stats === null || stats === void 0 ? void 0 : stats.isFile()) && !micromatch_1.default.isMatch(path, this.patterns)));
32+
},
3333
followSymlinks: true,
3434
awaitWriteFinish: {
3535
stabilityThreshold: 200,
@@ -39,6 +39,7 @@ class CssWatcher {
3939
// Setup event handlers
4040
this.watcher
4141
.on('add', (filePath) => {
42+
console.log('!!', filePath);
4243
this.updateClassesForFile(filePath);
4344
})
4445
.on('change', (filePath) => {

package-lock.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils/file-watcher.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from 'fs';
22
import chokidar, { type FSWatcher } from 'chokidar';
33
import { extractClassesFromCss } from './css-extractor';
4+
import micromatch from 'micromatch';
45

56
export class CssWatcher {
67
private state = {
@@ -17,23 +18,23 @@ export class CssWatcher {
1718
ignore: string[] = ['**/node_modules/**', '**/dist/**', '**/out/**', '**/build/**'],
1819
) {
1920
this.patterns = patterns;
20-
this.ignorePatterns = ignore;
21+
// Ignore hidden files by default
22+
this.ignorePatterns = ['**/.*', ...ignore];
2123
this.setupWatcher();
2224
}
2325

2426
private setupWatcher() {
25-
// Initial scan and watch setup
26-
const watchPatterns = this.patterns.map((pattern) => {
27-
// Convert Windows-style paths if necessary
28-
return pattern.replace(/\\/g, '/');
29-
});
30-
3127
// Set up chokidar with appropriate options
32-
this.watcher = chokidar.watch(watchPatterns, {
28+
const cwd = process.cwd();
29+
this.watcher = chokidar.watch(cwd, {
3330
persistent: true,
3431
ignoreInitial: false, // This ensures we get the initial scan
35-
ignored: [...this.ignorePatterns, /(^|[/\\])\../], // Ignore dotfiles and user-specified patterns
36-
cwd: '.', // Use current working directory as base
32+
ignored: (path, stats) => {
33+
return (
34+
micromatch.isMatch(path, this.ignorePatterns) ||
35+
!!(stats?.isFile() && !micromatch.isMatch(path, this.patterns))
36+
);
37+
},
3738
followSymlinks: true,
3839
awaitWriteFinish: {
3940
stabilityThreshold: 200,

0 commit comments

Comments
 (0)