create-clis 0.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/LICENSE +21 -0
- package/README.md +113 -0
- package/README.zh-CN.md +113 -0
- package/assets/manifest.json +99 -0
- package/assets/template/.editorconfig +12 -0
- package/assets/template/.gitattributes +18 -0
- package/assets/template/.github/ISSUE_TEMPLATE/bug_report.yml +86 -0
- package/assets/template/.github/ISSUE_TEMPLATE/feature_request.yml +45 -0
- package/assets/template/.github/PULL_REQUEST_TEMPLATE.md +26 -0
- package/assets/template/.github/workflows/ci.yml +42 -0
- package/assets/template/.github/workflows/release.yml +65 -0
- package/assets/template/.gitignorerc.json +21 -0
- package/assets/template/.nvmrc +1 -0
- package/assets/template/.oxlintrc.json +52 -0
- package/assets/template/.prettierignore +11 -0
- package/assets/template/.prettierrc +11 -0
- package/assets/template/.releaserc.json +17 -0
- package/assets/template/.vscode/extensions.json +8 -0
- package/assets/template/.vscode/launch.json +13 -0
- package/assets/template/.vscode/settings.json +14 -0
- package/assets/template/AGENTS.md +25 -0
- package/assets/template/CODE_OF_CONDUCT.md +91 -0
- package/assets/template/CONTRIBUTING.md +85 -0
- package/assets/template/CONTRIBUTING.zh-CN.md +85 -0
- package/assets/template/LICENSE +21 -0
- package/assets/template/README.md +22 -0
- package/assets/template/README.zh-CN.md +22 -0
- package/assets/template/SECURITY.md +21 -0
- package/assets/template/_gitignore +409 -0
- package/assets/template/_npmrc +6 -0
- package/assets/template/bunfig.toml +16 -0
- package/assets/template/docs/README.md +30 -0
- package/assets/template/docs/adrs/README.md +7 -0
- package/assets/template/docs/designs/README.md +11 -0
- package/assets/template/docs/designs/tech-debt.md +22 -0
- package/assets/template/docs/development.md +59 -0
- package/assets/template/lefthook.yml +55 -0
- package/assets/template/package.json +38 -0
- package/assets/template/packages/{{NAME}}/CHANGELOG.md +3 -0
- package/assets/template/packages/{{NAME}}/LICENSE +21 -0
- package/assets/template/packages/{{NAME}}/README.md +33 -0
- package/assets/template/packages/{{NAME}}/README.zh-CN.md +33 -0
- package/assets/template/packages/{{NAME}}/docs/README.md +21 -0
- package/assets/template/packages/{{NAME}}/package.json +40 -0
- package/assets/template/packages/{{NAME}}/scripts/build.ts +82 -0
- package/assets/template/packages/{{NAME}}/scripts/verify-release.test.ts +214 -0
- package/assets/template/packages/{{NAME}}/scripts/verify-release.ts +152 -0
- package/assets/template/packages/{{NAME}}/src/index.ts +15 -0
- package/assets/template/packages/{{NAME}}/tsconfig.build.json +12 -0
- package/assets/template/packages/{{NAME}}/tsconfig.json +5 -0
- package/assets/template/packages/{{NAME}}-cli/CHANGELOG.md +3 -0
- package/assets/template/packages/{{NAME}}-cli/LICENSE +21 -0
- package/assets/template/packages/{{NAME}}-cli/README.md +35 -0
- package/assets/template/packages/{{NAME}}-cli/README.zh-CN.md +35 -0
- package/assets/template/packages/{{NAME}}-cli/bin/{{BIN_NAME}} +30 -0
- package/assets/template/packages/{{NAME}}-cli/bin/{{BIN_NAME}}.cmd +30 -0
- package/assets/template/packages/{{NAME}}-cli/bin/{{BIN_NAME}}.d.mts +23 -0
- package/assets/template/packages/{{NAME}}-cli/bin/{{BIN_NAME}}.mjs +212 -0
- package/assets/template/packages/{{NAME}}-cli/docs/README.md +21 -0
- package/assets/template/packages/{{NAME}}-cli/package.json +48 -0
- package/assets/template/packages/{{NAME}}-cli/scripts/release-artifact.ts +141 -0
- package/assets/template/packages/{{NAME}}-cli/scripts/release.fixtures.ts +70 -0
- package/assets/template/packages/{{NAME}}-cli/scripts/verify-release.test.ts +444 -0
- package/assets/template/packages/{{NAME}}-cli/scripts/verify-release.ts +72 -0
- package/assets/template/packages/{{NAME}}-cli/scripts/write-dist-manifest.test.ts +126 -0
- package/assets/template/packages/{{NAME}}-cli/scripts/write-dist-manifest.ts +81 -0
- package/assets/template/packages/{{NAME}}-cli/src/cli.ts +36 -0
- package/assets/template/packages/{{NAME}}-cli/tsconfig.json +4 -0
- package/assets/template/scripts/ci.ts +163 -0
- package/assets/template/scripts/install-git-hooks.mjs +122 -0
- package/assets/template/scripts/install-git-hooks.test.ts +418 -0
- package/assets/template/scripts/lib/git-env.ts +21 -0
- package/assets/template/scripts/lib/release-verify.ts +431 -0
- package/assets/template/scripts/lib/tmp-root.ts +17 -0
- package/assets/template/scripts/lib/workspace.test.ts +92 -0
- package/assets/template/scripts/lib/workspace.ts +100 -0
- package/assets/template/scripts/lint-doc-examples.test.ts +129 -0
- package/assets/template/scripts/lint-doc-examples.ts +249 -0
- package/assets/template/scripts/lint-doc-references.test.ts +158 -0
- package/assets/template/scripts/lint-doc-references.ts +308 -0
- package/assets/template/scripts/lint-doc-shared.ts +59 -0
- package/assets/template/scripts/lint-stray-backups.test.ts +53 -0
- package/assets/template/scripts/lint-stray-backups.ts +39 -0
- package/assets/template/scripts/npm-trust-guard.test.ts +253 -0
- package/assets/template/scripts/npm-trust-guard.ts +533 -0
- package/assets/template/scripts/safe-install.ts +39 -0
- package/assets/template/scripts/transcription/api-harness.ts +219 -0
- package/assets/template/scripts/transcription/compare.ts +421 -0
- package/assets/template/scripts/transcription/corpus.ts +208 -0
- package/assets/template/scripts/transcription/fixture.ts +290 -0
- package/assets/template/scripts/transcription/make-mutants.ts +425 -0
- package/assets/template/scripts/transcription/report.ts +86 -0
- package/assets/template/scripts/transcription/run-conformance.ts +344 -0
- package/assets/template/scripts/transcription/validate-coverage.test.ts +119 -0
- package/assets/template/scripts/transcription/validate-coverage.ts +144 -0
- package/assets/template/scripts/transcription/validate.ts +366 -0
- package/assets/template/tsconfig.json +46 -0
- package/assets/template/turbo.jsonc +60 -0
- package/bin/create-clis +35 -0
- package/bin/create-clis.cmd +32 -0
- package/bin/create-clis.mjs +219 -0
- package/dist/create-clis.js +87682 -0
- package/dist/manifest.json +7 -0
- package/package.json +57 -0
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 发布凭据闸门单测: 纯函数层 (远端 URL 派生 / npm trust 输出解析 / 登记对账 / OIDC 环境判定 /
|
|
3
|
+
* 预检核对面过滤)。
|
|
4
|
+
*/
|
|
5
|
+
import { describe, expect, test } from 'bun:test';
|
|
6
|
+
|
|
7
|
+
import type { WorkspacePackage } from './lib/workspace.ts';
|
|
8
|
+
import {
|
|
9
|
+
classifyOidcEnv,
|
|
10
|
+
deriveRepoFromRemoteUrl,
|
|
11
|
+
diffTrust,
|
|
12
|
+
filterPublishable,
|
|
13
|
+
parseTrustListOutput,
|
|
14
|
+
ptyWrapArgs,
|
|
15
|
+
} from './npm-trust-guard.ts';
|
|
16
|
+
|
|
17
|
+
/** 终端控制符经 fromCharCode 构造: 防源码里的转义序列在落盘时被求值成真实不可见字符 */
|
|
18
|
+
const ESC = String.fromCharCode(27);
|
|
19
|
+
const green = (text: string): string => `${ESC}[32m${text}${ESC}[39m`;
|
|
20
|
+
|
|
21
|
+
describe('deriveRepoFromRemoteUrl', () => {
|
|
22
|
+
test('SSH 形态', () => {
|
|
23
|
+
expect(deriveRepoFromRemoteUrl('git@github.com:{{OWNER}}/{{NAME}}.git')).toBe(
|
|
24
|
+
'{{OWNER}}/{{NAME}}',
|
|
25
|
+
);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('HTTPS 形态 (带与不带 .git 后缀)', () => {
|
|
29
|
+
expect(deriveRepoFromRemoteUrl('{{REPO_URL}}.git')).toBe(
|
|
30
|
+
'{{OWNER}}/{{NAME}}',
|
|
31
|
+
);
|
|
32
|
+
expect(deriveRepoFromRemoteUrl('{{REPO_URL}}')).toBe(
|
|
33
|
+
'{{OWNER}}/{{NAME}}',
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('非 GitHub 远端与空串返回 null', () => {
|
|
38
|
+
expect(deriveRepoFromRemoteUrl('git@gitlab.com:foo/bar.git')).toBeNull();
|
|
39
|
+
expect(deriveRepoFromRemoteUrl('')).toBeNull();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('parseTrustListOutput', () => {
|
|
44
|
+
test('解析实测形态 (键值行, 值带 ANSI 着色)', () => {
|
|
45
|
+
const raw = [
|
|
46
|
+
`type: ${green('github')}`,
|
|
47
|
+
`id: ${green('625b8bc6-f738-4aac-9a92-70ba2f01ce80')}`,
|
|
48
|
+
`file: ${green('release.yml')}`,
|
|
49
|
+
`repository: ${green('{{OWNER}}/{{NAME}}')}`,
|
|
50
|
+
`environment: ${green('release')}`,
|
|
51
|
+
'permissions: publish, stage publish',
|
|
52
|
+
].join('\n');
|
|
53
|
+
expect(parseTrustListOutput(raw)).toEqual({
|
|
54
|
+
type: 'github',
|
|
55
|
+
id: '625b8bc6-f738-4aac-9a92-70ba2f01ce80',
|
|
56
|
+
file: 'release.yml',
|
|
57
|
+
repository: '{{OWNER}}/{{NAME}}',
|
|
58
|
+
environment: 'release',
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('混入认证提示等噪音行不影响解析; 缺行字段落成 null', () => {
|
|
63
|
+
const raw = [
|
|
64
|
+
'npm notice npm tokens that bypass 2FA are being restricted',
|
|
65
|
+
'Authenticate your account at:',
|
|
66
|
+
'https://www.npmjs.com/auth/cli/xxx',
|
|
67
|
+
'Press ENTER to open in the browser...',
|
|
68
|
+
'',
|
|
69
|
+
'type: github',
|
|
70
|
+
'repository: {{OWNER}}/{{NAME}}',
|
|
71
|
+
'file: release.yml',
|
|
72
|
+
].join('\n');
|
|
73
|
+
expect(parseTrustListOutput(raw)).toEqual({
|
|
74
|
+
type: 'github',
|
|
75
|
+
id: null,
|
|
76
|
+
file: 'release.yml',
|
|
77
|
+
repository: '{{OWNER}}/{{NAME}}',
|
|
78
|
+
environment: null,
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('未见 repository 行视为形状不符 (解析不出可信条目)', () => {
|
|
83
|
+
expect(parseTrustListOutput('npm error code EOTP\n')).toBeNull();
|
|
84
|
+
expect(parseTrustListOutput('')).toBeNull();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('spinner 的 CSI 光标控制序列 (非 m 结尾) 不残留进键值行', () => {
|
|
88
|
+
const csi = (tail: string): string => `${ESC}[1G${ESC}[0K${tail}`;
|
|
89
|
+
const raw = `${csi('type: github')}\r\n${csi('repository: {{OWNER}}/{{NAME}}')}\r\n${csi('file: release.yml')}\r\n`;
|
|
90
|
+
expect(parseTrustListOutput(raw)).toEqual({
|
|
91
|
+
type: 'github',
|
|
92
|
+
id: null,
|
|
93
|
+
file: 'release.yml',
|
|
94
|
+
repository: '{{OWNER}}/{{NAME}}',
|
|
95
|
+
environment: null,
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('script pty 的 ^D + 退格开场与 CRLF 行尾不影响解析', () => {
|
|
100
|
+
const raw =
|
|
101
|
+
[
|
|
102
|
+
`${String.fromCharCode(4, 8, 8)}type: github`,
|
|
103
|
+
'repository: {{OWNER}}/{{NAME}}',
|
|
104
|
+
'file: release.yml',
|
|
105
|
+
].join('\r\n') + '\r\n';
|
|
106
|
+
expect(parseTrustListOutput(raw)).toEqual({
|
|
107
|
+
type: 'github',
|
|
108
|
+
id: null,
|
|
109
|
+
file: 'release.yml',
|
|
110
|
+
repository: '{{OWNER}}/{{NAME}}',
|
|
111
|
+
environment: null,
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
describe('diffTrust', () => {
|
|
117
|
+
const expected = {
|
|
118
|
+
repository: '{{OWNER}}/{{NAME}}',
|
|
119
|
+
file: 'release.yml',
|
|
120
|
+
environment: 'release',
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
test('全一致返回空列表', () => {
|
|
124
|
+
expect(
|
|
125
|
+
diffTrust(
|
|
126
|
+
{
|
|
127
|
+
type: 'github',
|
|
128
|
+
id: 'x',
|
|
129
|
+
file: 'release.yml',
|
|
130
|
+
repository: '{{OWNER}}/{{NAME}}',
|
|
131
|
+
environment: 'release',
|
|
132
|
+
},
|
|
133
|
+
expected,
|
|
134
|
+
),
|
|
135
|
+
).toEqual([]);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test('repository 失配逐条列出 (改名事故的典型形态)', () => {
|
|
139
|
+
// 失配样本刻意取中性名 (不与仓库自身的名字重合): 它是「另一个仓库名」的任意代表,
|
|
140
|
+
// 判定链只比较两值是否相等, 取值本身无语义; 与仓库重名反而会让模板侧的两个值塌缩成同一个
|
|
141
|
+
const problems = diffTrust(
|
|
142
|
+
{
|
|
143
|
+
type: 'github',
|
|
144
|
+
id: 'x',
|
|
145
|
+
file: 'release.yml',
|
|
146
|
+
repository: '{{OWNER}}/legacy-repo',
|
|
147
|
+
environment: 'release',
|
|
148
|
+
},
|
|
149
|
+
expected,
|
|
150
|
+
);
|
|
151
|
+
expect(problems).toHaveLength(1);
|
|
152
|
+
expect(problems[0]).toContain('{{OWNER}}/legacy-repo');
|
|
153
|
+
expect(problems[0]).toContain('{{OWNER}}/{{NAME}}');
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test('file 与 environment 失配一并列出 (缺失值有占位)', () => {
|
|
157
|
+
const problems = diffTrust(
|
|
158
|
+
{
|
|
159
|
+
type: 'github',
|
|
160
|
+
id: 'x',
|
|
161
|
+
file: 'publish.yml',
|
|
162
|
+
repository: '{{OWNER}}/{{NAME}}',
|
|
163
|
+
environment: null,
|
|
164
|
+
},
|
|
165
|
+
expected,
|
|
166
|
+
);
|
|
167
|
+
expect(problems).toHaveLength(2);
|
|
168
|
+
expect(problems[1]).toContain('(未设置)');
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
describe('classifyOidcEnv', () => {
|
|
173
|
+
test('Actions 环境且 OIDC 变量齐备 → ready', () => {
|
|
174
|
+
expect(
|
|
175
|
+
classifyOidcEnv({
|
|
176
|
+
GITHUB_ACTIONS: 'true',
|
|
177
|
+
ACTIONS_ID_TOKEN_REQUEST_URL: 'https://example.test/oidc',
|
|
178
|
+
ACTIONS_ID_TOKEN_REQUEST_TOKEN: 'token',
|
|
179
|
+
}),
|
|
180
|
+
).toBe('ready');
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test('Actions 环境缺 OIDC 变量 → missing-permission (工作流漏配 id-token)', () => {
|
|
184
|
+
expect(classifyOidcEnv({ GITHUB_ACTIONS: 'true' })).toBe(
|
|
185
|
+
'missing-permission',
|
|
186
|
+
);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test('本地环境 → not-ci', () => {
|
|
190
|
+
expect(classifyOidcEnv({})).toBe('not-ci');
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
describe('ptyWrapArgs', () => {
|
|
195
|
+
test('darwin 用 script -q /dev/null 包裹 (退出码透传已实测)', () => {
|
|
196
|
+
expect(ptyWrapArgs('darwin', 'npm', ['trust', 'list', '@x/y'])).toEqual({
|
|
197
|
+
command: 'script',
|
|
198
|
+
args: ['-q', '/dev/null', 'npm', 'trust', 'list', '@x/y'],
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test('linux 用 script -qec 命令串 (实用输入受控无空白)', () => {
|
|
203
|
+
expect(
|
|
204
|
+
ptyWrapArgs('linux', 'npm', ['trust', 'github', '--repo', '{{OWNER}}/{{NAME}}']),
|
|
205
|
+
).toEqual({
|
|
206
|
+
command: 'script',
|
|
207
|
+
args: ['-qec', 'npm trust github --repo {{OWNER}}/{{NAME}}', '/dev/null'],
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test('win32 无 script, 降级直跑原命令', () => {
|
|
212
|
+
expect(ptyWrapArgs('win32', 'npm.cmd', ['trust', 'list'])).toEqual({
|
|
213
|
+
command: 'npm.cmd',
|
|
214
|
+
args: ['trust', 'list'],
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
describe('filterPublishable', () => {
|
|
220
|
+
/** 最小 WorkspacePackage 夹具 (过滤只看 manifest.private) */
|
|
221
|
+
const pkg = (name: string, isPrivate = false): WorkspacePackage => ({
|
|
222
|
+
name,
|
|
223
|
+
dir: `packages/${name}`,
|
|
224
|
+
manifest: isPrivate ? { name, private: true } : { name },
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test('private 包被排除, 非 private 包保留 (核对面与发布链 ignorePrivate 同源)', () => {
|
|
228
|
+
const packages = [
|
|
229
|
+
pkg('@x/api'),
|
|
230
|
+
pkg('@x/cli'),
|
|
231
|
+
pkg('@x/private-lib', true),
|
|
232
|
+
];
|
|
233
|
+
expect(filterPublishable(packages).map((item) => item.name)).toEqual([
|
|
234
|
+
'@x/api',
|
|
235
|
+
'@x/cli',
|
|
236
|
+
]);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test('private 字段缺失或非 true (如 false) 均视为可发布, 不误伤', () => {
|
|
240
|
+
const packages: WorkspacePackage[] = [
|
|
241
|
+
pkg('@x/api'),
|
|
242
|
+
{
|
|
243
|
+
name: '@x/flag',
|
|
244
|
+
dir: 'packages/flag',
|
|
245
|
+
manifest: { name: '@x/flag', private: false },
|
|
246
|
+
},
|
|
247
|
+
];
|
|
248
|
+
expect(filterPublishable(packages).map((item) => item.name)).toEqual([
|
|
249
|
+
'@x/api',
|
|
250
|
+
'@x/flag',
|
|
251
|
+
]);
|
|
252
|
+
});
|
|
253
|
+
});
|