Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: optimize svelte-check bundle size #2544

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/language-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"exports": {
"./package.json": "./package.json",
".": "./dist/src/index.js",
"./bin/server.js": "./bin/server.js"
"./bin/server.js": "./bin/server.js",
"./svelte-check": "./dist/src/svelte-check.js"
},
"scripts": {
"test": "cross-env TS_NODE_TRANSPILE_ONLY=true mocha --require ts-node/register \"test/**/*.test.ts\"",
Expand Down
49 changes: 34 additions & 15 deletions packages/language-server/src/svelte-check.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import { groupBy } from 'lodash';
import { isAbsolute } from 'path';
import ts from 'typescript';
import { Diagnostic, Position, Range } from 'vscode-languageserver';
import { WorkspaceFolder } from 'vscode-languageserver-protocol';
import { TextDocumentContentChangeEvent, WorkspaceFolder } from 'vscode-languageserver-protocol';
import { Document, DocumentManager } from './lib/documents';
import { Logger } from './logger';
import { LSConfigManager } from './ls-config';
import {
CSSPlugin,
LSAndTSDocResolver,
PluginHost,
SveltePlugin,
TypeScriptPlugin
} from './plugins';
import { Plugin } from './plugins';
import { CSSPlugin } from './plugins/css/CSSPlugin';
import { FileSystemProvider } from './plugins/css/FileSystemProvider';
import { createLanguageServices } from './plugins/css/service';
import { PluginHost } from './plugins/PluginHost';
import { SveltePlugin } from './plugins/svelte/SveltePlugin';
import { JSOrTSDocumentSnapshot } from './plugins/typescript/DocumentSnapshot';
import { DiagnosticsProviderImpl } from './plugins/typescript/features/DiagnosticsProvider';
import { isInGeneratedCode } from './plugins/typescript/features/utils';
import { LSAndTSDocResolver } from './plugins/typescript/LSAndTSDocResolver';
import { convertRange, getDiagnosticTag, mapSeverity } from './plugins/typescript/utils';
import { pathToUrl, urlToPath } from './utils';
import { groupBy } from 'lodash';

export { offsetAt } from './lib/documents';

export type SvelteCheckDiagnosticSource = 'js' | 'css' | 'svelte';

Expand Down Expand Up @@ -95,12 +96,7 @@ export class SvelteCheck {
}
);
this.pluginHost.register(
new TypeScriptPlugin(
this.configManager,
this.lsAndTSDocResolver,
workspaceUris,
this.docManager
)
new SvelteCheckTypeScriptPlugin(this.lsAndTSDocResolver, this.configManager)
);
}

Expand Down Expand Up @@ -354,3 +350,26 @@ export class SvelteCheck {
return this.lsAndTSDocResolver.getTSService(tsconfigPath);
}
}

export class SvelteCheckTypeScriptPlugin implements Plugin {
__name = 'ts';

constructor(lsAndTSDocResolver: LSAndTSDocResolver, lsConfigManager: LSConfigManager) {
this.lsAndTsDocResolver = lsAndTSDocResolver;
this.diagnosticsProvider = new DiagnosticsProviderImpl(lsAndTSDocResolver, lsConfigManager);
}

private readonly diagnosticsProvider: DiagnosticsProviderImpl;
private readonly lsAndTsDocResolver: LSAndTSDocResolver;

getDiagnostics(document: Document): Promise<Diagnostic[]> {
return this.diagnosticsProvider.getDiagnostics(document);
}

async updateTsOrJsFile(
fileName: string,
changes: TextDocumentContentChangeEvent[]
): Promise<void> {
await this.lsAndTsDocResolver.updateExistingTsOrJsFile(fileName, changes);
}
}
6 changes: 3 additions & 3 deletions packages/svelte-check/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
"svelte": "^4.2.19",
"svelte-language-server": "workspace:*",
"typescript": "^5.5.2",
"vscode-languageserver": "8.0.2",
"vscode-languageserver-protocol": "3.17.2",
"vscode-languageserver-types": "3.17.2",
"vscode-languageserver": "9.0.1",
"vscode-languageserver-protocol": "3.17.5",
"vscode-languageserver-types": "3.17.5",
"vscode-uri": "~3.0.0"
}
}
2 changes: 1 addition & 1 deletion packages/svelte-check/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { watch } from 'chokidar';
import * as fs from 'fs';
import { fdir } from 'fdir';
import * as path from 'path';
import { SvelteCheck, SvelteCheckOptions } from 'svelte-language-server';
import { SvelteCheck, SvelteCheckOptions } from 'svelte-language-server/svelte-check';
import { Diagnostic, DiagnosticSeverity } from 'vscode-languageserver-protocol';
import { URI } from 'vscode-uri';
import { parseOptions, SvelteCheckCliOptions } from './options';
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte-check/src/writers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import pc from 'picocolors';
import { sep } from 'path';
import { Writable } from 'stream';
import { Diagnostic, DiagnosticSeverity } from 'vscode-languageserver-protocol';
import { offsetAt } from 'svelte-language-server';
import { offsetAt } from 'svelte-language-server/svelte-check';

export interface Writer {
start: (workspaceDir: string) => void;
Expand Down
39 changes: 6 additions & 33 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.