From bdece721a98e465e71dc479bfe8c95815eacb188 Mon Sep 17 00:00:00 2001 From: Johann Schopplich Date: Thu, 14 Nov 2024 08:05:40 +0100 Subject: [PATCH] refactor: Node imports --- src/node/index.ts | 8 ++++---- src/node/plugins/build-cleanup.ts | 6 +++--- src/node/plugins/hmr.ts | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/node/index.ts b/src/node/index.ts index d6ead21..d6dc377 100644 --- a/src/node/index.ts +++ b/src/node/index.ts @@ -1,8 +1,8 @@ import type { OutputChunk, RollupOutput } from 'rollup' import type { InlineConfig, LogLevel } from 'vite' import type { BaseOptions, BuildOptions, PostCSSConfigResult, ServeOptions, UserConfig } from './types' -import { existsSync } from 'node:fs' -import { readFile } from 'node:fs/promises' +import * as fs from 'node:fs' +import * as fsp from 'node:fs/promises' import vuePlugin from '@vitejs/plugin-vue2' import vueJsxPlugin from '@vitejs/plugin-vue2-jsx' import { consola } from 'consola' @@ -155,7 +155,7 @@ async function generate(options: BuildOptions) { options.cwd, options.outDir, fileName, - code ?? (await readFile(resolve(options.outDir, fileName), 'utf8')), + code ?? (await fsp.readFile(resolve(options.outDir, fileName), 'utf8')), type, longest, ) @@ -278,6 +278,6 @@ export async function serve(options: ServeOptions) { } function assertEntryExists(options: BaseOptions) { - if (!existsSync(resolve(options.cwd, options.entry))) + if (!fs.existsSync(resolve(options.cwd, options.entry))) throw new PrettyError(`Cannot find "${options.entry}"`) } diff --git a/src/node/plugins/build-cleanup.ts b/src/node/plugins/build-cleanup.ts index b02b222..5598b08 100644 --- a/src/node/plugins/build-cleanup.ts +++ b/src/node/plugins/build-cleanup.ts @@ -1,6 +1,6 @@ import type { Plugin, ResolvedConfig } from 'vite' import type { BuildOptions } from '../types' -import { existsSync, unlinkSync } from 'node:fs' +import * as fs from 'node:fs' import { resolve } from 'pathe' export default function kirbyupBuildCleanupPlugin(options: BuildOptions): Plugin { @@ -14,8 +14,8 @@ export default function kirbyupBuildCleanupPlugin(options: BuildOptions): Plugin devIndexPath = resolve(config.root, options.outDir, 'index.dev.mjs') }, writeBundle() { - if (existsSync(devIndexPath)) - unlinkSync(devIndexPath) + if (fs.existsSync(devIndexPath)) + fs.unlinkSync(devIndexPath) }, } } diff --git a/src/node/plugins/hmr.ts b/src/node/plugins/hmr.ts index 7ec5fde..9fccc66 100644 --- a/src/node/plugins/hmr.ts +++ b/src/node/plugins/hmr.ts @@ -2,8 +2,8 @@ import type { AddressInfo } from 'node:net' import type { PackageManager } from 'nypm' import type { Plugin, ResolvedConfig } from 'vite' import type { ServeOptions } from '../types' -import { existsSync, unlinkSync } from 'node:fs' -import { writeFile } from 'node:fs/promises' +import * as fs from 'node:fs' +import * as fsp from 'node:fs/promises' import { detectPackageManager } from 'nypm' import { resolve } from 'pathe' import { __INJECTED_HMR_CODE__, isHmrRuntimeId } from './utils' @@ -48,13 +48,13 @@ export default function kirbyupHmrPlugin(options: ServeOptions): Plugin { const entryUrl = new URL(entryPath, baseUrl).href const pm = await detectPackageManager(config.root) - await writeFile(devIndexPath, getViteProxyModule(entryUrl, pm)) + await fsp.writeFile(devIndexPath, getViteProxyModule(entryUrl, pm)) }) }, closeBundle() { - if (existsSync(devIndexPath)) - unlinkSync(devIndexPath) + if (fs.existsSync(devIndexPath)) + fs.unlinkSync(devIndexPath) }, } }