Skip to content

Commit

Permalink
fix: autoAddExts usage with type imports
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Nov 21, 2024
1 parent d5fb870 commit 95ccd8f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
11 changes: 9 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ export const IsolatedDecl: UnpluginInstance<Options | undefined, false> =
const resolved = await resolve(context, i.source.value, id)
if (!resolved || resolved.external) continue
if (resolved.id.endsWith('.ts') || resolved.id.endsWith('.tsx')) {
i.source.value = `${i.source.value}.js`
i.source.value = `${((i.source as any).originalValue =
i.source.value)}.js`
s.overwrite(i.source.start + 1, i.source.end - 1, i.source.value)
}
}
Expand Down Expand Up @@ -194,7 +195,13 @@ export const IsolatedDecl: UnpluginInstance<Options | undefined, false> =
)
for (const i of typeImports) {
if (!i.source) continue
const resolved = (await resolve(context, i.source.value, id))?.id
const resolved = (
await resolve(
context,
(i.source as any).originalValue || i.source.value,
id,
)
)?.id
if (resolved && filter(resolved) && !outputFiles[stripExt(resolved)]) {
let source: string
try {
Expand Down
4 changes: 2 additions & 2 deletions tests/__snapshots__/rolldown.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ export { c, hello, num };
export declare function Component(): React.JSX.Element;
// temp/main.d.ts
import { type Num } from "./types";
import { type Num } from "./types.js";
export type Str = string;
export declare function hello(s: Str): Str;
export declare let c: React.JSX.Element;
export declare let num: Num;
// temp/types.d.ts
import type { Num2 } from "./types2";
import type { Num2 } from "./types2.js";
export type Num = Num2;
// temp/types2.d.ts
Expand Down
4 changes: 2 additions & 2 deletions tests/__snapshots__/rollup.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ export { c, hello, num };
export declare function Component(): React.JSX.Element;
// temp/main.d.ts
import { type Num } from './types';
import { type Num } from './types.js';
export type Str = string;
export declare function hello(s: Str): Str;
export declare let c: React.JSX.Element;
export declare let num: Num;
// temp/types.d.ts
import type { Num2 } from './types2';
import type { Num2 } from './types2.js';
export type Num = Num2;
// temp/types2.d.ts
Expand Down
1 change: 1 addition & 0 deletions tests/rolldown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ test('rolldown', async () => {
UnpluginIsolatedDecl({
extraOutdir: 'temp',
transformer: 'oxc',
autoAddExts: true,
}),
],
logLevel: 'silent',
Expand Down
1 change: 1 addition & 0 deletions tests/rollup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('rollup', () => {
plugins: [
UnpluginIsolatedDecl({
extraOutdir: 'temp',
autoAddExts: true,
}),
esbuild(),
],
Expand Down

0 comments on commit 95ccd8f

Please sign in to comment.