# publish-custom 定制包发布

只发布 resolutions 中列出的定制包到私有仓库,避免误发标品包。

# 使用方式

# 预览模式 — 查看哪些包需要发布,不实际执行
yarn publish:custom:dry

# 正式发布
yarn publish:custom
1
2
3
4
5

# 发布流程

1. 读取根目录 package.json 中的 resolutions
   └── 获取所有定制包名称和版本号

2. 在 workspace 中定位每个包的本地目录
   └── 通过 packages/ 扫描匹配

3. 逐个检查是否已发布
   └── npm view <包名>@<版本> 查询私有仓库

4. 对未发布的包执行 npm publish
   ├── 使用 customization.identifier 作为 dist-tag
   └── 不影响标品的 latest 标签

5. 输出发布报告
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# 命令参数

参数 说明
--dry-run 预览模式,只输出待发布列表不实际执行

# 实际操作示例

# 预览发布

$ yarn publish:custom:dry

[publish] 读取 resolutions 定制包列表...
[publish] 定制标识符: ai-platform-bankcomm
[publish] 
[publish] 检查发布状态:
[publish]   ✓ cloudpivot@1.1.2-ai-platform-bankcomm-2.3        — 已发布,跳过
[publish]   ✗ cloudpivot-form@1.1.2-ai-platform-bankcomm-2.5   — 未发布
[publish]   ✗ cloudpivot-admin-core@1.1.2-ai-platform-bankcomm-2.4 — 未发布
[publish] 
[publish] 待发布 2 个包(预览模式,未实际发布)
1
2
3
4
5
6
7
8
9
10
11

# 正式发布

$ yarn publish:custom

[publish] 发布中...
[publish]   cloudpivot-form@1.1.2-ai-platform-bankcomm-2.5 → 发布成功 (tag: ai-platform-bankcomm)
[publish]   cloudpivot-admin-core@1.1.2-ai-platform-bankcomm-2.4 → 发布成功 (tag: ai-platform-bankcomm)
[publish] 
[publish] 完成,共发布 2 个包
1
2
3
4
5
6
7

# 是否需要发布?

不是所有项目都需要执行 publish-custom。 详细对比见 介绍与安装 - 发布说明。

简单总结:

  • 本地开发 / 团队 Git 协作 → 不需要发布,workspace 本地链接即可
  • CI/CD 流水线构建 / 交付部署 → 需要发布到私有仓库

# 前置要求

# 1. 申请发布权限

发布目标为 https://nexus01.authine.cn/ (opens new window)(Sonatype Nexus 私有仓库)。

你需要先申请发布权限,联系运维或项目负责人开通你的账号对 npm-authine 仓库的写入权限。

# 2. 配置 .npmrc

获取 auth token 后,在项目根目录的 .npmrc 中配置:

registry=https://nexus01.authine.cn/repository/npm-all/
//nexus01.authine.cn/repository/npm-authine/:_authToken=你申请到的token
1
2

注意

不要将包含 token 的 .npmrc 提交到 Git 仓库。建议将 token 配置在全局 ~/.npmrc 或通过 CI 环境变量注入。

# dist-tag 说明

发布时使用 customization.identifier 作为 dist-tag(如 ai-platform-bankcomm),这意味着:

  • npm install cloudpivot-form → 安装标品 latest 版本
  • npm install cloudpivot-form@ai-platform-bankcomm → 安装定制版本

定制包的发布不会影响标品用户。

# 注意事项

  1. 权限:未申请权限直接发布会报 401 Unauthorized 或 403 Forbidden
  2. 发布前确保本地代码已提交,避免发布未完成的修改
  3. 已发布过的版本会自动跳过,不会重复发布
  4. 如果需要重新发布同一版本,需要先在私有仓库中 unpublish 该版本
  5. 建议先用 --dry-run 确认待发布列表,再正式发布