Skip to content

Commit

Permalink
feat: add jiti for dynamic imports in svelte because JSR converts the…
Browse files Browse the repository at this point in the history
…m to local import....

This commit introduces 'jiti' for handling dynamic imports in the
svelte compiler. This change is reflected in the 'svelte.ts' file
where 'jiti' is imported and used for importing the svelte compiler.
The 'jiti' package is also added to the package.json dependencies.
  • Loading branch information
ryoppippi committed Jul 14, 2024
1 parent 8e1c6db commit 00ebef1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions packages/unplugin-typia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
"eslint": "^9.5.0",
"eslint-plugin-format": "^0.1.2",
"find-cache-dir": "^5.0.0",
"jiti": "^1.21.6",
"pkg-types": "^1.1.1",
"rollup": "^4.6.1",
"type-fest": "^4.19.0",
Expand Down
5 changes: 4 additions & 1 deletion packages/unplugin-typia/src/core/languages/svelte.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import createJiti from 'jiti';
import type { Data, ID, Source } from '../types.js';
import { wrap } from '../types.js';

const jiti = (createJiti?.default ?? createJiti)(import.meta.url);

/**
* Check if a file is a Svelte file.
*/
Expand All @@ -23,7 +26,7 @@ export async function preprocess(
{ source, id, transform }:
{ source: Source; id: ID; transform: TransformFunction },
): Promise<{ code: Data }> {
const { preprocess: sveltePreprocess } = await import('svelte/compiler');
const { preprocess: sveltePreprocess } = await jiti.import('svelte/compiler', {}) as { preprocess: typeof import('svelte/compiler').preprocess };
const { code } = await sveltePreprocess(source, {
script: async ({ content, filename, attributes }) => {
if (filename == null) {
Expand Down

0 comments on commit 00ebef1

Please sign in to comment.