From b885aa603f1db30aa50361c2a011ea786af9d86f Mon Sep 17 00:00:00 2001 From: shulaoda Date: Wed, 14 Aug 2024 11:20:54 +0800 Subject: [PATCH] chore: use type PackageJson from type-fest --- package.json | 1 + packages/core/package.json | 1 + packages/core/src/config.ts | 6 +++--- packages/core/src/types/index.ts | 1 - packages/core/src/types/utils.ts | 6 ------ packages/core/src/utils/extension.ts | 5 +++-- packages/core/src/utils/helper.ts | 4 ++-- pnpm-lock.yaml | 14 +++++++++++++- 8 files changed, 23 insertions(+), 15 deletions(-) delete mode 100644 packages/core/src/types/utils.ts diff --git a/package.json b/package.json index 7cf5eb35c..f7fdcdcc2 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "prettier": "^3.3.2", "prettier-plugin-packagejson": "^2.5.0", "simple-git-hooks": "^2.11.1", + "type-fest": "^4.24.0", "typescript": "^5.5.3", "vitest": "^2.0.5" }, diff --git a/packages/core/package.json b/packages/core/package.json index afc218721..2c5badf07 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -51,6 +51,7 @@ "picocolors": "1.0.1", "prebundle": "1.1.0", "rslog": "^1.2.2", + "type-fest": "^4.24.0", "typescript": "^5.5.3" }, "peerDependencies": { diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index 98fa4e3a1..a6527fb75 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, @@ -85,7 +85,7 @@ export async function loadConfig( export const composeAutoExternalConfig = (options: { autoExternal: AutoExternal; - pkgJson?: PkgJson; + pkgJson?: PackageJson; userExternals?: NonNullable['externals']; }): RsbuildConfig => { const { autoExternal, pkgJson, userExternals } = options; @@ -230,7 +230,7 @@ const composeFormatConfig = (format: Format): RsbuildConfig => { const composeAutoExtensionConfig = ( format: Format, autoExtension: boolean, - pkgJson?: PkgJson, + pkgJson?: PackageJson, ): { config: RsbuildConfig; dtsExtension: string; diff --git a/packages/core/src/types/index.ts b/packages/core/src/types/index.ts index 1d6a9e831..f03c2281a 100644 --- a/packages/core/src/types/index.ts +++ b/packages/core/src/types/index.ts @@ -1,2 +1 @@ export * from './config'; -export * 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 98e64c2b1..9e83d42b1 100644 --- a/packages/core/src/utils/extension.ts +++ b/packages/core/src/utils/extension.ts @@ -1,9 +1,10 @@ -import type { Format, PkgJson } from 'src/types'; +import type { Format } from 'src/types'; +import type { PackageJson } from 'type-fest'; 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 ca36e081b..026070979 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'; /** @@ -102,7 +102,7 @@ async function calcLongestCommonPath( return lca; } -export const readPackageJson = (rootPath: string): undefined | PkgJson => { +export const readPackageJson = (rootPath: string): undefined | PackageJson => { const pkgJsonPath = path.resolve(rootPath, './package.json'); if (!fs.existsSync(pkgJsonPath)) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6aa301ba6..bad70d179 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -50,6 +50,9 @@ importers: simple-git-hooks: specifier: ^2.11.1 version: 2.11.1 + type-fest: + specifier: ^4.24.0 + version: 4.24.0 typescript: specifier: ^5.5.3 version: 5.5.3 @@ -214,6 +217,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.3 version: 5.5.3 @@ -3056,6 +3062,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'} @@ -4590,7 +4600,7 @@ snapshots: browserslist@4.23.2: dependencies: - caniuse-lite: 1.0.30001641 + caniuse-lite: 1.0.30001649 electron-to-chromium: 1.4.827 node-releases: 2.0.14 update-browserslist-db: 1.1.0(browserslist@4.23.2) @@ -6051,6 +6061,8 @@ snapshots: type-fest@3.13.1: {} + type-fest@4.24.0: {} + type-is@1.6.18: dependencies: media-typer: 0.3.0