From a55475f277c03d668213cc9d4edd50e1b7d35334 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Thu, 12 Sep 2024 19:54:54 -0700 Subject: [PATCH 1/4] chore: upgrade to chokidar 4 --- packages/language-server/package.json | 2 +- packages/svelte-check/package.json | 2 +- packages/svelte-check/src/index.ts | 13 +++++++++---- pnpm-lock.yaml | 22 ++++++++++++++++++---- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/packages/language-server/package.json b/packages/language-server/package.json index f3702c47b..e543b7013 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.0", "estree-walker": "^2.0.1", "fdir": "^6.2.0", "lodash": "^4.17.21", diff --git a/packages/svelte-check/package.json b/packages/svelte-check/package.json index 634a029f6..5ab1bd504 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.0", "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..27a432ca0 100644 --- a/packages/svelte-check/src/index.ts +++ b/packages/svelte-check/src/index.ts @@ -149,15 +149,20 @@ class DiagnosticsWatcher { filePathsToIgnore: string[], ignoreInitialAdd: boolean ) { - watch(`${workspaceUri.fsPath}/**/*.{svelte,d.ts,ts,js,jsx,tsx,mjs,cjs,mts,cts}`, { + const ifMatching = (path: string, f: Function) => { + if (/\.(svelte|d\.ts|ts|js|jsx|tsx|mjs|cjs|mts|cts)$/.test(path)) { + f(); + } + }; + watch(workspaceUri.fsPath, { ignored: ['node_modules', 'vite.config.{js,ts}.timestamp-*'] .concat(filePathsToIgnore) .map((ignore) => path.join(workspaceUri.fsPath, ignore)), ignoreInitial: ignoreInitialAdd }) - .on('add', (path) => this.updateDocument(path, true)) - .on('unlink', (path) => this.removeDocument(path)) - .on('change', (path) => this.updateDocument(path, false)); + .on('add', (path) => ifMatching(path, () => this.updateDocument(path, true))) + .on('unlink', (path) => ifMatching(path, () => this.removeDocument(path))) + .on('change', (path) => ifMatching(path, () => this.updateDocument(path, false))); if (ignoreInitialAdd) { this.scheduleDiagnostics(); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f1bc6d8f0..2c78eb74e 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.0 + version: 4.0.0 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.0 + version: 4.0.0 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.0: + resolution: {integrity: sha512-mxIojEAQcuEvT/lyXq+jf/3cO/KoA6z4CeNDGGevTybECPOMFCnQy3OPahluUkbqgPNGw5Bi78UC7Po6Lhy+NA==} + 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.0: + 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: From a4979955459847c49ca24c7c4066315de90211a3 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Mon, 23 Sep 2024 11:27:17 -0700 Subject: [PATCH 2/4] chokidar 4.0.1 --- packages/language-server/package.json | 2 +- packages/svelte-check/package.json | 2 +- pnpm-lock.yaml | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/language-server/package.json b/packages/language-server/package.json index e543b7013..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": "^4.0.0", + "chokidar": "^4.0.1", "estree-walker": "^2.0.1", "fdir": "^6.2.0", "lodash": "^4.17.21", diff --git a/packages/svelte-check/package.json b/packages/svelte-check/package.json index 5ab1bd504..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": "^4.0.0", + "chokidar": "^4.0.1", "fdir": "^6.2.0", "picocolors": "^1.0.0", "sade": "^1.7.4" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2c78eb74e..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: ^4.0.0 - version: 4.0.0 + 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: ^4.0.0 - version: 4.0.0 + specifier: ^4.0.1 + version: 4.0.1 fdir: specifier: ^6.2.0 version: 6.2.0 @@ -620,8 +620,8 @@ packages: resolution: {integrity: sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==} engines: {node: '>= 8.10.0'} - chokidar@4.0.0: - resolution: {integrity: sha512-mxIojEAQcuEvT/lyXq+jf/3cO/KoA6z4CeNDGGevTybECPOMFCnQy3OPahluUkbqgPNGw5Bi78UC7Po6Lhy+NA==} + chokidar@4.0.1: + resolution: {integrity: sha512-n8enUVCED/KVRQlab1hr3MVpcVMvxtZjmEa956u+4YijlmQED223XMSYj2tLuKvr4jcCTzNNMpQDUer72MMmzA==} engines: {node: '>= 14.16.0'} clean-stack@2.2.0: @@ -1692,7 +1692,7 @@ snapshots: optionalDependencies: fsevents: 2.3.3 - chokidar@4.0.0: + chokidar@4.0.1: dependencies: readdirp: 4.0.1 From 610982d4489de73888f83eaf4bce6c6ee74ff965 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Mon, 23 Sep 2024 12:27:06 -0700 Subject: [PATCH 3/4] format --- packages/svelte-check/src/index.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/svelte-check/src/index.ts b/packages/svelte-check/src/index.ts index 27a432ca0..94fe2c59a 100644 --- a/packages/svelte-check/src/index.ts +++ b/packages/svelte-check/src/index.ts @@ -149,20 +149,19 @@ class DiagnosticsWatcher { filePathsToIgnore: string[], ignoreInitialAdd: boolean ) { - const ifMatching = (path: string, f: Function) => { - if (/\.(svelte|d\.ts|ts|js|jsx|tsx|mjs|cjs|mts|cts)$/.test(path)) { - f(); - } - }; watch(workspaceUri.fsPath, { - ignored: ['node_modules', 'vite.config.{js,ts}.timestamp-*'] + ignored: [ + 'node_modules', + 'vite.config.{js,ts}.timestamp-*', + (path) => !/\.(svelte|d\.ts|ts|js|jsx|tsx|mjs|cjs|mts|cts)$/.test(path) + ] .concat(filePathsToIgnore) .map((ignore) => path.join(workspaceUri.fsPath, ignore)), ignoreInitial: ignoreInitialAdd }) - .on('add', (path) => ifMatching(path, () => this.updateDocument(path, true))) - .on('unlink', (path) => ifMatching(path, () => this.removeDocument(path))) - .on('change', (path) => ifMatching(path, () => this.updateDocument(path, false))); + .on('add', (path) => this.updateDocument(path, true)) + .on('unlink', (path) => this.removeDocument(path)) + .on('change', (path) => this.updateDocument(path, false)); if (ignoreInitialAdd) { this.scheduleDiagnostics(); From c1184f6fc018ee1da923b0868ebe244f25417bc5 Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Thu, 26 Sep 2024 12:28:46 +0200 Subject: [PATCH 4/4] cleanup + fix --- .../src/lib/FallbackWatcher.ts | 7 +- packages/svelte-check/src/index.ts | 78 ++++++++++++------- 2 files changed, 51 insertions(+), 34 deletions(-) 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/src/index.ts b/packages/svelte-check/src/index.ts index 94fe2c59a..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,14 +153,32 @@ class DiagnosticsWatcher { filePathsToIgnore: string[], ignoreInitialAdd: boolean ) { + 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: [ - 'node_modules', - 'vite.config.{js,ts}.timestamp-*', - (path) => !/\.(svelte|d\.ts|ts|js|jsx|tsx|mjs|cjs|mts|cts)$/.test(path) - ] - .concat(filePathsToIgnore) - .map((ignore) => path.join(workspaceUri.fsPath, ignore)), + 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))