diff --git a/packages/language-server/package.json b/packages/language-server/package.json index f3702c47b..2963ffe11 100644 --- a/packages/language-server/package.json +++ b/packages/language-server/package.json @@ -52,7 +52,7 @@ "dependencies": { "@jridgewell/trace-mapping": "^0.3.25", "@vscode/emmet-helper": "2.8.4", - "chokidar": "^3.4.1", + "chokidar": "^4.0.1", "estree-walker": "^2.0.1", "fdir": "^6.2.0", "lodash": "^4.17.21", diff --git a/packages/language-server/src/lib/FallbackWatcher.ts b/packages/language-server/src/lib/FallbackWatcher.ts index 81ec47349..4af7e71ff 100644 --- a/packages/language-server/src/lib/FallbackWatcher.ts +++ b/packages/language-server/src/lib/FallbackWatcher.ts @@ -25,12 +25,7 @@ export class FallbackWatcher { this.watcher = watch( workspacePaths.map((workspacePath) => join(workspacePath, recursivePatterns)), { - ignored: (path: string) => - gitOrNodeModules.test(path) && - // Handle Sapper's alias mapping - !path.includes('src/node_modules') && - !path.includes('src\\node_modules'), - + ignored: gitOrNodeModules, // typescript would scan the project files on init. // We only need to know what got updated. ignoreInitial: true, diff --git a/packages/svelte-check/package.json b/packages/svelte-check/package.json index 634a029f6..b49d294a2 100644 --- a/packages/svelte-check/package.json +++ b/packages/svelte-check/package.json @@ -27,7 +27,7 @@ }, "dependencies": { "@jridgewell/trace-mapping": "^0.3.25", - "chokidar": "^3.4.1", + "chokidar": "^4.0.1", "fdir": "^6.2.0", "picocolors": "^1.0.0", "sade": "^1.7.4" diff --git a/packages/svelte-check/src/index.ts b/packages/svelte-check/src/index.ts index 866d23bf3..f2aeb79fb 100644 --- a/packages/svelte-check/src/index.ts +++ b/packages/svelte-check/src/index.ts @@ -32,27 +32,7 @@ async function openAllDocuments( ) { const offset = workspaceUri.fsPath.length + 1; // We support a very limited subset of glob patterns: You can only have ** at the end or the start - const ignored: Array<(path: string) => boolean> = filePathsToIgnore.map((i) => { - if (i.endsWith('**')) i = i.slice(0, -2); - - if (i.startsWith('**')) { - i = i.slice(2); - - if (i.includes('*')) - throw new Error( - 'Invalid svelte-check --ignore pattern: Only ** at the start or end is supported' - ); - - return (path) => path.includes(i); - } - - if (i.includes('*')) - throw new Error( - 'Invalid svelte-check --ignore pattern: Only ** at the start or end is supported' - ); - - return (path) => path.startsWith(i); - }); + const ignored = createIgnored(filePathsToIgnore); const isIgnored = (path: string) => { path = path.slice(offset); for (const i of ignored) { @@ -84,6 +64,30 @@ async function openAllDocuments( } } +function createIgnored(filePathsToIgnore: string[]): Array<(path: string) => boolean> { + return filePathsToIgnore.map((i) => { + if (i.endsWith('**')) i = i.slice(0, -2); + + if (i.startsWith('**')) { + i = i.slice(2); + + if (i.includes('*')) + throw new Error( + 'Invalid svelte-check --ignore pattern: Only ** at the start or end is supported' + ); + + return (path) => path.includes(i); + } + + if (i.includes('*')) + throw new Error( + 'Invalid svelte-check --ignore pattern: Only ** at the start or end is supported' + ); + + return (path) => path.startsWith(i); + }); +} + async function getDiagnostics( workspaceUri: URI, writer: Writer, @@ -149,10 +153,32 @@ class DiagnosticsWatcher { filePathsToIgnore: string[], ignoreInitialAdd: boolean ) { - watch(`${workspaceUri.fsPath}/**/*.{svelte,d.ts,ts,js,jsx,tsx,mjs,cjs,mts,cts}`, { - ignored: ['node_modules', 'vite.config.{js,ts}.timestamp-*'] - .concat(filePathsToIgnore) - .map((ignore) => path.join(workspaceUri.fsPath, ignore)), + const fileEnding = /\.(svelte|d\.ts|ts|js|jsx|tsx|mjs|cjs|mts|cts)$/; + const viteConfigRegex = /vite\.config\.(js|ts)\.timestamp-/; + const userIgnored = createIgnored(filePathsToIgnore); + const offset = workspaceUri.fsPath.length + 1; + + watch(workspaceUri.fsPath, { + ignored: (path, stats) => { + if ( + path.includes('node_modules') || + path.includes('.git') || + (stats?.isFile() && (!fileEnding.test(path) || viteConfigRegex.test(path))) + ) { + return true; + } + + if (userIgnored.length !== 0) { + path = path.slice(offset); + for (const i of userIgnored) { + if (i(path)) { + return true; + } + } + } + + return false; + }, ignoreInitial: ignoreInitialAdd }) .on('add', (path) => this.updateDocument(path, true)) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f1bc6d8f0..f7d19793f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -31,8 +31,8 @@ importers: specifier: 2.8.4 version: 2.8.4 chokidar: - specifier: ^3.4.1 - version: 3.5.3 + specifier: ^4.0.1 + version: 4.0.1 estree-walker: specifier: ^2.0.1 version: 2.0.2 @@ -113,8 +113,8 @@ importers: specifier: ^0.3.25 version: 0.3.25 chokidar: - specifier: ^3.4.1 - version: 3.5.3 + specifier: ^4.0.1 + version: 4.0.1 fdir: specifier: ^6.2.0 version: 6.2.0 @@ -620,6 +620,10 @@ packages: resolution: {integrity: sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==} engines: {node: '>= 8.10.0'} + chokidar@4.0.1: + resolution: {integrity: sha512-n8enUVCED/KVRQlab1hr3MVpcVMvxtZjmEa956u+4YijlmQED223XMSYj2tLuKvr4jcCTzNNMpQDUer72MMmzA==} + engines: {node: '>= 14.16.0'} + clean-stack@2.2.0: resolution: {integrity: sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==} engines: {node: '>=6'} @@ -1108,6 +1112,10 @@ packages: resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==} engines: {node: '>=8.10.0'} + readdirp@4.0.1: + resolution: {integrity: sha512-GkMg9uOTpIWWKbSsgwb5fA4EavTR+SG/PMPoAY8hkhHfEEY0/vqljY+XHqtDf2cr2IJtoNRDbrrEpZUiZCkYRw==} + engines: {node: '>= 14.16.0'} + require-directory@2.1.1: resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==} engines: {node: '>=0.10.0'} @@ -1684,6 +1692,10 @@ snapshots: optionalDependencies: fsevents: 2.3.3 + chokidar@4.0.1: + dependencies: + readdirp: 4.0.1 + clean-stack@2.2.0: {} cliui@7.0.4: @@ -2162,6 +2174,8 @@ snapshots: dependencies: picomatch: 2.3.1 + readdirp@4.0.1: {} + require-directory@2.1.1: {} resolve@1.22.2: