Skip to content

feat: add support for loading svelte config with .ts or .mts #2804

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 7 additions & 3 deletions packages/language-server/src/lib/documents/configLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ const _dynamicImport = new Function('modulePath', 'return import(modulePath)') a
modulePath: URL
) => Promise<any>;

const configRegex = /\/svelte\.config\.(js|cjs|mjs)$/;
const configRegex = /\/svelte\.config\.(js|ts|cjs|mjs|mts)$/;

/**
* Loads svelte.config.{js,cjs,mjs} files. Provides both a synchronous and asynchronous
* Loads svelte.config.{js,ts,cjs,mjs,mts} files. Provides both a synchronous and asynchronous
* interface to get a config file because snapshots need access to it synchronously.
* This means that another instance (the ts service host on startup) should make
* sure that all config files are loaded before snapshots are retrieved.
Expand Down Expand Up @@ -143,7 +143,11 @@ export class ConfigLoader {
return this.fs.existsSync(path) ? path : undefined;
};
const configPath =
tryFindConfigPath('js') || tryFindConfigPath('cjs') || tryFindConfigPath('mjs');
tryFindConfigPath('js') ||
tryFindConfigPath('ts') ||
tryFindConfigPath('cjs') ||
tryFindConfigPath('mjs') ||
tryFindConfigPath('mts');
if (configPath) {
return configPath;
}
Expand Down
10 changes: 8 additions & 2 deletions packages/svelte-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ import { addFindComponentReferencesListener } from './typescript/findComponentRe
import { addFindFileReferencesListener } from './typescript/findFileReferences';
import { setupSvelteKit } from './sveltekit';
import { resolveCodeLensMiddleware } from './middlewares';

import { versions } from 'node:process';
const [node_major, node_minor] = (versions?.node ?? '0.0.0-unknown').split('.', 3).map(Number);
const add_experimental_strip_types_flag =
(node_major === 22 && node_minor > 5) || // added behind flag in 22.6.0
(node_major === 23 && node_minor < 6); // unflagged in 23.6
namespace TagCloseRequest {
export const type: RequestType<TextDocumentPositionParams, string, any> = new RequestType(
'html/tag'
Expand Down Expand Up @@ -123,7 +127,9 @@ export function activateSvelteLanguageServer(context: ExtensionContext) {
// Add --experimental-modules flag for people using node 12 < version < 12.17
// Remove this in mid 2022 and bump vs code minimum required version to 1.55
const runExecArgv: string[] = ['--experimental-modules'];

if (add_experimental_strip_types_flag) {
runExecArgv.push('--experimental-strip-types');
}
const runtimeArgs = runtimeConfig.get<string[]>('runtime-args');
if (runtimeArgs !== undefined) {
runExecArgv.push(...runtimeArgs);
Expand Down