Skip to content

Commit 1ca10a8

Browse files
committed
fix: generate with outDir
1 parent 66fbb8f commit 1ca10a8

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

src/index.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,28 +119,25 @@ export const IsolatedDecl: UnpluginInstance<Options | undefined, false> =
119119
break
120120
}
121121

122-
if (build.initialOptions.write ?? true) {
122+
const write = build.initialOptions.write ?? true
123+
if (write) {
123124
if (!build.initialOptions.outdir)
124125
throw new Error('outdir is required when write is true')
125-
126-
for (const [filename, source] of Object.entries(outputFiles)) {
127-
const outFile = `${path.relative(outBase, filename)}.d.${outExt}`
128-
129-
const filePath = path.resolve(
130-
build.initialOptions.outdir,
131-
outFile,
132-
)
133-
await mkdir(path.dirname(filePath), { recursive: true })
134-
await writeFile(filePath, source)
135-
}
136126
} else {
137127
result.outputFiles ||= []
138-
const textEncoder = new TextEncoder()
128+
}
139129

140-
for (const [filename, source] of Object.entries(outputFiles)) {
141-
const outFile = `${path.relative(outBase, filename)}.d.${outExt}`
142-
result.outputFiles.push({
143-
path: outFile,
130+
const textEncoder = new TextEncoder()
131+
for (const [filename, source] of Object.entries(outputFiles)) {
132+
const outDir = build.initialOptions.outdir
133+
const outFile = `${path.relative(outBase, filename)}.d.${outExt}`
134+
const filePath = outDir ? path.resolve(outDir, outFile) : outFile
135+
if (write) {
136+
await mkdir(path.dirname(filePath), { recursive: true })
137+
await writeFile(filePath, source)
138+
} else {
139+
result.outputFiles!.push({
140+
path: filePath,
144141
contents: textEncoder.encode(source),
145142
hash: '',
146143
text: source,

0 commit comments

Comments
 (0)