8000 fix: generator dts (no such file or directory) by lishaobos · Pull Request #585 · unplugin/unplugin-vue-components · GitHub
[go: up one dir, main page]

Skip to content

fix: generator dts (no such file or directory) #585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/core/declaration.ts
Original file line number Diff line number Diff line change
@@ -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