Skip to content

Commit 79bbde7

Browse files
authored
(fix) more plugin startup checks (#1159)
Check if the Svelte package can be resolved which hints at a Svelte project in order to determine if the typescript plugin should be loaded
1 parent d2cea3b commit 79bbde7

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

packages/typescript-plugin/src/index.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,15 @@ function init(modules: { typescript: typeof ts }) {
6666
(!compilerOptions.jsxFactory || compilerOptions.jsxFactory.startsWith('svelte')) &&
6767
!compilerOptions.jsxFragmentFactory &&
6868
!compilerOptions.jsxImportSource;
69-
return isNoJsxProject;
69+
try {
70+
const isSvelteProject =
71+
typeof compilerOptions.configFilePath !== 'string' ||
72+
require.resolve('svelte', { paths: [compilerOptions.configFilePath] });
73+
return isNoJsxProject && isSvelteProject;
74+
} catch (e) {
75+
// If require.resolve fails, we end up here
76+
return false;
77+
}
7078
}
7179

7280
return { create, getExternalFiles };

0 commit comments

Comments
 (0)