elements-new-package
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCreating a New Elements Package
创建新的Elements包
Use to scaffold a new workspace package. It creates all required files and registers the package in — the single source of truth for path aliases.
scripts/new-package@editframe/*tsconfig.json使用来搭建一个新的工作区包。它会创建所有必需的文件,并在中注册该包——这是路径别名的唯一可信来源。
scripts/new-package@editframe/*tsconfig.jsonQuick Start
快速开始
bash
undefinedbash
undefinedFrom the elements/ directory (or via the runner)
从elements/目录下执行(或通过运行器)
./scripts/new-package <name>
./scripts/new-package <name>
e.g. ./scripts/new-package captions
示例:./scripts/new-package captions
Then install to symlink the workspace package
然后安装以链接工作区包
./scripts/npm install
undefined./scripts/npm install
undefinedWhat the Script Does
脚本功能说明
Creates with:
packages/<name>/- — empty export stub
src/index.ts - — correct version, ESM exports,
package.jsonpublishConfig.access: "public" - — extends root config
tsconfig.json - — minimal build config
tsdown.config.ts
Inserts a path entry into :
elements/tsconfig.jsonjson
"@editframe/<name>": ["./packages/<name>/src/index.ts"]Both vitest configs (, ) derive their aliases from automatically via — no manual updates needed there.
vitest.config.tsvitest.config.browser.tstsconfig.jsonvitest.aliases.ts创建目录,包含以下文件:
packages/<name>/- —— 空导出占位文件
src/index.ts - —— 正确的版本、ESM导出配置,
package.jsonpublishConfig.access: "public" - —— 继承根目录配置
tsconfig.json - —— 极简构建配置
tsdown.config.ts
在中插入路径条目:
elements/tsconfig.jsonjson
"@editframe/<name>": ["./packages/<name>/src/index.ts"]两个vitest配置文件(、)会通过自动从获取别名,无需手动更新。
vitest.config.tsvitest.config.browser.tsvitest.aliases.tstsconfig.jsonPublishing a New Package to npm
将新包发布至npm
CI publishes via OIDC trusted publishing (no stored token). OIDC requires the package to exist on npm before trusted publishing can be configured, so the first publish is manual:
bash
undefinedCI通过OIDC可信发布机制进行发布(无需存储令牌)。OIDC要求包在npm上已存在才能配置可信发布,因此首次发布需要手动执行:
bash
undefinedOne-time, run locally while logged in to npm
仅需一次,在本地登录npm后运行
npm publish --access public --workspace @editframe/<name>
After that first publish:
1. Go to npmjs.com → `@editframe/<name>` → Settings → Trusted Publisher
2. Add GitHub Actions: repo `editframe/elements`, workflow `release.yaml`, environment `npm-publish`
All subsequent releases publish automatically via CI.npm publish --access public --workspace @editframe/<name>
首次发布完成后:
1. 访问npmjs.com → `@editframe/<name>` → 设置 → 可信发布者
2. 添加GitHub Actions:仓库`editframe/elements`,工作流`release.yaml`,环境`npm-publish`
后续所有版本发布将通过CI自动完成。Path Alias Registration
路径别名注册
tsconfig.json@editframe/foo/nodetsconfig.jsonsrc/<name>.ts仅需在中添加新条目,脚本会自动完成此操作。如果需要子路径导出(如),则必须手动在中添加——基础别名会通过Vite前缀替换自然处理子路径导入,因此仅当文件不遵循模式时才需要显式添加条目。
tsconfig.json@editframe/foo/nodetsconfig.jsonsrc/<name>.tsAdding Dependencies on Other Workspace Packages
添加对其他工作区包的依赖
Add the sibling package to in the new package's using the current workspace version (check the root ). Run to re-symlink. Run after a version bump to keep all cross-package pins in sync.
dependenciespackage.jsonpackage.json./scripts/npm install./scripts/node scripts/deps.js update-dependencies在新包的的中添加同级包,并使用当前工作区版本(查看根目录)。运行重新链接。版本更新后运行,以保持所有跨包依赖版本同步。
package.jsondependenciespackage.json./scripts/npm install./scripts/node scripts/deps.js update-dependencies