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

fix: watch mode not working with external outDir #1266

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
20 changes: 15 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,12 @@ export async function build(_options: Options) {
: [options.ignoreWatch]
: []

// Convert outDir to absolute path for reliable path comparison
const absoluteOutDir = path.resolve(process.cwd(), options.outDir)

const ignored = [
'**/{.git,node_modules}/**',
options.outDir,
absoluteOutDir,
...customIgnores,
]

Expand All @@ -399,15 +402,22 @@ export async function build(_options: Options) {
)
logger.info(
'CLI',
`Ignoring changes in ${ignored
.map((v) => `"${v}"`)
.join(' | ')}`,
`Ignoring paths: ${ignored.map((v) => `"${v}"`).join(' | ')}`,
)

const watcher = watch(await glob(watchPaths), {
ignoreInitial: true,
ignorePermissionErrors: true,
ignored: (p) => globSync(p, { ignore: ignored }).length === 0,
ignored: (p: string) => {
const absolutePath = path.resolve(process.cwd(), p)
// Check if path should be ignored using absolute path comparison
return ignored.some(ignore => {
const absoluteIgnore = path.isAbsolute(ignore)
? ignore
: path.resolve(process.cwd(), ignore)
return absolutePath.startsWith(absoluteIgnore)
})
},
})
watcher.on('all', async (type, file) => {
file = slash(file)
Expand Down