@capyclaw/plugin-validator 1.0.0 → 1.0.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/bin/cli.mjs +1 -1
- package/lib/index.mjs +14 -6
- package/package.json +3 -3
package/bin/cli.mjs
CHANGED
|
@@ -15,7 +15,7 @@ const pluginPath = process.argv[2]
|
|
|
15
15
|
|
|
16
16
|
if (!pluginPath) {
|
|
17
17
|
console.error('用法: validate-plugin <plugin-path>')
|
|
18
|
-
console.error('示例: validate-plugin
|
|
18
|
+
console.error('示例: validate-plugin B/official/capyclaw-port-sidebar')
|
|
19
19
|
process.exit(1)
|
|
20
20
|
}
|
|
21
21
|
|
package/lib/index.mjs
CHANGED
|
@@ -31,6 +31,7 @@ const RULES = {
|
|
|
31
31
|
|
|
32
32
|
// 基础设施包的锁定版本范围(统一走 @capyclaw/* scope 名)
|
|
33
33
|
INFRASTRUCTURE_VERSIONS: {
|
|
34
|
+
'@capyclaw/foundation': '^0.1.1',
|
|
34
35
|
'@capyclaw/plugin-kit': '^0.2.0',
|
|
35
36
|
'@capyclaw/service-host': '^0.1.0',
|
|
36
37
|
'@capyclaw/tool-host': '^0.1.0',
|
|
@@ -105,9 +106,11 @@ export async function validatePlugin(pluginPath) {
|
|
|
105
106
|
*/
|
|
106
107
|
function checkRequiredFiles(pluginPath, pkg, errors) {
|
|
107
108
|
const suiteOnly = pkg?.dsh?.suite && !pkg?.main
|
|
109
|
+
/* 入口有两种合法形态:legacy 的 lib/ 目录,或 foundation ABI 的 plugin.mjs
|
|
110
|
+
* (由 package.json main 指向)。只要 main 可达即可,不再强制 lib/。 */
|
|
111
|
+
const hasEntry = Boolean(pkg?.main) && existsSync(join(pluginPath, pkg.main))
|
|
108
112
|
for (const file of RULES.REQUIRED_FILES) {
|
|
109
|
-
|
|
110
|
-
if (file === 'lib' && suiteOnly) continue
|
|
113
|
+
if (file === 'lib' && (suiteOnly || hasEntry)) continue
|
|
111
114
|
const filePath = join(pluginPath, file)
|
|
112
115
|
if (!existsSync(filePath)) {
|
|
113
116
|
errors.push({
|
|
@@ -254,13 +257,18 @@ function checkDirectoryStructure(pluginPath, pkg, errors, warnings) {
|
|
|
254
257
|
function checkDependencies(pkg, errors, warnings) {
|
|
255
258
|
const deps = pkg.dependencies || {}
|
|
256
259
|
|
|
257
|
-
// 强制:必须依赖 @capyclaw/plugin-kit
|
|
260
|
+
// 强制:必须依赖 @capyclaw/foundation(新 ABI)或 @capyclaw/plugin-kit(legacy),suite 除外
|
|
258
261
|
if (pkg.dsh?.category !== 'suite') {
|
|
259
|
-
if (
|
|
262
|
+
if (deps['@capyclaw/foundation']) {
|
|
263
|
+
const expectedVersion = RULES.INFRASTRUCTURE_VERSIONS['@capyclaw/foundation']
|
|
264
|
+
if (expectedVersion && !semver.satisfies(semver.coerce(deps['@capyclaw/foundation']), expectedVersion)) {
|
|
265
|
+
warnings.push(`@capyclaw/foundation 版本建议使用 ${expectedVersion},当前: ${deps['@capyclaw/foundation']}`)
|
|
266
|
+
}
|
|
267
|
+
} else if (!deps['@capyclaw/plugin-kit']) {
|
|
260
268
|
errors.push({
|
|
261
269
|
rule: 'PLUGIN_KIT_REQUIRED',
|
|
262
|
-
message: '必须依赖 @capyclaw/plugin-kit',
|
|
263
|
-
hint: '在 dependencies 中添加 "@capyclaw/
|
|
270
|
+
message: '必须依赖 @capyclaw/foundation 或 @capyclaw/plugin-kit',
|
|
271
|
+
hint: '在 dependencies 中添加 "@capyclaw/foundation": "^0.1.0"(新插件)'
|
|
264
272
|
})
|
|
265
273
|
} else {
|
|
266
274
|
// 检查版本范围
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capyclaw/plugin-validator",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "DSH 插件强制验证工具:检查目录结构、依赖规范、代码质量",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.mjs",
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
21
21
|
"url": "git+https://github.com/Maple496/capyclaw.git",
|
|
22
|
-
"directory": "tools/capyclaw-plugin-validator"
|
|
22
|
+
"directory": "C/tools/capyclaw-plugin-validator"
|
|
23
23
|
},
|
|
24
24
|
"bugs": {
|
|
25
25
|
"url": "https://github.com/Maple496/capyclaw/issues"
|
|
26
26
|
},
|
|
27
|
-
"homepage": "https://github.com/Maple496/capyclaw/tree/main/tools/capyclaw-plugin-validator#readme"
|
|
27
|
+
"homepage": "https://github.com/Maple496/capyclaw/tree/main/C/tools/capyclaw-plugin-validator#readme"
|
|
28
28
|
}
|