Skip to content

Commit

Permalink
fix: adjust for moved compiler file in Svelte 5 (#2327)
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm authored Apr 1, 2024
1 parent 4abe9b3 commit 3ea9c01
Showing 1 changed file with 13 additions and 1 deletion.
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

0 comments on commit 3ea9c01

Please sign in to comment.