From 5db2b6ed2f25c47cf73078a28d08e3aa178bf4fc Mon Sep 17 00:00:00 2001 From: lishaobos <46661044+lishaobos@users.noreply.github.com> Date: Fri, 20 Jan 2023 20:17:47 +0800 Subject: [PATCH] fix: generator dts (no such file or directory) (#585) --- src/core/declaration.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/core/declaration.ts b/src/core/declaration.ts index c3f67786..1e6a8067 100644 --- a/src/core/declaration.ts +++ b/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' @@ -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) @@ -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) }