diff --git a/packages/core/package.json b/packages/core/package.json index 60450b151..18e5cd40f 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -51,6 +51,7 @@ "prebundle": "1.1.0", "rslib": "npm:@rslib/core@0.0.2", "rslog": "^1.2.2", + "type-fest": "^4.24.0", "typescript": "^5.5.4" }, "peerDependencies": { diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index 952165746..e9fc18a77 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -9,12 +9,12 @@ import { mergeRsbuildConfig, } from '@rsbuild/core'; import glob from 'fast-glob'; +import type { PackageJson } from 'type-fest'; import { DEFAULT_CONFIG_NAME, DEFAULT_EXTENSIONS } from './constant'; import type { AutoExternal, Format, LibConfig, - PkgJson, RslibConfig, RslibConfigAsyncFn, RslibConfigExport, @@ -89,7 +89,7 @@ export async function loadConfig({ export const composeAutoExternalConfig = (options: { autoExternal: AutoExternal; - pkgJson?: PkgJson; + pkgJson?: PackageJson; userExternals?: NonNullable['externals']; }): RsbuildConfig => { const { autoExternal, pkgJson, userExternals } = options; @@ -242,7 +242,7 @@ const composeFormatConfig = (format: Format): RsbuildConfig => { const composeAutoExtensionConfig = ( config: LibConfig, autoExtension: boolean, - pkgJson?: PkgJson, + pkgJson?: PackageJson, ): { config: RsbuildConfig; jsExtension: string; diff --git a/packages/core/src/types/index.ts b/packages/core/src/types/index.ts index 235e5fdbc..8af67e874 100644 --- a/packages/core/src/types/index.ts +++ b/packages/core/src/types/index.ts @@ -1,2 +1 @@ export type * from './config'; -export type * from './utils'; diff --git a/packages/core/src/types/utils.ts b/packages/core/src/types/utils.ts deleted file mode 100644 index 8b3d31293..000000000 --- a/packages/core/src/types/utils.ts +++ /dev/null @@ -1,6 +0,0 @@ -export type PkgJson = { - dependencies?: Record; - peerDependencies?: Record; - devDependencies?: Record; - [key: string]: unknown; -}; diff --git a/packages/core/src/utils/extension.ts b/packages/core/src/utils/extension.ts index 7d514a9e9..6fe9925d9 100644 --- a/packages/core/src/utils/extension.ts +++ b/packages/core/src/utils/extension.ts @@ -1,9 +1,10 @@ -import type { Format, PkgJson } from '../types'; +import type { PackageJson } from 'type-fest'; +import type { Format } from '../types'; import { logger } from './logger'; export const getDefaultExtension = (options: { format: Format; - pkgJson?: PkgJson; + pkgJson?: PackageJson; autoExtension: boolean; }): { jsExtension: string; diff --git a/packages/core/src/utils/helper.ts b/packages/core/src/utils/helper.ts index 387e20123..f72d06075 100644 --- a/packages/core/src/utils/helper.ts +++ b/packages/core/src/utils/helper.ts @@ -2,7 +2,7 @@ import fs from 'node:fs'; import fsP from 'node:fs/promises'; import path from 'node:path'; import color from 'picocolors'; -import type { PkgJson } from '../types'; +import type { PackageJson } from 'type-fest'; import { logger } from './logger'; /** @@ -107,7 +107,7 @@ export async function calcLongestCommonPath( return lca; } -export const readPackageJson = (rootPath: string): undefined | PkgJson => { +export const readPackageJson = (rootPath: string): undefined | PackageJson => { const pkgJsonPath = path.join(rootPath, './package.json'); if (!fs.existsSync(pkgJsonPath)) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 916a50b2b..f2dbbc7d6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -229,6 +229,9 @@ importers: rslog: specifier: ^1.2.2 version: 1.2.2 + type-fest: + specifier: ^4.24.0 + version: 4.24.0 typescript: specifier: ^5.5.4 version: 5.5.4 @@ -2420,6 +2423,10 @@ packages: resolution: {integrity: sha512-tLq3bSNx+xSpwvAJnzrK0Ep5CLNWjvFTOp71URMaAEWBfRb9nnJiBoUe0tF8bI4ZFO3omgBR6NvnbzVUT3Ly4g==} engines: {node: '>=14.16'} + type-fest@4.24.0: + resolution: {integrity: sha512-spAaHzc6qre0TlZQQ2aA/nGMe+2Z/wyGk5Z+Ru2VUfdNwT6kWO6TjevOlpebsATEG1EIQ2sOiDszud3lO5mt/Q==} + engines: {node: '>=16'} + type-is@1.6.18: resolution: {integrity: sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==} engines: {node: '>= 0.6'} @@ -4754,6 +4761,8 @@ snapshots: type-fest@3.13.1: {} + type-fest@4.24.0: {} + type-is@1.6.18: dependencies: media-typer: 0.3.0