create-clis 0.1.0 → 1.1.0
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.
- package/README.md +22 -14
- package/README.zh-CN.md +22 -14
- package/assets/manifest.json +7 -2
- package/assets/template/.github/ISSUE_TEMPLATE/bug_report.yml +15 -29
- package/assets/template/.github/ISSUE_TEMPLATE/feature_request.yml +6 -12
- package/assets/template/.github/PULL_REQUEST_TEMPLATE.md +3 -3
- package/assets/template/.github/workflows/ci.yml +69 -7
- package/assets/template/.github/workflows/release.yml +23 -23
- package/assets/template/.gitignorerc.json +1 -8
- package/assets/template/.oxlintrc.json +1 -6
- package/assets/template/.prettierignore +0 -1
- package/assets/template/.releaserc.json +6 -1
- package/assets/template/.vscode/launch.json +1 -1
- package/assets/template/.vscode/settings.json +1 -0
- package/assets/template/.vscode/tasks.json +45 -0
- package/assets/template/AGENTS.md +4 -4
- package/assets/template/CONTRIBUTING.md +6 -4
- package/assets/template/CONTRIBUTING.zh-CN.md +6 -4
- package/assets/template/_gitignore +7 -405
- package/assets/template/bunfig.toml +2 -11
- package/assets/template/docs/README.md +6 -6
- package/assets/template/docs/adrs/README.md +4 -2
- package/assets/template/docs/development.md +15 -9
- package/assets/template/lefthook.yml +20 -30
- package/assets/template/package.json +5 -6
- package/assets/template/packages/{{NAME}}/README.md +4 -4
- package/assets/template/packages/{{NAME}}/README.zh-CN.md +2 -2
- package/assets/template/packages/{{NAME}}/package.json +3 -1
- package/assets/template/packages/{{NAME}}/scripts/build.ts +50 -14
- package/assets/template/packages/{{NAME}}/scripts/verify-release.test.ts +140 -15
- package/assets/template/packages/{{NAME}}/scripts/verify-release.ts +27 -14
- package/assets/template/packages/{{NAME}}/tsconfig.build.json +1 -1
- package/assets/template/packages/{{NAME}}-cli/README.md +6 -6
- package/assets/template/packages/{{NAME}}-cli/README.zh-CN.md +2 -2
- package/assets/template/packages/{{NAME}}-cli/bin/bunfig.toml +3 -0
- package/assets/template/packages/{{NAME}}-cli/bin/{{BIN_NAME}} +43 -21
- package/assets/template/packages/{{NAME}}-cli/bin/{{BIN_NAME}}.cmd +8 -17
- package/assets/template/packages/{{NAME}}-cli/bin/{{BIN_NAME}}.d.mts +6 -3
- package/assets/template/packages/{{NAME}}-cli/bin/{{BIN_NAME}}.mjs +189 -107
- package/assets/template/packages/{{NAME}}-cli/package.json +3 -2
- package/assets/template/packages/{{NAME}}-cli/scripts/release-artifact.ts +24 -73
- package/assets/template/packages/{{NAME}}-cli/scripts/release.fixtures.ts +8 -3
- package/assets/template/packages/{{NAME}}-cli/scripts/verify-release.test.ts +16 -10
- package/assets/template/packages/{{NAME}}-cli/scripts/verify-release.ts +8 -52
- package/assets/template/packages/{{NAME}}-cli/scripts/write-dist-manifest.test.ts +3 -3
- package/assets/template/packages/{{NAME}}-cli/scripts/write-dist-manifest.ts +8 -68
- package/assets/template/scripts/ci.ts +285 -64
- package/assets/template/scripts/install-git-hooks.mjs +10 -0
- package/assets/template/scripts/install-git-hooks.test.ts +1 -1
- package/assets/template/scripts/lib/npm-trust-parse.ts +169 -0
- package/assets/template/scripts/lib/release-cli.ts +299 -0
- package/assets/template/scripts/lib/release-verify.ts +148 -15
- package/assets/template/scripts/lib/workspace.test.ts +63 -1
- package/assets/template/scripts/lib/workspace.ts +132 -42
- package/assets/template/scripts/lint-dependency-direction.test.ts +131 -0
- package/assets/template/scripts/lint-dependency-direction.ts +130 -0
- package/assets/template/scripts/lint-doc-examples.test.ts +45 -9
- package/assets/template/scripts/lint-doc-examples.ts +227 -50
- package/assets/template/scripts/lint-doc-references.test.ts +36 -0
- package/assets/template/scripts/lint-doc-references.ts +142 -57
- package/assets/template/scripts/lint-doc-shared.ts +26 -23
- package/assets/template/scripts/lint-stray-backups.test.ts +3 -1
- package/assets/template/scripts/lint-stray-backups.ts +7 -3
- package/assets/template/scripts/npm-trust-guard.test.ts +56 -8
- package/assets/template/scripts/npm-trust-guard.ts +116 -200
- package/assets/template/scripts/safe-install.ts +28 -23
- package/assets/template/scripts/transcription/api-harness.ts +28 -206
- package/assets/template/scripts/transcription/compare.test.ts +84 -0
- package/assets/template/scripts/transcription/compare.ts +4 -4
- package/assets/template/scripts/transcription/corpus.ts +9 -3
- package/assets/template/scripts/transcription/fixture.ts +2 -4
- package/assets/template/scripts/transcription/make-mutants.ts +116 -37
- package/assets/template/scripts/transcription/run-conformance.ts +57 -34
- package/assets/template/scripts/transcription/validate-coverage.test.ts +11 -14
- package/assets/template/scripts/transcription/validate-coverage.ts +8 -10
- package/assets/template/scripts/transcription/validate.ts +18 -3
- package/assets/template/tsconfig.json +2 -20
- package/assets/template/turbo.jsonc +7 -52
- package/bin/bunfig.toml +3 -0
- package/bin/create-clis.mjs +165 -104
- package/dist/create-clis.js +48 -87681
- package/dist/manifest.json +3 -3
- package/package.json +9 -5
- package/assets/template/packages/{{NAME}}/docs/README.md +0 -21
- package/assets/template/packages/{{NAME}}-cli/docs/README.md +0 -21
- package/bin/create-clis +0 -35
- package/bin/create-clis.cmd +0 -32
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 发布自证闸门 (
|
|
3
|
-
*
|
|
4
|
-
* 面包白名单 / manifest 契约), 并向包内消费方 (verify-release / write-dist-manifest / 测试)
|
|
5
|
-
* 保持稳定的导出面。
|
|
6
|
-
*
|
|
7
|
-
* 判定序 (共享库统一, 顺序即口径): 检出可信 (git 可读 / 有提交 / 工作树干净) → 产物就位
|
|
8
|
-
* (存在 / 非空 / 可读) → 清单与提交、产物对账 → 面包白名单。
|
|
2
|
+
* 发布自证闸门 ({{NAME}}-cli 包) 的声明式适配层:
|
|
3
|
+
* 通用逻辑全部收拢于仓根 scripts/lib/release-cli.ts 与 scripts/lib/release-verify.ts。
|
|
9
4
|
*/
|
|
10
|
-
import { resolve } from 'node:path';
|
|
5
|
+
import { dirname, resolve } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
11
7
|
|
|
8
|
+
import {
|
|
9
|
+
type CliDistManifest,
|
|
10
|
+
type GitFacts,
|
|
11
|
+
buildCliManifest,
|
|
12
|
+
collectGitFacts,
|
|
13
|
+
writeCliDistManifest,
|
|
14
|
+
} from '../../../scripts/lib/release-cli.ts';
|
|
12
15
|
import {
|
|
13
16
|
type DistState,
|
|
14
17
|
type ReleaseFacts,
|
|
@@ -16,44 +19,31 @@ import {
|
|
|
16
19
|
type VerifyProfile,
|
|
17
20
|
judgePackFiles as judgePackFilesCommon,
|
|
18
21
|
judgeRelease as judgeReleaseCommon,
|
|
19
|
-
normalizeCommit,
|
|
20
22
|
readDistState as readDistStateCommon,
|
|
21
|
-
readGitText,
|
|
22
23
|
} from '../../../scripts/lib/release-verify.ts';
|
|
23
24
|
|
|
24
|
-
export const PACKAGE_ROOT = resolve(
|
|
25
|
+
export const PACKAGE_ROOT = resolve(
|
|
26
|
+
dirname(fileURLToPath(import.meta.url)),
|
|
27
|
+
'..',
|
|
28
|
+
);
|
|
25
29
|
|
|
26
|
-
/** CLI 产物主文件 (dist/ 下) */
|
|
27
30
|
export const CLI_FILE = 'cli.js';
|
|
28
|
-
|
|
29
|
-
/** 产物清单文件名 (dist/ 下) */
|
|
30
31
|
export const MANIFEST_FILE = 'manifest.json';
|
|
31
|
-
|
|
32
|
-
/** 清单形状版本 */
|
|
33
32
|
export const MANIFEST_SCHEMA_VERSION = 1;
|
|
34
33
|
|
|
35
|
-
/**
|
|
36
|
-
* 发行面包的期望文件集: files 白名单 (dist) 的物化 + npm 强制包含项 (README / LICENSE /
|
|
37
|
-
* package.json 等文件由 npm 无条件收进包, 且官方没有任何「排除」通道 (npm docs configuring-npm/
|
|
38
|
-
* package-json「files」节的排除语义 + 本机 npm-packlist 的 strict 规则, 见 ADR 0009 补记),
|
|
39
|
-
* 仓库根多一份 README 备份就会被静默收进发行包。本常量把「包内应有什么」显式声明成契约,
|
|
40
|
-
* 发布前逐项对账。
|
|
41
|
-
*
|
|
42
|
-
* 改动义务: package.json 的 files / bin 变更, 或仓库根增删总是收录类文件时, 必须同步本清单,
|
|
43
|
-
* 否则闸门会拒绝发布 (这正是它存在的目的: 发行面变化必须是一次显式决定, 不能靠静默)。
|
|
44
|
-
*/
|
|
34
|
+
/** 发行面包的期望文件集 (files 白名单物化 + npm 强制包含项) */
|
|
45
35
|
export const PACK_FILES_EXPECTED: readonly string[] = [
|
|
46
36
|
'LICENSE',
|
|
47
37
|
'README.md',
|
|
48
38
|
'README.zh-CN.md',
|
|
39
|
+
'bin/bunfig.toml',
|
|
49
40
|
'bin/{{BIN_NAME}}.mjs',
|
|
50
41
|
'dist/cli.js',
|
|
51
42
|
'dist/manifest.json',
|
|
52
43
|
'package.json',
|
|
53
44
|
];
|
|
54
45
|
|
|
55
|
-
|
|
56
|
-
const PROFILE: VerifyProfile = {
|
|
46
|
+
export const PROFILE: VerifyProfile = {
|
|
57
47
|
entryFile: CLI_FILE,
|
|
58
48
|
manifestFile: MANIFEST_FILE,
|
|
59
49
|
shaField: 'cliSha256',
|
|
@@ -61,29 +51,8 @@ const PROFILE: VerifyProfile = {
|
|
|
61
51
|
packExpected: PACK_FILES_EXPECTED,
|
|
62
52
|
};
|
|
63
53
|
|
|
64
|
-
|
|
65
|
-
export
|
|
66
|
-
/** 形状版本, 恒为 MANIFEST_SCHEMA_VERSION */
|
|
67
|
-
schemaVersion: number;
|
|
68
|
-
/** 构建时 HEAD 的完整哈希; 非 git 检出为 null */
|
|
69
|
-
commit: string | null;
|
|
70
|
-
/** 构建时工作树是否不干净; 读不到为 null */
|
|
71
|
-
dirty: boolean | null;
|
|
72
|
-
/** 产物 (dist/cli.js) 的 sha256 十六进制 */
|
|
73
|
-
cliSha256: string;
|
|
74
|
-
/** 构建时刻 (ISO 8601), 仅供人读诊断; 时间不是判据, 判定只看提交与摘要 */
|
|
75
|
-
builtAt: string;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/** 构建侧 git 事实 (collectGitFacts 的产物, 写清单用) */
|
|
79
|
-
export interface GitFacts {
|
|
80
|
-
/** HEAD 提交的完整哈希 */
|
|
81
|
-
commit: string | null;
|
|
82
|
-
/** 工作树是否有未提交改动 (含未跟踪文件) */
|
|
83
|
-
dirty: boolean | null;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// ---- 共享库直通导出 (包内消费方经本文件取用, 路径与命名保持稳定) ----
|
|
54
|
+
export type DistManifest = CliDistManifest;
|
|
55
|
+
export type { GitFacts };
|
|
87
56
|
|
|
88
57
|
export {
|
|
89
58
|
countDirtyEntries,
|
|
@@ -102,40 +71,22 @@ export type {
|
|
|
102
71
|
ReleaseVerdict,
|
|
103
72
|
} from '../../../scripts/lib/release-verify.ts';
|
|
104
73
|
|
|
105
|
-
|
|
74
|
+
export { collectGitFacts, writeCliDistManifest };
|
|
75
|
+
|
|
106
76
|
export const readDistState = (distDir: string): DistState =>
|
|
107
77
|
readDistStateCommon(distDir, PROFILE);
|
|
108
78
|
|
|
109
|
-
/** 发行面包白名单判定 (CLI 口径) */
|
|
110
79
|
export const judgePackFiles = (
|
|
111
80
|
files: string[],
|
|
112
81
|
): { ok: true } | { ok: false; reason: string } =>
|
|
113
82
|
judgePackFilesCommon(files, PACK_FILES_EXPECTED);
|
|
114
83
|
|
|
115
|
-
/**
|
|
116
|
-
* 发布闸门判定 (纯函数, 不碰文件系统): 委托共享库按统一判定序执行 (CLI 无专属判定项)。
|
|
117
|
-
*/
|
|
118
84
|
export const judgeRelease = (facts: ReleaseFacts): ReleaseVerdict =>
|
|
119
85
|
judgeReleaseCommon(facts, PROFILE);
|
|
120
86
|
|
|
121
|
-
/** 采 git 事实 (构建侧写清单用): 在 root 内跑两条只读命令, 任一步读不到即落 null */
|
|
122
|
-
export const collectGitFacts = (root: string): GitFacts => {
|
|
123
|
-
const status = readGitText(root, ['status', '--porcelain']);
|
|
124
|
-
return {
|
|
125
|
-
commit: normalizeCommit(readGitText(root, ['rev-parse', 'HEAD'])),
|
|
126
|
-
dirty: status === null ? null : status.trim() !== '',
|
|
127
|
-
};
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
/** 组装清单 (构建侧写入的正是这份数据; 字段形状即契约) */
|
|
131
87
|
export const buildManifest = (fields: {
|
|
132
88
|
cliSha256: string;
|
|
133
89
|
git: GitFacts;
|
|
134
90
|
builtAt: string;
|
|
135
|
-
}): DistManifest =>
|
|
136
|
-
schemaVersion: MANIFEST_SCHEMA_VERSION
|
|
137
|
-
commit: fields.git.commit,
|
|
138
|
-
dirty: fields.git.dirty,
|
|
139
|
-
cliSha256: fields.cliSha256,
|
|
140
|
-
builtAt: fields.builtAt,
|
|
141
|
-
});
|
|
91
|
+
}): DistManifest =>
|
|
92
|
+
buildCliManifest({ ...fields, schemaVersion: MANIFEST_SCHEMA_VERSION });
|
|
@@ -22,7 +22,12 @@ export const makeTempDir = async (prefix: string): Promise<TempDir> => {
|
|
|
22
22
|
return {
|
|
23
23
|
root,
|
|
24
24
|
cleanup: async () => {
|
|
25
|
-
await rm(root, {
|
|
25
|
+
await rm(root, {
|
|
26
|
+
recursive: true,
|
|
27
|
+
force: true,
|
|
28
|
+
maxRetries: 5,
|
|
29
|
+
retryDelay: 100,
|
|
30
|
+
});
|
|
26
31
|
},
|
|
27
32
|
};
|
|
28
33
|
};
|
|
@@ -58,9 +63,9 @@ export const makeTempRepo = async (prefix: string): Promise<TempDir> => {
|
|
|
58
63
|
'-c',
|
|
59
64
|
'commit.gpgsign=false',
|
|
60
65
|
'-c',
|
|
61
|
-
'user.name=
|
|
66
|
+
'user.name=release-test',
|
|
62
67
|
'-c',
|
|
63
|
-
'user.email=
|
|
68
|
+
'user.email=release-test@example.com',
|
|
64
69
|
'commit',
|
|
65
70
|
'--no-verify',
|
|
66
71
|
'-m',
|
|
@@ -83,7 +83,7 @@ const patchManifest = async (
|
|
|
83
83
|
|
|
84
84
|
describe('发布前置闸门 · 临时检出端到端', () => {
|
|
85
85
|
test('干净检出 + 本提交产物 + 清单自洽 → 通过 (退出码 0)', async () => {
|
|
86
|
-
const repo = await makeTempRepo('
|
|
86
|
+
const repo = await makeTempRepo('cli-release-ok-');
|
|
87
87
|
try {
|
|
88
88
|
await stageArtifact(repo.root);
|
|
89
89
|
const { io, out, err } = capture();
|
|
@@ -97,7 +97,7 @@ describe('发布前置闸门 · 临时检出端到端', () => {
|
|
|
97
97
|
});
|
|
98
98
|
|
|
99
99
|
test('工作树脏 → 拒绝 (退出码 1, 拒绝原因带未提交改动条数)', async () => {
|
|
100
|
-
const repo = await makeTempRepo('
|
|
100
|
+
const repo = await makeTempRepo('cli-release-dirty-');
|
|
101
101
|
try {
|
|
102
102
|
await stageArtifact(repo.root);
|
|
103
103
|
await writeFile(join(repo.root, 'workspace.txt'), '半成品\n');
|
|
@@ -114,7 +114,7 @@ describe('发布前置闸门 · 临时检出端到端', () => {
|
|
|
114
114
|
});
|
|
115
115
|
|
|
116
116
|
test('产物缺失 → 拒绝 (退出码 1)', async () => {
|
|
117
|
-
const repo = await makeTempRepo('
|
|
117
|
+
const repo = await makeTempRepo('cli-release-nocli-');
|
|
118
118
|
try {
|
|
119
119
|
await stageArtifact(repo.root);
|
|
120
120
|
await rm(join(repo.root, 'dist', CLI_FILE));
|
|
@@ -128,7 +128,7 @@ describe('发布前置闸门 · 临时检出端到端', () => {
|
|
|
128
128
|
});
|
|
129
129
|
|
|
130
130
|
test('产物被替换 (摘要不符) → 拒绝', async () => {
|
|
131
|
-
const repo = await makeTempRepo('
|
|
131
|
+
const repo = await makeTempRepo('cli-release-swapped-');
|
|
132
132
|
try {
|
|
133
133
|
await stageArtifact(repo.root);
|
|
134
134
|
await writeFile(
|
|
@@ -145,7 +145,7 @@ describe('发布前置闸门 · 临时检出端到端', () => {
|
|
|
145
145
|
});
|
|
146
146
|
|
|
147
147
|
test('清单记录的是脏构建 → 拒绝', async () => {
|
|
148
|
-
const repo = await makeTempRepo('
|
|
148
|
+
const repo = await makeTempRepo('cli-release-dirtybuild-');
|
|
149
149
|
try {
|
|
150
150
|
await stageArtifact(repo.root);
|
|
151
151
|
await patchManifest(repo.root, { dirty: true });
|
|
@@ -159,7 +159,7 @@ describe('发布前置闸门 · 临时检出端到端', () => {
|
|
|
159
159
|
});
|
|
160
160
|
|
|
161
161
|
test('清单记录的提交与 HEAD 不一致 (构建后又有新提交) → 拒绝', async () => {
|
|
162
|
-
const repo = await makeTempRepo('
|
|
162
|
+
const repo = await makeTempRepo('cli-release-stale-');
|
|
163
163
|
try {
|
|
164
164
|
await stageArtifact(repo.root);
|
|
165
165
|
await patchManifest(repo.root, { commit: 'f'.repeat(40) });
|
|
@@ -173,7 +173,7 @@ describe('发布前置闸门 · 临时检出端到端', () => {
|
|
|
173
173
|
});
|
|
174
174
|
|
|
175
175
|
test('非 git 目录 → 拒绝 (读不到 git 状态)', async () => {
|
|
176
|
-
const temp = await makeTempDir('
|
|
176
|
+
const temp = await makeTempDir('cli-release-nogit-');
|
|
177
177
|
try {
|
|
178
178
|
const { io, err } = capture();
|
|
179
179
|
|
|
@@ -330,7 +330,7 @@ describe('发布前置闸门 · 字段级判定 (注入事实)', () => {
|
|
|
330
330
|
reason: '该项检查需要 npm',
|
|
331
331
|
},
|
|
332
332
|
{
|
|
333
|
-
name: '发行面包内多出文件 (
|
|
333
|
+
name: '发行面包内多出文件 (如包根备份被 npm 一并收进包)',
|
|
334
334
|
facts: {
|
|
335
335
|
...cleanFacts,
|
|
336
336
|
pack: {
|
|
@@ -381,7 +381,7 @@ describe('发行面白名单 · 注入式 (喂假 pack 输出, 一次 npm 都不
|
|
|
381
381
|
test('解析 npm pack --json 的输出: 取首个元素的 files[].path', () => {
|
|
382
382
|
const raw = JSON.stringify([
|
|
383
383
|
{
|
|
384
|
-
filename: '{{OWNER}}-{{NAME}}-0.3.0.tgz',
|
|
384
|
+
filename: '{{OWNER}}-{{NAME}}-cli-0.3.0.tgz',
|
|
385
385
|
files: [
|
|
386
386
|
{ path: 'LICENSE', size: 1063 },
|
|
387
387
|
{ path: 'dist/cli.js', size: 51965 },
|
|
@@ -421,15 +421,20 @@ describe('发行面白名单 · 注入式 (喂假 pack 输出, 一次 npm 都不
|
|
|
421
421
|
* 注册期判定 skip 并播报原因; dist 在场则全程维持原有全清单断言, 不削弱真问题抓取力。
|
|
422
422
|
*/
|
|
423
423
|
const hasDist = existsSync(join(PACKAGE_ROOT, 'dist'));
|
|
424
|
+
const skipPackTest = process.env.CI_SKIP_PACK_TEST === '1';
|
|
424
425
|
|
|
425
426
|
if (!hasDist) {
|
|
426
427
|
console.warn(
|
|
427
428
|
'[Skip] 工作树无构建产物 (先 bun run build); 本用例守护发行面杂质回归',
|
|
428
429
|
);
|
|
430
|
+
} else if (skipPackTest) {
|
|
431
|
+
console.warn(
|
|
432
|
+
'[Skip] 已设置 CI_SKIP_PACK_TEST=1, 跳过重复的真机 npm pack 对齐 (已在 Linux CI 与 prepublishOnly 覆盖)',
|
|
433
|
+
);
|
|
429
434
|
}
|
|
430
435
|
|
|
431
436
|
describe('发行面白名单 · 真实 npm 对齐 (本仓库实测)', () => {
|
|
432
|
-
test.skipIf(!hasDist)(
|
|
437
|
+
test.skipIf(!hasDist || skipPackTest)(
|
|
433
438
|
'本仓库工作树的 pack 清单与白名单逐项一致 (包根杂质复发的常驻回归)',
|
|
434
439
|
() => {
|
|
435
440
|
const facts = readPackFiles(PACKAGE_ROOT);
|
|
@@ -440,5 +445,6 @@ describe('发行面白名单 · 真实 npm 对齐 (本仓库实测)', () => {
|
|
|
440
445
|
// 断言携带 reason 而非裸 false: 失败时测试输出直接给出差异清单, 一眼看清是多出还是缺少
|
|
441
446
|
expect(verdict.ok ? '' : verdict.reason).toBe('');
|
|
442
447
|
},
|
|
448
|
+
30_000,
|
|
443
449
|
);
|
|
444
450
|
});
|
|
@@ -1,69 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* 四者齐备才放行发布。
|
|
4
|
-
*
|
|
5
|
-
* 由 package.json 的 prepublishOnly (`npm run build && npm run verify:release`) 在构建后调用,
|
|
6
|
-
* 手动复核即 `bun run verify:release`。分工: 事实采集 (含发行面清单, 跑一次只读的 npm pack) 与
|
|
7
|
-
* 判定都在 release-artifact.ts (判定是纯函数, 事实可注入), 本文件只负责坐标 (PACKAGE_ROOT) 与
|
|
8
|
-
* 输出面 (文案 + 退出码)。
|
|
9
|
-
*
|
|
10
|
-
* 用法: bun scripts/verify-release.ts
|
|
11
|
-
* 退出码: 0 通过; 1 拒绝 (原因与处置见 stderr)
|
|
2
|
+
* 发布侧闸门 ({{NAME}}-cli): 委托仓根 scripts/lib/release-cli.ts 统一判定。
|
|
12
3
|
*/
|
|
13
|
-
import {
|
|
14
|
-
|
|
4
|
+
import {
|
|
5
|
+
type ReleaseIo,
|
|
6
|
+
runVerifyReleaseCli,
|
|
7
|
+
} from '../../../scripts/lib/release-cli.ts';
|
|
15
8
|
import {
|
|
16
9
|
PACKAGE_ROOT,
|
|
10
|
+
PROFILE,
|
|
17
11
|
type PackFacts,
|
|
18
|
-
type ReleaseFacts,
|
|
19
|
-
judgeRelease,
|
|
20
|
-
normalizeCommit,
|
|
21
|
-
readDistState,
|
|
22
|
-
readGitText,
|
|
23
12
|
readPackFiles,
|
|
24
|
-
shortHash,
|
|
25
13
|
} from './release-artifact.ts';
|
|
26
14
|
|
|
27
|
-
|
|
28
|
-
export interface ReleaseIo {
|
|
29
|
-
out: (line: string) => void;
|
|
30
|
-
err: (line: string) => void;
|
|
31
|
-
}
|
|
15
|
+
export type { ReleaseIo };
|
|
32
16
|
|
|
33
|
-
/**
|
|
34
|
-
* 跑一次发布前置校验: 采事实 (git 状态 / HEAD + dist 现状 + 发行面包内清单) → judgeRelease →
|
|
35
|
-
* 输出结论。
|
|
36
|
-
* root 是包根 (默认 PACKAGE_ROOT; 测试注入临时仓库, 判定因此不依赖当前工作树状态)。
|
|
37
|
-
* packFacts 默认现场采集 (跑一次只读的 npm pack, 需要 npm); 测试注入假清单以摆脱 npm 依赖。
|
|
38
|
-
* 外部副作用:只读 (两条只读 git 命令 + 读 dist/ 下的产物与清单 + 一次 npm pack --dry-run)。
|
|
39
|
-
*/
|
|
40
17
|
export const verifyRelease = (
|
|
41
18
|
root: string,
|
|
42
19
|
io: ReleaseIo,
|
|
43
20
|
packFacts: PackFacts = readPackFiles(root),
|
|
44
|
-
): number =>
|
|
45
|
-
const facts: ReleaseFacts = {
|
|
46
|
-
gitStatus: readGitText(root, ['status', '--porcelain']),
|
|
47
|
-
gitHead: normalizeCommit(readGitText(root, ['rev-parse', 'HEAD'])),
|
|
48
|
-
dist: readDistState(join(root, 'dist')),
|
|
49
|
-
pack: packFacts,
|
|
50
|
-
};
|
|
51
|
-
const verdict = judgeRelease(facts);
|
|
52
|
-
if (verdict.ok) {
|
|
53
|
-
io.out(
|
|
54
|
-
`发布前置校验通过: 提交 ${shortHash(verdict.commit)} · 产物摘要 ${shortHash(verdict.sha256)}`,
|
|
55
|
-
);
|
|
56
|
-
return 0;
|
|
57
|
-
}
|
|
58
|
-
io.err(`发布前置校验未通过: ${verdict.reason}`);
|
|
59
|
-
io.err(
|
|
60
|
-
' 处置: 工作树不干净就提交或 stash 后重新构建再发 (npm run build 会同时写产物与清单);' +
|
|
61
|
-
' 发行面包内文件与白名单不符就清掉仓库根的多余文件 (如备份移出仓库), 或同步白名单常量。',
|
|
62
|
-
);
|
|
63
|
-
return 1;
|
|
64
|
-
};
|
|
21
|
+
): number => runVerifyReleaseCli(root, PROFILE, io, packFacts);
|
|
65
22
|
|
|
66
|
-
// 被测试 import 时不得跑入口 (只有直接运行才落退出码)
|
|
67
23
|
if (import.meta.main) {
|
|
68
24
|
process.exitCode = verifyRelease(PACKAGE_ROOT, {
|
|
69
25
|
out: (line) => process.stdout.write(`${line}\n`),
|
|
@@ -27,7 +27,7 @@ const makeDistDir = async (): Promise<{
|
|
|
27
27
|
distDir: string;
|
|
28
28
|
cleanup: () => Promise<void>;
|
|
29
29
|
}> => {
|
|
30
|
-
const temp = await makeTempDir('
|
|
30
|
+
const temp = await makeTempDir('cli-manifest-');
|
|
31
31
|
const distDir = join(temp.root, 'dist');
|
|
32
32
|
mkdirSync(distDir, { recursive: true });
|
|
33
33
|
return { distDir, cleanup: temp.cleanup };
|
|
@@ -97,7 +97,7 @@ describe('产物清单写入', () => {
|
|
|
97
97
|
});
|
|
98
98
|
|
|
99
99
|
test('非 git 检出: 事实如实落 null (不假装有提交)', async () => {
|
|
100
|
-
const temp = await makeTempDir('
|
|
100
|
+
const temp = await makeTempDir('cli-nogit-');
|
|
101
101
|
try {
|
|
102
102
|
expect(collectGitFacts(temp.root)).toEqual({ commit: null, dirty: null });
|
|
103
103
|
} finally {
|
|
@@ -106,7 +106,7 @@ describe('产物清单写入', () => {
|
|
|
106
106
|
});
|
|
107
107
|
|
|
108
108
|
test('真实检出: 干净时采到提交与净状态, 改动后转脏', async () => {
|
|
109
|
-
const repo = await makeTempRepo('
|
|
109
|
+
const repo = await makeTempRepo('cli-facts-');
|
|
110
110
|
try {
|
|
111
111
|
expect(collectGitFacts(repo.root)).toEqual({
|
|
112
112
|
commit: runGit(repo.root, ['rev-parse', 'HEAD']).trim(),
|
|
@@ -1,81 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* package.json 的 build = `bun build ... && bun scripts/write-dist-manifest.ts`: 产物与清单是
|
|
5
|
-
* 同一次构建的两半, 分开跑会留下「有产物无清单」的中间态, 而那种产物会被启动器拒收。
|
|
6
|
-
* 非 git 检出时不拒绝构建, 如实记 null (提交标识未知); 「发布必须来自干净检出」是
|
|
7
|
-
* verify-release.ts 的职责, 构建侧不越权。
|
|
8
|
-
*
|
|
9
|
-
* 用法: bun scripts/write-dist-manifest.ts
|
|
10
|
-
* 退出码: 0 清单已写入; 1 产物缺失或为空 (先跑构建)
|
|
2
|
+
* 构建侧入口 ({{NAME}}-cli): 给 dist/cli.js 写入自证清单 dist/manifest.json。
|
|
11
3
|
*/
|
|
12
|
-
import {
|
|
13
|
-
import { join } from 'node:path';
|
|
14
|
-
|
|
4
|
+
import { runWriteDistManifestCli } from '../../../scripts/lib/release-cli.ts';
|
|
15
5
|
import {
|
|
16
|
-
CLI_FILE,
|
|
17
6
|
type DistManifest,
|
|
18
7
|
type GitFacts,
|
|
19
|
-
MANIFEST_FILE,
|
|
20
8
|
PACKAGE_ROOT,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
sha256File,
|
|
24
|
-
shortHash,
|
|
9
|
+
PROFILE,
|
|
10
|
+
writeCliDistManifest,
|
|
25
11
|
} from './release-artifact.ts';
|
|
26
12
|
|
|
27
|
-
/**
|
|
28
|
-
* 写清单: 算产物摘要 → 采 git 事实 → 落盘, 返回写入的清单; 产物缺失 / 不是常规文件 /
|
|
29
|
-
* 零字节时返回 null (缺失是要落退出码的拒绝路径, 不是异常, 故用返回值而非抛错)。
|
|
30
|
-
* 外部副作用:写入 dist/manifest.json。
|
|
31
|
-
*/
|
|
32
13
|
export const writeDistManifest = (
|
|
33
14
|
distDir: string,
|
|
34
15
|
git: GitFacts,
|
|
35
16
|
builtAt: string,
|
|
36
|
-
): DistManifest | null =>
|
|
37
|
-
const cliPath = join(distDir, CLI_FILE);
|
|
38
|
-
if (!existsSync(cliPath)) return null;
|
|
39
|
-
// 存在但 stat 失败 / 摘要读不出属环境异常 (权限、坏盘), 让它抛: 失败要响亮, 不与「缺失」混同
|
|
40
|
-
const info = statSync(cliPath);
|
|
41
|
-
if (!info.isFile() || info.size === 0) return null;
|
|
42
|
-
const manifest = buildManifest({
|
|
43
|
-
cliSha256: sha256File(cliPath),
|
|
44
|
-
git,
|
|
45
|
-
builtAt,
|
|
46
|
-
});
|
|
47
|
-
writeFileSync(
|
|
48
|
-
join(distDir, MANIFEST_FILE),
|
|
49
|
-
`${JSON.stringify(manifest, null, 2)}\n`,
|
|
50
|
-
);
|
|
51
|
-
return manifest;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
/** 人读的来源标签: 提交短哈希 + 脏净标注; 非 git 检出如实说明 (不假装有提交) */
|
|
55
|
-
const sourceLabel = (manifest: DistManifest): string => {
|
|
56
|
-
if (manifest.commit === null) return '非 git 检出 (未记录提交)';
|
|
57
|
-
const dirty = manifest.dirty === true ? ' (脏工作树)' : '';
|
|
58
|
-
return `提交 ${shortHash(manifest.commit)}${dirty}`;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
/** 入口: 写清单并落退出码 (0 已写入 / 1 产物缺失或为空) */
|
|
62
|
-
const main = (): number => {
|
|
63
|
-
const manifest = writeDistManifest(
|
|
64
|
-
join(PACKAGE_ROOT, 'dist'),
|
|
65
|
-
collectGitFacts(PACKAGE_ROOT),
|
|
66
|
-
new Date().toISOString(),
|
|
67
|
-
);
|
|
68
|
-
if (manifest === null) {
|
|
69
|
-
process.stderr.write(
|
|
70
|
-
`产物清单未写入: dist/${CLI_FILE} 缺失或为空, 先跑 bun build 产出产物\n`,
|
|
71
|
-
);
|
|
72
|
-
return 1;
|
|
73
|
-
}
|
|
74
|
-
process.stdout.write(
|
|
75
|
-
`产物清单已写入 dist/${MANIFEST_FILE}: ${sourceLabel(manifest)} · 摘要 ${shortHash(manifest.cliSha256)}\n`,
|
|
76
|
-
);
|
|
77
|
-
return 0;
|
|
78
|
-
};
|
|
17
|
+
): DistManifest | null => writeCliDistManifest(distDir, PROFILE, git, builtAt);
|
|
79
18
|
|
|
80
|
-
|
|
81
|
-
|
|
19
|
+
if (import.meta.main) {
|
|
20
|
+
process.exitCode = runWriteDistManifestCli(PACKAGE_ROOT, PROFILE);
|
|
21
|
+
}
|