Skip to content
Closed
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
21 changes: 21 additions & 0 deletions packages/cli/src/lib/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ interface WatcherHandle {
* with one exception: `.flue/` is allowed through only when it is the
* selected source directory.
* - Editor backup/swap suffixes
* - Patterns read from `<root>/.gitignore` (loaded once at startup)
*/
function createWatcher(options: WatcherOptions): WatcherHandle {
const { root, sourceRoot, output, envFile, configFiles, onChange } = options;
Expand All @@ -351,6 +352,19 @@ function createWatcher(options: WatcherOptions): WatcherHandle {
// resolves into it, just to be safe across platforms.
const outputRelToRoot = path.relative(root, output).split(path.sep).join('/');

// Read .gitignore patterns once during watcher creation
const gitignorePath = path.join(root, '.gitignore');
let gitignorePatterns: string[] = [];
try {
const content = fs.readFileSync(gitignorePath, 'utf-8');
gitignorePatterns = content
.split('\n')
.map((l) => l.trim())
.filter((l) => l && !l.startsWith('#'));
} catch {
// .gitignore may not exist
}

const isIgnoredPath = (relPath: string): boolean => {
const normalized = relPath.replace(/\\/g, '/');
if (ignoredConfigFiles.has(path.resolve(root, relPath))) return true;
Expand All @@ -375,6 +389,13 @@ function createWatcher(options: WatcherOptions): WatcherHandle {
const base = parts[parts.length - 1] ?? '';
if (!base) return true;
if (base.endsWith('~') || base.endsWith('.swp') || base.endsWith('.swx')) return true;
// Match any path segment against .gitignore patterns
for (const pattern of gitignorePatterns) {
const p = pattern.endsWith('/') ? pattern.slice(0, -1) : pattern;
for (const part of parts) {
if (part === p) return true;
}
}
return false;
};

Expand Down
Loading