docs: use installed dsh command in publish tutorial

This commit is contained in:
Turtle
2026-08-13 14:02:07 +08:00
parent bca790481c
commit 4201bbceca
3 changed files with 28 additions and 28 deletions

View File

@@ -2,7 +2,7 @@
[English](publish.md) | 中文
前几篇教程通过 `--patch` overlay 加载本地插件。本教程把它打包成可安装的**组合包**bundle`pnpm dsh plugin add` 安装进一个 **profile**,并解释决定组合后配置的层顺序。请先完成[插件配置](./config.md)。
前几篇教程通过 `--patch` overlay 加载本地插件。本教程把它打包成可安装的**组合包**bundle`dsh plugin add` 安装进一个 **profile**,并解释决定组合后配置的层顺序。本文假设 `dsh` CLI 已安装。请先完成[插件配置](./config.md)。
## 两个概念,两种 manifest
@@ -11,11 +11,11 @@
- **组合包**是附带一个配置层的 npm 包。它的 manifest 声明 `dsh.bundle`,回答的是"这个包贡献什么?":一个插入或覆盖插件行的 patch 文件。
- **profile** 是位于 `$DSH_HOME/profiles/<name>` 下、描述一份可启动组合的目录。它的 manifest 声明 `dsh.profile`,回答的是"这套配置由哪些组合包按什么顺序组成?"。
组合包是你编写并分发的东西profile 是用户在当前源码 checkout 中用 `pnpm dsh --profile <name>` 启动的东西。没有东西同时是两者。
组合包是你编写并分发的东西profile 是用户`dsh --profile <name>` 启动的东西。没有东西同时是两者。
### 组合包 manifest
在仓库根目录创建包目录:
创建包目录:
```sh
mkdir -p hello-plugin
@@ -59,7 +59,7 @@ export function apply() {
name: dsh-hello-plugin
```
没有 `dsh.bundle` 声明的包仍然可以安装,但只作为普通依赖:`pnpm dsh plugin` 会打印警告,且不激活任何层。如果一个库供插件包 import而不是供用户启用就使用这种包格式。
没有 `dsh.bundle` 声明的包仍然可以安装,但只作为普通依赖:`dsh plugin` 会打印警告,且不激活任何层。如果一个库供插件包 import而不是供用户启用就使用这种包格式。
### profile manifest
@@ -68,14 +68,14 @@ profile 目录包含两个文件:
- `package.json` — profile 的树外插件依赖(由 pnpm 管理),加上 `dsh.profile` manifest 及其有序的 `bundles` 列表。
- `cordis.patch.yml` — 用户自己的 patch 层,在每个组合包层之后应用。
profile manifest 从不需要手写:`pnpm dsh plugin` 负责创建和维护它。下一节展示其结果。
profile manifest 从不需要手写:`dsh plugin` 负责创建和维护它。下一节展示其结果。
## 安装进 profile
`pnpm dsh plugin --profile <name> <args...>` 在 profile 目录内转发给 pnpm因此所有 pnpm 子命令都可用。在仓库根目录安装该包的 checkout
`dsh plugin --profile <name> <args...>` 在 profile 目录内转发给 pnpm因此所有 pnpm 子命令都可用。在包含 `hello-plugin`目录安装该包的 checkout
```sh
pnpm dsh plugin --profile demo add ./hello-plugin
dsh plugin --profile demo add ./hello-plugin
```
首次使用会初始化 profile`@deepseek-ai/dsh-base` 作为它的第一个组合包pnpm 链接该 checkout`dsh` 因为这个包声明了 `dsh.bundle`,把它追加进 `dsh.profile.bundles`
@@ -101,11 +101,11 @@ pnpm dsh plugin --profile demo add ./hello-plugin
先不启动、只验证该层,再启动:
```sh
pnpm dsh --profile demo --dump-config # shows a "# == dsh-hello-plugin" layer
pnpm dsh --profile demo
dsh --profile demo --dump-config # shows a "# == dsh-hello-plugin" layer
dsh --profile demo
```
`pnpm dsh plugin --profile demo remove dsh-hello-plugin` 会同时移除依赖和对应的层。
`dsh plugin --profile demo remove dsh-hello-plugin` 会同时移除依赖和对应的层。
## 加载顺序
@@ -153,7 +153,7 @@ pnpm dsh --profile demo
发布到注册表不是必须的——用户可以直接从 git 托管安装:
```sh
pnpm dsh plugin --profile demo add github:you/hello-plugin
dsh plugin --profile demo add github:you/hello-plugin
```
但 git 安装拉取的是**源码,不是构建产物**:没有任何环节运行你的 `build` 脚本,因此 TypeScript 包到手时没有 `lib/` 输出,加载会失败。必须两边各做一件事:
@@ -172,8 +172,8 @@ pnpm dsh plugin --profile demo add github:you/hello-plugin
如果不想让用户做这项授权,就改为分发构建产物——以下两种形式都不需要任何构建权限:
- **发布到 npm**,在 `pnpm publish` 时构建好 `lib/``pnpm dsh plugin add your-package` 安装的就是预构建代码。
- **交付 tarball**:用 `pnpm pack` 打包;用户执行 `pnpm dsh plugin add ./hello-plugin-0.1.0.tgz`。
- **发布到 npm**,在 `pnpm publish` 时构建好 `lib/``dsh plugin add your-package` 安装的就是预构建代码。
- **交付 tarball**:用 `pnpm pack` 打包;用户执行 `dsh plugin add ./hello-plugin-0.1.0.tgz`。
## 下一步