From a47e1e602700c905cdb6bc894f00347cf6629163 Mon Sep 17 00:00:00 2001 From: xfy Date: Thu, 2 Jul 2026 18:02:52 +0800 Subject: [PATCH] =?UTF-8?q?refactor(build):=20workspace=20=E6=A0=B9?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=E8=87=B3=20libs/,Makefile=20=E6=95=B4?= =?UTF-8?q?=E5=90=88=20lint/fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 pnpm workspace 根从项目根移到 libs/,项目根保持纯 Rust,JS 工作区自治: - package.json/pnpm-workspace.yaml/pnpm-lock.yaml/biome.json 迁入 libs/ - pnpm-workspace.yaml glob 从 'libs/*' 改为 '*'(已在 libs/ 内) - biome.json 关闭 vcs.useIgnoreFile(libs/ 无独立 .gitignore, files.includes 已显式排除 node_modules/dist) - Makefile 所有 pnpm/biome 调用加 'cd libs &&' 前缀 Makefile 同步整合 lint/fix(替代独立 clippy/fix target): - make lint = biome check (libs) + cargo clippy - make fix = biome format --write (libs) + cargo fix - 删除 8 个 build-*-incremental/build-* target,改为 build-libs 聚合 + build- 用 pnpm --filter 单库便利 target 修复 biome 格式化回归:tiptap-editor/src/index.ts:83 的 sourceTextarea!.value 被 biome 误转为可选链 ?.,导致 TS2345(string | undefined 不匹配 string), 已还原为非空断言。 --- Makefile | 77 ++++++++++----------------- biome.json => libs/biome.json | 11 +--- package.json => libs/package.json | 0 pnpm-lock.yaml => libs/pnpm-lock.yaml | 8 +-- libs/pnpm-workspace.yaml | 2 + libs/tiptap-editor/src/index.ts | 2 +- pnpm-workspace.yaml | 2 - 7 files changed, 36 insertions(+), 66 deletions(-) rename biome.json => libs/biome.json (88%) rename package.json => libs/package.json (100%) rename pnpm-lock.yaml => libs/pnpm-lock.yaml (99%) create mode 100644 libs/pnpm-workspace.yaml delete mode 100644 pnpm-workspace.yaml diff --git a/Makefile b/Makefile index 672fbdd..1a97107 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,8 @@ -.PHONY: dev build build-linux build-freebsd freebsd-sysroot docker css css-watch clean build-editor build-editor-incremental build-lightbox build-lightbox-incremental build-core build-core-incremental build-codemirror build-codemirror-incremental highlight-css test doc doc-open start clippy fix restore-webp +.PHONY: dev build build-linux build-freebsd freebsd-sysroot docker css css-watch clean build-libs build-editor build-codemirror build-lightbox build-core highlight-css test doc doc-open start lint fix restore-webp build: - @$(MAKE) build-editor - @$(MAKE) build-lightbox - @$(MAKE) build-core - @$(MAKE) build-codemirror + @cd libs && pnpm install --frozen-lockfile + @$(MAKE) build-libs @$(MAKE) highlight-css @tailwindcss -i input.css -o public/style.css --minify @$(MAKE) doc @@ -12,10 +10,8 @@ build: @$(MAKE) restore-webp build-linux: - @$(MAKE) build-editor - @$(MAKE) build-lightbox - @$(MAKE) build-core - @$(MAKE) build-codemirror + @cd libs && pnpm install --frozen-lockfile + @$(MAKE) build-libs @$(MAKE) highlight-css @tailwindcss -i input.css -o public/style.css --minify @dx build @client --release --debug-symbols=false --wasm-js-cfg false @@ -86,44 +82,19 @@ restore-webp: highlight-css: @cargo run --bin generate_highlight_css -build-editor: - @echo "Building Tiptap editor..." - @cd libs/tiptap-editor && pnpm ci --include=dev && pnpm run build - @echo "Tiptap editor built." +# 并行构建全部 4 个 libs/ 子项目(pnpm -r 拓扑顺序,无相互依赖则并发)。 +# 依赖安装由调用方负责(build/build-linux 用 pnpm install --frozen-lockfile, +# dev 假设 node_modules 已存在)。 +build-libs: + @cd libs && pnpm -r run build -# dev 用的增量构建:跳过 pnpm ci(假设 node_modules 已存在),仅 vite build。 -# 与 build-editor 分开,避免每次 make dev 都重装依赖。 -build-editor-incremental: - @cd libs/tiptap-editor && pnpm run build +# 单库便利 target(替代旧的 build-,用 pnpm --filter 精确定位)。 +build-editor: ; @cd libs && pnpm --filter @yggdrasil/tiptap-editor run build +build-codemirror: ; @cd libs && pnpm --filter @yggdrasil/codemirror-editor run build +build-lightbox: ; @cd libs && pnpm --filter @yggdrasil/lightbox run build +build-core: ; @cd libs && pnpm --filter @yggdrasil/core run build -build-lightbox: - @echo "Building Lightbox..." - @cd libs/lightbox && pnpm install && pnpm run build - @echo "Lightbox built." - -# dev 用的增量构建:跳过 pnpm ci(假设 node_modules 已存在),仅 vite build。 -build-lightbox-incremental: - @cd libs/lightbox && pnpm run build - -build-core: - @echo "Building yggdrasil-core..." - @cd libs/yggdrasil-core && pnpm install && pnpm run build - @echo "yggdrasil-core built." - -# dev 用的增量构建:跳过 pnpm install(假设 node_modules 已存在),仅 vite build。 -build-core-incremental: - @cd libs/yggdrasil-core && pnpm run build - -build-codemirror: - @echo "Building CodeMirror editor..." - @cd libs/codemirror-editor && pnpm ci --include=dev && pnpm run build - @echo "CodeMirror editor built." - -# dev 用的增量构建:跳过 pnpm ci(假设 node_modules 已存在),仅 vite build。 -build-codemirror-incremental: - @cd libs/codemirror-editor && pnpm run build - -dev: build-editor-incremental build-lightbox-incremental build-core-incremental build-codemirror-incremental highlight-css +dev: build-libs highlight-css @echo "Cleaning static/..." @rm -rf static/ @echo "Building CSS..." @@ -139,15 +110,20 @@ css-watch: test: @cargo test - @cd libs/tiptap-editor && pnpm test - @cd libs/lightbox && pnpm test - @cd libs/yggdrasil-core && pnpm test - @cd libs/codemirror-editor && pnpm test + @cd libs && pnpm -r run test -clippy: +# JS + Rust 一次性检查(不改动文件)。 +lint: + @echo "==> Biome check (libs)" + @cd libs && pnpm exec biome check . + @echo "==> Cargo clippy (Rust)" @cargo clippy --all-targets --all-features -- -D warnings +# JS + Rust 自动修复(直接写入文件)。 fix: + @echo "==> Biome format (libs, 写入文件)" + @cd libs && pnpm exec biome format --write . + @echo "==> Cargo fix (Rust)" @cargo fix --allow-dirty # 只编译当前 crate 的文档(--no-deps 跳过依赖,--document-private-items @@ -183,3 +159,4 @@ clean: @rm -f public/style.css public/highlight.css @rm -rf public/doc @rm -rf uploads/.cache + @rm -rf libs/node_modules libs/*/node_modules diff --git a/biome.json b/libs/biome.json similarity index 88% rename from biome.json rename to libs/biome.json index 270aba5..5aae8c2 100644 --- a/biome.json +++ b/libs/biome.json @@ -1,9 +1,7 @@ { "$schema": "https://biomejs.dev/schemas/2.5.1/schema.json", "vcs": { - "enabled": true, - "clientKind": "git", - "useIgnoreFile": true + "enabled": false }, "files": { "includes": [ @@ -14,12 +12,7 @@ "**/*.css", "**/*.html", "!**/node_modules", - "!**/dist", - "!**/target", - "!public", - "!.dioxus", - "!static", - "!input.css" + "!**/dist" ] }, "formatter": { diff --git a/package.json b/libs/package.json similarity index 100% rename from package.json rename to libs/package.json diff --git a/pnpm-lock.yaml b/libs/pnpm-lock.yaml similarity index 99% rename from pnpm-lock.yaml rename to libs/pnpm-lock.yaml index 64239fd..673326e 100644 --- a/pnpm-lock.yaml +++ b/libs/pnpm-lock.yaml @@ -24,7 +24,7 @@ importers: specifier: ^4.1.9 version: 4.1.9(@types/node@26.0.1)(happy-dom@20.10.6)(vite@8.1.2(@types/node@26.0.1)) - libs/codemirror-editor: + codemirror-editor: dependencies: '@catppuccin/codemirror': specifier: ^1.0.3 @@ -54,9 +54,9 @@ importers: specifier: ^6.0.1 version: 6.0.2 - libs/lightbox: {} + lightbox: {} - libs/tiptap-editor: + tiptap-editor: dependencies: '@tiptap/core': specifier: ^3.27.1 @@ -89,7 +89,7 @@ importers: specifier: ^3.27.1 version: 3.27.1(@floating-ui/dom@1.7.6)(@tiptap/core@3.27.1(@tiptap/pm@3.27.1))(@tiptap/pm@3.27.1) - libs/yggdrasil-core: {} + yggdrasil-core: {} packages: diff --git a/libs/pnpm-workspace.yaml b/libs/pnpm-workspace.yaml new file mode 100644 index 0000000..a2dc071 --- /dev/null +++ b/libs/pnpm-workspace.yaml @@ -0,0 +1,2 @@ +packages: + - '*' diff --git a/libs/tiptap-editor/src/index.ts b/libs/tiptap-editor/src/index.ts index ed6cf71..f4fcc65 100644 --- a/libs/tiptap-editor/src/index.ts +++ b/libs/tiptap-editor/src/index.ts @@ -80,7 +80,7 @@ class TiptapEditorInstance { this.sourceTextarea.addEventListener('input', () => { // 源码模式下通过 onUpdate 回调同步内容(替代旧版 window.__tiptap_content 缓存) if (this.options.onUpdate) { - this.options.onUpdate(this.sourceTextarea?.value); + this.options.onUpdate(this.sourceTextarea!.value); } }); el.appendChild(this.sourceTextarea); diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml deleted file mode 100644 index 92827f3..0000000 --- a/pnpm-workspace.yaml +++ /dev/null @@ -1,2 +0,0 @@ -packages: - - 'libs/*'