Skip to content

Commit

Permalink
perf(theme): improve typo
Browse files Browse the repository at this point in the history
  • Loading branch information
pengzhanbo committed Dec 8, 2024
1 parent 829fab5 commit 8d39305
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 27 deletions.
1 change: 0 additions & 1 deletion theme/src/node/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export * from './createFsCache.js'
export * from './hash.js'
export * from './interopDefault.js'
export * from './logger.js'
export * from './omit.js'
export * from './package.js'
export * from './path.js'
export * from './resolveContent.js'
Expand Down
2 changes: 1 addition & 1 deletion theme/src/node/utils/interopDefault.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type Awaitable<T> = T | Promise<T>
import type { Awaitable } from '@pengzhanbo/utils'

export async function interopDefault<T>(m: Awaitable<T>): Promise<T extends { default: infer U } ? U : T> {
const resolved = await m
Expand Down
12 changes: 0 additions & 12 deletions theme/src/node/utils/omit.ts

This file was deleted.

23 changes: 10 additions & 13 deletions theme/src/node/utils/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@ import process from 'node:process'
import { fs, path } from 'vuepress/utils'
import { resolve } from './path.js'

export function getPackage() {
let pkg = {} as any
export function readJsonFileAsync<T extends Record<string, any> = Record<string, any>>(filePath: string): T {
try {
const content = fs.readFileSync(path.join(process.cwd(), 'package.json'), 'utf-8')
pkg = JSON.parse(content)
const content = fs.readFileSync(filePath, 'utf-8')
return JSON.parse(content)
}
catch { }
return pkg
catch {}
return {} as T
}

export function getPackage() {
return readJsonFileAsync(path.join(process.cwd(), 'package.json'))
}

export function getThemePackage() {
let pkg = {} as any
try {
const content = fs.readFileSync(resolve('.../../package.json'), 'utf-8')
pkg = JSON.parse(content)
}
catch {}
return pkg
return readJsonFileAsync(resolve('.../../package.json'))
}

0 comments on commit 8d39305

Please sign in to comment.