Skip to content

Commit

Permalink
Handle an edge case with well-known ignores when applying exclusions (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
daniilsapa authored Dec 8, 2024
1 parent b55545e commit 5aaf1a3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
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

0 comments on commit 5aaf1a3

Please sign in to comment.