dsh-plugin-package-check 0.0.0-stage → 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 zjukop3
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,118 @@
1
- # Temporary Holding Version
1
+ # dsh-plugin-package-check
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Check that a DSH plugin package is **installable and findable** before you publish it.
4
+ Ten rules, all decidable from the package directory: no network, no running your code, no
5
+ registry.
6
+
7
+ <!-- example:start -->
8
+ ## 真实输入输出
9
+
10
+ 输入:命令里那个包目录(目录型输入,不是一份文档)
11
+
12
+ 真实运行(逐字输出,由测试与工具保持同步):
13
+
14
+ ```text
15
+ $ plugin-package-check ./packages/dsh-adr-check
16
+ ok: dsh-adr-check 0 errors, 0 warnings
17
+ ```
18
+
19
+ 出口码:0。
20
+ <!-- example:start -->
21
+
22
+ The catalog's most common rejection is a `package.json` that declares only `dsh.client` —
23
+ that alone is not installable, and `dsh plugin add` fails. The quieter failure is the one
24
+ below: everything declared, patch file present, but `files` drops the patch, so it runs
25
+ locally and breaks for everyone who installs it.
26
+
27
+ <!-- install:start -->
28
+ ## 装进 DSH
29
+
30
+ ```bash
31
+ dsh plugin --profile <profile> add dsh-plugin-package-check
32
+ ```
33
+
34
+ `--profile` 是 `dsh plugin` 的必填项(Desktop 用 `desktop`,Web 用 `web`)。装完在「插件」里启用,对话中就有这条检查的 host 路由;不装 DSH 也能用上面的 `npx`。
35
+ <!-- install:end -->
36
+
37
+ ## 它判定什么 / What it decides
38
+
39
+ | rule | level | what it decides |
40
+ | --- | --- | --- |
41
+ | `manifest-missing` | error | the directory has no `package.json` |
42
+ | `manifest-unparsable` | error | `package.json` is not valid JSON |
43
+ | `private` | error | `private: true` — it cannot be published to npm |
44
+ | `bundle-missing` | error | no `dsh.bundle.patch` — `dsh plugin add` cannot install it |
45
+ | `patch-missing` | error | `dsh.bundle.patch` points at a file that is not there |
46
+ | `patch-empty` | error | the patch has no `insert` row — the layer mounts nothing |
47
+ | `patch-name-mismatch` | error | the patch mounts neither this package nor one of its declared dependencies |
48
+ | `files-omits-patch` | warn | `files` exists but does not include the patch — the published tarball lacks it |
49
+ | `files-omits-detail` | warn | `docs/DETAIL.md` exists but is not shipped — the plugin detail page stays empty |
50
+ | `engines-missing` | warn | no `engines.dsh` — a reader cannot tell whether it fits their DSH |
51
+ | `bin-name-mismatch` | warn | `bin` has no key equal to the package name — `npx <package>` will 404 |
52
+ | `readme-missing` / `readme-install-missing` | warn | no README, or no `dsh plugin add …` line in it |
53
+ | `locale-missing` | warn | no `locale/` — the plugin page shows a package name and nothing else |
54
+ | `icon-missing` | warn | no icon — the plugin card is blank |
55
+
56
+ ## Requirements
57
+
58
+ - Node `>=22.19.0`. No dependencies.
59
+ - DSH `>=0.2.2-rc.1 <0.3.0-0` only for the host route; the CLI needs neither DSH nor a network.
60
+
61
+ ## Install (CLI)
62
+
63
+ ```
64
+ npx dsh-plugin-package-check ./packages/my-plugin
65
+ ```
66
+
67
+ ## 输出示例 / What you should see
68
+
69
+ A real run against a package that declares a patch file which is not in the same directory:
70
+
71
+ ```text
72
+ error patch-missing dsh.bundle.patch 指向 ./cordis.patch.yml,但目录里没有这个文件
73
+ warn engines-missing engines.dsh 没写——读者无从判断这个包跟自己的 DSH 版本兼不兼容
74
+ warn locale-missing 没有 locale/——插件页只能显示包名,没有标题与说明
75
+ warn icon-missing 没有图标(./icon 导出或 icon.svg)——插件卡片是空白的
76
+ fail: my-plugin 1 errors, 3 warnings
77
+ ```
78
+
79
+ Exit codes: 0 clean (warnings do not fail), 1 errors, 2 usage. It takes under 1 second — it reads a handful of files and runs nothing.
80
+
81
+ ## Install into DSH (host route)
82
+
83
+ ```
84
+ dsh plugin --profile <profile> add dsh-plugin-package-check
85
+ ```
86
+
87
+ then `POST /plugin-package-check/api` with `{"path": "/abs/path/to/package"}`. The route
88
+ and the CLI call the same function, so they cannot disagree.
89
+
90
+ ## 诚实的边界 / Honest scope
91
+
92
+ - **Calibrated on seven plugins other people wrote**, already installed on this machine:
93
+ `dsh-wechat`, `dsh-media-desk`, `dsh-bili-scroll`, `dsh-context`, `dsh-guizang-design`,
94
+ `dsh-purge-community`, `@claude-mem/dsh`. Five pass with at most two warnings; the two
95
+ that fail do so for reasons I checked by hand — `dsh-purge-community` has no `bin` key
96
+ equal to its package name, so `npx dsh-purge-community` 404s (the same mistake I made in
97
+ 27 of my own packages), and `@claude-mem/dsh` is `private: true`.
98
+ - **The first version was wrong about aggregation bundles.** It required the patch to name
99
+ the package itself; `dsh-check-suite` legitimately mounts its dependencies instead. The
100
+ rule now accepts either, and the suite is in the gate that requires this kit's own 30
101
+ packages to produce zero findings.
102
+ - **It cannot tell whether the plugin works.** It checks the packaging contract, not the
103
+ behaviour: whether the patch mounts the right entry, whether the icon is a good icon,
104
+ whether anyone wants the feature.
105
+ - **Installed packages are not the same artifact as published tarballs.** Checking a
106
+ directory in `node_modules` sees what npm chose to ship — which is exactly the point of
107
+ `files-omits-patch`, but the inverse mistake (a file in the directory that the tarball
108
+ drops) can only be seen by checking the unpacked tarball. `npm pack --dry-run` does that.
109
+
110
+ ## Getting help
111
+
112
+ Open an issue at <https://github.com/zjukop3/dsh-vertical-kit/issues> with the package.json
113
+ (redact anything private), the command, and this tool's verbatim output. A finding you
114
+ believe is wrong is a bug report about a rule, and the rule name is in the message.
115
+
116
+ ## License
117
+
118
+ MIT.
package/bin/cli.js ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env node
2
+ // Exit codes: 0 clean, 1 findings, 2 usage or read error.
3
+ import { existsSync, statSync } from 'node:fs'
4
+ import { lintPluginPackage } from '../src/index.js'
5
+
6
+ const argv = process.argv.slice(2)
7
+ const target = argv.find(argument => !argument.startsWith('--'))
8
+
9
+ if (!target) {
10
+ process.stderr.write('usage: dsh-plugin-package-check <package-dir> [--json]\n')
11
+ process.exit(2)
12
+ }
13
+
14
+ try {
15
+ if (!existsSync(target) || !statSync(target).isDirectory()) {
16
+ process.stderr.write(`不是目录:${target}\n`)
17
+ process.exit(2)
18
+ }
19
+ const dirName = target.replace(/\/+$/, '').split('/').pop()
20
+ const result = lintPluginPackage(target, { dirName })
21
+ if (argv.includes('--json')) {
22
+ process.stdout.write(`${JSON.stringify(result, null, 2)}\n`)
23
+ } else {
24
+ for (const finding of result.findings) {
25
+ process.stdout.write(`${finding.level} ${finding.rule} ${finding.message}\n`)
26
+ }
27
+ process.stdout.write(`${result.ok ? 'ok' : 'fail'}: ${result.checked.package ?? '?'} ${result.errors} errors, ${result.warnings} warnings\n`)
28
+ }
29
+ process.exit(result.ok ? 0 : 1)
30
+ } catch (error) {
31
+ process.stderr.write(`${error.message}\n`)
32
+ process.exit(2)
33
+ }
@@ -0,0 +1,4 @@
1
+ # One package adds a scenario route next to the Host API.
2
+ - insert:
3
+ - id: plugin-package-check
4
+ name: 'dsh-plugin-package-check'
package/docs/DETAIL.md ADDED
@@ -0,0 +1,57 @@
1
+ # Plugin package check
2
+
3
+ Check that a DSH plugin package is installable and findable before you publish it. Fifteen
4
+ rules, all decidable from the package directory: no network, no running your code.
5
+
6
+ ## What it does
7
+
8
+ The catalog's most common rejection is a `package.json` that declares only `dsh.client` —
9
+ that alone is not installable. The quieter failure is the one this check earns its place
10
+ with: everything declared, the patch file present, but `files` drops the patch, so the
11
+ package runs locally and breaks for everyone who installs it.
12
+
13
+ It reads four things: `package.json`, the patch file it points at, `files`, and whether the
14
+ README/locale/icon exist. It reports what a reader would hit — an install that cannot work,
15
+ a card with no title, an `npx <package>` that 404s because no `bin` key equals the package
16
+ name.
17
+
18
+ ## How to use it
19
+
20
+ ```
21
+ npx dsh-plugin-package-check ./packages/my-plugin
22
+ ```
23
+
24
+ Installed into DSH it answers at `POST /plugin-package-check/api` with `{"path": "…"}` —
25
+ this one takes a directory, not a document, so it is the only check in the kit whose route
26
+ does not accept `{"text": …}`. Its contract is covered by its own test rather than the
27
+ text-based parity matrix.
28
+
29
+ ## What it returns
30
+
31
+ ```
32
+ error patch-missing dsh.bundle.patch 指向 ./cordis.patch.yml,但目录里没有这个文件
33
+ warn engines-missing engines.dsh 没写——读者无从判断这个包跟自己的 DSH 版本兼不兼容
34
+ ```
35
+
36
+ Exit codes: 0 clean, 1 errors, 2 usage. Warnings never fail.
37
+
38
+ ## Calibration
39
+
40
+ Seven plugins other people wrote, already installed on this machine, plus this kit's own
41
+ thirty packages. Two of the third-party ones produce findings I checked by hand:
42
+ `dsh-purge-community` has no `bin` key equal to its package name, so `npx
43
+ dsh-purge-community` 404s, and `@claude-mem/dsh` is `private: true`.
44
+
45
+ The first version produced two mistakes of its own:
46
+
47
+ - It required the patch to mount the package itself, which fails aggregation bundles —
48
+ `dsh-check-suite` mounts its dependencies, and that is correct.
49
+ - It carried a `dir-name-mismatch` rule that fired on temporary directories and on
50
+ unpacked tarballs, where the directory name has nothing to do with the package. Removed
51
+ rather than tuned.
52
+
53
+ ## Limitations
54
+
55
+ - It cannot tell whether the plugin works, only whether it can be installed and seen.
56
+ - It cannot see files that the directory has and the tarball drops — that needs
57
+ `npm pack --dry-run`. It does catch the reverse: a `files` list that omits the patch.
package/icon.svg ADDED
@@ -0,0 +1,6 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" role="img" aria-label="Plugin package check">
2
+ <rect x="1.5" y="1.5" width="21" height="21" rx="4.5" fill="#1f6feb"/>
3
+ <path d="M12 4.6 19 8.3v7.4L12 19.4 5 15.7V8.3z" fill="#fff" opacity=".92"/>
4
+ <path d="M12 4.6 19 8.3 12 12 5 8.3z" fill="#9ec5ff"/>
5
+ <path d="m9.4 15 1.6 1.5 3.4-3.4" fill="none" stroke="#16a34a" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/>
6
+ </svg>
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Plugin package check",
4
+ "description": "Check that a DSH plugin package is installable and findable before you publish it: dsh.bundle.patch declared and present, the patch mounts this package, files does not drop the patch, engines.dsh, a bin key equal to the package name, README install line, locale and icon."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "插件包可安装性检查清单",
4
+ "description": "发布前确认这个插件包「装得上、找得到」:dsh.bundle.patch 声明了且在、patch 挂的是自己或自己的依赖、files 没把 patch 或 DETAIL 漏掉、engines.dsh、bin 里有一个键等于包名、README 里有安装命令、locale 与图标齐。十条规则,只看包目录。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,53 @@
1
1
  {
2
2
  "name": "dsh-plugin-package-check",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Check that a DSH plugin package is installable and findable before you publish it: dsh.bundle.patch declared and present, the patch mounts this package, files does not drop the patch, engines.dsh, a bin key equal to the package name, README install line, locale and icon.",
5
+ "type": "module",
6
+ "main": "./src/index.js",
7
+ "exports": {
8
+ ".": "./src/index.js",
9
+ "./package.json": "./package.json",
10
+ "./locale/*.json": "./locale/*.json",
11
+ "./icon": "./icon.svg"
12
+ },
13
+ "bin": {
14
+ "plugin-package-check": "./bin/cli.js",
15
+ "dsh-plugin-package-check": "./bin/cli.js"
16
+ },
17
+ "dsh": {
18
+ "bundle": {
19
+ "patch": "./cordis.patch.yml"
20
+ }
21
+ },
22
+ "engines": {
23
+ "node": ">=22.19.0",
24
+ "dsh": ">=0.2.2-rc.1 <0.3.0-0"
25
+ },
26
+ "files": [
27
+ "src",
28
+ "bin",
29
+ "cordis.patch.yml",
30
+ "docs",
31
+ "icon.svg",
32
+ "README.md",
33
+ "LICENSE",
34
+ "locale"
35
+ ],
36
+ "keywords": [
37
+ "dsh",
38
+ "dsh-plugin",
39
+ "deepseek-harness",
40
+ "package",
41
+ "lint",
42
+ "publish",
43
+ "插件打包",
44
+ "发布前检查"
45
+ ],
46
+ "license": "MIT",
47
+ "author": "zjukop3",
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://github.com/zjukop3/dsh-vertical-kit.git"
51
+ },
52
+ "homepage": "https://github.com/zjukop3/dsh-vertical-kit/tree/main/packages/dsh-plugin-package-check"
53
+ }
package/src/index.js ADDED
@@ -0,0 +1,141 @@
1
+ // 一个 DSH 插件包「装得上、找得到」吗——只看包目录本身。
2
+ //
3
+ // 为什么值得单独一个检查:目录收录门槛里最常被打回的一条是 package.json 没声明
4
+ // `dsh.bundle`(那样 `dsh plugin add` 装不上);而另一类错误更隐蔽——声明了、patch 文件也
5
+ // 在,但 files 数组没把它打进 tarball,于是本地能跑、发出去装不上。
6
+ //
7
+ // 十条规则全部在磁盘上可判定:不联网、不执行包代码、不读 registry。校准语料是这台机器上
8
+ // 已经装着的六个第三方插件(别人的包)加上本仓库自己的三十个包——别人的包不是摆设:
9
+ // dsh-purge-community 的 bin 键里没有它自己的包名,所以 README 让人敲 `npx dsh-purge-community`
10
+ // 会 404;这正是我在自己 27 个包上犯过的同一个错。
11
+
12
+ import { existsSync, readFileSync, statSync } from 'node:fs'
13
+ import { join } from 'node:path'
14
+
15
+ const IMAGE = /\.(svg|png|jpe?g|webp)$/i
16
+
17
+ /** 规则清单:checked.rules 由它推出,测试断言「跑出来的规则都在这里」——数字不能是手写的。 */
18
+ export const RULES = [
19
+ 'manifest-missing', 'manifest-unparsable', 'private',
20
+ 'bundle-missing', 'patch-missing', 'patch-empty', 'patch-name-mismatch',
21
+ 'files-omits-patch', 'files-omits-detail', 'engines-missing', 'bin-name-mismatch',
22
+ 'readme-missing', 'readme-install-missing', 'locale-missing', 'icon-missing',
23
+ ]
24
+
25
+ /** 从 package.json 与目录结构判定。dir 是一个已安装或已打包的插件包目录。 */
26
+ export function lintPluginPackage(dir, options = {}) {
27
+ const findings = []
28
+ const add = (level, rule, message) => findings.push({ level, rule, line: 0, message })
29
+ const read = (name) => {
30
+ const path = join(dir, name)
31
+ return existsSync(path) ? readFileSync(path, 'utf8') : null
32
+ }
33
+
34
+ const manifestText = read('package.json')
35
+ if (!manifestText) {
36
+ add('error', 'manifest-missing', '目录里没有 package.json——这不是一个包')
37
+ return finish(findings, {})
38
+ }
39
+ let manifest
40
+ try {
41
+ manifest = JSON.parse(manifestText)
42
+ } catch (error) {
43
+ add('error', 'manifest-unparsable', `package.json 不是合法 JSON:${String(error.message).slice(0, 80)}`)
44
+ return finish(findings, {})
45
+ }
46
+ if (manifest.private) add('error', 'private', 'package.json 标了 private——发不到 npm(从 git 或本地 link 装仍然可以)')
47
+
48
+ const bundle = manifest.dsh?.bundle
49
+ if (!bundle || typeof bundle !== 'object' || !bundle.patch) {
50
+ // 这是目录收录的第一号打回理由:只有 dsh.client 是不够的,那样 dsh plugin add 装不上。
51
+ add('error', 'bundle-missing', 'dsh.bundle.patch 没声明——`dsh plugin add` 装不上,目录也不会收')
52
+ } else {
53
+ const patchPath = join(dir, bundle.patch)
54
+ if (!existsSync(patchPath)) {
55
+ add('error', 'patch-missing', `dsh.bundle.patch 指向 ${bundle.patch},但目录里没有这个文件`)
56
+ } else {
57
+ const patch = readFileSync(patchPath, 'utf8')
58
+ const names = [...patch.matchAll(/name:\s*['"]?([^'"\n]+?)['"]?\s*$/gm)].map(match => match[1].trim())
59
+ // 聚合包合法地「不挂自己」:dsh-check-suite 的 patch 挂的是它的依赖们。所以判据是
60
+ // 「挂的东西要么是自己,要么是自己声明的依赖」——第一版只认自己,把套件判成了错。
61
+ const deps = new Set(Object.keys(manifest.dependencies ?? {}))
62
+ if (names.length === 0) add('error', 'patch-empty', `${bundle.patch} 里没有任何 insert 行——这一层什么也不挂`)
63
+ else if (!names.includes(manifest.name) && !names.some(entry => deps.has(entry))) {
64
+ add('error', 'patch-name-mismatch', `${bundle.patch} 挂的是 ${names.slice(0, 3).join(' / ')},既不是本包的 ${manifest.name},也不是它声明的依赖`)
65
+ }
66
+ }
67
+ }
68
+
69
+ // files 白名单:声明了就不该漏掉运行必需的东西。漏了本地照样跑,发出去才坏。
70
+ const files = Array.isArray(manifest.files) ? manifest.files : null
71
+ const inFiles = (target) => !files || files.some(entry => target === entry || target.startsWith(`${entry.replace(/\/$/, '')}/`))
72
+ if (files && bundle?.patch && !inFiles(bundle.patch.replace(/^\.\//, ''))) {
73
+ add('warn', 'files-omits-patch', `files 里没有 ${bundle.patch}——发出去的 tarball 里没有它,装的时候解析不到`)
74
+ }
75
+ if (files && existsSync(join(dir, 'docs/DETAIL.md')) && !inFiles('docs/DETAIL.md')) {
76
+ add('warn', 'files-omits-detail', 'files 里没有 docs/DETAIL.md——插件详情页会空着')
77
+ }
78
+
79
+ if (!manifest.engines?.dsh) add('warn', 'engines-missing', 'engines.dsh 没写——读者无从判断这个包跟自己的 DSH 版本兼不兼容')
80
+
81
+ const bin = manifest.bin && typeof manifest.bin === 'object' ? Object.keys(manifest.bin) : []
82
+ if (bin.length > 0 && !bin.includes(manifest.name)) {
83
+ // npx 拿第一段当**包名**去 registry 找,所以 bin 键必须有一个等于包名,否则
84
+ // `npx <包名>` 404——我在自己 27 个包上正是这么错的。
85
+ add('warn', 'bin-name-mismatch', `bin 键是 ${bin.join(' / ')},没有一个是包名——\`npx ${manifest.name}\` 会 404`)
86
+ }
87
+
88
+ const readme = read('README.md')
89
+ if (!readme) add('warn', 'readme-missing', '没有 README.md——目录页与 npm 页都没有可读的第一屏')
90
+ else if (!/dsh plugin\s+(--profile\s+\S+\s+)?add/.test(readme)) {
91
+ add('warn', 'readme-install-missing', 'README 里没有一条 `dsh plugin add …` 安装命令——读者得自己猜怎么装')
92
+ }
93
+
94
+ if (!existsSync(join(dir, 'locale'))) add('warn', 'locale-missing', '没有 locale/——插件页只能显示包名,没有标题与说明')
95
+ const iconExported = manifest.exports && Object.keys(manifest.exports).includes('./icon')
96
+ const iconFile = [...(manifest.files ?? []), 'icon.svg', 'icon.png'].find(name => IMAGE.test(name) && existsSync(join(dir, name)))
97
+ if (!iconExported && !iconFile) add('warn', 'icon-missing', '没有图标(./icon 导出或 icon.svg)——插件卡片是空白的')
98
+
99
+ return finish(findings, { name: manifest.name, version: manifest.version })
100
+ }
101
+
102
+ function finish(findings, meta) {
103
+ const errors = findings.filter(finding => finding.level === 'error').length
104
+ const warnings = findings.filter(finding => finding.level === 'warn').length
105
+ const order = { error: 0, warn: 1 }
106
+ findings.sort((a, b) => order[a.level] - order[b.level] || a.rule.localeCompare(b.rule))
107
+ return {
108
+ ok: errors === 0,
109
+ errors,
110
+ warnings,
111
+ findings,
112
+ checked: { package: meta.name ?? null, version: meta.version ?? null, rules: RULES.length },
113
+ }
114
+ }
115
+
116
+ export const name = 'plugin-package-check'
117
+ export const inject = ['webServer']
118
+
119
+ export function apply(ctx, config = {}) {
120
+ const prefix = config.path || '/plugin-package-check/api'
121
+ const handler = async (req, res) => {
122
+ const reply = (status, body) => {
123
+ res.statusCode = status
124
+ res.setHeader('content-type', 'application/json; charset=utf-8')
125
+ res.end(JSON.stringify(body))
126
+ }
127
+ try {
128
+ if (req.method !== 'POST') return reply(405, { error: 'POST only' })
129
+ const chunks = []
130
+ for await (const chunk of req) chunks.push(chunk)
131
+ const body = JSON.parse(Buffer.concat(chunks).toString('utf8') || '{}')
132
+ const dir = typeof body.path === 'string' ? body.path : ''
133
+ if (!dir) return reply(400, { error: 'path is required: the package directory' })
134
+ if (!existsSync(dir) || !statSync(dir).isDirectory()) return reply(400, { error: `not a directory: ${dir}` })
135
+ return reply(200, lintPluginPackage(dir, { dirName: body.dirName }))
136
+ } catch (error) {
137
+ return reply(400, { error: error.message || 'request failed' })
138
+ }
139
+ }
140
+ ctx.effect(() => ctx.webServer.register({ kind: 'prefix', path: prefix, handler }))
141
+ }