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

Handle an edge case with well-known ignores when applying exclusions #141

Merged
merged 6 commits into from
Dec 8, 2024
Merged
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
5 changes: 5 additions & 0 deletions .changeset/eleven-numbers-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'steiger': patch
---

Handle an edge case with well-known ignores (like .DS_Store on macOS) when applying glob exclusions
21 changes: 19 additions & 2 deletions packages/steiger/src/features/transfer-fs-to-vfs.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
import { join, sep } from 'node:path'
import { join, sep, resolve, parse, dirname } from 'node:path'
import { existsSync } from 'node:fs'
import chokidar from 'chokidar'
import type { Folder } from '@steiger/types'
import { isGitIgnored } from 'globby'

import { createVfsRoot } from '../models/vfs'

function findGitRoot(startDir: string): string | null {
let currentDir = resolve(startDir)

while (currentDir !== parse(currentDir).root) {
const gitFolderOrLinkPath = join(currentDir, '.git')

if (existsSync(gitFolderOrLinkPath)) {
return currentDir
}
// Move up one directory
currentDir = dirname(currentDir)
}

return null
}

/**
* Start watching a given path with chokidar.
*
* Returns a reactive virtual file system (VFS) and a reference to the watcher
*/
export async function createWatcher(path: string) {
const vfs = createVfsRoot(path)
const isIgnored = await isGitIgnored({ cwd: path })
const isIgnored = await isGitIgnored({ cwd: findGitRoot(path) || path })

const watcher = chokidar.watch(path, {
ignored: (path) => path.split(sep).includes('node_modules') || isIgnored(path),
Expand Down
Loading