Skip to content

Commit

Permalink
refactor: Node imports
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Nov 14, 2024
1 parent a4327b9 commit bdece72
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/node/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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}"`)
}
6 changes: 3 additions & 3 deletions src/node/plugins/build-cleanup.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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)
},
}
}
10 changes: 5 additions & 5 deletions src/node/plugins/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
},
}
}
Expand Down

0 comments on commit bdece72

Please sign in to comment.