Unable to exclude directories from being watched with --tsconfig
Describe the bug
When running svelte-check in watch mode I run into an issue
Getting Svelte diagnostics...
failed to load config from /Users/.../vite.config.ts
Preprocessing failed
Error: spawn EBADF
at ChildProcess.spawn (node:internal/child_process:421:11)
at Object.spawn (node:child_process:762:9)
at ensureServiceIsRunning (/Users/.../node_modules/esbuild/lib/main.js:1982:29)
which I tracked down to be related to the chokidar from version 4 with projects including a lot of files on macOS https://github.com/paulmillr/chokidar/issues/1385
Both downgrading to [email protected] with as [email protected] dependency or removing some directories containing a lot of files from the project solve the issue. So I would like to exclude these directories from being watched. The docs say
--ignore <paths> Only has an effect when used in conjunction with --no-tsconfig. When used in conjunction with --tsconfig, this will only have effect on the files watched, not on the files that are diagnosed, which is then determined by the tsconfig.json.
Which is contradictory. Adding the --ignore flag gives the error
> svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch --ignore="build"
Error: Invalid svelte-check CLI args: `--ignore` only has an effect when using `--no-tsconfig`
that is caused by this line https://github.com/sveltejs/language-tools/blob/14dc5841442eb972bc57b724067979ce5b4df24a/packages/svelte-check/src/options.ts#L76 that was added with https://github.com/sveltejs/language-tools/pull/2453 to solve https://github.com/sveltejs/language-tools/issues/1074 so the docs don't seem to be up to date.
If the --ignore flag can't be used in conjunction with --tsconfig, how can I prevent the directories from being watched without disabling the checking of .js / .ts files? Excluding the directories in tsconfig.json doesn't seem to have an effect on that.
Reproduction
Use --ignore flag in cunjuntion with --tsconfig
Expected behaviour
Exclude ignored directories from being watched
System Info
macOS 13.7.2 svelte-check 4.2.2
Which package is the issue about?
svelte-check
Additional Information, eg. Screenshots
No response
Yeah. The error about --ignore is intentional. The flag can't be used when tsconfig.json exists. We'll probably have to watch files according to the include config in the tsconfig.json, and potentially watch some individual files that are referenced but not under the include pattern.
EDIT: I misread the original message, my bad
It is because it is confusing to have an ignore flag only for ignoring files in file watch, but not for checking.
EDIT: I misread the original message, my bad
I don't think it makes sense to add a new CLI flag to "work around" a bug. Additionally, the other intention for disallowing --ignore with' tsconfig' is that the file loading logic should be close to tsc.
Can you explain in more detail why you have so many files to begin with? Please only mention things that are relevant to the issue itself. If you're referring to "git worktree", the "branches" are usually outside of your project, so I don't quite understand why it'll cause "too many files being watched".
My issue is with git worktrees, since we don't respect my TSConfig excludes I get EMFILE issues. Placing the worktrees above my repo root bricks AI assistants with security issues.
I created a pretty simple repro: https://github.com/aewing/svelte-check-emfile-repro
I just saw in your initial response you said we SHOULD use tsconfig include/exclude and I totally misread that the first time. Forgive me for that waste of time.
I actually have a branch I prepared to respect the tsconfig settings I had prepared before leaving on vacation (I just got back), I will open an MR shortly.
https://github.com/sveltejs/language-tools/pull/2807