Skip to content

Commit 81f0f8b

Browse files
committed
refactor: update imports
1 parent 6bd1c31 commit 81f0f8b

2 files changed

Lines changed: 7 additions & 9 deletions

File tree

src/bin/build.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { resolve, parse } from 'node:path'
2-
import { cp, readdir } from 'node:fs/promises'
32
import { stat } from 'node:fs/promises'
43
import { dim } from '@hypernym/colors'
4+
import { write, copy, readdir } from '@hypernym/utils/fs'
55
import { isObject, isString } from '@hypernym/utils'
6-
import { writeFile } from '@hypernym/utils/fs'
76
import { rollup } from 'rollup'
87
import { getLogFilter } from 'rollup/getLogFilter'
98
import replacePlugin from '@rollup/plugin-replace'
@@ -95,7 +94,7 @@ export async function build(
9594
const fileSrc = resolve(cwd, copyInput)
9695
const fileDist = resolve(cwd, _entry.output, copyInput)
9796

98-
await cp(fileSrc, fileDist, {
97+
await copy(fileSrc, fileDist, {
9998
recursive: _entry.recursive,
10099
filter: _entry.filter,
101100
}).catch(error)
@@ -105,7 +104,7 @@ export async function build(
105104

106105
if (!stats.isDirectory()) totalSize = stats.size
107106
else {
108-
const files = await readdir(fileDist, { recursive: true })
107+
const files = await readdir(fileDist)
109108
for (const file of files) {
110109
const filePath = resolve(fileDist, file)
111110
const fileStat = await stat(filePath)
@@ -307,7 +306,7 @@ export async function build(
307306
output: entry.output,
308307
}
309308

310-
await writeFile(_entry.output, `${_entry.template}`, 'utf-8')
309+
await write(_entry.output, _entry.template)
311310

312311
const stats = await stat(resolve(cwd, _entry.output))
313312

src/bin/loader.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { resolve } from 'node:path'
2-
import { readFile } from 'node:fs/promises'
3-
import { exists, writeFile } from '@hypernym/utils/fs'
2+
import { exists, write, read } from '@hypernym/utils/fs'
43
import { cyan } from '@hypernym/colors'
54
import { build } from 'esbuild'
65
import { externals } from '@/config'
@@ -23,7 +22,7 @@ export async function loadConfig(
2322
})
2423
const code = result.outputFiles[0].text
2524
const tempConfig = resolve(cwd, 'node_modules/.hypernym/bundler/config.mjs')
26-
await writeFile(tempConfig, code, 'utf-8')
25+
await write(tempConfig, code)
2726
const content = await import(tempConfig)
2827
const config: Options = {
2928
...defaults,
@@ -38,7 +37,7 @@ export async function createConfigLoader(
3837
args: Args,
3938
): Promise<ConfigLoader> {
4039
const pkgPath = resolve(cwd, 'package.json')
41-
const pkg = await readFile(pkgPath, 'utf-8').catch(error)
40+
const pkg = await read(pkgPath).catch(error)
4241
const { dependencies } = JSON.parse(pkg)
4342

4443
const warnMessage = `Missing required configuration. To start bundling, add the ${cyan(

0 commit comments

Comments
 (0)