Skip to content

Commit 37d631f

Browse files
authored
(perf) replace glob with fast-glob (#1151)
Also relax ignore pattern. Should result in faster startup times. #1139
1 parent 8690878 commit 37d631f

File tree

7 files changed

+53
-46
lines changed

7 files changed

+53
-46
lines changed

docs/preprocessors/typescript.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,24 @@ When you provide a library, you also should provide type definitions alongside y
5050
import { SvelteComponentTyped } from 'svelte';
5151

5252
export interface FooProps {
53-
propA: string;
54-
// ...
53+
propA: string;
54+
// ...
5555
}
5656

5757
export interface FooEvents {
58-
click: MouseEvent;
59-
customEvent: CustomEvent<boolean>;
58+
click: MouseEvent;
59+
customEvent: CustomEvent<boolean>;
6060
}
6161

6262
export interface FooSlots {
63-
default: { slotValue: string };
64-
named: { slotValue: string };
63+
default: { slotValue: string };
64+
named: { slotValue: string };
6565
}
6666

6767
export default class Foo extends SvelteComponentTyped<FooProps, FooEvents, FooSlots> {}
6868
```
6969

70-
SvelteKit's `package` command will give you these capabilities - transpiling and creating type definitions - out of the box: https://kit.svelte.dev/docs#packaging
70+
SvelteKit's `package` command will give you these capabilities - transpiling and creating type definitions - out of the box: https://kit.svelte.dev/docs#packaging
7171

7272
## Typing component events
7373

packages/language-server/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"devDependencies": {
3737
"@tsconfig/node12": "^1.0.0",
3838
"@types/estree": "^0.0.42",
39-
"@types/glob": "^7.1.1",
4039
"@types/lodash": "^4.14.116",
4140
"@types/mocha": "^7.0.2",
4241
"@types/node": "^13.9.0",
@@ -51,7 +50,7 @@
5150
"dependencies": {
5251
"chokidar": "^3.4.1",
5352
"estree-walker": "^2.0.1",
54-
"glob": "^7.1.6",
53+
"fast-glob": "^3.2.7",
5554
"lodash": "^4.17.21",
5655
"prettier": "2.3.0",
5756
"prettier-plugin-svelte": "~2.3.0",

packages/language-server/src/lib/documents/configLoader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Logger } from '../../logger';
22
import { CompileOptions } from 'svelte/types/compiler/interfaces';
33
import { PreprocessorGroup } from 'svelte/types/compiler/preprocess/types';
44
import { importSveltePreprocess } from '../../importPackage';
5-
import _glob from 'glob';
5+
import _glob from 'fast-glob';
66
import _path from 'path';
77
import _fs from 'fs';
88
import { pathToFileURL, URL } from 'url';
@@ -80,7 +80,7 @@ export class ConfigLoader {
8080
try {
8181
const pathResults = this.globSync('**/svelte.config.{js,cjs,mjs}', {
8282
cwd: directory,
83-
ignore: 'node_modules/**'
83+
ignore: ['**/node_modules/**']
8484
});
8585
const someConfigIsImmediateFileInDirectory =
8686
pathResults.length > 0 && pathResults.some((res) => !this.path.dirname(res));

packages/language-server/test/lib/documents/configLoader.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('ConfigLoader', () => {
3232

3333
it('should load all config files below and the one inside/above given directory', async () => {
3434
const configLoader = new ConfigLoader(
35-
() => ['svelte.config.js', 'below/svelte.config.js'],
35+
(() => ['svelte.config.js', 'below/svelte.config.js']) as any,
3636
{ existsSync: () => true },
3737
path,
3838
(module: URL) => Promise.resolve({ default: { preprocess: module.toString() } })
@@ -99,14 +99,14 @@ describe('ConfigLoader', () => {
9999
let firstGlobCall = true;
100100
let nrImportCalls = 0;
101101
const configLoader = new ConfigLoader(
102-
() => {
102+
(() => {
103103
if (firstGlobCall) {
104104
firstGlobCall = false;
105105
return ['svelte.config.js'];
106106
} else {
107107
return [];
108108
}
109-
},
109+
}) as any,
110110
{
111111
existsSync: (p) =>
112112
typeof p === 'string' &&

packages/svelte-check/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"dependencies": {
2222
"chalk": "^4.0.0",
2323
"chokidar": "^3.4.1",
24-
"glob": "^7.1.6",
24+
"fast-glob": "^3.2.7",
2525
"import-fresh": "^3.2.1",
2626
"minimist": "^1.2.5",
2727
"sade": "^1.7.4",
@@ -44,7 +44,6 @@
4444
"@rollup/plugin-node-resolve": "^9.0.0",
4545
"@rollup/plugin-replace": "2.3.3",
4646
"@tsconfig/node12": "^1.0.0",
47-
"@types/glob": "^7.1.1",
4847
"@types/minimist": "^1.2.0",
4948
"@types/sade": "^1.7.2",
5049
"rollup": "2.52.7",

packages/svelte-check/src/index.ts

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import { watch } from 'chokidar';
66
import * as fs from 'fs';
7-
import glob from 'glob';
7+
import glob from 'fast-glob';
88
import * as path from 'path';
99
import { SvelteCheck } from 'svelte-language-server';
1010
import { Diagnostic, DiagnosticSeverity } from 'vscode-languageserver-protocol';
@@ -30,37 +30,22 @@ async function openAllDocuments(
3030
filePathsToIgnore: string[],
3131
svelteCheck: SvelteCheck
3232
) {
33-
return new Promise<void>((resolve, reject) => {
34-
glob(
35-
'**/*.svelte',
33+
const files = await glob('**/*.svelte', {
34+
cwd: workspaceUri.fsPath,
35+
ignore: ['node_modules/**'].concat(filePathsToIgnore.map((ignore) => `${ignore}/**`))
36+
});
37+
const absFilePaths = files.map((f) => path.resolve(workspaceUri.fsPath, f));
38+
39+
for (const absFilePath of absFilePaths) {
40+
const text = fs.readFileSync(absFilePath, 'utf-8');
41+
svelteCheck.upsertDocument(
3642
{
37-
cwd: workspaceUri.fsPath,
38-
ignore: ['node_modules/**'].concat(
39-
filePathsToIgnore.map((ignore) => `${ignore}/**`)
40-
)
43+
uri: URI.file(absFilePath).toString(),
44+
text
4145
},
42-
(err, files) => {
43-
if (err) {
44-
reject(err);
45-
return;
46-
}
47-
48-
const absFilePaths = files.map((f) => path.resolve(workspaceUri.fsPath, f));
49-
50-
for (const absFilePath of absFilePaths) {
51-
const text = fs.readFileSync(absFilePath, 'utf-8');
52-
svelteCheck.upsertDocument(
53-
{
54-
uri: URI.file(absFilePath).toString(),
55-
text
56-
},
57-
true
58-
);
59-
}
60-
resolve();
61-
}
46+
true
6247
);
63-
});
48+
}
6449
}
6550

6651
async function getDiagnostics(

yarn.lock

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,17 @@ fast-glob@^3.0.3, fast-glob@^3.1.1:
11511151
micromatch "^4.0.2"
11521152
picomatch "^2.2.1"
11531153

1154+
fast-glob@^3.2.7:
1155+
version "3.2.7"
1156+
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.7.tgz#fd6cb7a2d7e9aa7a7846111e85a196d6b2f766a1"
1157+
integrity sha512-rYGMRwip6lUMvYD3BTScMwT1HtAs2d71SMv66Vrxs0IekGZEjhM0pcMfjQPnknBt2zeCwQMEupiN02ZP4DiT1Q==
1158+
dependencies:
1159+
"@nodelib/fs.stat" "^2.0.2"
1160+
"@nodelib/fs.walk" "^1.2.3"
1161+
glob-parent "^5.1.2"
1162+
merge2 "^1.3.0"
1163+
micromatch "^4.0.4"
1164+
11541165
fast-json-stable-stringify@^2.0.0:
11551166
version "2.1.0"
11561167
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633"
@@ -1255,7 +1266,7 @@ get-caller-file@^2.0.5:
12551266
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e"
12561267
integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==
12571268

1258-
glob-parent@^5.0.0, glob-parent@^5.1.0, glob-parent@~5.1.0, glob-parent@~5.1.2:
1269+
glob-parent@^5.0.0, glob-parent@^5.1.0, glob-parent@^5.1.2, glob-parent@~5.1.0, glob-parent@~5.1.2:
12591270
version "5.1.2"
12601271
resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.2.tgz#869832c58034fe68a4093c17dc15e8340d8401c4"
12611272
integrity sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==
@@ -1724,6 +1735,14 @@ micromatch@^4.0.2:
17241735
braces "^3.0.1"
17251736
picomatch "^2.0.5"
17261737

1738+
micromatch@^4.0.4:
1739+
version "4.0.4"
1740+
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.4.tgz#896d519dfe9db25fce94ceb7a500919bf881ebf9"
1741+
integrity sha512-pRmzw/XUcwXGpD9aI9q/0XOwLNygjETJ8y0ao0wdqprrzDa4YnxLcz7fQRZr8voh8V10kGhABbNcHVk5wHgWwg==
1742+
dependencies:
1743+
braces "^3.0.1"
1744+
picomatch "^2.2.3"
1745+
17271746
min-indent@^1.0.0:
17281747
version "1.0.0"
17291748
resolved "https://registry.yarnpkg.com/min-indent/-/min-indent-1.0.0.tgz#cfc45c37e9ec0d8f0a0ec3dd4ef7f7c3abe39256"
@@ -2036,6 +2055,11 @@ picomatch@^2.0.5, picomatch@^2.2.1, picomatch@^2.2.2:
20362055
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.2.2.tgz#21f333e9b6b8eaff02468f5146ea406d345f4dad"
20372056
integrity sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==
20382057

2058+
picomatch@^2.2.3:
2059+
version "2.3.0"
2060+
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.0.tgz#f1f061de8f6a4bf022892e2d128234fb98302972"
2061+
integrity sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==
2062+
20392063
pify@^2.0.0:
20402064
version "2.3.0"
20412065
resolved "https://registry.yarnpkg.com/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c"

0 commit comments

Comments
 (0)