Skip to content

Commit 7327e55

Browse files
fix(ui~cli): file watcher ignore directory logic (#1549)
* feat(cli): enhance file exclusion and extension handling - Added new directories to the exclusion list in consts.ts. - Introduced an `allowedExtensions` array to manage file types for processing. - Updated the `dev`, `generateClassList`, and `findFiles` commands to utilize the new `allowedExtensions` for improved file filtering * chore: add changeset
1 parent 8a8fa60 commit 7327e55

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

.changeset/mighty-buttons-poke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"flowbite-react": patch
3+
---
4+
5+
fix file watcher ignore directory logic leading to false positives

packages/ui/src/cli/commands/dev.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import fs from "fs/promises";
2+
import { basename } from "path";
23
import chokidar from "chokidar";
34
import { isEqual } from "../../helpers/is-equal";
4-
import { automaticClassGenerationMessage, classListFilePath, configFilePath, excludeDirs } from "../consts";
5+
import {
6+
allowedExtensions,
7+
automaticClassGenerationMessage,
8+
classListFilePath,
9+
configFilePath,
10+
excludeDirs,
11+
} from "../consts";
512
import { buildClassList } from "../utils/build-class-list";
613
import { extractComponentImports } from "../utils/extract-component-imports";
714
import { getClassList } from "../utils/get-class-list";
@@ -50,12 +57,10 @@ export async function dev() {
5057
const watcher = chokidar.watch(".", {
5158
ignored: (path, stats) => {
5259
if (stats?.isDirectory()) {
53-
return excludeDirs.some((dir) => path.endsWith(dir));
60+
return excludeDirs.includes(basename(path));
5461
}
5562
if (stats?.isFile()) {
56-
return ![".astro", ".js", ".jsx", ".md", ".mdx", ".ts", ".tsx", configFilePath].some((type) =>
57-
path.endsWith(type),
58-
);
63+
return !allowedExtensions.concat(configFilePath).some((ext) => path.endsWith(ext));
5964
}
6065
return false;
6166
},

packages/ui/src/cli/commands/generate-class-list.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from "fs/promises";
2-
import { classListFilePath, excludeDirs } from "../consts";
2+
import { allowedExtensions, classListFilePath, excludeDirs } from "../consts";
33
import { buildClassList } from "../utils/build-class-list";
44
import { extractComponentImports } from "../utils/extract-component-imports";
55
import { findFiles } from "../utils/find-files";
@@ -11,7 +11,7 @@ export async function generateClassList() {
1111

1212
if (!config.components.length) {
1313
const files = await findFiles({
14-
patterns: ["**/*.astro", "**/*.js", "**/*.jsx", "**/*.md", "**/*.mdx", "**/*.ts", "**/*.tsx"],
14+
patterns: allowedExtensions.map((ext) => `**/*${ext}`),
1515
excludeDirs,
1616
});
1717
const importedComponents = new Set<string>();

packages/ui/src/cli/consts.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ export const classListFilePath = path.join(outputDir, classListFile);
1313
export const configFilePath = path.join(outputDir, configFile);
1414

1515
export const excludeDirs = [
16+
".astro",
1617
".contentlayer",
1718
".git",
1819
".next",
20+
".parcel-cache",
1921
".turbo",
2022
".vercel",
23+
".vscode",
2124
"build",
2225
"coverage",
2326
"dist",
@@ -26,4 +29,6 @@ export const excludeDirs = [
2629
"storybook-static",
2730
];
2831

32+
export const allowedExtensions = [".astro", ".js", ".jsx", ".md", ".mdx", ".ts", ".tsx"];
33+
2934
export const automaticClassGenerationMessage = `Components specified in ${configFilePath}. Automatic class generation is disabled.`;

packages/ui/src/cli/utils/find-files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export async function findFiles({
5555
// Recursive search function
5656
async function search(directory: string): Promise<void> {
5757
// Skip excluded directories
58-
if (excludeDirs.some((dir) => directory.endsWith(dir))) {
58+
if (excludeDirs.includes(path.basename(directory))) {
5959
return;
6060
}
6161

0 commit comments

Comments
 (0)