Skip to content

Commit

Permalink
(fix) more plugin startup checks (sveltejs#1159)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dummdidumm authored Sep 1, 2021
1 parent d2cea3b commit 79bbde7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/typescript-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@ function init(modules: { typescript: typeof ts }) {
(!compilerOptions.jsxFactory || compilerOptions.jsxFactory.startsWith('svelte')) &&
!compilerOptions.jsxFragmentFactory &&
!compilerOptions.jsxImportSource;
return isNoJsxProject;
try {
const isSvelteProject =
typeof compilerOptions.configFilePath !== 'string' ||
require.resolve('svelte', { paths: [compilerOptions.configFilePath] });
return isNoJsxProject && isSvelteProject;
} catch (e) {
// If require.resolve fails, we end up here
return false;
}
}

return { create, getExternalFiles };
Expand Down

0 comments on commit 79bbde7

Please sign in to comment.