Skip to content

Commit

Permalink
chore: optimize svelte-check bundle size
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonlyu123 committed Oct 24, 2024
1 parent 156bd7d commit 95279c0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
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
48 changes: 35 additions & 13 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,11 +96,9 @@ export class SvelteCheck {
}
);
this.pluginHost.register(
new TypeScriptPlugin(
this.configManager,
new SvelteCheckTypeScriptPlugin(
this.lsAndTSDocResolver,
workspaceUris,
this.docManager
this.configManager,
)
);
}
Expand Down Expand Up @@ -354,3 +353,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);
}
}
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

0 comments on commit 95279c0

Please sign in to comment.