chore: 升级依赖并适配 Vitest 5

This commit is contained in:
roymondchen 2026-09-20 17:12:09 +08:00
parent 489a1143b7
commit 77e9f86efb
28 changed files with 1564 additions and 1832 deletions

1
.gitignore vendored
View File

@ -28,6 +28,7 @@ pnpm-debug.log*
*.sw? *.sw?
coverage coverage
.vitest
auto-imports.d.ts auto-imports.d.ts
components.d.ts components.d.ts

View File

@ -11,15 +11,15 @@
"dependencies": { "dependencies": {
"@eslint/js": "^10.0.1", "@eslint/js": "^10.0.1",
"@stylistic/eslint-plugin": "^5.10.0", "@stylistic/eslint-plugin": "^5.10.0",
"@typescript-eslint/eslint-plugin": "^8.66.0", "@typescript-eslint/eslint-plugin": "^8.70.0",
"@typescript-eslint/parser": "^8.66.0", "@typescript-eslint/parser": "^8.70.0",
"eslint-config-prettier": "^10.1.8", "eslint-config-prettier": "^10.1.8",
"eslint-plugin-import": "^2.32.0", "eslint-plugin-import": "^2.32.0",
"eslint-plugin-prettier": "^5.5.6", "eslint-plugin-prettier": "^5.5.6",
"eslint-plugin-simple-import-sort": "^14.0.0", "eslint-plugin-simple-import-sort": "^14.0.0",
"eslint-plugin-vue": "^10.10.0", "eslint-plugin-vue": "^10.11.0",
"globals": "^17.9.0", "globals": "^17.12.0",
"typescript-eslint": "^8.66.0", "typescript-eslint": "^8.70.0",
"vue-eslint-parser": "^10.4.1" "vue-eslint-parser": "^10.4.1"
}, },
"peerDependencies": { "peerDependencies": {

View File

@ -6,7 +6,7 @@
"packageManager": "pnpm@11.21.0", "packageManager": "pnpm@11.21.0",
"scripts": { "scripts": {
"bootstrap": "pnpm i && pnpm build", "bootstrap": "pnpm i && pnpm build",
"clean:top": "rimraf packages/*/dist packages/*/types runtime/*/dist runtime/*/types vue-components/*/dist vue-components/*/types react-components/*/dist react-components/*/types playground/dist coverage dwt* temp packages/cli/lib", "clean:top": "rimraf packages/*/dist packages/*/types runtime/*/dist runtime/*/types vue-components/*/dist vue-components/*/types react-components/*/dist react-components/*/types playground/dist coverage .vitest dwt* temp packages/cli/lib",
"clean:modules": "rimraf node_modules **/node_modules **/**/node_modules", "clean:modules": "rimraf node_modules **/node_modules **/**/node_modules",
"clean:all": "pnpm clean:top && pnpm clean:modules", "clean:all": "pnpm clean:top && pnpm clean:modules",
"lint": "eslint --cache .", "lint": "eslint --cache .",
@ -41,44 +41,44 @@
"url": "https://github.com/Tencent/tmagic-editor.git" "url": "https://github.com/Tencent/tmagic-editor.git"
}, },
"devDependencies": { "devDependencies": {
"@commitlint/cli": "^21.2.1", "@commitlint/cli": "^21.2.3",
"@commitlint/config-conventional": "^21.2.0", "@commitlint/config-conventional": "^21.2.3",
"@tmagic/eslint-config": "workspace:*", "@tmagic/eslint-config": "workspace:*",
"@types/node": "26.1.2", "@types/node": "26.6.2",
"@vitejs/plugin-vue": "^6.0.8", "@vitejs/plugin-vue": "^6.0.9",
"@vitest/coverage-v8": "^4.1.10", "@vitest/coverage-v8": "^5.0.1",
"@vue/compiler-sfc": "catalog:", "@vue/compiler-sfc": "catalog:",
"c8": "^12.0.0", "c8": "^12.0.0",
"commitizen": "^4.3.2", "commitizen": "^4.3.2",
"conventional-changelog-cli": "^5.0.0", "conventional-changelog-cli": "^5.0.0",
"cosmiconfig": "^10.0.0", "cosmiconfig": "^10.0.1",
"cz-conventional-changelog": "^3.3.0", "cz-conventional-changelog": "^3.3.0",
"element-plus": "catalog:", "element-plus": "catalog:",
"enquirer": "^2.4.1", "enquirer": "^2.4.1",
"eslint": "^10.8.1", "eslint": "^10.11.0",
"execa": "^10.0.1", "execa": "^10.0.1",
"happy-dom": "^20.11.2", "happy-dom": "^20.14.5",
"highlight.js": "^11.11.1", "highlight.js": "^11.12.0",
"husky": "^9.1.7", "husky": "^9.1.7",
"jsdom": "^30.0.1", "jsdom": "^30.1.0",
"lint-staged": "^17.3.0", "lint-staged": "^17.5.1",
"minimist": "^1.2.8", "minimist": "^1.2.8",
"picocolors": "^1.1.1", "picocolors": "^1.1.1",
"prettier": "^3.9.6", "prettier": "^3.9.8",
"recast": "^0.23.20", "recast": "^0.23.20",
"rimraf": "^6.1.3", "rimraf": "^6.1.3",
"rolldown": "^1.2.3", "rolldown": "^1.2.9",
"rolldown-plugin-dts": "^0.28.1", "rolldown-plugin-dts": "^0.28.6",
"sass-embedded": "^1.100.0", "sass-embedded": "^1.104.1",
"semver": "^7.8.5", "semver": "^7.8.5",
"serialize-javascript": "^7.1.0", "serialize-javascript": "^7.1.1",
"shx": "^0.4.0", "shx": "^0.4.0",
"typescript": "catalog:", "typescript": "catalog:",
"vite": "catalog:", "vite": "catalog:",
"vitepress": "2.0.0-alpha.19", "vitepress": "2.0.0-alpha.20",
"vitest": "^4.1.10", "vitest": "^5.0.1",
"vue": "^3.5.41", "vue": "^3.5.43",
"vue-tsc": "^3.3.9" "vue-tsc": "^3.3.11"
}, },
"config": { "config": {
"commitizen": { "commitizen": {

View File

@ -37,8 +37,8 @@
}, },
"devDependencies": { "devDependencies": {
"@types/fs-extra": "^11.0.4", "@types/fs-extra": "^11.0.4",
"@types/node": "^26.1.2", "@types/node": "^26.6.2",
"rolldown": "^1.2.2", "rolldown": "^1.2.9",
"rolldown-plugin-dts": "^0.28.0" "rolldown-plugin-dts": "^0.28.6"
} }
} }

View File

@ -66,7 +66,7 @@
"keycon": "^1.4.0", "keycon": "^1.4.0",
"lodash-es": "^4.18.1", "lodash-es": "^4.18.1",
"moveable": "^0.53.0", "moveable": "^0.53.0",
"serialize-javascript": "^7.0.7", "serialize-javascript": "^7.1.1",
"sortablejs": "^1.15.7" "sortablejs": "^1.15.7"
}, },
"devDependencies": { "devDependencies": {
@ -74,7 +74,7 @@
"@types/lodash-es": "^4.17.12", "@types/lodash-es": "^4.17.12",
"@types/serialize-javascript": "^5.0.4", "@types/serialize-javascript": "^5.0.4",
"@types/sortablejs": "^1.15.9", "@types/sortablejs": "^1.15.9",
"@vue/test-utils": "^2.4.11" "@vue/test-utils": "^2.5.1"
}, },
"peerDependencies": { "peerDependencies": {
"@tmagic/core": "workspace:*", "@tmagic/core": "workspace:*",

View File

@ -118,7 +118,7 @@ const emit = defineEmits<{
change: [v: string[]]; change: [v: string[]];
}>(); }>();
const modelValue = defineModel<string[] | any>('modelValue', { default: [] }); const modelValue = defineModel<string[] | any>('modelValue', { default: () => [] });
const optionComponent = getDesignConfig('components')?.option; const optionComponent = getDesignConfig('components')?.option;

View File

@ -90,21 +90,16 @@ vi.mock('@editor/utils/editor', () => ({
getGuideLineFromCache: vi.fn(() => []), getGuideLineFromCache: vi.fn(() => []),
})); }));
const localStorageMock = {
setItem: vi.fn(),
removeItem: vi.fn(),
getItem: vi.fn(),
};
beforeEach(() => { beforeEach(() => {
StageCoreCtor.mockClear(); StageCoreCtor.mockClear();
Object.keys(stageInstance.handlers).forEach((k) => delete stageInstance.handlers[k]); Object.keys(stageInstance.handlers).forEach((k) => delete stageInstance.handlers[k]);
vi.clearAllMocks(); vi.spyOn(globalThis.localStorage, 'setItem').mockImplementation(() => undefined);
globalThis.localStorage = localStorageMock as any; vi.spyOn(globalThis.localStorage, 'removeItem').mockImplementation(() => undefined);
vi.spyOn(globalThis.localStorage, 'getItem').mockImplementation(() => null);
}); });
afterEach(() => { afterEach(() => {
delete (globalThis as any).localStorage; vi.restoreAllMocks();
}); });
describe('useStage', () => { describe('useStage', () => {
@ -262,14 +257,14 @@ describe('useStage', () => {
test('change-guides 事件: 写入 localStorage', () => { test('change-guides 事件: 写入 localStorage', () => {
useStage({} as any); useStage({} as any);
stageInstance.handlers['change-guides'][0]({ type: 'h', guides: [10, 20] }); stageInstance.handlers['change-guides'][0]({ type: 'h', guides: [10, 20] });
expect(localStorageMock.setItem).toHaveBeenCalled(); expect(globalThis.localStorage.setItem).toHaveBeenCalled();
expect(uiService.set).toHaveBeenCalledWith('showGuides', true); expect(uiService.set).toHaveBeenCalledWith('showGuides', true);
}); });
test('change-guides 事件: 空 guides 删除 localStorage', () => { test('change-guides 事件: 空 guides 删除 localStorage', () => {
useStage({} as any); useStage({} as any);
stageInstance.handlers['change-guides'][0]({ type: 'v', guides: [] }); stageInstance.handlers['change-guides'][0]({ type: 'v', guides: [] });
expect(localStorageMock.removeItem).toHaveBeenCalled(); expect(globalThis.localStorage.removeItem).toHaveBeenCalled();
}); });
test('page-el-update 事件 重置 stageLoading', () => { test('page-el-update 事件 重置 stageLoading', () => {

View File

@ -340,12 +340,12 @@ describe('select', () => {
expect(page?.id).toBe(NodeId.PAGE_ID); expect(page?.id).toBe(NodeId.PAGE_ID);
}); });
test('参数是id undefined', () => { test('参数是id undefined', async () => {
expect(() => editorService.select(NodeId.ERROR_NODE_ID)).rejects.toThrowError('获取不到组件信息'); await expect(editorService.select(NodeId.ERROR_NODE_ID)).rejects.toThrowError('获取不到组件信息');
}); });
test('参数是config 没有id', () => { test('参数是config 没有id', async () => {
expect(() => editorService.select({ id: '', type: 'text' })).rejects.toThrowError('没有ID无法选中'); await expect(editorService.select({ id: '', type: 'text' })).rejects.toThrowError('没有ID无法选中');
}); });
}); });
@ -399,11 +399,11 @@ describe('add', () => {
expect(rootNode?.items.length).toBe(2); expect(rootNode?.items.length).toBe(2);
}); });
test('往root下添加普通节点', () => { test('往root下添加普通节点', async () => {
editorService.set('root', cloneDeep(root)); editorService.set('root', cloneDeep(root));
// 根节点下只能加页面 // 根节点下只能加页面
const rootNode = editorService.get('root'); const rootNode = editorService.get('root');
expect(() => await expect(
editorService.add( editorService.add(
{ {
type: 'text', type: 'text',
@ -556,7 +556,7 @@ describe('remove', () => {
}); });
test('undefine', async () => { test('undefine', async () => {
expect(() => editorService.remove({ id: NodeId.ERROR_NODE_ID, type: 'text' })).rejects.toThrow(); await expect(editorService.remove({ id: NodeId.ERROR_NODE_ID, type: 'text' })).rejects.toThrow();
}); });
test('doNotSelect: true 不更新选中节点', async () => { test('doNotSelect: true 不更新选中节点', async () => {

View File

@ -46,14 +46,14 @@
"@element-plus/icons-vue": "^2.3.2", "@element-plus/icons-vue": "^2.3.2",
"@popperjs/core": "^2.11.8", "@popperjs/core": "^2.11.8",
"async-validator": "^4.2.5", "async-validator": "^4.2.5",
"dayjs": "^1.11.21", "dayjs": "^1.11.23",
"lodash-es": "^4.18.1", "lodash-es": "^4.18.1",
"sortablejs": "^1.15.7" "sortablejs": "^1.15.7"
}, },
"devDependencies": { "devDependencies": {
"@types/lodash-es": "^4.17.12", "@types/lodash-es": "^4.17.12",
"@types/sortablejs": "^1.15.9", "@types/sortablejs": "^1.15.9",
"@vue/test-utils": "^2.4.11" "@vue/test-utils": "^2.5.1"
}, },
"peerDependencies": { "peerDependencies": {
"@tmagic/design": "workspace:*", "@tmagic/design": "workspace:*",

View File

@ -42,7 +42,7 @@
}, },
"devDependencies": { "devDependencies": {
"@types/lodash-es": "^4.17.12", "@types/lodash-es": "^4.17.12",
"@vue/test-utils": "^2.4.11" "@vue/test-utils": "^2.5.1"
}, },
"peerDependencies": { "peerDependencies": {
"@tmagic/design": "workspace:*", "@tmagic/design": "workspace:*",

View File

@ -17,21 +17,21 @@
"@tmagic/editor": "1.8.0-beta.28", "@tmagic/editor": "1.8.0-beta.28",
"@tmagic/element-plus-adapter": "1.8.0-beta.28", "@tmagic/element-plus-adapter": "1.8.0-beta.28",
"@tmagic/tdesign-vue-next-adapter": "1.8.0-beta.28", "@tmagic/tdesign-vue-next-adapter": "1.8.0-beta.28",
"@tmagic/tmagic-form-runtime": "1.1.6", "@tmagic/tmagic-form-runtime": "1.1.8",
"element-plus": "catalog:", "element-plus": "catalog:",
"lodash-es": "^4.18.1", "lodash-es": "^4.18.1",
"monaco-editor": "^0.56.0", "monaco-editor": "^0.56.0",
"serialize-javascript": "^7.1.0", "serialize-javascript": "^7.1.1",
"tdesign-vue-next": "^1.20.5", "tdesign-vue-next": "^1.20.8",
"vue": "catalog:", "vue": "catalog:",
"vue-router": "^5.2.0" "vue-router": "^5.3.1"
}, },
"devDependencies": { "devDependencies": {
"@types/lodash-es": "^4.17.12", "@types/lodash-es": "^4.17.12",
"@types/node": "^26.1.2", "@types/node": "^26.6.2",
"@types/serialize-javascript": "^5.0.4", "@types/serialize-javascript": "^5.0.4",
"@vitejs/plugin-legacy": "^8.2.3", "@vitejs/plugin-legacy": "^8.2.3",
"@vitejs/plugin-vue": "^6.0.8", "@vitejs/plugin-vue": "^6.0.9",
"@vitejs/plugin-vue-jsx": "^5.1.6", "@vitejs/plugin-vue-jsx": "^5.1.6",
"@vue/compiler-sfc": "catalog:", "@vue/compiler-sfc": "catalog:",
"typescript": "catalog:", "typescript": "catalog:",

3200
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -18,12 +18,12 @@ allowBuilds:
esbuild: true esbuild: true
catalog: catalog:
"@vue/compiler-sfc": ^3.5.41 "@vue/compiler-sfc": ^3.5.43
typescript: "^6.0.3" typescript: "^6.0.3"
vite: ^8.2.1 vite: ^8.3.0
vue: ^3.5.41 vue: ^3.5.43
element-plus: ^2.14.4 element-plus: ^2.14.6
overrides: overrides:
element-plus: ^2.14.4 element-plus: ^2.14.6
vue: ^3.5.41 vue: ^3.5.43

View File

@ -29,7 +29,7 @@
} }
}, },
"devDependencies": { "devDependencies": {
"@types/react": "^19.2.18", "@types/react": "^19.3.0",
"@types/react-dom": "^19.2.4" "@types/react-dom": "^19.3.0"
} }
} }

View File

@ -29,7 +29,7 @@
} }
}, },
"devDependencies": { "devDependencies": {
"@types/react": "^19.2.18", "@types/react": "^19.3.0",
"@types/react-dom": "^19.2.4" "@types/react-dom": "^19.3.0"
} }
} }

View File

@ -29,7 +29,7 @@
} }
}, },
"devDependencies": { "devDependencies": {
"@types/react": "^19.2.18", "@types/react": "^19.3.0",
"@types/react-dom": "^19.2.4" "@types/react-dom": "^19.3.0"
} }
} }

View File

@ -29,7 +29,7 @@
} }
}, },
"devDependencies": { "devDependencies": {
"@types/react": "^19.2.18", "@types/react": "^19.3.0",
"@types/react-dom": "^19.2.4" "@types/react-dom": "^19.3.0"
} }
} }

View File

@ -29,7 +29,7 @@
} }
}, },
"devDependencies": { "devDependencies": {
"@types/react": "^19.2.18", "@types/react": "^19.3.0",
"@types/react-dom": "^19.2.4" "@types/react-dom": "^19.3.0"
} }
} }

View File

@ -29,7 +29,7 @@
} }
}, },
"devDependencies": { "devDependencies": {
"@types/react": "^19.2.18", "@types/react": "^19.3.0",
"@types/react-dom": "^19.2.4" "@types/react-dom": "^19.3.0"
} }
} }

View File

@ -29,7 +29,7 @@
} }
}, },
"devDependencies": { "devDependencies": {
"@types/react": "^19.2.18", "@types/react": "^19.3.0",
"@types/react-dom": "^19.2.4" "@types/react-dom": "^19.3.0"
} }
} }

View File

@ -29,7 +29,7 @@
} }
}, },
"devDependencies": { "devDependencies": {
"@types/react": "^19.2.18", "@types/react": "^19.3.0",
"@types/react-dom": "^19.2.4" "@types/react-dom": "^19.3.0"
} }
} }

View File

@ -31,7 +31,7 @@
}, },
"devDependencies": { "devDependencies": {
"@types/qrcode": "^1.5.6", "@types/qrcode": "^1.5.6",
"@types/react": "^19.2.18", "@types/react": "^19.3.0",
"@types/react-dom": "^19.2.4" "@types/react-dom": "^19.3.0"
} }
} }

View File

@ -29,7 +29,7 @@
} }
}, },
"devDependencies": { "devDependencies": {
"@types/react": "^19.2.18", "@types/react": "^19.3.0",
"@types/react-dom": "^19.2.4" "@types/react-dom": "^19.3.0"
} }
} }

View File

@ -49,6 +49,6 @@
}, },
"devDependencies": { "devDependencies": {
"@types/lodash-es": "^4.17.12", "@types/lodash-es": "^4.17.12",
"@types/react": "^19.2.18" "@types/react": "^19.3.0"
} }
} }

View File

@ -19,17 +19,17 @@
"@tmagic/core": "1.8.0-beta.28", "@tmagic/core": "1.8.0-beta.28",
"@tmagic/react-runtime-help": "0.2.2", "@tmagic/react-runtime-help": "0.2.2",
"@tmagic/stage": "1.8.0-beta.28", "@tmagic/stage": "1.8.0-beta.28",
"axios": "^1.19.0", "axios": "^1.20.0",
"qrcode": "^1.5.4", "qrcode": "^1.5.4",
"react": "^19.2.8", "react": "^19.3.0",
"react-dom": "^19.2.8" "react-dom": "^19.3.0"
}, },
"devDependencies": { "devDependencies": {
"@tmagic/cli": "1.8.0-beta.28", "@tmagic/cli": "1.8.0-beta.28",
"@types/fs-extra": "^11.0.4", "@types/fs-extra": "^11.0.4",
"@types/react": "^19.2.18", "@types/react": "^19.3.0",
"@types/react-dom": "^19.2.4", "@types/react-dom": "^19.3.0",
"@vitejs/plugin-legacy": "^8.2.2", "@vitejs/plugin-legacy": "^8.2.3",
"@vitejs/plugin-react-refresh": "^1.3.6", "@vitejs/plugin-react-refresh": "^1.3.6",
"fs-extra": "^11.4.0", "fs-extra": "^11.4.0",
"typescript": "catalog:", "typescript": "catalog:",

View File

@ -44,6 +44,6 @@
} }
}, },
"devDependencies": { "devDependencies": {
"@vue/test-utils": "^2.4.11" "@vue/test-utils": "^2.5.1"
} }
} }

View File

@ -19,15 +19,15 @@
"@tmagic/core": "1.8.0-beta.28", "@tmagic/core": "1.8.0-beta.28",
"@tmagic/stage": "1.8.0-beta.28", "@tmagic/stage": "1.8.0-beta.28",
"@tmagic/vue-runtime-help": "^2.0.4", "@tmagic/vue-runtime-help": "^2.0.4",
"axios": "^1.19.0", "axios": "^1.20.0",
"vue": "catalog:" "vue": "catalog:"
}, },
"devDependencies": { "devDependencies": {
"@tmagic/cli": "1.8.0-beta.28", "@tmagic/cli": "workspace:*",
"@types/fs-extra": "^11.0.4", "@types/fs-extra": "^11.0.4",
"@types/node": "^26.1.2", "@types/node": "^26.6.2",
"@vitejs/plugin-legacy": "^8.2.2", "@vitejs/plugin-legacy": "^8.2.3",
"@vitejs/plugin-vue": "^6.0.8", "@vitejs/plugin-vue": "^6.0.9",
"@vitejs/plugin-vue-jsx": "^5.1.6", "@vitejs/plugin-vue-jsx": "^5.1.6",
"@vue/compiler-sfc": "catalog:", "@vue/compiler-sfc": "catalog:",
"fs-extra": "^11.4.0", "fs-extra": "^11.4.0",

View File

@ -1,9 +1,9 @@
import { resolve } from 'path'; import { resolve } from 'node:path';
import { defineConfig } from 'vitest/config'; import { defineConfig } from 'vitest/config';
import Vue from '@vitejs/plugin-vue'; import Vue from '@vitejs/plugin-vue';
const r = (p: string) => resolve(__dirname, p); const r = (p: string) => resolve(import.meta.dirname, p);
const alias = { const alias = {
'@editor': r('./packages/editor/src'), '@editor': r('./packages/editor/src'),