Skip to content

Commit 3e8446b

Browse files
committed
fix: circular dep
1 parent e8fd672 commit 3e8446b

File tree

6 files changed

+20
-3
lines changed

6 files changed

+20
-3
lines changed

src/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ export const IsolatedDecl: UnpluginInstance<Options | undefined, false> =
2525
const filter = createFilter(options.include, options.exclude)
2626

2727
const outputFiles: Record<string, string> = {}
28+
function stripExt(filename: string) {
29+
return filename.replace(/\.(.?)[jt]s$/, '')
30+
}
2831
function addOutput(filename: string, source: string) {
29-
outputFiles[filename.replace(/\.(.?)[jt]s$/, '')] = source
32+
outputFiles[stripExt(filename)] = source
3033
}
3134

3235
const rollup: Partial<Plugin> = {
@@ -200,14 +203,14 @@ export const IsolatedDecl: UnpluginInstance<Options | undefined, false> =
200203
}
201204
for (const i of typeImports) {
202205
const resolved = await resolve(i.source.value, id)
203-
if (resolved) {
206+
if (resolved && filter(resolved) && !outputFiles[stripExt(resolved)]) {
204207
let source: string
205208
try {
206209
source = await readFile(resolved, 'utf8')
207210
} catch {
208211
continue
209212
}
210-
transform.call(this, source, resolved)
213+
await transform.call(this, source, resolved)
211214
}
212215
}
213216
}

tests/__snapshots__/esbuild.test.ts.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export declare let num: Num;
2121
",
2222
"// types.d.ts
2323
export type Num = number;
24+
",
25+
"// types2.d.ts
26+
export type Num2 = number;
2427
",
2528
]
2629
`;
@@ -43,6 +46,8 @@ export {
4346
};
4447
",
4548
"export type Num = number;
49+
",
50+
"export type Num2 = number;
4651
",
4752
]
4853
`;

tests/__snapshots__/rolldown.test.ts.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ let num = 1;
2020
export { hello, num };",
2121
"// types.d.ts
2222
export type Num = number;
23+
",
24+
"// types2.d.ts
25+
export type Num2 = number;
2326
",
2427
]
2528
`;

tests/__snapshots__/rollup.test.ts.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ export declare let num: Num;
1818
",
1919
"// types.d.ts
2020
export type Num = number;
21+
",
22+
"// types2.d.ts
23+
export type Num2 = number;
2124
",
2225
]
2326
`;

tests/fixtures/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
import type { Num2 } from './types2'
12
export type Num = number

tests/fixtures/types2.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import type { Num } from './types'
2+
export type Num2 = number

0 commit comments

Comments
 (0)