Skip to content

Commit 4b58df0

Browse files
committed
chore: bump version
1 parent 6d505ec commit 4b58df0

File tree

11 files changed

+39
-15
lines changed

11 files changed

+39
-15
lines changed

.changeset/clean-docs-oidc.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@icebreakers/monorepo": patch
3+
---
4+
5+
Make `monorepo clean` include private packages and remove README.zh-CN by default, plus document npm OIDC publishing guidance.

apps/website/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ layout: doc
1818

1919
1. **拉取模板**[GitHub](https://github.com/sonofmagic/monorepo-template) 右上角 `Use this template`,或克隆源码。
2020
2. **安装依赖**:在 `pnpm-workspace.yaml` 所在目录执行 `pnpm install`(需要 Node.js ≥ 20,推荐 `npm i -g pnpm`)。
21-
3. **可选清理**运行 `pnpm script:clean` 移除演示包,仅保留最小打包模板;随后再次执行 `pnpm install` 更新 lockfile
21+
3. **可选清理**直接运行 `npx -y @icebreakers/monorepo@latest clean` 远程执行清理,移除演示包后再执行 `pnpm install`(避免依赖本地构建 `monorepo`);如已安装依赖,也可使用 `pnpm script:clean`
2222
4. **初始化元数据**`pnpm script:init` 会批量更新 `package.json``README.md` 等公共信息。
2323

2424
## 仓库结构速览
@@ -49,7 +49,7 @@ layout: doc
4949

5050
```bash
5151
npx monorepo new # 创建子包/应用
52-
npx monorepo clean # 批量删除已勾选的子项目
52+
npx -y @icebreakers/monorepo@latest clean # 远程清理已勾选的子项目,避免依赖本地构建
5353
npx monorepo sync # 同步所有包到 npmmirror
5454
npx monorepo mirror # 写入 VS Code 镜像配置
5555
npx monorepo up # 从最新模板同步配置文件

apps/website/monorepo/publish.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,25 @@ jobs:
9898
- uses: pnpm/action-setup@v4
9999
- uses: actions/setup-node@v4
100100
with:
101-
node-version: 22
101+
# 这是为了使用新版本的 npm, 只有 npm@11.5.x 以上版本才支持 OIDC
102+
# 否则你就必须使用 npm i -g npm@latest 来升级 npm 版本
103+
node-version: 24
102104
cache: pnpm
105+
registry-url: https://registry.npmjs.org
103106
- run: pnpm install
104107
- name: Create Release Pull Request or Publish to npm
105108
uses: changesets/action@v1
106109
with:
107110
publish: pnpm publish-packages
108111
env:
109112
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
110-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
113+
# npm/action-oidc-auth 会设置 NODE_AUTH_TOKEN 供 publish 使用
111114
```
112115

113116
`pnpm publish-packages` 为模板内脚本,可替换为自定义构建+发布流程。
114117

118+
> 说明:npm 现行 token 默认 90 天过期,推荐在 CI 中使用 OIDC(如上)动态获取 `NODE_AUTH_TOKEN`,无需手动传入 `NPM_TOKEN`。若使用自托管或其他 CI,需要确保工作流具备 `id-token: write` 权限。
119+
115120
## 与其他方案对比
116121

117122
| 能力 / 工具 | changesets | lerna 经典模式 | 手写脚本 |

apps/website/why/publish-basic-npm-package.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ registry.npmjs.org/:_authToken=npm_hashhashhashhashhashhashhashhashhash
6868

6969
假如这一行存在,说明你本地的 `npm Access Token` 就设置好了,然后你才有发包的权限。
7070

71-
> 你也可以在 `https://www.npmjs.com/settings/<你的用户名>/tokens` 中管理你的 `token`,给不同的 `token` 设置不同的作用域,有效期和 `ip` 限制,帮助你适配正常开发,`CI/CD``Token` 分发的各种场景
71+
> 你也可以在 `https://www.npmjs.com/settings/<你的用户名>/tokens` 中管理你的 `token`,给不同的 `token` 设置不同的作用域,有效期(目前最长 90 天)和 `ip` 限制,帮助你适配正常开发,`CI/CD``Token` 分发的各种场景;如需避免手动轮换,CI 场景推荐使用 npm 官方的 OIDC 方案获取临时 `NODE_AUTH_TOKEN`,并在工作流开启 `id-token: write` 权限。
7272
7373
同样发私有源包也是同理:
7474

monorepo.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default defineMonorepoConfig({
88
},
99
clean: {
1010
autoConfirm: false,
11-
ignorePackages: ['@icebreakers/website'],
11+
includePrivate: true,
1212
},
1313
sync: {
1414
concurrency: 4,

packages/monorepo/src/cli/program.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ aiCommand.command('create')
109109
const shouldUseTasks = Boolean(tasksFile && !opts.output && !opts.name)
110110

111111
if (shouldUseTasks) {
112+
if (!tasksFile) {
113+
throw new Error('tasks file path is required when using tasks mode')
114+
}
112115
const tasks = await loadAgenticTasks(tasksFile, cwd)
113116
await generateAgenticTemplates(tasks, {
114117
cwd,

packages/monorepo/src/commands/clean.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ import set from 'set-value'
66
import { resolveCommandConfig } from '../core/config'
77
import { getWorkspaceData } from '../core/workspace'
88

9-
function mergeCleanConfig(base: CleanCommandConfig, overrides?: Partial<CleanCommandConfig>) {
9+
function mergeCleanConfig(base?: CleanCommandConfig, overrides?: Partial<CleanCommandConfig>): CleanCommandConfig {
10+
const normalizedBase = base ?? {}
1011
if (!overrides) {
11-
return base
12+
return normalizedBase
1213
}
1314
const definedOverrides = Object.fromEntries(
1415
Object.entries(overrides).filter(([, value]) => value !== undefined),
1516
) as Partial<CleanCommandConfig>
1617
return {
17-
...base,
18+
...normalizedBase,
1819
...definedOverrides,
1920
}
2021
}
@@ -24,7 +25,8 @@ function mergeCleanConfig(base: CleanCommandConfig, overrides?: Partial<CleanCom
2425
*/
2526
export async function cleanProjects(cwd: string, overrides?: Partial<CleanCommandConfig>) {
2627
const cleanConfig = mergeCleanConfig(await resolveCommandConfig('clean', cwd), overrides)
27-
const workspaceOptions = cleanConfig?.includePrivate ? { ignorePrivatePackage: false } : undefined
28+
const includePrivate = cleanConfig?.includePrivate ?? true
29+
const workspaceOptions = includePrivate ? { ignorePrivatePackage: false } : undefined
2830
const { packages, workspaceDir } = await getWorkspaceData(cwd, workspaceOptions)
2931

3032
// 根据配置过滤需要跳过的包,默认全部参与清理。
@@ -59,7 +61,11 @@ export async function cleanProjects(cwd: string, overrides?: Partial<CleanComman
5961
})
6062
}
6163

62-
const candidates = Array.from(new Set(cleanDirs.filter(Boolean)))
64+
const readmeZh = path.resolve(workspaceDir, 'README.zh-CN.md')
65+
const candidates = Array.from(new Set([
66+
...cleanDirs.filter(Boolean),
67+
readmeZh,
68+
]))
6369
await Promise.all(candidates.map(async (dir) => {
6470
if (await fs.pathExists(dir)) {
6571
await fs.remove(dir)

packages/monorepo/src/types/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export interface CleanCommandConfig {
104104
ignorePackages?: string[]
105105
/**
106106
* 是否包含 private 包。
107-
* @default false
107+
* @default true
108108
*/
109109
includePrivate?: boolean
110110
/**

packages/monorepo/test/commands/clean.coverage.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,10 @@ describe('clean coverage', () => {
129129

130130
await cleanProjects(workspaceDir)
131131

132+
expect(getWorkspaceDataMock).toHaveBeenCalledWith(workspaceDir, { ignorePrivatePackage: false })
132133
expect(checkboxMock).toHaveBeenCalled()
133134
expect(removeMock).toHaveBeenCalledWith('/repo/packages/keep-me')
135+
expect(removeMock).toHaveBeenCalledWith('/repo/README.zh-CN.md')
134136
expect(readJsonMock).toHaveBeenCalledWith('/repo/package.json')
135137
expect(outputJsonMock).toHaveBeenCalledWith('/repo/package.json', {
136138
devDependencies: {

packages/monorepo/test/commands/maintenance.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ describe('cleanProjects', () => {
3333
const packagesDir = path.join(workspaceDir, 'packages')
3434
const pkgFooDir = path.join(packagesDir, 'foo')
3535
const pkgBarDir = path.join(packagesDir, 'bar')
36+
const readmeZhPath = path.join(workspaceDir, 'README.zh-CN.md')
3637

3738
await fs.ensureDir(pkgFooDir)
3839
await fs.ensureDir(pkgBarDir)
40+
await fs.writeFile(readmeZhPath, 'should be removed')
3941
await fs.writeJSON(path.join(workspaceDir, 'package.json'), {
4042
devDependencies: {
4143
'@icebreakers/monorepo': '^0.1.0',
@@ -66,6 +68,7 @@ describe('cleanProjects', () => {
6668

6769
expect(await fs.pathExists(pkgFooDir)).toBe(false)
6870
expect(await fs.pathExists(pkgBarDir)).toBe(false)
71+
expect(await fs.pathExists(readmeZhPath)).toBe(false)
6972

7073
const rootPkg = await fs.readJSON(path.join(workspaceDir, 'package.json'))
7174
expect(rootPkg.devDependencies['@icebreakers/monorepo']).toBe('latest')

0 commit comments

Comments
 (0)