Skip to content

Commit 190a3e5

Browse files
committed
fix: revert #110
1 parent 0a53bc9 commit 190a3e5

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

src/resolver.ts

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,59 +5,27 @@ import {
55
filename_to_dts,
66
RE_CSS,
77
RE_DTS,
8-
RE_JS,
98
RE_NODE_MODULES,
109
RE_TS,
1110
RE_VUE,
1211
} from './filename.ts'
1312
import type { OptionsResolved } from './options.ts'
1413
import type { Plugin, ResolvedId } from 'rolldown'
1514

15+
function isSourceFile(id: string) {
16+
return RE_TS.test(id) || RE_VUE.test(id)
17+
}
18+
1619
export function createDtsResolvePlugin({
1720
tsconfig,
1821
resolve,
1922
}: Pick<OptionsResolved, 'tsconfig' | 'resolve'>): Plugin {
20-
const isSourceFile = (p: string) =>
21-
RE_TS.test(p) || RE_JS.test(p) || RE_VUE.test(p)
22-
23-
const shouldBundleNodeModule = (id: string) => {
24-
if (typeof resolve === 'boolean') return resolve
25-
return resolve.some((pattern) =>
26-
typeof pattern === 'string' ? id === pattern : pattern.test(id),
27-
)
28-
}
29-
3023
const baseDtsResolver = createResolver({
3124
tsconfig,
3225
resolveNodeModules: !!resolve,
3326
ResolverFactory,
3427
})
3528

36-
function resolveDtsPath(
37-
id: string,
38-
importer: string,
39-
rolldownResolution: ResolvedId | null,
40-
): string | null {
41-
let dtsPath = baseDtsResolver(id, importer)
42-
if (dtsPath) {
43-
dtsPath = path.normalize(dtsPath)
44-
}
45-
46-
if (!dtsPath || !isSourceFile(dtsPath)) {
47-
if (
48-
rolldownResolution &&
49-
isFilePath(rolldownResolution.id) &&
50-
isSourceFile(rolldownResolution.id) &&
51-
!rolldownResolution.external
52-
) {
53-
return rolldownResolution.id
54-
}
55-
return null
56-
}
57-
58-
return dtsPath
59-
}
60-
6129
return {
6230
name: 'rolldown-plugin-dts:resolver',
6331

@@ -115,6 +83,38 @@ export function createDtsResolvePlugin({
11583
},
11684
},
11785
}
86+
87+
function shouldBundleNodeModule(id: string) {
88+
if (typeof resolve === 'boolean') return resolve
89+
return resolve.some((pattern) =>
90+
typeof pattern === 'string' ? id === pattern : pattern.test(id),
91+
)
92+
}
93+
94+
function resolveDtsPath(
95+
id: string,
96+
importer: string,
97+
rolldownResolution: ResolvedId | null,
98+
): string | null {
99+
let dtsPath = baseDtsResolver(id, importer)
100+
if (dtsPath) {
101+
dtsPath = path.normalize(dtsPath)
102+
}
103+
104+
if (!dtsPath || !isSourceFile(dtsPath)) {
105+
if (
106+
rolldownResolution &&
107+
isFilePath(rolldownResolution.id) &&
108+
isSourceFile(rolldownResolution.id) &&
109+
!rolldownResolution.external
110+
) {
111+
return rolldownResolution.id
112+
}
113+
return null
114+
}
115+
116+
return dtsPath
117+
}
118118
}
119119

120120
function isFilePath(id: string) {

0 commit comments

Comments
 (0)