From b9d90f8299c1b3c3801bfb5dcd61a491579cee57 Mon Sep 17 00:00:00 2001 From: lijianan <574980606@qq.com> Date: Wed, 24 Apr 2024 11:06:12 +0800 Subject: [PATCH] chore: simplify import expression from package.json (#48602) --- .dumi/theme/plugin.ts | 11 +++++------ scripts/check-repo.ts | 4 +--- scripts/check-version-md.ts | 4 +--- scripts/generate-version.ts | 4 +--- tests/index.test.ts | 6 +++--- 5 files changed, 11 insertions(+), 18 deletions(-) diff --git a/.dumi/theme/plugin.ts b/.dumi/theme/plugin.ts index fb86cb0941..c22b43803e 100644 --- a/.dumi/theme/plugin.ts +++ b/.dumi/theme/plugin.ts @@ -7,14 +7,16 @@ import type { IApi, IRoute } from 'dumi'; import ReactTechStack from 'dumi/dist/techStacks/react'; import sylvanas from 'sylvanas'; -import localPackage from '../../package.json'; +import { dependencies, devDependencies } from '../../package.json'; function extractEmotionStyle(html: string) { // copy from emotion ssr // https://github.com/vercel/next.js/blob/deprecated-main/examples/with-emotion-vanilla/pages/_document.js const styles = global.__ANTD_STYLE_CACHE_MANAGER_FOR_SSR__.getCacheList().map((cache) => { const result = createEmotionServer(cache).extractCritical(html); - if (!result.css) return null; + if (!result.css) { + return null; + } const { css, ids } = result; @@ -46,10 +48,7 @@ class AntdReactTechStack extends ReactTechStack { const codePath = opts.fileAbsPath!.replace(/\.\w+$/, '.tsx'); const code = fs.existsSync(codePath) ? fs.readFileSync(codePath, 'utf-8') : ''; - props.pkgDependencyList = { - ...localPackage.devDependencies, - ...localPackage.dependencies, - }; + props.pkgDependencyList = { ...devDependencies, ...dependencies }; props.jsx = sylvanas.parseText(code); if (md) { diff --git a/scripts/check-repo.ts b/scripts/check-repo.ts index 118082938b..ce18952116 100644 --- a/scripts/check-repo.ts +++ b/scripts/check-repo.ts @@ -5,9 +5,7 @@ import ora from 'ora'; import simpleGit from 'simple-git'; import type { StatusResult } from 'simple-git'; -import localPackage from '../package.json'; - -const { version } = localPackage; +import { version } from '../package.json'; const cwd = process.cwd(); const git = simpleGit(cwd); diff --git a/scripts/check-version-md.ts b/scripts/check-version-md.ts index cf2c10c7f6..ea2db2fd30 100644 --- a/scripts/check-version-md.ts +++ b/scripts/check-version-md.ts @@ -5,9 +5,7 @@ import chalk from 'chalk'; import dayjs from 'dayjs'; import isBetween from 'dayjs/plugin/isBetween'; -import localPackage from '../package.json'; - -const { version } = localPackage; +import { version } from '../package.json'; dayjs.extend(isBetween); diff --git a/scripts/generate-version.ts b/scripts/generate-version.ts index c4e89dd6bb..61a7df5e93 100644 --- a/scripts/generate-version.ts +++ b/scripts/generate-version.ts @@ -1,9 +1,7 @@ import fs from 'fs'; import path from 'path'; -import localPackage from '../package.json'; - -const { version } = localPackage; +import { version } from '../package.json'; fs.writeFileSync( path.join(__dirname, '..', 'components', 'version', 'version.ts'), diff --git a/tests/index.test.ts b/tests/index.test.ts index bbc286a7e8..0d75e75685 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -1,5 +1,5 @@ /* eslint-disable global-require */ -import pkg from '../package.json'; +import { version as packageVersion } from '../package.json'; const testDist = process.env.LIB_DIR === 'dist'; const testDistMin = process.env.LIB_DIR === 'dist-min'; @@ -28,14 +28,14 @@ describe('antd dist files', () => { // eslint-disable-next-line global-require,import/no-unresolved const antd = require('../dist/antd'); expect(antd).toBeTruthy(); - expect(antd.version).toBe(pkg.version); + expect(antd.version).toBe(packageVersion); }); it('antd.min.js should export version', () => { // eslint-disable-next-line global-require,import/no-unresolved const antd = require('../dist/antd.min'); expect(antd).toBeTruthy(); - expect(antd.version).toBe(pkg.version); + expect(antd.version).toBe(packageVersion); }); } });