Skip to content

Commit 5db2b6e

Browse files
authored
fix: generator dts (no such file or directory) (unplugin#585)
1 parent d997e55 commit 5db2b6e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/core/declaration.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { dirname, isAbsolute, relative } from 'path'
22
import { existsSync } from 'fs'
3-
import { readFile, writeFile } from 'fs/promises'
3+
import { mkdir, readFile, writeFile as writeFile_ } from 'fs/promises'
44
import { notNullish, slash } from '@antfu/utils'
55
import type { ComponentInfo } from '../../dist'
66
import type { Options } from '../types'
@@ -145,6 +145,11 @@ ${head}`
145145
return code
146146
}
147147

148+
async function writeFile(filePath: string, content: string) {
149+
await mkdir(dirname(filePath), { recursive: true })
150+
return await writeFile_(filePath, content, 'utf-8')
151+
}
152+
148153
export async function writeDeclaration(ctx: Context, filepath: string, removeUnused = false) {
149154
const originalContent = existsSync(filepath) ? await readFile(filepath, 'utf-8') : ''
150155
const originalImports = removeUnused ? undefined : parseDeclaration(originalContent)
@@ -154,5 +159,5 @@ export async function writeDeclaration(ctx: Context, filepath: string, removeUnu
154159
return
155160

156161
if (code !== originalContent)
157-
await writeFile(filepath, code, 'utf-8')
162+
await writeFile(filepath, code)
158163
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy