Skip to content

Commit

Permalink
(perf) replace glob with fast-glob
Browse files Browse the repository at this point in the history
Also relax ignore pattern. Should result in faster startup times.
sveltejs#1139
  • Loading branch information
Simon Holthausen committed Aug 30, 2021
1 parent 8690878 commit eb78046
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 36 deletions.
3 changes: 1 addition & 2 deletions packages/language-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"devDependencies": {
"@tsconfig/node12": "^1.0.0",
"@types/estree": "^0.0.42",
"@types/glob": "^7.1.1",
"@types/lodash": "^4.14.116",
"@types/mocha": "^7.0.2",
"@types/node": "^13.9.0",
Expand All @@ -51,7 +50,7 @@
"dependencies": {
"chokidar": "^3.4.1",
"estree-walker": "^2.0.1",
"glob": "^7.1.6",
"fast-glob": "^3.2.7",
"lodash": "^4.17.21",
"prettier": "2.3.0",
"prettier-plugin-svelte": "~2.3.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/language-server/src/lib/documents/configLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Logger } from '../../logger';
import { CompileOptions } from 'svelte/types/compiler/interfaces';
import { PreprocessorGroup } from 'svelte/types/compiler/preprocess/types';
import { importSveltePreprocess } from '../../importPackage';
import _glob from 'glob';
import _glob from 'fast-glob';
import _path from 'path';
import _fs from 'fs';
import { pathToFileURL, URL } from 'url';
Expand Down Expand Up @@ -80,7 +80,7 @@ export class ConfigLoader {
try {
const pathResults = this.globSync('**/svelte.config.{js,cjs,mjs}', {
cwd: directory,
ignore: 'node_modules/**'
ignore: ['**/node_modules/**']
});
const someConfigIsImmediateFileInDirectory =
pathResults.length > 0 && pathResults.some((res) => !this.path.dirname(res));
Expand Down
3 changes: 1 addition & 2 deletions packages/svelte-check/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dependencies": {
"chalk": "^4.0.0",
"chokidar": "^3.4.1",
"glob": "^7.1.6",
"fast-glob": "^3.2.7",
"import-fresh": "^3.2.1",
"minimist": "^1.2.5",
"sade": "^1.7.4",
Expand All @@ -44,7 +44,6 @@
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-replace": "2.3.3",
"@tsconfig/node12": "^1.0.0",
"@types/glob": "^7.1.1",
"@types/minimist": "^1.2.0",
"@types/sade": "^1.7.2",
"rollup": "2.52.7",
Expand Down
43 changes: 14 additions & 29 deletions packages/svelte-check/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { watch } from 'chokidar';
import * as fs from 'fs';
import glob from 'glob';
import glob from 'fast-glob';
import * as path from 'path';
import { SvelteCheck } from 'svelte-language-server';
import { Diagnostic, DiagnosticSeverity } from 'vscode-languageserver-protocol';
Expand All @@ -30,37 +30,22 @@ async function openAllDocuments(
filePathsToIgnore: string[],
svelteCheck: SvelteCheck
) {
return new Promise<void>((resolve, reject) => {
glob(
'**/*.svelte',
const files = await glob('**/*.svelte', {
cwd: workspaceUri.fsPath,
ignore: ['node_modules/**'].concat(filePathsToIgnore.map((ignore) => `${ignore}/**`))
});
const absFilePaths = files.map((f) => path.resolve(workspaceUri.fsPath, f));

for (const absFilePath of absFilePaths) {
const text = fs.readFileSync(absFilePath, 'utf-8');
svelteCheck.upsertDocument(
{
cwd: workspaceUri.fsPath,
ignore: ['node_modules/**'].concat(
filePathsToIgnore.map((ignore) => `${ignore}/**`)
)
uri: URI.file(absFilePath).toString(),
text
},
(err, files) => {
if (err) {
reject(err);
return;
}

const absFilePaths = files.map((f) => path.resolve(workspaceUri.fsPath, f));

for (const absFilePath of absFilePaths) {
const text = fs.readFileSync(absFilePath, 'utf-8');
svelteCheck.upsertDocument(
{
uri: URI.file(absFilePath).toString(),
text
},
true
);
}
resolve();
}
true
);
});
}
}

async function getDiagnostics(
Expand Down
26 changes: 25 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,17 @@ fast-glob@^3.0.3, fast-glob@^3.1.1:
micromatch "^4.0.2"
picomatch "^2.2.1"

fast-glob@^3.2.7:
version "3.2.7"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.7.tgz#fd6cb7a2d7e9aa7a7846111e85a196d6b2f766a1"
integrity sha512-rYGMRwip6lUMvYD3BTScMwT1HtAs2d71SMv66Vrxs0IekGZEjhM0pcMfjQPnknBt2zeCwQMEupiN02ZP4DiT1Q==
dependencies:
"@nodelib/fs.stat" "^2.0.2"
"@nodelib/fs.walk" "^1.2.3"
glob-parent "^5.1.2"
merge2 "^1.3.0"
micromatch "^4.0.4"

fast-json-stable-stringify@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633"
Expand Down Expand Up @@ -1255,7 +1266,7 @@ get-caller-file@^2.0.5:
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e"
integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==

glob-parent@^5.0.0, glob-parent@^5.1.0, glob-parent@~5.1.0, glob-parent@~5.1.2:
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:
version "5.1.2"
resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.2.tgz#869832c58034fe68a4093c17dc15e8340d8401c4"
integrity sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==
Expand Down Expand Up @@ -1724,6 +1735,14 @@ micromatch@^4.0.2:
braces "^3.0.1"
picomatch "^2.0.5"

micromatch@^4.0.4:
version "4.0.4"
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.4.tgz#896d519dfe9db25fce94ceb7a500919bf881ebf9"
integrity sha512-pRmzw/XUcwXGpD9aI9q/0XOwLNygjETJ8y0ao0wdqprrzDa4YnxLcz7fQRZr8voh8V10kGhABbNcHVk5wHgWwg==
dependencies:
braces "^3.0.1"
picomatch "^2.2.3"

min-indent@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/min-indent/-/min-indent-1.0.0.tgz#cfc45c37e9ec0d8f0a0ec3dd4ef7f7c3abe39256"
Expand Down Expand Up @@ -2036,6 +2055,11 @@ picomatch@^2.0.5, picomatch@^2.2.1, picomatch@^2.2.2:
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.2.2.tgz#21f333e9b6b8eaff02468f5146ea406d345f4dad"
integrity sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==

picomatch@^2.2.3:
version "2.3.0"
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.0.tgz#f1f061de8f6a4bf022892e2d128234fb98302972"
integrity sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==

pify@^2.0.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c"
Expand Down

0 comments on commit eb78046

Please sign in to comment.