@wwkit/shared 1.0.31 → 1.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/release.js +32 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wwkit/shared",
3
- "version": "1.0.31",
3
+ "version": "1.0.33",
4
4
  "author": "bluesliu <langcai163@163.com>",
5
5
  "description": "Shared utilities for @wwkit packages — config loader, platform detection",
6
6
  "type": "module",
package/src/release.js CHANGED
@@ -57,6 +57,11 @@ export function preflight({ pkgDirs = [] } = {}) {
57
57
  // 任一包失败立即返回 false(调用方须中止发布)。dryRun 只打印计划命令,不执行。
58
58
  function runGate({ title, script, pkgDirs, dryRun = false }) {
59
59
  console.log(`\n━━━ ${title}(发布门禁) ━━━`)
60
+ // 门禁的「零修改」保证隐式依赖工作区关闭 pnpm run 的自动 install:
61
+ // 若 verifyDepsBeforeRun 不是 false,`pnpm run ut/it` 会在门禁阶段写入
62
+ // node_modules / pnpm-lock.yaml(实测工作区外 pnpm run 即如此),违背承诺。
63
+ // 这里显式校验,防止有人误删该设置后无声破坏门禁语义。
64
+ if (!dryRun && !verifyGateSideEffectPrereq(pkgDirs)) return false
60
65
  for (const pkgDir of pkgDirs) {
61
66
  const { name } = readPackage(pkgDir)
62
67
  if (dryRun) {
@@ -75,6 +80,33 @@ function runGate({ title, script, pkgDirs, dryRun = false }) {
75
80
  return true
76
81
  }
77
82
 
83
+ // 校验工作区已设置 verifyDepsBeforeRun: false(门禁零副作用前提)。
84
+ // 找不到 pnpm-workspace.yaml 或设置缺失/非 false → 告警并阻止门禁执行。
85
+ function verifyGateSideEffectPrereq(pkgDirs) {
86
+ const root = findMonorepoRoot(pkgDirs[0])
87
+ const wsFile = join(root, 'pnpm-workspace.yaml')
88
+ if (!existsSync(wsFile)) {
89
+ console.error('\n✗ 未找到 pnpm-workspace.yaml,无法确认门禁零副作用前提,已阻止')
90
+ console.error(' 请在 monorepo 根目录执行发布')
91
+ return false
92
+ }
93
+ const content = readFileSync(wsFile, 'utf-8')
94
+ const m = content.match(/^\s*verifyDepsBeforeRun\s*:\s*(\S+)/m)
95
+ if (!m) {
96
+ console.error(`\n✗ ${wsFile} 缺少 verifyDepsBeforeRun: false,发布门禁已阻止`)
97
+ console.error(' 原因:未关闭自动 install 时,`pnpm run ut/it` 会写入 node_modules/pnpm-lock.yaml,')
98
+ console.error(' 破坏「测试门禁在任何修改前执行」的保证')
99
+ console.error(' 修复:在 pnpm-workspace.yaml 追加 `verifyDepsBeforeRun: false`')
100
+ return false
101
+ }
102
+ if (m[1] !== 'false') {
103
+ console.error(`\n✗ ${wsFile} 的 verifyDepsBeforeRun 为 ${m[1]}(应为 false),发布门禁已阻止`)
104
+ console.error(' 原因:自动 install 会让门禁阶段写入依赖文件,破坏零修改保证')
105
+ return false
106
+ }
107
+ return true
108
+ }
109
+
78
110
  // 发布门禁第 1 关: 单元测试(`pnpm run ut`)。
79
111
  // 与第 2 关(集成测试)都在任何修改(bump/publish/tag)之前执行——
80
112
  // 测试不通过则直接中止,绝不留下半成品改动。