Skip to content

Commit

Permalink
fix: generator dts (no such file or directory) (#585)
Browse files Browse the repository at this point in the history
  • Loading branch information
lishaobos committed Jan 20, 2023
1 parent d997e55 commit 5db2b6e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/core/declaration.ts
@@ -1,6 +1,6 @@
import { dirname, isAbsolute, relative } from 'path'
import { existsSync } from 'fs'
import { readFile, writeFile } from 'fs/promises'
import { mkdir, readFile, writeFile as writeFile_ } from 'fs/promises'
import { notNullish, slash } from '@antfu/utils'
import type { ComponentInfo } from '../../dist'
import type { Options } from '../types'
Expand Down Expand Up @@ -145,6 +145,11 @@ ${head}`
return code
}

async function writeFile(filePath: string, content: string) {
await mkdir(dirname(filePath), { recursive: true })
return await writeFile_(filePath, content, 'utf-8')
}

export async function writeDeclaration(ctx: Context, filepath: string, removeUnused = false) {
const originalContent = existsSync(filepath) ? await readFile(filepath, 'utf-8') : ''
const originalImports = removeUnused ? undefined : parseDeclaration(originalContent)
Expand All @@ -154,5 +159,5 @@ export async function writeDeclaration(ctx: Context, filepath: string, removeUnu
return

if (code !== originalContent)
await writeFile(filepath, code, 'utf-8')
await writeFile(filepath, code)
}

0 comments on commit 5db2b6e

Please sign in to comment.