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

fix: adjust for moved compiler file in Svelte 5 #2327

Merged
merged 1 commit into from
Apr 1, 2024
Merged
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
14 changes: 13 additions & 1 deletion packages/language-server/src/importPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,19 @@ export function importSvelte(fromPath: string): typeof svelte {
const pkg = getPackageInfo('svelte', fromPath);
const main = resolve(pkg.path, 'compiler');
Logger.debug('Using Svelte v' + pkg.version.full, 'from', main);
return dynamicRequire(main + (pkg.version.major >= 4 ? '.cjs' : ''));
if (pkg.version.major === 4) {
return dynamicRequire(main + '.cjs');
} else if (pkg.version.major === 5) {
// TODO remove once Svelte 5 is released
// (we switched from compiler.cjs to compiler/index.js at some point)
try {
return dynamicRequire(main);
} catch (e) {
return dynamicRequire(main + '.cjs');
}
} else {
return dynamicRequire(main);
}
}

export function importSveltePreprocess(fromPath: string): typeof sveltePreprocess {
Expand Down
Loading