Build Tutorial / Build @stack/tutorial (kaniko) (push) Failing after 49s
## 背景 design-system 混居在 `apps/tutorial/src/design-system` 一个桶里:token 的事实源是 tailwind v4 `@theme`,token/基础组件/业务组件三层没有物理边界,样式范式被 tailwind 绑死。按三层分类(token/ui-kit 基础行为件/业务组件)拆成两个 workspace 包,token 用 vanilla-extract 最小用法(theme var + style,不用 recipe/sprinkles)重建事实源,整体减少对 tailwind 的依赖。 ## 变更内容 **两包结构(源码直出,`@idealjs/stack` 同款 exports 指 .ts)** - `@idealjs/stack-ui-kit`:token 层 + 基础组件层。颜色 token 分两层(`design/colors` 规范的机器可执行形式):**色板描述层** `--palette-*`(coral/teal/mustard/violet/pink/blue/green/black/cream/sand/clay/graphite,色值唯一事实源,theme switch 只切这层)与**语义描述层** `--color-*`(clash 对槽位与中性角色,组件组成只消费这层,值全部 `var(--palette-*)`);semantic 层以 `createGlobalThemeContract` + mapFn **按原名**输出 `--color-*`/`--shadow-*`/`--text-*`(learning.css 约 166 处、app 手写 css、全部 inline `var()` 按原名消费,改名即断),业务包 `--color-ch1..7` 同样映射 palette 槽位;组件 11 件全量 ve 化(Button/ShadowButton/ShadowCard/Ticket/BrowserMockup/shapes/Scatter/dock 三件),`.hover-host` 系与 `.ticket-*` 打孔机制平移为 `globalStyle` - `@idealjs/stack-site-ui-kit`:业务层(types/章节图谱件/Site 壳/PageFlipZone/learning 12 件/Gallery),`learning.css` 与 page-flip 动画段归位包内;本版业务件仍以 tailwind 类书写,靠桥接层消费 token(后续逐步 ve 化,见包 README「已知后续」) - 行为/语义拆两层:ui-kit 新增 `Tabs`(tablist roving)/`FlipCard`(双面常驻 DOM)/`ToggleButton`(aria-pressed)骨架与 `useControllableState`;FolderTabs/FlashCard/Bookmark 改为骨架 + learning 皮薄封装,DOM 与类名不变;`SiteNavbar`/`SiteSidebar` 本轮不动样式(含 #61 的 nested 零投影形态,已 rebase 合入并保留 API) **stack CLI 插件适配(零 core 侵入,全部现有 hook 先例)** - `@idealjs/stack-ui-kit/stack-plugin`:真 esbuild + 官方 ve 插件求值 `.css.ts`,`config.load` 返回静态类名产物(发生在 import 解析前,依赖图干净);`WatchHook` 监听 default 产出向每个 html 注入 `__shared/ui-kit.css` 并超集重发,链序 default → vanilla-extract → tutorial-build → ssg;缓存按内容指纹 - ssg 插件的 esbuild-wasm 通道加 `.css.ts` onLoad(走同一编译产物) - `stack dev/watch` 新增 `config.watchRoots` 多根监听,tutorial 挂两包源码热更(实测改包内组件触发重建) **app 侧** - `tokens.css` 拆解为桥接层 `src/styles/tailwind.css`(`@theme inline` 同名引用 ve 变量生成 utility + 排版工具类),app 侧 ~456 行 token 类用法零改动;token 唯一事实源移交 ve - 消费方 import 全部改双包名(tsconfig paths 走 aliasResolve);24 个 html 的 learning.css link 改包说明符,产物落 `__shared/` - 删除 `src/design-system/`,README 拆为两包各自文档 ## 自测结果 - `yarn workspace @stack/tutorial build`:24 输入 169 模块,ve css 落 `__shared/ui-kit.css`,html link 重写正确 - `yarn workspace @stack/tutorial test:e2e`:**134 全过**(rebase 到含 #61 的 main 后,#61 重建的基线含此前 main 上既有失败的 flip-nav-overlay) - `yarn workspace @idealjs/stack-ui-kit typecheck` / `stack-site-ui-kit typecheck` 通过;`packages/stack` 测试 74 全过;`node scripts/strip-comments.mjs` 零注释;`biome format` 收敛 - dev 模式实测:改两包源码触发热更(watchRoots 生效) - 颜色两层拆分后 e2e 134 全过(最终计算色值不变);`design/colors` 文档页按两层重写(中性阶补齐五档),视觉基线以 `--update-snapshots=all` 刻意更新,前后对照: 颜色页(design/colors,两层结构与中性阶补齐):  - 前后对照截图(main@7b6797a vs 本分支,stack preview + playwright 1280×900,fonts.ready 后截,滚动容器展开取整页): --------- Co-authored-by: cqh963852 <cqh963852@hotmail.com> Reviewed-on: #62
61 lines
1.9 KiB
TypeScript
61 lines
1.9 KiB
TypeScript
import { statSync } from 'node:fs'
|
|
import { readFile } from 'node:fs/promises'
|
|
|
|
import { dirname, join } from 'node:path'
|
|
import type { StackHook, WatchHook } from '@idealjs/stack'
|
|
import { compile } from '@tailwindcss/node'
|
|
import { Scanner } from '@tailwindcss/oxide'
|
|
|
|
export interface TutorialBuildOptions {
|
|
root: string
|
|
}
|
|
|
|
const TOKENS_PATH = 'src/styles/tailwind.css'
|
|
|
|
export function tutorialBuild(options: TutorialBuildOptions): StackHook {
|
|
const hook: WatchHook = {
|
|
name: 'tutorial-build',
|
|
watch: ['vanilla-extract'],
|
|
lower: async (ctx, watched) => {
|
|
const files = watched.files.map((file) => ({ ...file }))
|
|
const byPath = new Map(files.map((file) => [file.path, file]))
|
|
await compileTailwind(byPath, options.root)
|
|
ctx.output({ name: 'tutorial-build', dir: watched.dir, files })
|
|
},
|
|
}
|
|
return hook
|
|
}
|
|
|
|
const compileTailwind = async (
|
|
byPath: Map<string, { path: string; code: string }>,
|
|
root: string,
|
|
): Promise<void> => {
|
|
const target = byPath.get(TOKENS_PATH)
|
|
if (target === undefined) {
|
|
throw new Error(`[tutorial-build] 产出里找不到 ${TOKENS_PATH}——html 需以 link 引入 tokens.css`)
|
|
}
|
|
const tokensPath = join(root, TOKENS_PATH)
|
|
const raw = await readFile(tokensPath, 'utf8')
|
|
const compiler = await compile(raw, {
|
|
base: dirname(tokensPath),
|
|
onDependency: () => {},
|
|
})
|
|
const sources =
|
|
compiler.root === 'none'
|
|
? []
|
|
: compiler.root === null
|
|
? [{ base: root, pattern: '**/*', negated: false }]
|
|
: [{ base: compiler.root.base, pattern: compiler.root.pattern, negated: false }]
|
|
const scanner = new Scanner({
|
|
sources: [...sources, ...compiler.sources].filter((source) => {
|
|
try {
|
|
return statSync(source.base).isDirectory()
|
|
} catch {
|
|
return false
|
|
}
|
|
}),
|
|
})
|
|
const candidates = new Set(scanner.scan())
|
|
target.code = compiler.build([...candidates])
|
|
}
|