dsh-plugin-publish-check 0.0.0-stage → 0.1.2
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 +11 -2
- package/bin/dsh-plugin-publish-check.mjs +35 -0
- package/package.json +34 -4
- package/src/index.mjs +180 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 dsh-plugin-e2e contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-plugin-publish-check
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
发布体检(publish-readiness)for DSH plugins。检查包目录能否顺利、规范地发布。
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
dsh-plugin-publish-check check --dir <pluginDir> # 人读
|
|
7
|
+
dsh-plugin-publish-check check --dir <pluginDir> --json # 机读
|
|
8
|
+
dsh-plugin-publish-check check --dir <pluginDir> --pack # 附带 npm pack --dry-run
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
检查项:`name/version/private/license/repository/description`;`main/types/bin/exports` 目标是否真实存在;`files` 项是否存在;`dsh.bundle` + `patch` + `client.js`;运行时 `dependencies`;可选 `npm pack --dry-run`。
|
|
12
|
+
退出码:`0` 通过(可含警告)/`1` 有错误。
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { checkPublish } from '../src/index.mjs'
|
|
3
|
+
|
|
4
|
+
const USAGE = '用法: dsh-plugin-publish-check check --dir <pluginDir> [--json] [--pack]'
|
|
5
|
+
const args = process.argv.slice(2)
|
|
6
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
7
|
+
console.log(USAGE)
|
|
8
|
+
process.exit(0)
|
|
9
|
+
}
|
|
10
|
+
const sub = args[0] && !args[0].startsWith('--') ? args[0] : null
|
|
11
|
+
if (sub !== 'check') {
|
|
12
|
+
console.error(USAGE)
|
|
13
|
+
process.exit(2)
|
|
14
|
+
}
|
|
15
|
+
const opt = (n, d) => {
|
|
16
|
+
const i = args.indexOf('--' + n)
|
|
17
|
+
return i >= 0 ? args[i + 1] : d
|
|
18
|
+
}
|
|
19
|
+
const dir = opt('dir', '.')
|
|
20
|
+
if (dir === undefined || String(dir).startsWith('-')) {
|
|
21
|
+
console.error('--dir 缺值\n' + USAGE)
|
|
22
|
+
process.exit(2)
|
|
23
|
+
}
|
|
24
|
+
const r = checkPublish(dir, { pack: args.includes('--pack') })
|
|
25
|
+
if (args.includes('--json')) {
|
|
26
|
+
console.log(JSON.stringify(r, null, 2))
|
|
27
|
+
} else {
|
|
28
|
+
console.log('release check: ' + r.dir)
|
|
29
|
+
for (const c of r.checks) {
|
|
30
|
+
const mark = c.status === 'ok' ? '✓' : c.status === 'warn' ? '⚠' : '✗'
|
|
31
|
+
console.log(' ' + mark + ' ' + c.name + (c.detail ? ' ' + c.detail : '') + (c.fix ? ' → ' + c.fix : ''))
|
|
32
|
+
}
|
|
33
|
+
console.log('\n=== ' + (r.errors.length ? '✗ ' + r.errors.length + ' 错误' : '✓ 通过') + (r.warnings.length ? ' ⚠ ' + r.warnings.length + ' 警告' : '') + ' ===')
|
|
34
|
+
}
|
|
35
|
+
process.exit(r.errors.length ? 1 : 0)
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-publish-check",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"private": false,
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"description": "Publish-readiness check for DSH plugins: package.json metadata (name/version/private/license/repository), entry/bin/files targets exist, dsh.bundle + patch + client.js, runtime deps, and optional npm pack dry-run.",
|
|
8
|
+
"bin": {
|
|
9
|
+
"dsh-plugin-publish-check": "bin/dsh-plugin-publish-check.mjs"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./src/index.mjs"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"bin/",
|
|
16
|
+
"src/",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/metal-huang/dsh-devtools.git",
|
|
22
|
+
"directory": "packages/dsh-plugin-publish-check"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public",
|
|
26
|
+
"registry": "https://registry.npmjs.org/"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"dsh": ">=0.2.2-rc.5",
|
|
30
|
+
"node": ">=22.15.0"
|
|
31
|
+
},
|
|
32
|
+
"dshTestedOn": [
|
|
33
|
+
"0.2.2-rc.5",
|
|
34
|
+
"0.2.3-alpha.2"
|
|
35
|
+
]
|
|
36
|
+
}
|
package/src/index.mjs
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// 发布体检:读包目录,检查"能不能发/发得好不好"。返回 {checks, errors, warnings}。
|
|
2
|
+
import { readFileSync, existsSync, readdirSync } from 'node:fs'
|
|
3
|
+
import { join } from 'node:path'
|
|
4
|
+
import { spawnSync } from 'node:child_process'
|
|
5
|
+
|
|
6
|
+
const readJson = (p) => {
|
|
7
|
+
try {
|
|
8
|
+
return JSON.parse(readFileSync(p, 'utf8'))
|
|
9
|
+
} catch {
|
|
10
|
+
return null
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const ARTICLE_EXT = /\.(js|mjs|cjs|json|d\.ts|ts)$/
|
|
14
|
+
|
|
15
|
+
/** glob -> 正则(支持 * 与 **),用于校验通配 exports 是否真的有匹配文件。 */
|
|
16
|
+
function globToRegExp(g) {
|
|
17
|
+
const esc = String(g)
|
|
18
|
+
.replace(/[.+^${}()|[\]\\]/g, '\\$&')
|
|
19
|
+
.replace(/\*\*/g, '\u0000')
|
|
20
|
+
.replace(/\*/g, '[^/]*')
|
|
21
|
+
.replace(/\u0000/g, '.*')
|
|
22
|
+
return new RegExp('^' + esc + '$')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** 在 dir 下递归展开 glob(相对路径,正斜杠)。 */
|
|
26
|
+
export function expandGlob(dir, pattern) {
|
|
27
|
+
const rel = String(pattern).replace(/^\.\//, '').replace(/\\/g, '/')
|
|
28
|
+
const re = globToRegExp(rel)
|
|
29
|
+
let all
|
|
30
|
+
try {
|
|
31
|
+
all = readdirSync(dir, { recursive: true })
|
|
32
|
+
} catch {
|
|
33
|
+
return []
|
|
34
|
+
}
|
|
35
|
+
return all.map((p) => String(p).replace(/\\/g, '/')).filter((p) => re.test(p))
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** 返回 targets([label, rel],rel 可为 glob)里未被打进 tarball 的项;用于 --pack 拦"发布缺入口"。 */
|
|
39
|
+
export function entriesMissingFromTarball(targets, packedPaths, dir) {
|
|
40
|
+
const norm = (p) => String(p).replace(/^\.\//, '').replace(/\\/g, '/')
|
|
41
|
+
const packed = new Set((packedPaths || []).map(norm))
|
|
42
|
+
const missing = []
|
|
43
|
+
for (const [label, rel] of targets) {
|
|
44
|
+
if (!rel) continue
|
|
45
|
+
const matches = String(rel).includes('*') ? (dir ? expandGlob(dir, rel) : []) : [norm(rel)]
|
|
46
|
+
if (matches.length === 0) {
|
|
47
|
+
missing.push([label, rel + '(无匹配文件)'])
|
|
48
|
+
continue
|
|
49
|
+
}
|
|
50
|
+
for (const m of matches) {
|
|
51
|
+
const want = norm(m)
|
|
52
|
+
if (!packed.has(want)) missing.push([label, want])
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return missing
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function checkPublish(dir, { pack = false } = {}) {
|
|
59
|
+
const checks = []
|
|
60
|
+
const errors = []
|
|
61
|
+
const warnings = []
|
|
62
|
+
const add = (status, name, detail = '', fix = '') => {
|
|
63
|
+
checks.push({ status, name, detail, fix })
|
|
64
|
+
if (status === 'error') errors.push(name)
|
|
65
|
+
if (status === 'warn') warnings.push(name)
|
|
66
|
+
}
|
|
67
|
+
const pjPath = join(dir, 'package.json')
|
|
68
|
+
const pkg = readJson(pjPath)
|
|
69
|
+
if (!pkg) {
|
|
70
|
+
add('error', 'package.json', '读不到 ' + pjPath)
|
|
71
|
+
return { dir, checks, errors, warnings }
|
|
72
|
+
}
|
|
73
|
+
if (pkg.name) add('ok', 'name', pkg.name)
|
|
74
|
+
else add('error', 'name', '缺失')
|
|
75
|
+
if (pkg.version) {
|
|
76
|
+
if (pkg.version === '0.0.0') add('warn', 'version', '0.0.0(建议语义版本)', '改 0.1.0 起')
|
|
77
|
+
else add('ok', 'version', pkg.version)
|
|
78
|
+
} else add('error', 'version', '缺失')
|
|
79
|
+
if (pkg.private === true) add('error', 'private', 'private:true 会阻止发布', '去掉 private 或设 false')
|
|
80
|
+
else add('ok', 'private', '不是 private')
|
|
81
|
+
const hasLicense = !!pkg.license || ['LICENSE', 'LICENSE.md', 'LICENSE.txt'].some((f) => existsSync(join(dir, f)))
|
|
82
|
+
if (hasLicense) add('ok', 'license', pkg.license || 'LICENSE 文件')
|
|
83
|
+
else add('warn', 'license', '无 license 字段/文件', '加 license 字段与 LICENSE')
|
|
84
|
+
if (pkg.repository) {
|
|
85
|
+
const url = typeof pkg.repository === 'string' ? pkg.repository : pkg.repository.url || ''
|
|
86
|
+
if (/<[^>]*>|your-org|example\.com/i.test(url)) add('warn', 'repository', '仍是占位符: ' + url, '发布前换真实仓库地址')
|
|
87
|
+
else add('ok', 'repository', url)
|
|
88
|
+
} else add('warn', 'repository', '缺失', '补 repository 与 directory')
|
|
89
|
+
if (pkg.description) add('ok', 'description')
|
|
90
|
+
else add('warn', 'description', '缺失')
|
|
91
|
+
|
|
92
|
+
// 入口目标是否存在
|
|
93
|
+
const targets = []
|
|
94
|
+
if (typeof pkg.main === 'string') targets.push(['main', pkg.main])
|
|
95
|
+
if (typeof pkg.types === 'string') targets.push(['types', pkg.types])
|
|
96
|
+
if (pkg.bin) {
|
|
97
|
+
if (typeof pkg.bin === 'string') targets.push(['bin', pkg.bin])
|
|
98
|
+
else for (const k of Object.keys(pkg.bin)) targets.push(['bin:' + k, pkg.bin[k]])
|
|
99
|
+
}
|
|
100
|
+
if (pkg.exports) {
|
|
101
|
+
const walk = (v, path) => {
|
|
102
|
+
if (typeof v === 'string') {
|
|
103
|
+
if (ARTICLE_EXT.test(v) || v.includes('*')) targets.push(['exports' + path, v])
|
|
104
|
+
} else if (v && typeof v === 'object') {
|
|
105
|
+
for (const k of Object.keys(v)) walk(v[k], path + '/' + k)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
walk(pkg.exports, '')
|
|
109
|
+
}
|
|
110
|
+
for (const [label, rel] of targets) {
|
|
111
|
+
if (String(rel).includes('*')) {
|
|
112
|
+
const m = expandGlob(dir, rel)
|
|
113
|
+
if (m.length) add('ok', label, rel + '(' + m.length + ' 个)')
|
|
114
|
+
else add('error', label + ' 通配无匹配文件', rel, '检查 glob 路径 / 先 build')
|
|
115
|
+
} else if (existsSync(join(dir, rel))) add('ok', label, rel)
|
|
116
|
+
else add('error', label + ' 目标不存在', rel, '检查路径 / 先 build')
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// files 项存在性
|
|
120
|
+
if (Array.isArray(pkg.files)) {
|
|
121
|
+
for (const f of pkg.files) {
|
|
122
|
+
if (f.includes('*')) continue
|
|
123
|
+
if (existsSync(join(dir, f.replace(/\/$/, '')))) add('ok', 'files: ' + f)
|
|
124
|
+
else add('warn', 'files 项不存在: ' + f, '', '删掉该条或补目录')
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// DSH bundle
|
|
129
|
+
const dsh = pkg.dsh || {}
|
|
130
|
+
const bundle = dsh.bundle
|
|
131
|
+
if (bundle) {
|
|
132
|
+
add('ok', 'dsh.bundle')
|
|
133
|
+
const patch = typeof bundle.patch === 'string' ? bundle.patch : null
|
|
134
|
+
if (patch) {
|
|
135
|
+
if (existsSync(join(dir, patch))) add('ok', 'dsh.bundle.patch', patch)
|
|
136
|
+
else add('error', 'dsh.bundle.patch 文件缺失', patch)
|
|
137
|
+
}
|
|
138
|
+
const client = dsh.client || (pkg.exports && pkg.exports['./client'])
|
|
139
|
+
if (client) {
|
|
140
|
+
if (existsSync(join(dir, 'client.js'))) add('ok', 'client 产物 client.js')
|
|
141
|
+
else add('error', 'client.js 缺失(UI 不显示)', '', '在插件目录 build')
|
|
142
|
+
}
|
|
143
|
+
} else {
|
|
144
|
+
// 没有 dsh.bundle:属库/工具包(非 DSH 插件),不按插件规则要求 bundle。
|
|
145
|
+
add('ok', '包类型', '非 DSH 插件包(无 dsh.bundle,按库/工具处理)')
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// 运行时依赖:插件包要求无运行时依赖(bundle);库/工具包有依赖是正常的。
|
|
149
|
+
const deps = Object.keys(pkg.dependencies || {})
|
|
150
|
+
if (bundle) {
|
|
151
|
+
if (deps.length) add('warn', '运行时 dependencies', deps.length + ' 个: ' + deps.join(','), '确认可安装,或改为 build 时 bundle')
|
|
152
|
+
else add('ok', '运行时 dependencies', '无')
|
|
153
|
+
} else {
|
|
154
|
+
add('ok', '运行时 dependencies', deps.length ? deps.length + ' 个(库/工具包,正常)' : '无')
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (pack) {
|
|
158
|
+
const r = spawnSync('npm pack --dry-run --json', { cwd: dir, encoding: 'utf8', shell: true })
|
|
159
|
+
if (r.status === 0) {
|
|
160
|
+
let n = 0
|
|
161
|
+
let packed = []
|
|
162
|
+
try {
|
|
163
|
+
const arr = JSON.parse(r.stdout)
|
|
164
|
+
n = arr[0]?.files?.length ?? 0
|
|
165
|
+
packed = (arr[0]?.files || []).map((f) => f.path)
|
|
166
|
+
} catch {}
|
|
167
|
+
add('ok', 'npm pack --dry-run', '可打包' + (n ? ',' + n + ' 个文件' : ''))
|
|
168
|
+
const missing = entriesMissingFromTarball(targets, packed, dir)
|
|
169
|
+
if (missing.length) {
|
|
170
|
+
for (const [label, want] of missing) add('error', 'tarball 缺少 ' + label, want, '把该文件纳入 files(或修正 exports/bin/main/types)')
|
|
171
|
+
} else {
|
|
172
|
+
add('ok', 'tarball 含入口文件', 'exports/bin/main/types 均被打包')
|
|
173
|
+
}
|
|
174
|
+
} else {
|
|
175
|
+
add('error', 'npm pack --dry-run', (String(r.stderr || r.stdout || '').split('\n')[0] || 'failed').trim(), '先修打包错误')
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return { dir, checks, errors, warnings }
|
|
180
|
+
}
|