dsh-git-push 2.17.0 → 2.18.1
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 +2 -1
- package/lib/app/command-registry.js +10 -0
- package/lib/app/tool-call.js +14 -0
- package/lib/npm/smoke.js +67 -8
- package/lib/npm/unpublish.js +155 -0
- package/lib/self/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,7 +17,8 @@ DSH 的 git 提交推送与代码审计插件:提交前自动过审计门禁
|
|
|
17
17
|
| 改名 | 给远程仓库改名(dryRun 默认开,列出旧名出现位置) | `git_remote_rename` / `rename` |
|
|
18
18
|
| 凭据与账号 | 校验 GitHub token 与 SSH 公钥、生成密钥对 | `git_account_check` / `git_gen_ssh_key` |
|
|
19
19
|
| 身份改写 | 把历史提交身份统一成登录账号 | `git_identity_rewrite` / `identity-rewrite` |
|
|
20
|
-
|
|
|
20
|
+
| 发布 | 发布 npm 包(dryRun 默认只体检;含发布前冒烟) | `npm_publish` / — |
|
|
21
|
+
| 撤包 | 从 registry 撤版本(默认 dryRun 预检,不可逆) | `npm_unpublish` / `unpublish` |
|
|
21
22
|
| 豁免标记 | 给文件加/删豁免注释并校验是否真生效 | `exempt` |
|
|
22
23
|
| I/O 风险扫描 | 扫描读写操作的风险分级 | `io_scan` / `file-io` |
|
|
23
24
|
| 链接检查 | 检查文档里的 URL 是否有效 | `link_check` / `link-check` |
|
|
@@ -122,6 +122,16 @@ export const TOOL_REGISTRY = [
|
|
|
122
122
|
{ flag: 'writeOnly', type: 'boolean', desc: '只看写操作' },
|
|
123
123
|
],
|
|
124
124
|
},
|
|
125
|
+
{
|
|
126
|
+
name: 'npm_unpublish', cli: 'unpublish', description: '从 npm registry 撤包(不可逆):默认 dryRun 只预检——查版本是否存在、是否被 dist-tag 指向、发布距今是否在 72h 窗口内、是否该包唯一版本,并说明撤掉的后果;真撤需同时传 dryRun:false 与 confirm:true。超出 72h 只有「无依赖者+周下载<300+单一维护者」才允许,不满足请改用 deprecate',
|
|
127
|
+
params: [
|
|
128
|
+
{ flag: 'name', type: 'string', positional: 0, required: true, desc: '包名(支持 @scope/name)' },
|
|
129
|
+
{ flag: 'version', type: 'string', positional: 1, desc: '要撤的版本(整包撤请改用 wholePackage:true)' },
|
|
130
|
+
{ flag: 'wholePackage', type: 'boolean', desc: '撤整个包(所有版本,会给 npm unpublish 加 --force)' },
|
|
131
|
+
{ flag: 'dryRun', type: 'boolean', desc: '只预检不真撤(默认 true)' },
|
|
132
|
+
{ flag: 'confirm', type: 'boolean', desc: '真撤确认(dryRun:false 时必填)' },
|
|
133
|
+
],
|
|
134
|
+
},
|
|
125
135
|
{
|
|
126
136
|
name: 'npm_publish', cli: 'npm-publish',
|
|
127
137
|
description: 'npm 发包(后台 job + dryRun):默认 dryRun=true 只做体检与 npm publish --dry-run(不写 registry);真发必须同时 confirm=true 且 dryRun=false。dir=目标包目录(缺省工作区)、tag=发布 tag(默认 latest)、otp=2FA 一次性口令(可选)。前置体检:private:true 拦截、同名版本占用检测、npm pack 文件清单',
|
package/lib/app/tool-call.js
CHANGED
|
@@ -602,6 +602,20 @@ export async function callTool(toolName, args = {}, env = {}, cfg = defaultConfi
|
|
|
602
602
|
}
|
|
603
603
|
case 'npm_publish':
|
|
604
604
|
return callNpmPublishJob(args, jobs, exec, log, env, cfg);
|
|
605
|
+
case 'npm_unpublish': {
|
|
606
|
+
// 撤包不可逆:默认 dryRun(只预检并说明后果),真撤要 dryRun:false + confirm:true
|
|
607
|
+
const dryRun = !(args.dryRun === false || args.dryRun === 'false' || args.noDryRun === true);
|
|
608
|
+
const { unpublishPackage } = await import('../npm/unpublish.js');
|
|
609
|
+
return unpublishPackage({
|
|
610
|
+
name: String(args.name || args.pkg || ''),
|
|
611
|
+
version: String(args.version || ''),
|
|
612
|
+
wholePackage: args.wholePackage === true,
|
|
613
|
+
registry: cfg?.npmRegistry || '',
|
|
614
|
+
workspaceRoot: env.workspaceRoot || '',
|
|
615
|
+
dryRun,
|
|
616
|
+
confirm: args.confirm === true,
|
|
617
|
+
});
|
|
618
|
+
}
|
|
605
619
|
case 'git_remote_create': {
|
|
606
620
|
if (!args.repo) return { ok: false, error: MSG_REPO_REQUIRED };
|
|
607
621
|
const created = await ensureRemoteRepo({ repoPath: args.repo, visibility: args.visibility || 'private', dryRun: args.dryRun === true });
|
package/lib/npm/smoke.js
CHANGED
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
* 不做的事:不跑单测、不启宿主。它只回答「包本身能不能被正常消费」;
|
|
17
17
|
* 「宿主能不能加载插件」属于隔离实例验证(test_env)的范畴,成本高得多,不做进默认门禁。
|
|
18
18
|
*/
|
|
19
|
+
import { extname } from "node:path";
|
|
20
|
+
|
|
21
|
+
/** 能被 Node 直接当模块加载的扩展名(空扩展名按无后缀 ESM/CJS 处理)。 */
|
|
22
|
+
const MODULE_EXTS = new Set(['', '.js', '.mjs', '.cjs', '.jsx', '.ts', '.tsx']);
|
|
19
23
|
import { mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
20
24
|
import { join } from 'node:path';
|
|
21
25
|
import { tmpdir } from 'node:os';
|
|
@@ -31,6 +35,68 @@ const SMOKE_TIMEOUT_MS = 240000;
|
|
|
31
35
|
* 没有 exports 时退化为包名根入口。
|
|
32
36
|
*/
|
|
33
37
|
/** 浏览器端入口(如 `./client`):只能在宿主前端环境加载,Node 里 import 必然失败,冒烟时跳过。 */
|
|
38
|
+
/**
|
|
39
|
+
* 从 package.json 里挑出「本次冒烟该 import 哪些公开面」。
|
|
40
|
+
*
|
|
41
|
+
* 【判据】
|
|
42
|
+
* · `exports` 的点出口(`"."`)= 主入口,**必须测**;没有 main/exports 的纯 CLI 包没有库入口,跳过
|
|
43
|
+
* · 子出口里只挑能当模块加载的目标:`.yml`/`.json`/`.css`/图片等资源虽然也登记在 exports,
|
|
44
|
+
* 但对它们 import 会得到 ERR_UNKNOWN_FILE_EXTENSION —— 那是误判,不是包的问题
|
|
45
|
+
* · 浏览器专属出口(前端 bundle)不在这里加载,单独归到 browserEntries 只是为了让报告如实列出
|
|
46
|
+
*
|
|
47
|
+
* @param {object} pkg package.json 内容
|
|
48
|
+
* @returns {{nodeEntries: string[], browserEntries: string[]}} 可直接交给 `import(spec)` 的规格名
|
|
49
|
+
*/
|
|
50
|
+
export function selectImportSpecs(pkg) {
|
|
51
|
+
const name = String(pkg?.name || '');
|
|
52
|
+
const nodeEntries = [];
|
|
53
|
+
const browserEntries = [];
|
|
54
|
+
if (!name) return { nodeEntries, browserEntries };
|
|
55
|
+
const hasLibraryEntry = Boolean(pkg?.main) || Boolean(pkg?.exports);
|
|
56
|
+
const exportMap = (pkg?.exports && typeof pkg.exports === 'object') ? pkg.exports : { '.': null };
|
|
57
|
+
for (const key of Object.keys(exportMap)) {
|
|
58
|
+
// 清单不是模块;对它 import 没有意义
|
|
59
|
+
if (key === './package.json') continue;
|
|
60
|
+
const spec = key === '.' ? name : `${name}/${key.slice(2)}`;
|
|
61
|
+
if (key !== '.' && isBrowserEntry(key)) { browserEntries.push(spec); continue; }
|
|
62
|
+
if (key === '.' && !hasLibraryEntry) continue;
|
|
63
|
+
const target = exportMap[key] === undefined || exportMap[key] === null
|
|
64
|
+
? (key === '.' ? pkg.main : key)
|
|
65
|
+
: exportMap[key];
|
|
66
|
+
if (!isModuleTarget(target)) continue;
|
|
67
|
+
nodeEntries.push(spec);
|
|
68
|
+
}
|
|
69
|
+
return { nodeEntries, browserEntries };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 判断一个 exports 目标是否可能是「可被 Node 加载的模块」。
|
|
74
|
+
*
|
|
75
|
+
* 【为什么需要】exports 不只为 JS 服务:资源文件(.yml/.json/.css/图片)也常登记在
|
|
76
|
+
* exports 里供消费方按子路径取用。冒烟若对这些子路径执行 import,会得到
|
|
77
|
+
* ERR_UNKNOWN_FILE_EXTENSION —— 那是包被误判,不是包有问题。
|
|
78
|
+
*
|
|
79
|
+
* @param {unknown} value exports 的值(字符串、条件对象,或 null)
|
|
80
|
+
* @returns {boolean} 是否值得尝试 import
|
|
81
|
+
*/
|
|
82
|
+
function isModuleTarget(value) {
|
|
83
|
+
// 没有显式目标(如 {'.': null}):按包名 import 主入口,交给 Node 判定
|
|
84
|
+
if (value === undefined || value === null) return true;
|
|
85
|
+
if (typeof value === 'string') {
|
|
86
|
+
if (value.endsWith('/')) return true; // 目录映射
|
|
87
|
+
const ext = extname(value).toLowerCase();
|
|
88
|
+
return MODULE_EXTS.has(ext);
|
|
89
|
+
}
|
|
90
|
+
if (typeof value === 'object') {
|
|
91
|
+
// 条件导出:取第一个存在的条件继续判断(import 优先,其次 default/require/node)
|
|
92
|
+
for (const condition of ['import', 'default', 'require', 'node']) {
|
|
93
|
+
if (value[condition] !== undefined) return isModuleTarget(value[condition]);
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
34
100
|
export function isBrowserEntry(key) {
|
|
35
101
|
// `./client`、`./client/index`、`./lib/client.js` 都算浏览器端入口
|
|
36
102
|
return /(^|\/)client(\/|\.js)?(\/|$)|browser/i.test(String(key).replace(/^\.\//, ''));
|
|
@@ -128,14 +194,7 @@ export async function smokeTestPackage({ dir = '', workspaceRoot = '', registry
|
|
|
128
194
|
const probe = join(consumer, 'probe.mjs');
|
|
129
195
|
const deps = Object.keys(pkg.dependencies || {});
|
|
130
196
|
// nodeEntries = 可在 Node 里加载的公开面;browserEntries = 仅前端可加载(跳过但如实列出)
|
|
131
|
-
const nodeEntries =
|
|
132
|
-
const browserEntries = [];
|
|
133
|
-
for (const key of Object.keys(pkg.exports && typeof pkg.exports === 'object' ? pkg.exports : { '.': null })) {
|
|
134
|
-
const spec = key === '.' ? name : `${name}/${key.slice(2)}`;
|
|
135
|
-
if (key !== '.' && isBrowserEntry(key)) browserEntries.push(spec);
|
|
136
|
-
else if (!key.startsWith('./') || key === './package.json') continue;
|
|
137
|
-
else nodeEntries.push(spec);
|
|
138
|
-
}
|
|
197
|
+
const { nodeEntries, browserEntries } = selectImportSpecs(pkg);
|
|
139
198
|
writeFileSync(probe, [
|
|
140
199
|
'import { createRequire } from "node:module";',
|
|
141
200
|
'import { existsSync } from "node:fs";',
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* npm 撤包(`npm unpublish`)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么单独做、且**默认 dryRun**:撤包不可逆——
|
|
5
|
+
* · 一个 `包@版本` 一旦用过,即使撤掉也**永久不能再发**同一个号;
|
|
6
|
+
* · 官方只承诺 registry 不再提供,不承诺清 CDN/第三方镜像/已下载副本;
|
|
7
|
+
* · 撤掉 `latest` 会让 dist-tags 悬空,影响所有 `npm i <包>` 的人。
|
|
8
|
+
* 所以调用方必须先看清「要撤什么、撤完会怎样」,再显式 `confirm` 才真撤。
|
|
9
|
+
*
|
|
10
|
+
* 预检能回答什么(都不联网到第三方,只查 registry 元数据):
|
|
11
|
+
* · 版本是否存在;dist-tags 是否指向它(撤 latest 有额外影响);
|
|
12
|
+
* · 发布距今是否在 72 小时窗口内(窗口内且无依赖者才符合官方条件);
|
|
13
|
+
* · 是否该包唯一版本(撤光会让包名冷却 24h)。
|
|
14
|
+
* 预检**不能**回答:是否有其它包依赖它(公共 registry 没有 reverse-deps 接口),
|
|
15
|
+
* 这一条只能由 npm 服务端判定,失败时如实把 npm 的报错回传。
|
|
16
|
+
*/
|
|
17
|
+
import { DEFAULT_REGISTRY, NPM_TIMEOUT_MS, normalizeRegistry, runNpm } from './registry.js';
|
|
18
|
+
import { npmArgs, writeNpmrc } from './npmrc.js';
|
|
19
|
+
import { readNpmToken } from '../core/credentials.js';
|
|
20
|
+
|
|
21
|
+
/** 官方 unpublish 政策里的时间窗:发布 72h 内(且无依赖者)可自由撤。 */
|
|
22
|
+
const UNPUBLISH_WINDOW_MS = 72 * 60 * 60 * 1000;
|
|
23
|
+
/** 整包撤光后,同名包 24h 内不能发布。 */
|
|
24
|
+
const WHOLE_PACKAGE_COOLDOWN_MS = 24 * 60 * 60 * 1000;
|
|
25
|
+
|
|
26
|
+
/** 归一化包名/版本入参,做前置校验(不联网)。 */
|
|
27
|
+
export function parseTarget({ name = '', version = '', wholePackage = false } = {}) {
|
|
28
|
+
const pkg = String(name || '').trim();
|
|
29
|
+
const ver = String(version || '').trim();
|
|
30
|
+
if (!pkg) return { ok: false, error: '缺 name(要撤的包名)' };
|
|
31
|
+
if (!/^(@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*$/i.test(pkg)) return { ok: false, error: `包名不合法:${pkg}` };
|
|
32
|
+
if (!wholePackage && !ver) return { ok: false, error: '缺 version;若确实要撤整个包,请显式传 wholePackage:true(会连带撤所有版本)' };
|
|
33
|
+
if (!wholePackage && !/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/.test(ver)) return { ok: false, error: `版本号不合法:${ver}` };
|
|
34
|
+
return { ok: true, name: pkg, version: ver, wholePackage: wholePackage === true };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 预检:查 registry 元数据,给出「撤这个版本会发生什么」。
|
|
39
|
+
* @param {{name:string, version:string, wholePackage?:boolean,
|
|
40
|
+
* registry?:string, timeoutMs?:number, fetchImpl?:Function}} o
|
|
41
|
+
*/
|
|
42
|
+
export async function preflightUnpublish({ name = '', version = '', wholePackage = false, registry = DEFAULT_REGISTRY, timeoutMs = NPM_TIMEOUT_MS, fetchImpl = globalThis.fetch } = {}) {
|
|
43
|
+
const target = parseTarget({ name, version, wholePackage });
|
|
44
|
+
if (!target.ok) return { ok: false, error: target.error };
|
|
45
|
+
const reg = normalizeRegistry(registry);
|
|
46
|
+
const url = `${reg.replace(/\/$/, '')}/${name.replace('/', '%2f')}`;
|
|
47
|
+
const ctrl = new AbortController();
|
|
48
|
+
const timer = setTimeout(() => ctrl.abort(), timeoutMs);
|
|
49
|
+
try {
|
|
50
|
+
const res = await fetchImpl(url, { signal: ctrl.signal, headers: { accept: 'application/json' } });
|
|
51
|
+
if (res.status === 404) return { ok: false, error: `registry 上不存在该包:${name}` };
|
|
52
|
+
if (res.status !== 200) return { ok: false, error: `查询失败:HTTP ${res.status}` };
|
|
53
|
+
const doc = await res.json();
|
|
54
|
+
const versions = Object.keys(doc.versions || {});
|
|
55
|
+
const publishedAt = (doc.time || {})[target.version] || '';
|
|
56
|
+
const ageMs = publishedAt ? Date.now() - Date.parse(publishedAt) : null;
|
|
57
|
+
const tagsPointingHere = Object.entries(doc['dist-tags'] || {}).filter(([, v]) => v === target.version).map(([t]) => t);
|
|
58
|
+
if (!wholePackage && !versions.includes(target.version)) {
|
|
59
|
+
return { ok: false, error: `版本不存在:${name}@${target.version}(现有版本:${versions.join(', ')})` };
|
|
60
|
+
}
|
|
61
|
+
const warnings = [];
|
|
62
|
+
if (tagsPointingHere.length) {
|
|
63
|
+
warnings.push(`dist-tag ${tagsPointingHere.join('/')} 指向该版本:撤掉后这些 tag 会失效/悬空(建议先把 tag 移到其它版本)`);
|
|
64
|
+
}
|
|
65
|
+
if (versions.length <= 1) {
|
|
66
|
+
warnings.push(`该包只有 1 个版本:撤光后同名包名将冷却 ${WHOLE_PACKAGE_COOLDOWN_MS / 3600000} 小时`);
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
ok: true,
|
|
70
|
+
name, version: target.version, wholePackage: target.wholePackage,
|
|
71
|
+
exists: true,
|
|
72
|
+
versions,
|
|
73
|
+
publishedAt,
|
|
74
|
+
ageHours: ageMs === null ? null : Math.round(ageMs / 3600000),
|
|
75
|
+
withinWindow: ageMs === null ? null : ageMs <= UNPUBLISH_WINDOW_MS,
|
|
76
|
+
tagsPointingHere,
|
|
77
|
+
warnings,
|
|
78
|
+
// 72h 内只是「可以申请撤」的必要条件之一;依赖者一条只有服务端能判
|
|
79
|
+
policyHint: ageMs !== null && ageMs > UNPUBLISH_WINDOW_MS
|
|
80
|
+
? '已超出 72h 窗口:只有「无依赖者 + 近一周下载<300 + 单一维护者」三者同时满足才允许撤,否则只能 npm deprecate'
|
|
81
|
+
: '在 72h 窗口内:无其它包依赖它时可直接撤',
|
|
82
|
+
// 撤包不可逆的提醒:即使成功,该版本号也永久作废
|
|
83
|
+
irreversible: `撤掉后 ${name}@${target.version} 永久不能再发布(只能发新版本号)`,
|
|
84
|
+
};
|
|
85
|
+
} catch (e) {
|
|
86
|
+
return { ok: false, error: `查询失败:${String(e?.message || e).slice(0, 200)}` };
|
|
87
|
+
} finally { clearTimeout(timer); }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 执行撤包。
|
|
92
|
+
* @param {{name:string, version?:string, wholePackage?:boolean, registry?:string,
|
|
93
|
+
* workspaceRoot?:string, dryRun?:boolean, confirm?:boolean, timeoutMs?:number}} o
|
|
94
|
+
*/
|
|
95
|
+
export async function unpublishPackage({
|
|
96
|
+
name = '', version = '', wholePackage = false,
|
|
97
|
+
registry = DEFAULT_REGISTRY, workspaceRoot = '',
|
|
98
|
+
dryRun = true, confirm = false, timeoutMs = 120000,
|
|
99
|
+
// 可注入(测试用):npm 执行器、registry 查询、凭据
|
|
100
|
+
runNpmImpl = runNpm, fetchImpl = globalThis.fetch, token = '',
|
|
101
|
+
} = {}) {
|
|
102
|
+
const pre = await preflightUnpublish({ name, version, wholePackage, registry, fetchImpl });
|
|
103
|
+
if (!pre.ok) return { ok: false, blocked: 'preflight-failed', error: pre.error };
|
|
104
|
+
if (dryRun) {
|
|
105
|
+
return {
|
|
106
|
+
ok: true, dryRun: true, ...pre,
|
|
107
|
+
wouldRun: `npm unpublish ${name}${wholePackage ? '' : `@${pre.version}`}${wholePackage ? ' --force' : ''}`,
|
|
108
|
+
hint: '确认无误后传 dryRun:false + confirm:true 才真正撤包(不可逆)',
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
if (confirm !== true) {
|
|
112
|
+
return { ok: false, blocked: 'need-confirm', ...pre, error: '真实撤包不可逆:需同时传 dryRun:false 与 confirm:true' };
|
|
113
|
+
}
|
|
114
|
+
const tokenValue = token || (() => { try { return readNpmToken({ workspaceRoot }); } catch { return ''; } })();
|
|
115
|
+
// 没有凭据必须当场拒绝:实测 npm 在**无认证**时会对 unpublish 发 PUT 拿到 404,
|
|
116
|
+
// 但**退出码仍是 0** 并打印「- pkg@ver」,看起来像撤成功(历史假成功就是这么来的)。
|
|
117
|
+
if (!tokenValue) {
|
|
118
|
+
return { ...pre, ok: false, blocked: 'no-token', error: '插件配置里没有可用的 npmToken(或未生效),无法撤包;请先配置 npm 凭据' };
|
|
119
|
+
}
|
|
120
|
+
const rc = writeNpmrc({ workspaceRoot, registry, token: tokenValue });
|
|
121
|
+
if (!rc.ok) return { ok: false, error: rc.error || 'npmrc 写入失败' };
|
|
122
|
+
const args = ['unpublish', wholePackage ? name : `${name}@${pre.version}`, ...npmArgs({ npmrcFile: rc.file, registry })];
|
|
123
|
+
if (wholePackage) args.push('--force');
|
|
124
|
+
const r = runNpmImpl(args, { timeoutMs, env: { NO_UPDATE_NOTIFIER: '1' } });
|
|
125
|
+
const npmText = String(r.error || r.stderr || r.stdout || '');
|
|
126
|
+
if (!r.ok) {
|
|
127
|
+
// granular token 的 2FA 限制是最常见的硬阻塞,单独给出可执行指引
|
|
128
|
+
const twoFactorBlocked = /granular access token/i.test(npmText) || /bypass two-factor/i.test(npmText);
|
|
129
|
+
return {
|
|
130
|
+
...pre, ok: false,
|
|
131
|
+
error: `npm unpublish 失败:${npmText.slice(0, 400)}`,
|
|
132
|
+
...(twoFactorBlocked
|
|
133
|
+
? { hint: '该 token 是「绕过 2FA 的 granular token」,npm 禁止它执行撤包。改用:① npm 网站手动撤(需 2FA);② 换 classic token 并带 --otp;③ 本机 npm login 后执行' }
|
|
134
|
+
: { hint: '若提示 72h/依赖者/下载量限制,说明不满足官方撤包条件——改用 npm deprecate 让使用者看到警告而不破坏构建' }),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
// **关键**:npm 的 unpublish 在若干失败情形下仍会 exit 0 并打印「- pkg@ver」。
|
|
138
|
+
// 唯一可信的判据是回读 registry:版本真的没了才算成功。
|
|
139
|
+
const after = await preflightUnpublish({ name, version: pre.version, wholePackage, registry, fetchImpl });
|
|
140
|
+
const stillThere = after.ok && !wholePackage && Array.isArray(after.versions) && after.versions.includes(pre.version);
|
|
141
|
+
if (stillThere) {
|
|
142
|
+
return {
|
|
143
|
+
...pre, ok: false, verified: false,
|
|
144
|
+
error: `npm 退出码为 0,但 registry 里 ${name}@${pre.version} 仍在——撤包未生效`,
|
|
145
|
+
npmOutput: npmText.slice(-600),
|
|
146
|
+
hint: '常见原因:token 无权限/需 2FA/被 granular token 策略禁止。请改用 npm 网站或 classic token + --otp',
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
ok: true, dryRun: false, ...pre,
|
|
151
|
+
unpublishd: wholePackage ? `${name}(全部版本)` : `${name}@${pre.version}`,
|
|
152
|
+
stdout: String(r.stdout || '').slice(-2000),
|
|
153
|
+
note: '撤包不可逆:该版本号永久作废;对外索引(第三方镜像/文档)不会自动清理',
|
|
154
|
+
};
|
|
155
|
+
}
|
package/lib/self/index.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
export const VERSION = '2.
|
|
12
|
+
export const VERSION = '2.18.1'; // 2.18.1:修发布前冒烟的两个选项目缺陷——① `exports` 里的非 JS 资源(.yml/.json 等)曾被当模块 import,对正常包抛 ERR_UNKNOWN_FILE_EXTENSION,把好包拦在发布前;② 点出口 `"."` 曾被跳过,导致主入口从来没被测过、门禁形同虚设。现在按目标扩展名与条件导出挑出「真正能被 Node 加载」的入口,并给两侧行为补了单测。历史:2.18.0 新增 npm_unpublish(撤包,默认 dryRun)。
|
|
13
13
|
// 实测后果:该目录有 package.json ⇒ npm 去打包整棵 DSH 树、输出 2.1MB > spawnSync 默认 maxBuffer 1MB ⇒ ENOBUFS(npm_publish 的体检与真发全部失败);
|
|
14
14
|
// 该目录没有 package.json 时报 ENOENT。现 publish 的两个调用点显式传 cwd=目标包目录,并给 runNpm 加 16MB maxBuffer。
|
|
15
15
|
// 2.8.3:文案修正——「零改动 / 无新提交」明确为**正常成功路径**(注入用法、工具描述、README、skill 同批改),并修 job 输出自相矛盾(cleanSkipCommit 路径补 committed:false,不再显示「已提交,未推送」)
|