Skip to content

Commit fc2144b

Browse files
authored
chore: upgrade to chokidar 4 (#2502)
Also remove long-obsolete sapper handling
1 parent 7c76ec5 commit fc2144b

File tree

5 files changed

+72
-37
lines changed

5 files changed

+72
-37
lines changed

packages/language-server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"dependencies": {
5353
"@jridgewell/trace-mapping": "^0.3.25",
5454
"@vscode/emmet-helper": "2.8.4",
55-
"chokidar": "^3.4.1",
55+
"chokidar": "^4.0.1",
5656
"estree-walker": "^2.0.1",
5757
"fdir": "^6.2.0",
5858
"lodash": "^4.17.21",

packages/language-server/src/lib/FallbackWatcher.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@ export class FallbackWatcher {
2525
this.watcher = watch(
2626
workspacePaths.map((workspacePath) => join(workspacePath, recursivePatterns)),
2727
{
28-
ignored: (path: string) =>
29-
gitOrNodeModules.test(path) &&
30-
// Handle Sapper's alias mapping
31-
!path.includes('src/node_modules') &&
32-
!path.includes('src\\node_modules'),
33-
28+
ignored: gitOrNodeModules,
3429
// typescript would scan the project files on init.
3530
// We only need to know what got updated.
3631
ignoreInitial: true,

packages/svelte-check/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
},
2828
"dependencies": {
2929
"@jridgewell/trace-mapping": "^0.3.25",
30-
"chokidar": "^3.4.1",
30+
"chokidar": "^4.0.1",
3131
"fdir": "^6.2.0",
3232
"picocolors": "^1.0.0",
3333
"sade": "^1.7.4"

packages/svelte-check/src/index.ts

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,7 @@ async function openAllDocuments(
3232
) {
3333
const offset = workspaceUri.fsPath.length + 1;
3434
// We support a very limited subset of glob patterns: You can only have ** at the end or the start
35-
const ignored: Array<(path: string) => boolean> = filePathsToIgnore.map((i) => {
36-
if (i.endsWith('**')) i = i.slice(0, -2);
37-
38-
if (i.startsWith('**')) {
39-
i = i.slice(2);
40-
41-
if (i.includes('*'))
42-
throw new Error(
43-
'Invalid svelte-check --ignore pattern: Only ** at the start or end is supported'
44-
);
45-
46-
return (path) => path.includes(i);
47-
}
48-
49-
if (i.includes('*'))
50-
throw new Error(
51-
'Invalid svelte-check --ignore pattern: Only ** at the start or end is supported'
52-
);
53-
54-
return (path) => path.startsWith(i);
55-
});
35+
const ignored = createIgnored(filePathsToIgnore);
5636
const isIgnored = (path: string) => {
5737
path = path.slice(offset);
5838
for (const i of ignored) {
@@ -84,6 +64,30 @@ async function openAllDocuments(
8464
}
8565
}
8666

67+
function createIgnored(filePathsToIgnore: string[]): Array<(path: string) => boolean> {
68+
return filePathsToIgnore.map((i) => {
69+
if (i.endsWith('**')) i = i.slice(0, -2);
70+
71+
if (i.startsWith('**')) {
72+
i = i.slice(2);
73+
74+
if (i.includes('*'))
75+
throw new Error(
76+
'Invalid svelte-check --ignore pattern: Only ** at the start or end is supported'
77+
);
78+
79+
return (path) => path.includes(i);
80+
}
81+
82+
if (i.includes('*'))
83+
throw new Error(
84+
'Invalid svelte-check --ignore pattern: Only ** at the start or end is supported'
85+
);
86+
87+
return (path) => path.startsWith(i);
88+
});
89+
}
90+
8791
async function getDiagnostics(
8892
workspaceUri: URI,
8993
writer: Writer,
@@ -149,10 +153,32 @@ class DiagnosticsWatcher {
149153
filePathsToIgnore: string[],
150154
ignoreInitialAdd: boolean
151155
) {
152-
watch(`${workspaceUri.fsPath}/**/*.{svelte,d.ts,ts,js,jsx,tsx,mjs,cjs,mts,cts}`, {
153-
ignored: ['node_modules', 'vite.config.{js,ts}.timestamp-*']
154-
.concat(filePathsToIgnore)
155-
.map((ignore) => path.join(workspaceUri.fsPath, ignore)),
156+
const fileEnding = /\.(svelte|d\.ts|ts|js|jsx|tsx|mjs|cjs|mts|cts)$/;
157+
const viteConfigRegex = /vite\.config\.(js|ts)\.timestamp-/;
158+
const userIgnored = createIgnored(filePathsToIgnore);
159+
const offset = workspaceUri.fsPath.length + 1;
160+
161+
watch(workspaceUri.fsPath, {
162+
ignored: (path, stats) => {
163+
if (
164+
path.includes('node_modules') ||
165+
path.includes('.git') ||
166+
(stats?.isFile() && (!fileEnding.test(path) || viteConfigRegex.test(path)))
167+
) {
168+
return true;
169+
}
170+
171+
if (userIgnored.length !== 0) {
172+
path = path.slice(offset);
173+
for (const i of userIgnored) {
174+
if (i(path)) {
175+
return true;
176+
}
177+
}
178+
}
179+
180+
return false;
181+
},
156182
ignoreInitial: ignoreInitialAdd
157183
})
158184
.on('add', (path) => this.updateDocument(path, true))

pnpm-lock.yaml

Lines changed: 18 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)