dsh-plugin-diagnose 0.2.9 → 0.2.10

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 CHANGED
@@ -1,14 +1,118 @@
1
1
  # dsh-plugin-diagnose
2
2
 
3
- 诊断「DSH 插件装了但没生效」。**版本感知**:先报 DSH 版本,再做文件级检查(跨版本稳定),可选接官方 `--dump-config` 补充。
3
+ English | [简体中文](./README.zh-CN.md)
4
+
5
+ Answer "my DSH plugin is installed but nothing shows up": version-aware, file-level checks (dependency declared, install / dangling link, `dsh.bundle`, patch file, `client.js`) plus optional official `--dump-config` warnings. Built on [`dsh-plugin-compat`](../dsh-plugin-compat).
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm i -D dsh-plugin-diagnose
11
+ # or run it straight from the registry
12
+ npx dsh-plugin-diagnose --profile-dir ~/.dsh/profiles/web
13
+ ```
14
+
15
+ - Node `>= 22.15.0`, DSH `>= 0.2.2-rc.5` (see `engines` in `package.json`).
16
+ - Runtime dependency: `dsh-plugin-compat` (provides every check).
17
+
18
+ ## Quick start
19
+
20
+ ```bash
21
+ npx dsh-plugin-diagnose --profile-dir ~/.dsh/profiles/web --plugin dsh-my-plugin
22
+ ```
23
+
24
+ Output looks like this (paths shortened; the check names and hints really are Chinese):
25
+
26
+ ```text
27
+ doctor: profile=/home/me/.dsh/profiles/web plugin=dsh-my-plugin
28
+ ✓ dsh-my-plugin 声明依赖 ^0.1.0
29
+ ✓ dsh-my-plugin 已安装 /home/me/dev/dsh-my-plugin
30
+ ✓ dsh-my-plugin 包版本 dsh-my-plugin@0.1.0
31
+ ✓ dsh-my-plugin dsh.bundle declared
32
+ ✓ dsh-my-plugin cordis patch ./cordis.patch.yml
33
+ ✗ dsh-my-plugin client.js 缺失(UI 不显示) → 在插件目录执行 build
34
+
35
+ === 结论: ✗ 1 个问题 ===
36
+ ```
37
+
38
+ Exit code is `1` because one check failed. Fix the hint (`npm run build` in the plugin directory), rerun, and the line turns into `✓ ... client 产物 client.js exists` with `=== 结论: ✓ 健康 ===`.
39
+
40
+ Checking the whole profile (no `--plugin`) plus the official dump:
41
+
42
+ ```bash
43
+ npx dsh-plugin-diagnose --profile-dir ~/.dsh/profiles/web --dsh "$DSH_CLI" --dump
44
+ ```
45
+
46
+ ## Usage
4
47
 
5
48
  ```bash
6
- dsh-plugin-diagnose --profile-dir <profileDir> [--plugin <pkgName>] [--dsh <dsh-cli>] [--dump]
49
+ dsh-plugin-diagnose [--profile-dir <profileDir>] [--plugin <pkgName>] [--dsh <dshCli>] [--dump]
50
+ dsh-plugin-diagnose --help
51
+ ```
52
+
53
+ ## Options
54
+
55
+ | Option | Default | Meaning |
56
+ |---|---|---|
57
+ | `--profile-dir <dir>` | `process.cwd()` | The profile directory to inspect (e.g. `~/.dsh/profiles/web`). **Must be a real DSH profile** — see [Notes](#notes). |
58
+ | `--plugin <name>` | all `dependencies` of the profile | Check only this one package instead of every declared dependency. |
59
+ | `--dsh <cli>` | none | Path to the `dsh` executable. Used to print the DSH version (`--version`) and, with `--dump`, to run `--dump-config`. |
60
+ | `--dump` | off | Also run the official `--dump-config` and report patch/error warnings. If the CLI is missing or the command is unavailable, it says so and the run falls back to file-level checks only — it never fails because of the dump. |
61
+ | `--help`, `-h` | — | Print usage, exit `0`. |
62
+
63
+ ## What it checks
64
+
65
+ Every row comes from `runFileChecks(profileDir, { plugin })` in `dsh-plugin-compat`; a `✗` row counts as an issue, a `⚠` row does not.
66
+
67
+ | Check | Passes when | On failure |
68
+ |---|---|---|
69
+ | dependency declared | the package appears in the profile's `dependencies` | `✗ … 未在 profile dependencies 声明`, fix hint `dsh plugin --profile <p> add <name>` |
70
+ | installed | `<profile>/node_modules/<name>` exists | `✗ … 未安装(node_modules 无此包)`, fix hint "reinstall the plugin" |
71
+ | link alive | `realpath` of that path resolves | `✗ … 符号链接悬空`, fix hint "rebuild the link / rebuild + release, then reinstall" |
72
+ | package manifest | the installed `package.json` parses | `✗ … package.json 读不到` |
73
+ | package version | the installed `package.json` parses (this row is skipped entirely when the package is not installed) | — |
74
+ | `dsh.bundle` | `dsh.bundle` is set | `⚠ … 无 dsh.bundle` (library package, or wrong shape) |
75
+ | patch file | `dsh.bundle.patch` is a string **and** the file exists inside the package; no row at all when `patch` is not a string | `✗ … cordis patch 文件缺失`, fix hint "check `files` / patch path" |
76
+ | `client.js` | only when the package declares `dsh.bundle` **and** (`dsh.client` or `exports["./client"]` or `exports["."]`); the file must exist | `✗ … client.js 缺失(UI 不显示)`, fix hint "run the build in the plugin directory" |
77
+
78
+ The `client.js` check is skipped entirely for packages without `dsh.bundle`, so plain libraries do not get a false "missing client".
79
+
80
+ ## API
81
+
82
+ `src/index.mjs` is a one-line re-export; every function below comes from `dsh-plugin-compat`.
83
+
84
+ | Export | Signature | Returns / does |
85
+ |---|---|---|
86
+ | `runFileChecks` | `(profileDir, { plugin } = {})` | `{ profileDir, plugin, checks, issues, notes }`; each check is `{ status: 'ok' \| 'warn' \| 'bad', name, detail, fix }`. `bad` → `issues`, `warn` → `notes`. |
87
+ | `detectVersion` | `(dshCli)` | `{ dshCli, version, ok, firstStderrLine }`. Runs `<cli> --version` and takes the first stdout line. |
88
+ | `runDsh` | `(dshCli, args, { env, cwd } = {})` | `{ status, stdout, stderr, error }`. Always spawned through a shell (so Windows `.cmd` works), 120 s timeout, every argument quoted. |
89
+ | `extractWarnings` | `(result)` | `string[]` — lines from stdout+stderr matching `patch: entry … not found` or `error:`. |
90
+
91
+ ```js
92
+ import { runFileChecks } from 'dsh-plugin-diagnose'
93
+
94
+ const r = runFileChecks('/home/me/.dsh/profiles/web', { plugin: 'dsh-my-plugin' })
95
+ if (r.issues.length) process.exitCode = 1
7
96
  ```
8
97
 
9
- - `--profile-dir`:某个 profile 目录(如 `~/.dsh/profiles/desktop`)。
10
- - `--plugin`:只查某个插件包;不给则查该 profile 的全部 dependencies。
11
- - `--dsh`:给 dsh CLI 以探测版本(并可 `--dump`)。
12
- - `--dump`:额外跑官方 `--dump-config`,抓 patch 警告(desktop profile 被官方拒绝时自动降级为仅文件级检查)。
98
+ ## Exit codes
99
+
100
+ | Code | When |
101
+ |---|---|
102
+ | `0` | No failing check (`✓ 健康`). Warnings alone still exit `0`. |
103
+ | `1` | At least one `✗` check, **or** `--profile-dir` is not a profile directory. |
104
+ | `2` | Usage error: unknown option, missing option value, or extra positional argument. |
105
+
106
+ ## Notes
107
+
108
+ - **It refuses to run outside a profile directory.** `--profile-dir` must contain a `package.json` whose `dsh.profile` field is set. Anything else exits `1` with `这不是 profile 目录(…)` — the tool never reports a plain Node project as "healthy". Since the default is the current directory, running it inside a plugin checkout fails this way on purpose.
109
+ - **No `--opt=value` form.** `--profile-dir=..` is rejected as an unknown option (exit `2`); write `--profile-dir ..`.
110
+ - **No positional arguments.** A bare `extra` argument exits `2`.
111
+ - **Warnings do not fail the run.** A package without `dsh.bundle` prints `⚠` and the verdict stays `✓ 健康 ⚠ 1`, exit `0`.
112
+ - **`--dump` needs `--dsh`.** Without it you get `⚠ 未提供 --dsh,跳过 dump`; if the CLI exists but `--dump-config` fails, the note says so and file-level checks still stand.
113
+ - **It does not start DSH.** The only runtime interaction is `--version` / `--dump-config`. Runtime behaviour (plugin throwing on load, slot never rendering) is out of scope — use `dsh-plugin-e2e` for that.
114
+ - **Console text is Chinese.** Check names and fix hints are emitted in Chinese; parse the `✓ ⚠ ✗` prefix and the exit code if you need machine-readable results, or call `runFileChecks` directly.
115
+
116
+ ## License
13
117
 
14
- 检查:依赖是否声明 / `node_modules` 是否安装(悬空链接)/ 插件 `package.json` / `dsh.bundle` / `cordis.patch.yml` 是否存在 / `client.js` 产物是否存在。结论 `✓ 健康` 或 `✗ N 个问题`;有问题退出码 1。
118
+ MIT
@@ -0,0 +1,118 @@
1
+ # dsh-plugin-diagnose
2
+
3
+ [English](./README.md) | 简体中文
4
+
5
+ 回答「我的 DSH 插件装了,为什么界面上没有」:版本感知 + 文件级检查(依赖声明、安装/悬空链接、`dsh.bundle`、patch 文件、`client.js`),可选接官方 `--dump-config` 补充警告。检查逻辑来自 [`dsh-plugin-compat`](../dsh-plugin-compat)。
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ npm i -D dsh-plugin-diagnose
11
+ # 或直接用 npx 跑
12
+ npx dsh-plugin-diagnose --profile-dir ~/.dsh/profiles/web
13
+ ```
14
+
15
+ - Node `>= 22.15.0`,DSH `>= 0.2.2-rc.5`(见 `package.json` 的 `engines`)。
16
+ - 运行时依赖:`dsh-plugin-compat`(所有检查项都由它提供)。
17
+
18
+ ## 快速开始
19
+
20
+ ```bash
21
+ npx dsh-plugin-diagnose --profile-dir ~/.dsh/profiles/web --plugin dsh-my-plugin
22
+ ```
23
+
24
+ 真实输出:
25
+
26
+ ```text
27
+ doctor: profile=/home/me/.dsh/profiles/web plugin=dsh-my-plugin
28
+ ✓ dsh-my-plugin 声明依赖 ^0.1.0
29
+ ✓ dsh-my-plugin 已安装 /home/me/dev/dsh-my-plugin
30
+ ✓ dsh-my-plugin 包版本 dsh-my-plugin@0.1.0
31
+ ✓ dsh-my-plugin dsh.bundle declared
32
+ ✓ dsh-my-plugin cordis patch ./cordis.patch.yml
33
+ ✗ dsh-my-plugin client.js 缺失(UI 不显示) → 在插件目录执行 build
34
+
35
+ === 结论: ✗ 1 个问题 ===
36
+ ```
37
+
38
+ 因为有 1 项 `✗`,退出码是 `1`。按提示(在插件目录跑 `npm run build`)修完再跑,那一行会变成 `✓ … client 产物 client.js exists`,结论变成 `=== 结论: ✓ 健康 ===`。
39
+
40
+ 查整个 profile(不给 `--plugin`)并接官方 dump:
41
+
42
+ ```bash
43
+ npx dsh-plugin-diagnose --profile-dir ~/.dsh/profiles/web --dsh "$DSH_CLI" --dump
44
+ ```
45
+
46
+ ## 用法
47
+
48
+ ```bash
49
+ dsh-plugin-diagnose [--profile-dir <profile目录>] [--plugin <包名>] [--dsh <cli>] [--dump]
50
+ dsh-plugin-diagnose --help
51
+ ```
52
+
53
+ ## 选项
54
+
55
+ | 选项 | 默认值 | 说明 |
56
+ |---|---|---|
57
+ | `--profile-dir <目录>` | `process.cwd()` | 要检查的 profile 目录(如 `~/.dsh/profiles/web`)。**必须是真的 DSH profile**,见[注意事项](#注意事项)。 |
58
+ | `--plugin <包名>` | profile 的全部 `dependencies` | 只查这一个包,不逐个查已声明依赖。 |
59
+ | `--dsh <cli>` | 无 | `dsh` 可执行文件路径。用来打印 DSH 版本(`--version`),配合 `--dump` 时用来跑 `--dump-config`。 |
60
+ | `--dump` | 关 | 额外跑官方 `--dump-config`,报告 patch / error 警告。CLI 不存在或命令不可用时会说明原因,并退回「仅文件级检查」——不会因为 dump 失败而报错。 |
61
+ | `--help`、`-h` | — | 打印用法,退出 `0`。 |
62
+
63
+ ## 检查项
64
+
65
+ 每一行都来自 `dsh-plugin-compat` 的 `runFileChecks(profileDir, { plugin })`;`✗` 计入问题数,`⚠` 不计入。
66
+
67
+ | 检查 | 通过条件 | 失败表现 |
68
+ |---|---|---|
69
+ | 依赖声明 | 包出现在 profile 的 `dependencies` 里 | `✗ … 未在 profile dependencies 声明`,修复提示 `dsh plugin --profile <p> add <name>` |
70
+ | 已安装 | `<profile>/node_modules/<name>` 存在 | `✗ … 未安装(node_modules 无此包)`,提示重装该插件 |
71
+ | 链接有效 | 该路径 `realpath` 能解析 | `✗ … 符号链接悬空`,提示重建 link / 重新 build+release 后重装 |
72
+ | 包清单 | 装好的 `package.json` 能解析 | `✗ … package.json 读不到` |
73
+ | 包版本 | 装好的 `package.json` 能解析(包未安装时这一行整体跳过) | — |
74
+ | `dsh.bundle` | `dsh.bundle` 已声明 | `⚠ … 无 dsh.bundle`(是库包,或声明形状不对) |
75
+ | patch 文件 | `dsh.bundle.patch` 是字符串**且**该文件在包内存在;`patch` 不是字符串时不出这一行 | `✗ … cordis patch 文件缺失`,提示检查 `files` / patch 路径 |
76
+ | `client.js` | 仅当包声明了 `dsh.bundle` **且**(`dsh.client` 或 `exports["./client"]` 或 `exports["."]`)时检查,文件必须存在 | `✗ … client.js 缺失(UI 不显示)`,提示在插件目录执行 build |
77
+
78
+ 没有 `dsh.bundle` 的包完全跳过 `client.js` 检查,所以普通库包不会被误报「缺 client」。
79
+
80
+ ## API
81
+
82
+ `src/index.mjs` 是一行转发,下列函数全部来自 `dsh-plugin-compat`。
83
+
84
+ | 导出 | 签名 | 返回 / 行为 |
85
+ |---|---|---|
86
+ | `runFileChecks` | `(profileDir, { plugin } = {})` | `{ profileDir, plugin, checks, issues, notes }`;每个 check 是 `{ status: 'ok' \| 'warn' \| 'bad', name, detail, fix }`。`bad` 进 `issues`,`warn` 进 `notes`。 |
87
+ | `detectVersion` | `(dshCli)` | `{ dshCli, version, ok, firstStderrLine }`。跑 `<cli> --version`,取 stdout 首行。 |
88
+ | `runDsh` | `(dshCli, args, { env, cwd } = {})` | `{ status, stdout, stderr, error }`。始终经 shell 启动(Windows 的 `.cmd` 才能跑),超时 120 秒,每个参数都加引号。 |
89
+ | `extractWarnings` | `(result)` | `string[]`——stdout+stderr 里匹配 `patch: entry … not found` 或 `error:` 的行。 |
90
+
91
+ ```js
92
+ import { runFileChecks } from 'dsh-plugin-diagnose'
93
+
94
+ const r = runFileChecks('/home/me/.dsh/profiles/web', { plugin: 'dsh-my-plugin' })
95
+ if (r.issues.length) process.exitCode = 1
96
+ ```
97
+
98
+ ## 退出码
99
+
100
+ | 码 | 何时 |
101
+ |---|---|
102
+ | `0` | 没有失败项(`✓ 健康`)。只有警告时仍是 `0`。 |
103
+ | `1` | 至少一个 `✗`,**或** `--profile-dir` 不是 profile 目录。 |
104
+ | `2` | 用法错误:未知参数、参数缺值、多余位置参数。 |
105
+
106
+ ## 注意事项
107
+
108
+ - **它拒绝在非 profile 目录上跑。** `--profile-dir` 必须含 `package.json`,且其中 `dsh.profile` 字段有值。否则直接 `这不是 profile 目录(…)` 并退出 `1`——**不会**把普通 Node 项目假报成「健康」。默认值是当前目录,所以在插件仓库里直接跑就是这种失败,这是设计如此。
109
+ - **不支持 `--opt=value` 写法。** `--profile-dir=..` 会被当成未知参数(退出 `2`),要写 `--profile-dir ..`。
110
+ - **不接受位置参数。** 多写一个裸参数(如 `extra`)退出 `2`。
111
+ - **警告不影响结论。** 没有 `dsh.bundle` 的包打印 `⚠`,结论仍是 `✓ 健康 ⚠ 1`,退出 `0`。
112
+ - **`--dump` 需要 `--dsh`。** 不给会打印 `⚠ 未提供 --dsh,跳过 dump`;CLI 存在但 `--dump-config` 失败时会注明原因,文件级检查结论照旧有效。
113
+ - **它不启动 DSH。** 唯一的外部调用是 `--version` / `--dump-config`。运行期问题(插件加载即抛错、slot 根本没渲染)不在范围内,用 `dsh-plugin-e2e` 查。
114
+ - **控制台输出是中文。** 检查名与修复提示都是中文;要机器可读结果请直接调 `runFileChecks`,或解析 `✓ ⚠ ✗` 前缀加退出码。
115
+
116
+ ## License
117
+
118
+ MIT
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-diagnose",
3
- "version": "0.2.9",
3
+ "version": "0.2.10",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -12,7 +12,7 @@
12
12
  ".": "./src/index.mjs"
13
13
  },
14
14
  "dependencies": {
15
- "dsh-plugin-compat": "^0.2.9"
15
+ "dsh-plugin-compat": "^0.2.10"
16
16
  },
17
17
  "repository": {
18
18
  "type": "git",
@@ -22,7 +22,8 @@
22
22
  "files": [
23
23
  "bin/",
24
24
  "src/",
25
- "README.md"
25
+ "README.md",
26
+ "README.zh-CN.md"
26
27
  ],
27
28
  "publishConfig": {
28
29
  "access": "public",