@cobre-npm/ds-v3

中文文档
0.169.0发布于 2026/11/06TypeScriptES Module近 30 天下载 4236

Vue 3 + TypeScript component library for the Cobre platform, documented and developed through Storybook.

原始使用文档
文档目录11 节
  1. Prerequisites
  2. Project Setup
  3. Develop with Storybook (primary workflow)
  4. Common Commands
  5. Testing
  6. The coverage floor ratchets
  7. Adding tests
  8. Recommended IDE Setup
  9. Type Support for .vue Imports in TS
  10. Project Structure & Conventions
  11. Troubleshooting

Cobre Design System V3 (@cobre-npm/ds-v3)

Vue 3 + TypeScript component library for the Cobre platform, documented and developed through Storybook.

Heads up: this project uses pnpm, not npm. Running npm install will generate a stray package-lock.json and can produce a broken node_modules. Always use pnpm.

Prerequisites

  • Node.js ≥ 20 (CI uses Node 24).
  • pnpm ≥ 10. The exact version is pinned via the packageManager field in package.json, so the simplest setup is to let corepack match it:
    corepack enable
    
    To install manually instead: npm install -g pnpm.

Project Setup

pnpm install

On a fresh checkout, pnpm may prompt you to approve build scripts for native dependencies (esbuild, @swc/core, @parcel/watcher, unrs-resolver, vue-demi). If it does, approve them:

pnpm approve-builds

Then re-run pnpm install if needed.

postinstall downloads the headless Chromium the render lane tests against (~95 MB, once per machine, idempotent). It lives in postinstall rather than in the test script because the browser is a dependency of the suite, and because more than one command runs that suite — putting it in test left every other entry point without a browser. SKIP_TEST_BROWSER=1 skips it, for any image that installs dependencies and never runs the suite — the Dockerfile that builds the Storybook showcase sets it. On Alpine it skips itself, because Playwright publishes glibc builds only. --ignore-scripts skips it too, and pnpm test:browsers gets it back.

Develop with Storybook (primary workflow)

This is a component library — day-to-day development happens in Storybook, which renders every component with its variants and docs:

pnpm storybook

Opens at http://localhost:6006.

pnpm dev (plain vite) only serves the minimal src/main.ts / App.vue harness. It is not the component gallery — use pnpm storybook for normal development.

Common Commands

CommandWhat it does
pnpm installInstall dependencies
pnpm storybookRun Storybook dev server on port 6006 (main dev workflow)
pnpm devBare Vite dev harness (src/main.ts) — rarely needed
pnpm buildType-check + build the publishable library into dist/
pnpm build-storybookBuild the static Storybook site
pnpm testThe whole gate: story render lane, logic lane with coverage, invariants
pnpm test:storiesRender lane only — mounts all 81 stories in headless Chromium
pnpm test:unitLogic lane only, with coverage enforced against coverage-floor.json
pnpm test:browsersRe-download the Chromium build the render lane needs — normally unnecessary, pnpm install does it
pnpm lintLint & auto-fix with ESLint

Testing

The suite is split in two lanes because the two numbers would not mean the same thing (ADR-0008):

  • Render lane (test:stories) — every story mounts without error, in headless Chromium via @storybook/addon-vitest. It is binary: no percentage is attached to it. Storybook marks a line covered when a story renders it while asserting nothing, so a percentage built that way measures exercised, not verified.
  • Logic lane (test:unit) — the non-component sources (src/**/*.ts minus stories, tests, type-only modules, barrels and the dev entry), with coverage thresholds enforced.

The coverage floor ratchets

coverage-floor.json holds the thresholds, and it is a floor, not a target. It was set to what the repo measured the day the gate was switched on — there is no retroactive 95% and no backfill of the existing components as a precondition. It may only rise:

  • scripts/check-invariants.mjs fails the build when any number in the file drops below the base ref. It is a change-level check, so it runs in CI, or locally with pnpm test:invariants -- --base origin/trunk.
  • src/utils/repo-invariants.test.ts fails when vitest.config.mts stops reading its thresholds from that file, which would otherwise be a silent way to lower the gate to nothing.

To raise the floor: improve coverage, run pnpm test:unit, and copy the reported totals into coverage-floor.json.

Adding tests

Component behaviour belongs in a story — it is the lane that already exists and the one consuming apps read as documentation. Reach for the logic lane when the subject is a composable, a pure function or shared state.

VSCode + Vue - Official (Volar) (disable Vetur).

Type Support for .vue Imports in TS

TypeScript can't type .vue imports on its own, so we use vue-tsc for type checking and the Vue (Volar) extension to make the editor's TS language service aware of .vue types.

Project Structure & Conventions

See CLAUDE.md for the full architecture overview: Atomic Design layout (atoms/molecules/organisms), the Cobre* / co- naming conventions, the SCSS token system, and how to add a new component (each lives in its own folder with a .vue, a .stories.ts, and an index.ts, and must be exported from src/components/index.ts and src/index.ts).

Troubleshooting

  • npm run dev / npm install fails or behaves oddly — you're using the wrong package manager. Delete any package-lock.json, then use pnpm install.
  • pnpm asks to approve build scripts — run pnpm approve-builds, then re-run pnpm install if needed.
  • Stale or broken node_modules — rm -rf node_modules && pnpm install.

版本与发布记录

@cobre-npm/ds-v3 共发布 428 个版本,首次发布于 2024/07/03;过去 12 个月发布了 180 个版本。

版本发布日期距今
0.169.0latest2026/11/063 天前
0.168.02026/10/3011 天前
0.167.02026/10/3011 天前
0.166.02026/10/2911 天前
0.165.02026/10/2813 天前
0.164.12026/10/2713 天前

关于 @cobre-npm/ds-v3 的常见问题

@cobre-npm/ds-v3 是什么?

Vue 3 + TypeScript component library for the Cobre platform, documented and developed through Storybook.

如何安装 @cobre-npm/ds-v3?

在项目目录运行 npm install @cobre-npm/ds-v3,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:date-fns(^2.30.0)、date-fns-tz(^2.0.1)、@vuepic/vue-datepicker(^9.0.3)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@cobre-npm/ds-v3 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cobre-npm/ds-v3 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@cobre-npm/ds-v3 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cobre-npm/ds-v3 可以商用吗?

@cobre-npm/ds-v3 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@cobre-npm/ds-v3 的下载量有多少?

根据 npm 官方下载统计,@cobre-npm/ds-v3 在 2026/10/10 – 2026/11/08 这 30 天内被下载 4,236 次,日均约 141 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cobre-npm/ds-v3 还在维护吗?

最新版本 0.169.0 发布于 2026/11/06(3 天前);至今共发布 428 个版本,其中过去 12 个月发布了 180 个;首次发布于 2024/07/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。