From 08894ce422c60662c485ddf4cb749dce29b65b8f Mon Sep 17 00:00:00 2001 From: co Date: Mon, 18 Mar 2024 15:26:40 +0800 Subject: [PATCH] Revert "refactor: improve vue tech stack support (#2036)" This reverts commit 19ebd41dd0bd2c6b7db36a5f882d02c3c0f2f8a5. --- .eslintignore | 1 + bundler-utils.d.ts | 5 ++ bundler-utils.js | 7 +++ package.json | 2 + src/assetParsers/BaseParser.ts | 46 ++++++++----------- src/assetParsers/__tests__/FakeParser.d.ts | 3 ++ src/assetParsers/__tests__/FakeParser.js | 8 ++-- src/assetParsers/__tests__/FakeParser.ts | 25 ++++++++++ .../__tests__/parser.fork.test.ts | 5 +- src/assetParsers/__tests__/setup.js | 12 +++++ src/assetParsers/__tests__/tsconfig.test.json | 14 ++++++ src/assetParsers/atom.ts | 12 ++--- src/assetParsers/utils.ts | 14 +++--- src/client/pages/Demo/index.ts | 3 +- src/client/theme-api/index.ts | 1 + src/features/parser.ts | 14 ++---- src/index.ts | 12 ++++- src/loaders/markdown/index.ts | 2 + .../markdown/transformer/rehypeDemo.ts | 2 +- src/types.ts | 38 +++++++++++++-- suites/dumi-vue-meta/.fatherrc.ts | 4 ++ suites/preset-vue/src/atomParser/index.ts | 14 +++--- suites/preset-vue/src/compiler/index.ts | 2 +- suites/preset-vue/src/compiler/node.ts | 2 +- suites/preset-vue/src/vue/webpack/config.ts | 2 +- tech-stack-utils.d.ts | 11 ----- tech-stack-utils.js | 10 +--- vitest.config.ts | 1 + 28 files changed, 179 insertions(+), 93 deletions(-) create mode 100644 bundler-utils.d.ts create mode 100644 bundler-utils.js create mode 100644 src/assetParsers/__tests__/FakeParser.d.ts create mode 100644 src/assetParsers/__tests__/FakeParser.ts create mode 100644 src/assetParsers/__tests__/setup.js create mode 100644 src/assetParsers/__tests__/tsconfig.test.json diff --git a/.eslintignore b/.eslintignore index 264604a6e0..20a7623a43 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,5 +1,6 @@ /dist /compiled /theme-default +/runtime /suites/*/compiled /suites/preset-vue/lib diff --git a/bundler-utils.d.ts b/bundler-utils.d.ts new file mode 100644 index 0000000000..abf8d8501c --- /dev/null +++ b/bundler-utils.d.ts @@ -0,0 +1,5 @@ +import type * as BabelCore from '@umijs/bundler-utils/compiled/@babel/core'; +export { BabelCore }; +export const babelCore: () => typeof import('@umijs/bundler-utils/compiled/@babel/core'); +export const babelPresetTypeScript: () => BabelCore.PluginItem; +export const babelPresetEnv: () => BabelCore.PluginItem; diff --git a/bundler-utils.js b/bundler-utils.js new file mode 100644 index 0000000000..2a9e5e75d3 --- /dev/null +++ b/bundler-utils.js @@ -0,0 +1,7 @@ +module.exports = { + babelCore: () => require('@umijs/bundler-utils/compiled/babel/core'), + babelPresetTypeScript: () => + require('@umijs/bundler-utils/compiled/babel/preset-typescript'), + babelPresetEnv: () => + require('@umijs/bundler-utils/compiled/babel/preset-env'), +}; diff --git a/package.json b/package.json index e509a19934..85617b10bd 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,8 @@ "index.d.ts", "plugin-utils.js", "plugin-utils.d.ts", + "bundler-utils.js", + "bundler-utils.d.ts", "tech-stack-utils.js", "tech-stack-utils.d.ts" ], diff --git a/src/assetParsers/BaseParser.ts b/src/assetParsers/BaseParser.ts index 06e1a465d1..1b4bc1f41b 100644 --- a/src/assetParsers/BaseParser.ts +++ b/src/assetParsers/BaseParser.ts @@ -1,28 +1,23 @@ -import type { AtomComponentAsset, AtomFunctionAsset } from 'dumi-assets-types'; +import type { AtomAssetsParser, AtomAssetsParserResult } from '@/types'; import path from 'path'; import { chokidar, lodash, logger } from 'umi/plugin-utils'; -export interface IPatchFile { +export interface PatchFile { event: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir'; fileName: string; } -export interface IAtomAssetsParserResult { - components: Record; - functions: Record; -} - /** * The parsing and extraction of language metadata should be implemented separately */ -export interface ILanguageMetaParser { - patch(file: IPatchFile): void; - parse(): Promise; +export interface LanguageMetaParser { + patch(file: PatchFile): void; + parse(): Promise; destroy(): Promise; } -export interface IHandleWatcherArgs { - patch: ILanguageMetaParser['patch']; +export interface HandleWatcherArgs { + patch: LanguageMetaParser['patch']; parse: () => void; watchArgs: { paths: string | string[]; @@ -30,34 +25,35 @@ export interface IHandleWatcherArgs { }; } -export interface IBaseAtomAssetsParserParams { +export interface BaseAtomAssetsParserParams { entryFile: string; resolveDir: string; parser: T; handleWatcher?: ( watcher: chokidar.FSWatcher, - params: IHandleWatcherArgs, + params: HandleWatcherArgs, ) => chokidar.FSWatcher; watchOptions?: chokidar.WatchOptions; } export class BaseAtomAssetsParser< - T extends ILanguageMetaParser = ILanguageMetaParser, -> { - private watchArgs!: IHandleWatcherArgs['watchArgs']; + T extends LanguageMetaParser = LanguageMetaParser, +> implements AtomAssetsParser +{ + private watchArgs!: HandleWatcherArgs['watchArgs']; private watcher: chokidar.FSWatcher | null = null; - private handleWatcher?: IBaseAtomAssetsParserParams['handleWatcher']; + private handleWatcher?: BaseAtomAssetsParserParams['handleWatcher']; private entryDir!: string; private resolveDir!: string; private readonly parser!: T; private isParsing = false; - private parseDeferrer: Promise | null = null; - private cbs: Array<(data: IAtomAssetsParserResult) => void> = []; + private parseDeferrer: Promise | null = null; + private cbs: Array<(data: AtomAssetsParserResult) => void> = []; - constructor(opts: IBaseAtomAssetsParserParams) { + constructor(opts: BaseAtomAssetsParserParams) { const { entryFile, resolveDir, watchOptions, parser, handleWatcher } = opts; this.resolveDir = resolveDir; const absEntryFile = path.resolve(resolveDir, entryFile); @@ -92,7 +88,7 @@ export class BaseAtomAssetsParser< return this.parseDeferrer; } - public watch(cb: (data: IAtomAssetsParserResult) => void): void { + public watch(cb: (data: AtomAssetsParserResult) => void): void { // save watch callback this.cbs.push(cb); // initialize watcher @@ -123,7 +119,7 @@ export class BaseAtomAssetsParser< } }, watchArgs: this.watchArgs, - patch: (file: IPatchFile) => { + patch: (file: PatchFile) => { this.parser.patch(file); }, }); @@ -132,7 +128,7 @@ export class BaseAtomAssetsParser< } } - public unwatch(cb: (data: IAtomAssetsParserResult) => void) { + public unwatch(cb: (data: AtomAssetsParserResult) => void) { this.cbs.splice(this.cbs.indexOf(cb), 1); } @@ -157,5 +153,3 @@ export class BaseAtomAssetsParser< await this.parser.destroy(); } } - -export type IAtomAssetsParser = InstanceType; diff --git a/src/assetParsers/__tests__/FakeParser.d.ts b/src/assetParsers/__tests__/FakeParser.d.ts new file mode 100644 index 0000000000..0a70266753 --- /dev/null +++ b/src/assetParsers/__tests__/FakeParser.d.ts @@ -0,0 +1,3 @@ +export declare const FakeParser: () => import('../../../dist').BaseAtomAssetsParser< + import('../../../dist').LanguageMetaParser +>; diff --git a/src/assetParsers/__tests__/FakeParser.js b/src/assetParsers/__tests__/FakeParser.js index 1b507b8f5e..df2f7fb3d8 100644 --- a/src/assetParsers/__tests__/FakeParser.js +++ b/src/assetParsers/__tests__/FakeParser.js @@ -1,6 +1,8 @@ -const { createApiParser } = require('../../../tech-stack-utils'); - -module.exports.FakeParser = createApiParser({ +'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); +exports.FakeParser = void 0; +const dist_1 = require('../../../dist'); +exports.FakeParser = (0, dist_1.createApiParser)({ filename: __filename, worker: class { patch() {} diff --git a/src/assetParsers/__tests__/FakeParser.ts b/src/assetParsers/__tests__/FakeParser.ts new file mode 100644 index 0000000000..47e8f6b604 --- /dev/null +++ b/src/assetParsers/__tests__/FakeParser.ts @@ -0,0 +1,25 @@ +import { AtomAssetsParserResult, createApiParser } from '../../../dist'; + +export const FakeParser = createApiParser({ + filename: __filename, + worker: class { + patch() {} + parse() { + return new Promise((resolve) => { + setTimeout(() => { + resolve({ + components: {}, + functions: {}, + }); + }, 1000); + }); + } + async destroy() {} + }, + // If the worker class has no parameters + // entryFile and resolveDir must be passed in manually. + parseOptions: { + entryFile: __filename, + resolveDir: __dirname, + }, +}); diff --git a/src/assetParsers/__tests__/parser.fork.test.ts b/src/assetParsers/__tests__/parser.fork.test.ts index d7c0e11c27..8d8e0728e2 100644 --- a/src/assetParsers/__tests__/parser.fork.test.ts +++ b/src/assetParsers/__tests__/parser.fork.test.ts @@ -1,11 +1,10 @@ import { expect, test } from 'vitest'; -// @ts-ignore -import { FakeParser } from './FakeParser'; +import { FakeParser } from './FakeParser.js'; test('AtomAssetsParser: create worker mode', async () => { const parser = FakeParser(); const now = performance.now(); - parser.parse().then((result: any) => { + parser.parse().then((result) => { expect(result).toStrictEqual({ components: {}, functions: {}, diff --git a/src/assetParsers/__tests__/setup.js b/src/assetParsers/__tests__/setup.js new file mode 100644 index 0000000000..67e97f4bf2 --- /dev/null +++ b/src/assetParsers/__tests__/setup.js @@ -0,0 +1,12 @@ +import { exec } from 'node:child_process'; +import { promisify } from 'node:util'; +import path from 'path'; + +const execPromise = promisify(exec); + +export default async function () { + const tsconfigPath = path.join(__dirname, 'tsconfig.test.json'); + const files = path.resolve(__dirname, './FakeParser.{js,d.ts}'); + await execPromise(`tsc --project ${tsconfigPath}`); + await execPromise(`prettier ${files} --write`); +} diff --git a/src/assetParsers/__tests__/tsconfig.test.json b/src/assetParsers/__tests__/tsconfig.test.json new file mode 100644 index 0000000000..34af9164e5 --- /dev/null +++ b/src/assetParsers/__tests__/tsconfig.test.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "strict": true, + "target": "ESNext", + "module": "CommonJS", + "moduleResolution": "Node", + "declaration": true, + "skipLibCheck": true, + "esModuleInterop": true, + "baseUrl": "./", + "types": ["vitest/globals"] + }, + "include": ["FakeParser.ts"] +} diff --git a/src/assetParsers/atom.ts b/src/assetParsers/atom.ts index f55baf38b5..d8f65da3b5 100644 --- a/src/assetParsers/atom.ts +++ b/src/assetParsers/atom.ts @@ -2,11 +2,11 @@ import { getProjectRoot } from '@/utils'; import { SchemaParser, SchemaResolver } from 'dumi-afx-deps/compiled/parser'; import path from 'path'; import { logger } from 'umi/plugin-utils'; +import { AtomAssetsParserResult } from '../types'; import { BaseAtomAssetsParser, - IAtomAssetsParserResult, - ILanguageMetaParser, - IPatchFile, + LanguageMetaParser, + PatchFile, } from './BaseParser'; // maximum support 512kb for each atoms @@ -20,7 +20,7 @@ interface ParserParams { parseOptions?: object; } -class ReactMetaParser implements ILanguageMetaParser { +class ReactMetaParser implements LanguageMetaParser { private parser: SchemaParser; private resolveFilter: (args: { type: 'COMPONENT' | 'FUNCTION'; @@ -53,7 +53,7 @@ class ReactMetaParser implements ILanguageMetaParser { }); // parse atoms from resolver - const result: IAtomAssetsParserResult = { + const result: AtomAssetsParserResult = { components: {}, functions: {}, }; @@ -121,7 +121,7 @@ class ReactMetaParser implements ILanguageMetaParser { return this.parser.$$destroyWorker(); } - public patch(file: IPatchFile): void { + public patch(file: PatchFile): void { this.unresolvedFiles.push(file.fileName); } } diff --git a/src/assetParsers/utils.ts b/src/assetParsers/utils.ts index 070343647c..033058a675 100644 --- a/src/assetParsers/utils.ts +++ b/src/assetParsers/utils.ts @@ -4,8 +4,8 @@ import { lodash } from 'umi/plugin-utils'; import { Worker, isMainThread, parentPort } from 'worker_threads'; import { BaseAtomAssetsParser, - IBaseAtomAssetsParserParams, - ILanguageMetaParser, + BaseAtomAssetsParserParams, + LanguageMetaParser, } from './BaseParser'; /** @@ -94,7 +94,7 @@ export function createRemoteClass< } as unknown as T; } -interface ICreateApiParserOptions { +export interface CreateApiParserOptions { /** * The full file name (absolute path) of the file where `parseWorker` is located */ @@ -109,7 +109,7 @@ interface ICreateApiParserOptions { parseOptions?: C; } -export interface IBaseApiParserOptions { +export interface BaseApiParserOptions { entryFile: string; resolveDir: string; } @@ -150,10 +150,8 @@ export interface IBaseApiParserOptions { */ export function createApiParser< P extends new (...args: ConstructorParameters

) => InstanceType

& - ILanguageMetaParser, ->( - options: ICreateApiParserOptions>>, -) { + LanguageMetaParser, +>(options: CreateApiParserOptions>>) { const { filename, worker, parseOptions } = options; const ParserClass = createRemoteClass(filename, worker); return (...args: ConstructorParameters

) => diff --git a/src/client/pages/Demo/index.ts b/src/client/pages/Demo/index.ts index c90b96f5c9..4c714e3b3a 100644 --- a/src/client/pages/Demo/index.ts +++ b/src/client/pages/Demo/index.ts @@ -1,6 +1,5 @@ -import { useDemo, useLiveDemo, useParams } from 'dumi'; +import { useDemo, useLiveDemo, useParams, useRenderer } from 'dumi'; import { ComponentType, createElement, useEffect, type FC } from 'react'; -import { useRenderer } from '../../theme-api/useRenderer'; import './index.less'; const DemoRenderPage: FC = () => { diff --git a/src/client/theme-api/index.ts b/src/client/theme-api/index.ts index a66497e3ce..0db8649e4b 100644 --- a/src/client/theme-api/index.ts +++ b/src/client/theme-api/index.ts @@ -31,6 +31,7 @@ export { useLiveDemo } from './useLiveDemo'; export { useLocale } from './useLocale'; export { useNavData } from './useNavData'; export { usePrefersColor } from './usePrefersColor'; +export { useRenderer } from './useRenderer'; export { useRouteMeta } from './useRouteMeta'; export { useFullSidebarData, useSidebarData } from './useSidebarData'; export { useSiteSearch } from './useSiteSearch'; diff --git a/src/features/parser.ts b/src/features/parser.ts index fedd3b8974..f7866d387f 100644 --- a/src/features/parser.ts +++ b/src/features/parser.ts @@ -1,13 +1,10 @@ -import type { IApi } from '@/types'; +import type { AtomAssetsParser, IApi } from '@/types'; import { lodash } from '@umijs/utils'; import assert from 'assert'; -import { - BaseAtomAssetsParser, - type IAtomAssetsParser, -} from '../assetParsers/BaseParser'; +import { BaseAtomAssetsParser } from '../assetParsers/BaseParser'; import { ATOMS_META_PATH } from './meta'; -type IParsedAtomAssets = Awaited>; +type IParsedAtomAssets = Awaited>; function filterIgnoredProps( props: IParsedAtomAssets['components'][string]['propsConfig']['properties'], @@ -91,10 +88,7 @@ export default (api: IApi) => { default: ReactAtomAssetsParser, }: typeof import('@/assetParsers/atom') = require('@/assetParsers/atom'); - const apiParser = api.config.apiParser as Exclude< - IApi['config']['apiParser'], - false | undefined - >; + const apiParser = api.config.apiParser || {}; api.service.atomParser = new ReactAtomAssetsParser({ entryFile: api.config.resolve.entryFile!, diff --git a/src/index.ts b/src/index.ts index 23487f1d72..3870cf250b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,6 @@ import type { + AtomAssetsParser, + AtomAssetsParserResult, IDumiTechStack, IDumiTechStackRuntimeOpts, IDumiUserConfig, @@ -11,6 +13,14 @@ let unistUtilVisit: typeof import('unist-util-visit'); })(); export * from 'umi'; +export * from './assetParsers/BaseParser'; +export * from './assetParsers/utils'; export { getProjectRoot } from './utils'; -export { unistUtilVisit, IDumiTechStack, IDumiTechStackRuntimeOpts }; +export { + unistUtilVisit, + IDumiTechStack, + IDumiTechStackRuntimeOpts, + AtomAssetsParser, + AtomAssetsParserResult, +}; export const defineConfig = (config: IDumiUserConfig) => config; diff --git a/src/loaders/markdown/index.ts b/src/loaders/markdown/index.ts index d8a07dc532..db17845a54 100644 --- a/src/loaders/markdown/index.ts +++ b/src/loaders/markdown/index.ts @@ -124,9 +124,11 @@ function emitDemo( export const demos = { {{#demos}} '{{{id}}}': { + id: "{{{id}}}", {{#component}} component: {{{component}}}, {{/component}} + renderOpts: {{{renderRenderOpts}}}, asset: {{{renderAsset}}}, context: {{{renderContext}}}, renderOpts: {{{renderRenderOpts}}}, diff --git a/src/loaders/markdown/transformer/rehypeDemo.ts b/src/loaders/markdown/transformer/rehypeDemo.ts index 5a48e1bc72..a5b3d1f479 100644 --- a/src/loaders/markdown/transformer/rehypeDemo.ts +++ b/src/loaders/markdown/transformer/rehypeDemo.ts @@ -247,7 +247,7 @@ export default function rehypeDemo( ? [vFile.data.frontmatter!.atomId] : [], fileAbsPath: '', - lang: codeNode.data!.lang, + lang: (codeNode.data?.lang as string) || 'tsx', entryPointCode: codeType === 'external' ? undefined : codeValue, resolver: opts.resolver, techStack, diff --git a/src/types.ts b/src/types.ts index 2aba1dfa58..076df27786 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/ban-types */ -import type { BaseAtomAssetsParser as IAtomAssetsParser } from '@/assetParsers/BaseParser'; +// import type AtomAssetsParser from '@/assetParsers/atom'; import type { IParsedBlockAsset } from '@/assetParsers/block'; import type { IDumiDemoProps } from '@/client/theme-api/DumiDemo'; import type { ILocalesConfig, IThemeConfig } from '@/client/theme-api/types'; @@ -10,7 +10,12 @@ import { OnLoadResult, } from '@umijs/bundler-utils/compiled/esbuild'; import type { IModify } from '@umijs/core'; -import type { AssetsPackage, ExampleBlockAsset } from 'dumi-assets-types'; +import type { + AssetsPackage, + AtomComponentAsset, + AtomFunctionAsset, + ExampleBlockAsset, +} from 'dumi-assets-types'; import type { Element } from 'hast'; import type { IApi as IUmiApi, defineConfig as defineUmiConfig } from 'umi'; @@ -156,12 +161,39 @@ export abstract class IDumiTechStack { ): IDumiTechStackOnBlockLoadResult | null; } +export interface AtomAssetsParserResult { + components: Record; + functions: Record; +} + +export abstract class AtomAssetsParser { + /** + * parse component metadata + */ + abstract parse(): Promise; + + /** + * monitor documents and codes, update component metadata at any time + */ + abstract watch(cb: (data: AtomAssetsParserResult) => void): void; + + /** + * cancel monitoring + */ + abstract unwatch(cb: (data: AtomAssetsParserResult) => void): void; + + /** + * cancel parsing + */ + abstract destroyWorker(): void; +} + export type IApi = IUmiApi & { config: IDumiConfig & { [key: string]: any }; userConfig: IDumiUserConfig; service: IUmiApi['service'] & { themeData: IThemeLoadResult; - atomParser: IAtomAssetsParser; + atomParser: AtomAssetsParser; }; /** * register a new tech stack diff --git a/suites/dumi-vue-meta/.fatherrc.ts b/suites/dumi-vue-meta/.fatherrc.ts index c45e1a9a84..7eee87086b 100644 --- a/suites/dumi-vue-meta/.fatherrc.ts +++ b/suites/dumi-vue-meta/.fatherrc.ts @@ -2,4 +2,8 @@ import { defineConfig } from 'father'; export default defineConfig({ cjs: {}, + esm: {}, + prebundle: { + deps: {}, + }, }); diff --git a/suites/preset-vue/src/atomParser/index.ts b/suites/preset-vue/src/atomParser/index.ts index aa0a244378..bfae9e4070 100644 --- a/suites/preset-vue/src/atomParser/index.ts +++ b/suites/preset-vue/src/atomParser/index.ts @@ -1,20 +1,20 @@ import type { MetaCheckerOptions } from '@dumijs/vue-meta'; import { createProject, dumiTransfomer } from '@dumijs/vue-meta'; import { - IBaseApiParserOptions, - ILanguageMetaParser, - IPatchFile, + BaseApiParserOptions, + LanguageMetaParser, + PatchFile, createApiParser, -} from 'dumi/tech-stack-utils'; +} from 'dumi'; import path from 'path'; import { fsExtra } from 'umi/plugin-utils'; -export interface VueParserOptions extends IBaseApiParserOptions { +export interface VueParserOptions extends BaseApiParserOptions { tsconfigPath?: string; checkerOptions?: MetaCheckerOptions; } -class VueMetaParser implements ILanguageMetaParser { +class VueMetaParser implements LanguageMetaParser { protected entryFile: string; protected resolveDir: string; private checkerOptions!: MetaCheckerOptions; @@ -32,7 +32,7 @@ class VueMetaParser implements ILanguageMetaParser { checkerOptions: this.checkerOptions, }); } - async patch(file: IPatchFile) { + async patch(file: PatchFile) { const { event, fileName } = file; switch (event) { case 'add': diff --git a/suites/preset-vue/src/compiler/index.ts b/suites/preset-vue/src/compiler/index.ts index 3b6e6478dc..c45526e6a2 100644 --- a/suites/preset-vue/src/compiler/index.ts +++ b/suites/preset-vue/src/compiler/index.ts @@ -1,4 +1,4 @@ -import type { BabelCore, babelCore } from 'dumi/tech-stack-utils'; +import type { BabelCore, babelCore } from 'dumi/bundler-utils'; import { CompilerError, CompilerOptions, diff --git a/suites/preset-vue/src/compiler/node.ts b/suites/preset-vue/src/compiler/node.ts index 9d28200286..1529f1177a 100644 --- a/suites/preset-vue/src/compiler/node.ts +++ b/suites/preset-vue/src/compiler/node.ts @@ -2,7 +2,7 @@ import { babelCore, babelPresetEnv, babelPresetTypeScript, -} from 'dumi/tech-stack-utils'; +} from 'dumi/bundler-utils'; import { COMP_IDENTIFIER, createCompiler, type CompileOptions } from './index'; const babel = babelCore(); diff --git a/suites/preset-vue/src/vue/webpack/config.ts b/suites/preset-vue/src/vue/webpack/config.ts index 207caf0c62..4c3fb22b03 100644 --- a/suites/preset-vue/src/vue/webpack/config.ts +++ b/suites/preset-vue/src/vue/webpack/config.ts @@ -1,5 +1,5 @@ import type Config from '@umijs/bundler-webpack/compiled/webpack-5-chain'; -import { babelPresetTypeScript } from 'dumi/tech-stack-utils'; +import { babelPresetTypeScript } from 'dumi/bundler-utils'; import type { IApi } from 'umi'; import VueLoaderPlugin from 'vue-loader/dist/pluginWebpack5.js'; // Webpack configuration mainly refers to @umijs/preset-vue diff --git a/tech-stack-utils.d.ts b/tech-stack-utils.d.ts index 4a4822cba9..54396916d1 100644 --- a/tech-stack-utils.d.ts +++ b/tech-stack-utils.d.ts @@ -1,12 +1 @@ -import type * as BabelCore from '@umijs/bundler-utils/compiled/@babel/core'; -export { - IBaseApiParserOptions, - ILanguageMetaParser, - IPatchFile, -} from './dist/assetParsers/BaseParser'; -export { createApiParser } from './dist/assetParsers/utils'; export * from './dist/techStacks/utils'; -export { BabelCore }; -export const babelCore: () => typeof import('@umijs/bundler-utils/compiled/@babel/core'); -export const babelPresetTypeScript: () => BabelCore.PluginItem; -export const babelPresetEnv: () => BabelCore.PluginItem; diff --git a/tech-stack-utils.js b/tech-stack-utils.js index c21c1810e4..414f7e74bb 100644 --- a/tech-stack-utils.js +++ b/tech-stack-utils.js @@ -1,9 +1 @@ -module.exports = { - ...require('./dist/techStacks/utils'), - createApiParser: require('./dist/assetParsers/utils').createApiParser, - babelCore: () => require('@umijs/bundler-utils/compiled/babel/core'), - babelPresetTypeScript: () => - require('@umijs/bundler-utils/compiled/babel/preset-typescript'), - babelPresetEnv: () => - require('@umijs/bundler-utils/compiled/babel/preset-env'), -}; +module.exports = require('./dist/techStacks/utils'); diff --git a/vitest.config.ts b/vitest.config.ts index df4363e4e2..90f860455b 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -7,6 +7,7 @@ export default defineConfig({ alias: { '@': path.join(__dirname, 'src'), }, + globalSetup: [path.join(__dirname, 'src/assetParsers/__tests__/setup.js')], poolMatchGlobs: [['**/__tests__/**/*.fork.test.*', 'child_process']], }, });