diff --git a/theme/src/node/utils/index.ts b/theme/src/node/utils/index.ts index 6575b1e9..05b34926 100644 --- a/theme/src/node/utils/index.ts +++ b/theme/src/node/utils/index.ts @@ -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' diff --git a/theme/src/node/utils/interopDefault.ts b/theme/src/node/utils/interopDefault.ts index 5be4386c..57b062cc 100644 --- a/theme/src/node/utils/interopDefault.ts +++ b/theme/src/node/utils/interopDefault.ts @@ -1,4 +1,4 @@ -export type Awaitable = T | Promise +import type { Awaitable } from '@pengzhanbo/utils' export async function interopDefault(m: Awaitable): Promise { const resolved = await m diff --git a/theme/src/node/utils/omit.ts b/theme/src/node/utils/omit.ts deleted file mode 100644 index 878c7c6d..00000000 --- a/theme/src/node/utils/omit.ts +++ /dev/null @@ -1,12 +0,0 @@ -export function omit< - T extends Record = Record, ->(obj: T, ...attrs: (keyof T)[]): Omit { - const res = {} as T - - for (const key in obj) { - if (!attrs.includes(key)) { - res[key] = obj[key] - } - } - return res -} diff --git a/theme/src/node/utils/package.ts b/theme/src/node/utils/package.ts index 16292696..5cf80992 100644 --- a/theme/src/node/utils/package.ts +++ b/theme/src/node/utils/package.ts @@ -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 = Record>(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')) }