@wwkit/opm 1.0.8 → 1.0.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 +30 -20
- package/docs/managers/apt.md +2 -3
- package/docs/managers/brew.md +2 -6
- package/docs/managers/bun.md +2 -4
- package/docs/managers/composer.md +2 -6
- package/docs/managers/dnf.md +2 -3
- package/docs/managers/npm.md +2 -6
- package/docs/managers/nvm.md +2 -0
- package/docs/managers/phpenv.md +2 -0
- package/docs/managers/pip.md +2 -6
- package/docs/managers/uv.md +2 -0
- package/docs/opm.html +13 -23
- package/package.json +3 -3
- package/src/cli/groups/ensure.js +25 -4
- package/src/cli/groups/nvm.js +5 -1
- package/src/cli/groups/overlay.js +169 -0
- package/src/cli/groups/package.js +42 -18
- package/src/cli/groups/phpenv.js +5 -1
- package/src/cli/groups/uv.js +5 -1
- package/src/cli/groups/version-manager.js +27 -0
- package/src/cli/index.js +4 -0
- package/src/config.json5 +1 -0
- package/src/harnesses/base.js +88 -20
- package/src/harnesses/harness/index.js +132 -0
- package/src/harnesses/opencode/index.js +1 -1
- package/src/index.js +2 -0
- package/src/managers/apt.js +3 -12
- package/src/managers/base.js +17 -2
- package/src/managers/brew.js +3 -5
- package/src/managers/bun.js +0 -18
- package/src/managers/composer.js +65 -9
- package/src/managers/dnf.js +3 -12
- package/src/managers/node.js +17 -8
- package/src/managers/npm.js +51 -45
- package/src/managers/php.js +17 -8
- package/src/managers/pip.js +24 -18
- package/src/managers/python.js +18 -8
- package/src/managers/winget.js +3 -13
- package/src/tools/webwork/index.js +132 -463
package/docs/opm.html
CHANGED
|
@@ -119,7 +119,7 @@
|
|
|
119
119
|
<div id="managers_apt" class="doc-content" style="display:block;"><h1>apt 命令对照表</h1>
|
|
120
120
|
<p><code>@wwkit/opm</code> 统一命令管理 apt 包(Debian / Ubuntu 等 dpkg 系,系统级)。</p>
|
|
121
121
|
<h2>命令对照</h2>
|
|
122
|
-
<table><thead><tr><th>统一命令</th><th>原始命令</th><th>说明</th></tr></thead><tbody><tr><td><code>opm apt version</code></td><td><code>apt --version</code></td><td
|
|
122
|
+
<table><thead><tr><th>统一命令</th><th>原始命令</th><th>说明</th></tr></thead><tbody><tr><td><code>opm apt version [name]</code></td><td><code>apt --version</code></td><td>无 name 显示 apt 版本;有 name 显示包在全局作用域的版本(无项目作用域,project 显示未安装)</td></tr><tr><td><code>opm apt registry</code></td><td>读 <code>/etc/apt/sources.list.d/opm.list</code></td><td>查询当前启用源</td></tr><tr><td><code>opm apt registry set <url|preset></code></td><td>写 <code>/etc/apt/sources.list.d/opm.list</code> + <code>apt update</code></td><td>设置镜像源</td></tr><tr><td><code>opm apt registry presets</code></td><td>—</td><td>列出可用镜像预设</td></tr><tr><td><code>opm apt search <name></code></td><td><code>apt-cache search</code></td><td>查询包在源是否可用</td></tr><tr><td><code>opm apt view <name></code></td><td><code>dpkg -l</code> / <code>apt list --installed</code></td><td>查询包在全局作用域的安装信息(无项目作用域,project 显示未安装)</td></tr><tr><td><code>opm apt info <name></code></td><td><code>apt-cache show</code></td><td>包详情</td></tr><tr><td><code>opm apt versions <name></code></td><td><code>apt-cache madison</code> / <code>policy</code></td><td>所有可用版本</td></tr><tr><td><code>opm apt outdated</code></td><td><code>apt list --upgradable</code></td><td>过期包</td></tr><tr><td><code>opm apt install <name></code></td><td><code>apt install</code></td><td>安装</td></tr><tr><td><code>opm apt uninstall <name></code></td><td><code>apt remove</code></td><td>卸载</td></tr><tr><td><code>opm apt upgrade <name></code></td><td><code>apt upgrade</code></td><td>升级</td></tr><tr><td><code>opm apt cache clean</code></td><td><code>apt clean</code></td><td>清理缓存</td></tr></tbody></table>
|
|
123
123
|
<h2>镜像预设</h2>
|
|
124
124
|
<table><thead><tr><th>预设名</th><th>地址</th></tr></thead><tbody><tr><td><code>ubuntu-tsinghua</code></td><td><code>deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse</code></td></tr><tr><td><code>ubuntu-huawei</code></td><td><code>deb https://mirrors.huaweicloud.com/ubuntu/ focal main restricted universe multiverse</code></td></tr><tr><td><code>ubuntu-aliyun</code></td><td><code>deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse</code></td></tr><tr><td><code>debian-official</code></td><td><code>deb http://deb.debian.org/debian/ bookworm main</code></td></tr><tr><td><code>debian-tsinghua</code></td><td><code>deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main</code></td></tr></tbody></table>
|
|
125
125
|
<h2>示例</h2>
|
|
@@ -134,7 +134,7 @@ opm apt cache clean</code></pre></div>
|
|
|
134
134
|
<div id="managers_brew" class="doc-content" style="display:none;"><h1>brew 命令对照表</h1>
|
|
135
135
|
<p><code>@wwkit/opm</code> 统一命令与 Homebrew 原始命令的映射关系(macOS)。</p>
|
|
136
136
|
<h2>命令对照</h2>
|
|
137
|
-
<table><thead><tr><th>统一命令</th><th>原始命令</th><th>说明</th></tr></thead><tbody><tr><td><code>opm brew version</code></td><td><code>brew --version</code></td><td
|
|
137
|
+
<table><thead><tr><th>统一命令</th><th>原始命令</th><th>说明</th></tr></thead><tbody><tr><td><code>opm brew version [name]</code></td><td><code>brew --version</code></td><td>无 name 显示 brew 本身版本;有 name 显示包在全局作用域的版本(无项目作用域,project 显示未安装)</td></tr><tr><td><code>opm brew registry</code></td><td>读 <code>~/.config/opm/config.json5</code> 的 <code>brew.registry.active</code></td><td>查询配置中的激活镜像(不读系统配置)</td></tr><tr><td><code>opm brew registry set <url|preset></code></td><td>写 <code>~/.config/opm/config.json5</code> 的 <code>brew.registry.active</code></td><td>设置激活镜像(支持预设名,install/upgrade 自动传 <code>HOMEBREW_API_DOMAIN</code> / <code>HOMEBREW_BOTTLE_DOMAIN</code>;仅作用于本工具发起的命令,不改系统 brew 配置)</td></tr><tr><td><code>opm brew registry presets</code></td><td>—</td><td>列出可用镜像预设</td></tr><tr><td><code>opm brew search <name></code></td><td><code>brew info --json=v2 <name></code></td><td>查询包在源是否可用(返回最新版本 + 版本列表)</td></tr><tr><td><code>opm brew search <name> <version></code></td><td><code>brew info --json=v2 <name></code></td><td>查询指定版本是否可用</td></tr><tr><td><code>opm brew view <name></code></td><td><code>brew list --versions <name></code></td><td>查询包在全局作用域的安装信息(无项目作用域,project 显示未安装)</td></tr><tr><td><code>opm brew info <name></code></td><td><code>brew info --json=v2 <name></code></td><td>查询包详情(描述/主页/许可证/仓库等)</td></tr><tr><td><code>opm brew versions <name></code></td><td><code>brew info --json=v2 <name></code></td><td>列出所有可用版本</td></tr><tr><td><code>opm brew outdated</code></td><td><code>brew outdated --json=v2</code></td><td>列出过期包</td></tr><tr><td><code>opm brew install <name></code></td><td><code>brew install <name></code></td><td>安装包(formula / cask 均可)</td></tr><tr><td><code>opm brew install <name> <version></code></td><td><code>brew install <name>@<version></code></td><td>安装指定版本(versioned formula)</td></tr><tr><td><code>opm brew uninstall <name></code></td><td><code>brew uninstall <name></code></td><td>卸载包</td></tr><tr><td><code>opm brew upgrade <name></code></td><td><code>brew upgrade <name></code></td><td>升级包到最新版本</td></tr><tr><td><code>opm brew cache clean</code></td><td><code>brew cleanup -s --prune=all</code></td><td>清理缓存</td></tr><tr><td><code>opm brew help</code></td><td>—</td><td>显示 brew 命令清单</td></tr></tbody></table>
|
|
138
138
|
<h2>镜像预设</h2>
|
|
139
139
|
<table><thead><tr><th>预设名</th><th>地址</th></tr></thead><tbody><tr><td><code>official</code></td><td><code>https://ghcr.io/v2/homebrew</code></td></tr><tr><td><code>tsinghua</code></td><td><code>https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles</code></td></tr><tr><td><code>ustc</code></td><td><code>https://mirrors.ustc.edu.cn/homebrew-bottles</code></td></tr></tbody></table>
|
|
140
140
|
<blockquote>镜像预设记录的是 bottle 域名;使用非 official 镜像时,<code>HOMEBREW_API_DOMAIN</code> 取 <code>${bottle}/api</code>,<code>HOMEBREW_BOTTLE_DOMAIN</code> 取 bottle 域名本身。</blockquote>
|
|
@@ -163,9 +163,6 @@ opm brew info wget
|
|
|
163
163
|
# 列出 wget 所有可用版本
|
|
164
164
|
opm brew versions wget
|
|
165
165
|
|
|
166
|
-
# 列出所有已安装包
|
|
167
|
-
opm brew list
|
|
168
|
-
|
|
169
166
|
# 列出过期包
|
|
170
167
|
opm brew outdated
|
|
171
168
|
|
|
@@ -190,7 +187,7 @@ opm brew help</code></pre></div>
|
|
|
190
187
|
<p><code>@wwkit/opm</code> 统一命令管理 Bun 包。</p>
|
|
191
188
|
<p>Bun 是全栈 JS 工具链(runtime + 包管理器 + 打包器),包管理与 npm 兼容。</p>
|
|
192
189
|
<h2>命令对照</h2>
|
|
193
|
-
<table><thead><tr><th>统一命令</th><th>原始命令</th><th>说明</th></tr></thead><tbody><tr><td><code>opm bun version</code></td><td><code>bun --version</code></td><td
|
|
190
|
+
<table><thead><tr><th>统一命令</th><th>原始命令</th><th>说明</th></tr></thead><tbody><tr><td><code>opm bun version [name]</code></td><td><code>bun --version</code></td><td>无 name 显示 bun 版本;有 name 显示包在全局与项目作用域的版本</td></tr><tr><td><code>opm bun registry</code></td><td>读 <code>~/.config/opm/config.json5</code> 的 <code>bun.registry.active</code></td><td>查询 bun registry 镜像</td></tr><tr><td><code>opm bun registry set <url|preset></code></td><td>写 <code>~/.config/opm/config.json5</code></td><td>设置 bun registry 镜像(传给 <code>BUN_CONFIG_REGISTRY</code>)</td></tr><tr><td><code>opm bun registry presets</code></td><td>—</td><td>列出可用镜像预设</td></tr><tr><td><code>opm bun search <name> [version]</code></td><td>HTTP 查 npm registry</td><td>查询包是否可用</td></tr><tr><td><code>opm bun view <name></code></td><td>查 <code>node_modules/<name>/package.json</code></td><td>查询包在全局与项目作用域的安装信息</td></tr><tr><td><code>opm bun info <name></code></td><td>HTTP 查 npm registry</td><td>显示包详情</td></tr><tr><td><code>opm bun versions <name></code></td><td>HTTP 查 npm registry</td><td>列出所有可用版本</td></tr><tr><td><code>opm bun outdated [-g]</code></td><td><code>bun outdated</code></td><td>列出过期包</td></tr><tr><td><code>opm bun install <name> [version]</code></td><td><code>bun add <name>@<version></code></td><td>安装包</td></tr><tr><td><code>opm bun uninstall <name></code></td><td><code>bun remove <name></code></td><td>卸载包</td></tr><tr><td><code>opm bun upgrade <name></code></td><td><code>bun update <name></code></td><td>升级包</td></tr><tr><td><code>opm bun cache clean</code></td><td><code>bun pm cache rm</code></td><td>清理缓存</td></tr></tbody></table>
|
|
194
191
|
<h2>镜像预设</h2>
|
|
195
192
|
<table><thead><tr><th>预设名</th><th>地址</th></tr></thead><tbody><tr><td><code>official</code></td><td><code>https://registry.npmjs.org/</code></td></tr><tr><td><code>taobao</code></td><td><code>https://registry.npmmirror.com/</code></td></tr><tr><td><code>huawei</code></td><td><code>https://cmc.centralrepo.rnd.huawei.com/artifactory/api/npm/npm-central-repo/</code></td></tr></tbody></table>
|
|
196
193
|
<blockquote>镜像通过 <code>BUN_CONFIG_REGISTRY</code> 环境变量传递给 bun 命令。</blockquote>
|
|
@@ -199,7 +196,6 @@ opm brew help</code></pre></div>
|
|
|
199
196
|
opm bun registry set taobao
|
|
200
197
|
opm bun search axios
|
|
201
198
|
opm bun info react
|
|
202
|
-
opm bun list
|
|
203
199
|
opm bun outdated
|
|
204
200
|
opm bun install axios
|
|
205
201
|
opm bun install react@18
|
|
@@ -236,7 +232,7 @@ opm cft registry set official</code></pre></div>
|
|
|
236
232
|
<div id="managers_composer" class="doc-content" style="display:none;"><h1>composer 命令对照表</h1>
|
|
237
233
|
<p><code>@wwkit/opm</code> 统一命令与 Composer(PHP)原始命令的映射关系。</p>
|
|
238
234
|
<h2>命令对照</h2>
|
|
239
|
-
<table><thead><tr><th>统一命令</th><th>原始命令</th><th>说明</th></tr></thead><tbody><tr><td><code>opm composer version</code></td><td><code>composer --version</code></td><td
|
|
235
|
+
<table><thead><tr><th>统一命令</th><th>原始命令</th><th>说明</th></tr></thead><tbody><tr><td><code>opm composer version [name]</code></td><td><code>composer --version</code></td><td>无 name 显示 composer 本身版本;有 name 显示包在项目作用域的版本(无全局作用域,global 显示未安装)</td></tr><tr><td><code>opm composer registry</code></td><td>读 <code>~/.config/opm/config.json5</code> 的 <code>composer.registry.active</code></td><td>查询配置中的激活镜像(不读系统配置)</td></tr><tr><td><code>opm composer registry set <url|preset></code></td><td>写 <code>~/.config/opm/config.json5</code> 的 <code>composer.registry.active</code></td><td>设置激活镜像(支持预设名;镜像作用于 search/info/versions 的 P2 元数据拉取)</td></tr><tr><td><code>opm composer registry presets</code></td><td>—</td><td>列出可用镜像预设</td></tr><tr><td><code>opm composer search <name></code></td><td><code>{registry}/p2/{name}.json</code></td><td>查询包在源是否可用(返回最新版本 + 版本列表)</td></tr><tr><td><code>opm composer search <name> <version></code></td><td><code>{registry}/p2/{name}.json</code></td><td>查询指定版本是否可用</td></tr><tr><td><code>opm composer view <name></code></td><td>读 <code>vendor/composer/installed.json</code></td><td>查询包在项目作用域的安装信息(无全局作用域,global 显示未安装)</td></tr><tr><td><code>opm composer info <name></code></td><td><code>{registry}/p2/{name}.json</code></td><td>查询包详情(描述/作者/主页/许可证等)</td></tr><tr><td><code>opm composer versions <name></code></td><td><code>{registry}/p2/{name}.json</code></td><td>列出所有可用版本</td></tr><tr><td><code>opm composer outdated</code></td><td><code>composer outdated --format=json</code></td><td>列出过期包</td></tr><tr><td><code>opm composer install <name></code></td><td><code>composer require <name> --no-interaction</code></td><td>安装包</td></tr><tr><td><code>opm composer install <name> <version></code></td><td><code>composer require <name>:<version> --no-interaction</code></td><td>安装指定版本约束</td></tr><tr><td><code>opm composer uninstall <name></code></td><td><code>composer remove <name> --no-interaction</code></td><td>卸载包</td></tr><tr><td><code>opm composer upgrade <name></code></td><td><code>composer update <name> --no-interaction</code></td><td>升级包</td></tr><tr><td><code>opm composer cache clean</code></td><td><code>composer clear-cache</code></td><td>清理缓存</td></tr><tr><td><code>opm composer help</code></td><td>—</td><td>显示 composer 命令清单</td></tr></tbody></table>
|
|
240
236
|
<h2>镜像预设</h2>
|
|
241
237
|
<table><thead><tr><th>预设名</th><th>地址</th></tr></thead><tbody><tr><td><code>official</code></td><td><code>https://repo.packagist.org</code></td></tr><tr><td><code>aliyun</code></td><td><code>https://mirrors.aliyun.com/composer</code></td></tr><tr><td><code>tencent</code></td><td><code>https://mirrors.cloud.tencent.com/composer</code></td></tr></tbody></table>
|
|
242
238
|
<blockquote>镜像作用于 search/info/versions 的 Packagist P2 元数据拉取(<code>{base}/p2/{vendor}/{package}.json</code>)。<br>install/upgrade 使用 composer CLI 自身的仓库配置(项目 composer.json / 全局 config)。</blockquote>
|
|
@@ -268,9 +264,6 @@ opm composer info monolog/monolog
|
|
|
268
264
|
# 列出 monolog/monolog 所有可用版本
|
|
269
265
|
opm composer versions monolog/monolog
|
|
270
266
|
|
|
271
|
-
# 列出所有已安装包
|
|
272
|
-
opm composer list
|
|
273
|
-
|
|
274
267
|
# 列出过期包
|
|
275
268
|
opm composer outdated
|
|
276
269
|
|
|
@@ -310,7 +303,7 @@ opm config python.registry</code></pre></div>
|
|
|
310
303
|
<div id="managers_dnf" class="doc-content" style="display:none;"><h1>dnf 命令对照表</h1>
|
|
311
304
|
<p><code>@wwkit/opm</code> 统一命令管理 dnf 包(Fedora / RHEL / EulerOS 等 rpm 系,系统级)。</p>
|
|
312
305
|
<h2>命令对照</h2>
|
|
313
|
-
<table><thead><tr><th>统一命令</th><th>原始命令</th><th>说明</th></tr></thead><tbody><tr><td><code>opm dnf version</code></td><td><code>dnf --version</code></td><td
|
|
306
|
+
<table><thead><tr><th>统一命令</th><th>原始命令</th><th>说明</th></tr></thead><tbody><tr><td><code>opm dnf version [name]</code></td><td><code>dnf --version</code></td><td>无 name 显示 dnf 版本;有 name 显示包在全局作用域的版本(无项目作用域,project 显示未安装)</td></tr><tr><td><code>opm dnf registry</code></td><td>读 <code>/etc/yum.repos.d/opm.repo</code></td><td>查询当前启用仓库</td></tr><tr><td><code>opm dnf registry set <url|preset></code></td><td>写 <code>/etc/yum.repos.d/opm.repo</code> + <code>dnf clean</code></td><td>设置镜像仓库</td></tr><tr><td><code>opm dnf registry presets</code></td><td>—</td><td>列出可用镜像预设</td></tr><tr><td><code>opm dnf search <name></code></td><td><code>dnf search</code></td><td>查询包在源是否可用</td></tr><tr><td><code>opm dnf view <name></code></td><td><code>dnf list installed</code></td><td>查询包在全局作用域的安装信息(无项目作用域,project 显示未安装)</td></tr><tr><td><code>opm dnf info <name></code></td><td><code>dnf info</code></td><td>包详情</td></tr><tr><td><code>opm dnf versions <name></code></td><td><code>dnf list --showduplicates</code></td><td>所有可用版本</td></tr><tr><td><code>opm dnf outdated</code></td><td><code>dnf check-update</code></td><td>过期包</td></tr><tr><td><code>opm dnf install <name></code></td><td><code>dnf install</code></td><td>安装</td></tr><tr><td><code>opm dnf uninstall <name></code></td><td><code>dnf remove</code></td><td>卸载</td></tr><tr><td><code>opm dnf upgrade <name></code></td><td><code>dnf upgrade</code></td><td>升级</td></tr><tr><td><code>opm dnf cache clean</code></td><td><code>dnf clean all</code></td><td>清理缓存</td></tr></tbody></table>
|
|
314
307
|
<h2>镜像预设</h2>
|
|
315
308
|
<table><thead><tr><th>预设名</th><th>地址</th></tr></thead><tbody><tr><td><code>hce</code></td><td><code>http://his-mirrors.huawei.com/install/hce/2.0/os/x86_64/</code></td></tr><tr><td><code>hce-updates</code></td><td><code>http://his-mirrors.huawei.com/install/hce/2.0/updates/x86_64/</code></td></tr><tr><td><code>fedora</code></td><td><code>https://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/$basearch/os/</code></td></tr><tr><td><code>fedora-updates</code></td><td><code>https://download.fedoraproject.org/pub/fedora/linux/updates/$releasever/Everything/$basearch/</code></td></tr><tr><td><code>epel</code></td><td><code>https://dl.fedoraproject.org/pub/epel/$releasever/Everything/$basearch/</code></td></tr><tr><td><code>epel-testing</code></td><td><code>https://dl.fedoraproject.org/pub/epel/testing/$releasever/Everything/$basearch/</code></td></tr></tbody></table>
|
|
316
309
|
<h2>示例</h2>
|
|
@@ -400,7 +393,7 @@ opm node upgrade</code></pre></div>
|
|
|
400
393
|
<div id="managers_npm" class="doc-content" style="display:none;"><h1>npm 命令对照表</h1>
|
|
401
394
|
<p><code>@wwkit/opm</code> 统一命令与 npm 原始命令的映射关系。</p>
|
|
402
395
|
<h2>命令对照</h2>
|
|
403
|
-
<table><thead><tr><th>统一命令</th><th>原始命令</th><th>说明</th></tr></thead><tbody><tr><td><code>opm npm version</code></td><td><code>npm --version</code></td><td
|
|
396
|
+
<table><thead><tr><th>统一命令</th><th>原始命令</th><th>说明</th></tr></thead><tbody><tr><td><code>opm npm version [name]</code></td><td><code>npm --version</code></td><td>无 name 显示 npm 本身版本;有 name 显示包在全局与项目作用域的版本</td></tr><tr><td><code>opm npm registry</code></td><td>读 <code>~/.config/opm/config.json5</code> 的 <code>npm.registry.active</code></td><td>查询配置中的激活镜像(不读系统配置)</td></tr><tr><td><code>opm npm registry set <url|preset></code></td><td>写 <code>~/.config/opm/config.json5</code> 的 <code>npm.registry.active</code></td><td>设置激活镜像(支持预设名,install/upgrade 自动带 <code>--registry</code>)</td></tr><tr><td><code>opm npm registry presets</code></td><td>—</td><td>列出可用镜像预设</td></tr><tr><td><code>opm npm search <name></code></td><td><code>npm view <name></code></td><td>查询包在源是否可用(返回最新版本 + 版本列表)</td></tr><tr><td><code>opm npm search <name> <version></code></td><td><code>npm view <name>@<version></code></td><td>查询指定版本是否可用</td></tr><tr><td><code>opm npm view <name></code></td><td><code>npm list <name></code> / 读 <code>node_modules/<name>/package.json</code></td><td>查询包在全局与项目作用域的安装信息</td></tr><tr><td><code>opm npm info <name></code></td><td><code>npm view <name></code></td><td>查询包详情(描述/作者/主页/许可证等)</td></tr><tr><td><code>opm npm versions <name></code></td><td><code>npm view <name> versions</code></td><td>列出所有可用版本</td></tr><tr><td><code>opm npm outdated</code></td><td><code>npm outdated</code></td><td>列出过期包</td></tr><tr><td><code>opm npm install <name></code></td><td><code>npm install <name></code></td><td>安装包</td></tr><tr><td><code>opm npm install <name> <version></code></td><td><code>npm install <name>@<version></code></td><td>安装指定版本</td></tr><tr><td><code>opm npm install -g <name></code></td><td><code>npm install -g <name></code></td><td>全局安装</td></tr><tr><td><code>opm npm uninstall <name></code></td><td><code>npm uninstall <name></code></td><td>卸载包</td></tr><tr><td><code>opm npm uninstall -g <name></code></td><td><code>npm uninstall -g <name></code></td><td>全局卸载</td></tr><tr><td><code>opm npm upgrade <name></code></td><td><code>npm install <name>@latest</code></td><td>升级包到最新版本</td></tr><tr><td><code>opm npm upgrade -g <name></code></td><td><code>npm install -g <name>@latest</code></td><td>全局升级</td></tr><tr><td><code>opm npm cache clean</code></td><td><code>npm cache clean --force</code></td><td>清理缓存</td></tr><tr><td><code>opm npm help</code></td><td>—</td><td>显示 npm 命令清单</td></tr></tbody></table>
|
|
404
397
|
<h2>镜像预设</h2>
|
|
405
398
|
<table><thead><tr><th>预设名</th><th>地址</th></tr></thead><tbody><tr><td><code>official</code></td><td><code>https://registry.npmjs.org/</code></td></tr><tr><td><code>taobao</code></td><td><code>https://registry.npmmirror.com/</code></td></tr><tr><td><code>huawei</code></td><td><code>https://cmc.centralrepo.rnd.huawei.com/artifactory/api/npm/npm-central-repo/</code></td></tr></tbody></table>
|
|
406
399
|
<h2>选项</h2>
|
|
@@ -431,9 +424,6 @@ opm npm info axios
|
|
|
431
424
|
# 列出 axios 所有版本
|
|
432
425
|
opm npm versions axios
|
|
433
426
|
|
|
434
|
-
# 列出所有已安装包
|
|
435
|
-
opm npm list
|
|
436
|
-
|
|
437
427
|
# 列出过期包
|
|
438
428
|
opm npm outdated
|
|
439
429
|
|
|
@@ -460,7 +450,7 @@ opm npm help</code></pre></div>
|
|
|
460
450
|
<div id="managers_nvm" class="doc-content" style="display:none;"><h1>nvm 命令对照表</h1>
|
|
461
451
|
<p><code>@wwkit/opm</code> 统一命令管理 nvm 自身(安装/升级/卸载)。</p>
|
|
462
452
|
<h2>命令对照</h2>
|
|
463
|
-
<table><thead><tr><th>统一命令</th><th>原始命令</th><th>说明</th></tr></thead><tbody><tr><td><code>opm nvm version</code></td><td><code>nvm --version</code></td><td>查看 nvm 版本</td></tr><tr><td><code>opm nvm registry</code></td><td>读 <code>~/.config/opm/config.json5</code> 的 <code>nvm.registry.active</code></td><td>查询 nvm git 镜像</td></tr><tr><td><code>opm nvm registry set <url|preset></code></td><td>写 <code>~/.config/opm/config.json5</code></td><td>设置 nvm git 镜像</td></tr><tr><td><code>opm nvm registry presets</code></td><td>—</td><td>列出可用镜像预设</td></tr><tr><td><code>opm nvm install</code></td><td><code>git clone <mirror> ~/.nvm</code> + 写 shell profile</td><td>安装 nvm</td></tr><tr><td><code>opm nvm upgrade</code></td><td><code>cd ~/.nvm && git pull --tags</code></td><td>更新 nvm</td></tr><tr><td><code>opm nvm uninstall</code></td><td><code>rm -rf ~/.nvm</code></td><td>卸载 nvm</td></tr><tr><td><code>opm nvm dir</code></td><td>返回 <code>~/.nvm</code> 安装目录</td></tr></tbody></table>
|
|
453
|
+
<table><thead><tr><th>统一命令</th><th>原始命令</th><th>说明</th></tr></thead><tbody><tr><td><code>opm nvm version</code></td><td><code>nvm --version</code></td><td>查看 nvm 版本</td></tr><tr><td><code>opm nvm registry</code></td><td>读 <code>~/.config/opm/config.json5</code> 的 <code>nvm.registry.active</code></td><td>查询 nvm git 镜像</td></tr><tr><td><code>opm nvm registry set <url|preset></code></td><td>写 <code>~/.config/opm/config.json5</code></td><td>设置 nvm git 镜像</td></tr><tr><td><code>opm nvm registry presets</code></td><td>—</td><td>列出可用镜像预设</td></tr><tr><td><code>opm nvm install</code></td><td><code>git clone <mirror> ~/.nvm</code> + 写 shell profile</td><td>安装 nvm</td></tr><tr><td><code>opm nvm upgrade</code></td><td><code>cd ~/.nvm && git pull --tags</code></td><td>更新 nvm</td></tr><tr><td><code>opm nvm uninstall</code></td><td><code>rm -rf ~/.nvm</code></td><td>卸载 nvm</td></tr><tr><td><code>opm nvm dir</code></td><td>返回 <code>~/.nvm</code> 安装目录</td></tr><tr><td><code>opm nvm list</code></td><td><code>nvm ls --no-colors</code></td><td>列出已安装 Node.js 版本</td></tr></tbody></table>
|
|
464
454
|
<h2>镜像预设</h2>
|
|
465
455
|
<table><thead><tr><th>预设名</th><th>地址</th></tr></thead><tbody><tr><td><code>official</code></td><td><code>https://github.com/nvm-sh/nvm.git</code></td></tr><tr><td><code>gitee</code></td><td><code>https://gitee.com/mirrors/nvm.git</code></td></tr></tbody></table>
|
|
466
456
|
<h2>示例</h2>
|
|
@@ -468,6 +458,7 @@ opm npm help</code></pre></div>
|
|
|
468
458
|
opm nvm registry set gitee
|
|
469
459
|
opm nvm install
|
|
470
460
|
opm nvm upgrade
|
|
461
|
+
opm nvm list
|
|
471
462
|
opm nvm dir
|
|
472
463
|
opm nvm uninstall</code></pre></div>
|
|
473
464
|
<div id="managers_php" class="doc-content" style="display:none;"><h1>php 命令对照表</h1>
|
|
@@ -492,7 +483,7 @@ opm php upgrade</code></pre></div>
|
|
|
492
483
|
<div id="managers_phpenv" class="doc-content" style="display:none;"><h1>phpenv 命令对照表</h1>
|
|
493
484
|
<p><code>@wwkit/opm</code> 统一命令管理 phpenv 自身(安装/升级/卸载)。</p>
|
|
494
485
|
<h2>命令对照</h2>
|
|
495
|
-
<table><thead><tr><th>统一命令</th><th>原始命令</th><th>说明</th></tr></thead><tbody><tr><td><code>opm phpenv version</code></td><td><code>phpenv --version</code></td><td>查看 phpenv 版本</td></tr><tr><td><code>opm phpenv registry</code></td><td>读 <code>~/.config/opm/config.json5</code> 的 <code>phpenv.registry.active</code></td><td>查询 phpenv git 镜像</td></tr><tr><td><code>opm phpenv registry set <url|preset></code></td><td>写 <code>~/.config/opm/config.json5</code></td><td>设置 phpenv git 镜像</td></tr><tr><td><code>opm phpenv registry presets</code></td><td>—</td><td>列出可用镜像预设</td></tr><tr><td><code>opm phpenv install</code></td><td><code>git clone <mirror> ~/.phpenv</code> + <code>git clone php-build</code> + 写 shell profile</td><td>安装 phpenv + php-build 插件</td></tr><tr><td><code>opm phpenv upgrade</code></td><td><code>cd ~/.phpenv && git pull</code> + <code>cd plugins/php-build && git pull</code></td><td>更新 phpenv + php-build</td></tr><tr><td><code>opm phpenv uninstall</code></td><td><code>rm -rf ~/.phpenv</code></td><td>卸载 phpenv</td></tr><tr><td><code>opm phpenv dir</code></td><td>返回 <code>~/.phpenv</code> 安装目录</td></tr></tbody></table>
|
|
486
|
+
<table><thead><tr><th>统一命令</th><th>原始命令</th><th>说明</th></tr></thead><tbody><tr><td><code>opm phpenv version</code></td><td><code>phpenv --version</code></td><td>查看 phpenv 版本</td></tr><tr><td><code>opm phpenv registry</code></td><td>读 <code>~/.config/opm/config.json5</code> 的 <code>phpenv.registry.active</code></td><td>查询 phpenv git 镜像</td></tr><tr><td><code>opm phpenv registry set <url|preset></code></td><td>写 <code>~/.config/opm/config.json5</code></td><td>设置 phpenv git 镜像</td></tr><tr><td><code>opm phpenv registry presets</code></td><td>—</td><td>列出可用镜像预设</td></tr><tr><td><code>opm phpenv install</code></td><td><code>git clone <mirror> ~/.phpenv</code> + <code>git clone php-build</code> + 写 shell profile</td><td>安装 phpenv + php-build 插件</td></tr><tr><td><code>opm phpenv upgrade</code></td><td><code>cd ~/.phpenv && git pull</code> + <code>cd plugins/php-build && git pull</code></td><td>更新 phpenv + php-build</td></tr><tr><td><code>opm phpenv uninstall</code></td><td><code>rm -rf ~/.phpenv</code></td><td>卸载 phpenv</td></tr><tr><td><code>opm phpenv dir</code></td><td>返回 <code>~/.phpenv</code> 安装目录</td></tr><tr><td><code>opm phpenv list</code></td><td><code>phpenv versions</code></td><td>列出已安装 PHP 版本</td></tr></tbody></table>
|
|
496
487
|
<h2>镜像预设</h2>
|
|
497
488
|
<table><thead><tr><th>预设名</th><th>地址</th></tr></thead><tbody><tr><td><code>official</code></td><td><code>https://github.com/phpenv/phpenv.git</code></td></tr><tr><td><code>gitee</code></td><td><code>https://gitee.com/mirrors/phpenv.git</code></td></tr></tbody></table>
|
|
498
489
|
<h2>示例</h2>
|
|
@@ -500,12 +491,13 @@ opm php upgrade</code></pre></div>
|
|
|
500
491
|
opm phpenv registry set gitee
|
|
501
492
|
opm phpenv install
|
|
502
493
|
opm phpenv upgrade
|
|
494
|
+
opm phpenv list
|
|
503
495
|
opm phpenv dir
|
|
504
496
|
opm phpenv uninstall</code></pre></div>
|
|
505
497
|
<div id="managers_pip" class="doc-content" style="display:none;"><h1>pip 命令对照表</h1>
|
|
506
498
|
<p><code>@wwkit/opm</code> 统一命令与 pip 原始命令的映射关系。</p>
|
|
507
499
|
<h2>命令对照</h2>
|
|
508
|
-
<table><thead><tr><th>统一命令</th><th>原始命令</th><th>说明</th></tr></thead><tbody><tr><td><code>opm pip version</code></td><td><code>pip --version</code></td><td
|
|
500
|
+
<table><thead><tr><th>统一命令</th><th>原始命令</th><th>说明</th></tr></thead><tbody><tr><td><code>opm pip version [name]</code></td><td><code>pip --version</code></td><td>无 name 显示 pip 本身版本;有 name 显示包在全局与项目作用域的版本</td></tr><tr><td><code>opm pip registry</code></td><td>读 <code>~/.config/opm/config.json5</code> 的 <code>pip.registry.active</code></td><td>查询配置中的激活镜像(不读系统配置)</td></tr><tr><td><code>opm pip registry set <url|preset></code></td><td>写 <code>~/.config/opm/config.json5</code> 的 <code>pip.registry.active</code></td><td>设置激活镜像(支持预设名,install/upgrade 自动带 <code>--index-url</code>)</td></tr><tr><td><code>opm pip registry presets</code></td><td>—</td><td>列出可用镜像预设</td></tr><tr><td><code>opm pip search <name></code></td><td>PyPI JSON API / simple index</td><td>查询包在源是否可用(返回最新版本 + 版本列表)</td></tr><tr><td><code>opm pip search <name> <version></code></td><td>PyPI JSON API / simple index</td><td>查询指定版本是否可用</td></tr><tr><td><code>opm pip view <name></code></td><td><code>pip show <name></code></td><td>查询包在全局与项目作用域的安装信息</td></tr><tr><td><code>opm pip info <name></code></td><td>PyPI JSON API / <code>pip show <name></code></td><td>查询包详情(描述/作者/主页/许可证等)</td></tr><tr><td><code>opm pip versions <name></code></td><td>PyPI JSON API / simple index</td><td>列出所有可用版本</td></tr><tr><td><code>opm pip outdated</code></td><td><code>pip list --outdated</code></td><td>列出过期包</td></tr><tr><td><code>opm pip install <name></code></td><td><code>pip install <name></code></td><td>安装包</td></tr><tr><td><code>opm pip install <name> <version></code></td><td><code>pip install <name>==<version></code></td><td>安装指定版本</td></tr><tr><td><code>opm pip uninstall <name></code></td><td><code>pip uninstall -y <name></code></td><td>卸载包</td></tr><tr><td><code>opm pip upgrade <name></code></td><td><code>pip install --upgrade <name></code></td><td>升级包到最新版本</td></tr><tr><td><code>opm pip cache clean</code></td><td><code>pip cache purge</code></td><td>清理缓存</td></tr><tr><td><code>opm pip help</code></td><td>—</td><td>显示 pip 命令清单</td></tr></tbody></table>
|
|
509
501
|
<h2>镜像预设</h2>
|
|
510
502
|
<table><thead><tr><th>预设名</th><th>地址</th></tr></thead><tbody><tr><td><code>official</code></td><td><code>https://pypi.org/simple</code></td></tr><tr><td><code>tsinghua</code></td><td><code>https://pypi.tuna.tsinghua.edu.cn/simple</code></td></tr><tr><td><code>huawei</code></td><td><code>https://cmc.centralrepo.rnd.huawei.com/artifactory/api/pypi/pypi-repo/simple</code></td></tr></tbody></table>
|
|
511
503
|
<h2>选项</h2>
|
|
@@ -536,9 +528,6 @@ opm pip info requests
|
|
|
536
528
|
# 列出 requests 所有版本
|
|
537
529
|
opm pip versions requests
|
|
538
530
|
|
|
539
|
-
# 列出所有已安装包
|
|
540
|
-
opm pip list
|
|
541
|
-
|
|
542
531
|
# 列出过期包
|
|
543
532
|
opm pip outdated
|
|
544
533
|
|
|
@@ -623,7 +612,7 @@ opm python upgrade</code></pre></div>
|
|
|
623
612
|
<p><code>@wwkit/opm</code> 统一命令管理 uv 自身(安装/升级/卸载)。</p>
|
|
624
613
|
<p>uv 是 Astral 出品的快速 Python 包/版本管理器(Rust 实现),替代 pyenv + pip。</p>
|
|
625
614
|
<h2>命令对照</h2>
|
|
626
|
-
<table><thead><tr><th>统一命令</th><th>原始命令</th><th>说明</th></tr></thead><tbody><tr><td><code>opm uv version</code></td><td><code>uv --version</code></td><td>查看 uv 版本</td></tr><tr><td><code>opm uv registry</code></td><td>读 <code>~/.config/opm/config.json5</code> 的 <code>uv.registry.active</code></td><td>查询激活的安装脚本 URL</td></tr><tr><td><code>opm uv registry set <url|preset></code></td><td>写 <code>~/.config/opm/config.json5</code> 的 <code>uv.registry.active</code></td><td>设置激活安装脚本 URL(支持预设名)</td></tr><tr><td><code>opm uv registry presets</code></td><td>—</td><td>列出可用镜像预设</td></tr><tr><td><code>opm uv install</code></td><td><code>curl -LsSf <active> | sh</code></td><td>安装 uv(脚本 URL 来自 <code>uv.registry.active</code>)</td></tr><tr><td><code>opm uv upgrade</code></td><td><code>uv self update</code></td><td>更新 uv</td></tr><tr><td><code>opm uv uninstall</code></td><td><code>rm ~/.local/bin/uv</code> + <code>rm -rf ~/.local/share/uv</code></td><td>卸载 uv</td></tr><tr><td><code>opm uv dir</code></td><td>返回 uv 安装目录</td></tr></tbody></table>
|
|
615
|
+
<table><thead><tr><th>统一命令</th><th>原始命令</th><th>说明</th></tr></thead><tbody><tr><td><code>opm uv version</code></td><td><code>uv --version</code></td><td>查看 uv 版本</td></tr><tr><td><code>opm uv registry</code></td><td>读 <code>~/.config/opm/config.json5</code> 的 <code>uv.registry.active</code></td><td>查询激活的安装脚本 URL</td></tr><tr><td><code>opm uv registry set <url|preset></code></td><td>写 <code>~/.config/opm/config.json5</code> 的 <code>uv.registry.active</code></td><td>设置激活安装脚本 URL(支持预设名)</td></tr><tr><td><code>opm uv registry presets</code></td><td>—</td><td>列出可用镜像预设</td></tr><tr><td><code>opm uv install</code></td><td><code>curl -LsSf <active> | sh</code></td><td>安装 uv(脚本 URL 来自 <code>uv.registry.active</code>)</td></tr><tr><td><code>opm uv upgrade</code></td><td><code>uv self update</code></td><td>更新 uv</td></tr><tr><td><code>opm uv uninstall</code></td><td><code>rm ~/.local/bin/uv</code> + <code>rm -rf ~/.local/share/uv</code></td><td>卸载 uv</td></tr><tr><td><code>opm uv dir</code></td><td>返回 uv 安装目录</td></tr><tr><td><code>opm uv list</code></td><td><code>uv python list --only-installed</code></td><td>列出已安装 Python 版本</td></tr></tbody></table>
|
|
627
616
|
<blockquote>安装脚本 URL 通过 <code>uv.registry.active</code> 配置(<code>opm uv registry set <url></code>);Windows 仍使用官方 <code>install.ps1</code>。</blockquote>
|
|
628
617
|
<h2>示例</h2>
|
|
629
618
|
<pre><code class="lang-bash">opm uv version
|
|
@@ -632,6 +621,7 @@ opm uv registry presets
|
|
|
632
621
|
opm uv registry set official
|
|
633
622
|
opm uv install
|
|
634
623
|
opm uv upgrade
|
|
624
|
+
opm uv list
|
|
635
625
|
opm uv dir
|
|
636
626
|
opm uv uninstall</code></pre></div>
|
|
637
627
|
<div id="packages_opencode" class="doc-content" style="display:none;"><h1>opencode 命令对照</h1>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wwkit/opm",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"author": "bluesliu <langcai163@163.com>",
|
|
5
5
|
"description": "Unified CLI — package management (npm/pip/dnf/apt) + config view + opencode maintenance",
|
|
6
6
|
"type": "module",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"basic-ftp": "^6.2.1",
|
|
36
36
|
"extract-zip": "^2.0.1",
|
|
37
37
|
"systeminformation": "^5.23.0",
|
|
38
|
-
"@wwkit/harness": "1.0.
|
|
39
|
-
"@wwkit/shared": "1.0.
|
|
38
|
+
"@wwkit/harness": "1.0.19",
|
|
39
|
+
"@wwkit/shared": "1.0.14"
|
|
40
40
|
},
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"registry": "https://registry.npmjs.org/",
|
package/src/cli/groups/ensure.js
CHANGED
|
@@ -21,6 +21,18 @@ const RUNTIMES = {
|
|
|
21
21
|
python: () => new PythonManager(),
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* 按前缀(x 或 x.y)匹配已安装版本列表,返回完整版本号
|
|
26
|
+
* @param {{ version: string }[]} items
|
|
27
|
+
* @param {string} version
|
|
28
|
+
* @returns {string}
|
|
29
|
+
*/
|
|
30
|
+
export function resolveVersion(items, version) {
|
|
31
|
+
const v = version.replace(/^v/, '')
|
|
32
|
+
const hit = items.find((i) => i.version.replace(/^v/, '').startsWith(v))
|
|
33
|
+
return hit ? hit.version : ''
|
|
34
|
+
}
|
|
35
|
+
|
|
24
36
|
export class EnsureGroup {
|
|
25
37
|
constructor() {
|
|
26
38
|
this.name = 'ensure'
|
|
@@ -47,11 +59,18 @@ export class EnsureGroup {
|
|
|
47
59
|
|
|
48
60
|
let satisfied = false
|
|
49
61
|
let currentVersion = ''
|
|
62
|
+
let installVersion = ''
|
|
50
63
|
|
|
51
64
|
if (version) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
65
|
+
// 支持 x / x.y 简写:按前缀匹配已安装版本
|
|
66
|
+
const installed = await manager.listInstalled()
|
|
67
|
+
const full = resolveVersion(installed, version)
|
|
68
|
+
if (full) {
|
|
69
|
+
satisfied = true
|
|
70
|
+
currentVersion = full
|
|
71
|
+
} else {
|
|
72
|
+
installVersion = version
|
|
73
|
+
}
|
|
55
74
|
} else {
|
|
56
75
|
const result = await manager.getVersion()
|
|
57
76
|
satisfied = result.installed
|
|
@@ -63,7 +82,9 @@ export class EnsureGroup {
|
|
|
63
82
|
return
|
|
64
83
|
}
|
|
65
84
|
|
|
66
|
-
|
|
85
|
+
if (!installVersion) {
|
|
86
|
+
installVersion = manager.getDefaultVersion ? manager.getDefaultVersion() : ''
|
|
87
|
+
}
|
|
67
88
|
if (!installVersion) {
|
|
68
89
|
console.error(`No version specified and no defaultVersion configured for ${runtime}`)
|
|
69
90
|
process.exit(1)
|
package/src/cli/groups/nvm.js
CHANGED
|
@@ -13,7 +13,7 @@ import os from 'node:os'
|
|
|
13
13
|
import { ToolManagerGroup } from './version-manager.js'
|
|
14
14
|
import { Shell } from '@wwkit/shared'
|
|
15
15
|
import { getActiveRegistry } from '../../config.js'
|
|
16
|
-
import { installNvm } from '../../managers/node.js'
|
|
16
|
+
import { installNvm, parseNvmInstalled } from '../../managers/node.js'
|
|
17
17
|
|
|
18
18
|
const shell = new Shell()
|
|
19
19
|
|
|
@@ -35,6 +35,8 @@ export class NvmGroup extends ToolManagerGroup {
|
|
|
35
35
|
getPath: () => getNvmDir(),
|
|
36
36
|
versionCmd: () => `source "${path.join(getNvmDir(), 'nvm.sh')}" && nvm --version`,
|
|
37
37
|
parseVersion: (out) => out.trim(),
|
|
38
|
+
listCmd: () => `source "${path.join(getNvmDir(), 'nvm.sh')}" && nvm ls --no-colors`,
|
|
39
|
+
parseList: parseNvmInstalled,
|
|
38
40
|
install: (proxy) => installNvm(proxy),
|
|
39
41
|
upgrade: () => {
|
|
40
42
|
const nvmDir = getNvmDir()
|
|
@@ -62,6 +64,7 @@ export class NvmGroup extends ToolManagerGroup {
|
|
|
62
64
|
['upgrade', 'Update nvm (git pull)'],
|
|
63
65
|
['uninstall', 'Remove nvm (~/.nvm)'],
|
|
64
66
|
['dir', 'Show nvm install directory'],
|
|
67
|
+
['list', 'List installed Node.js versions (nvm ls --no-colors)'],
|
|
65
68
|
['help', 'Show this help'],
|
|
66
69
|
],
|
|
67
70
|
examples: [
|
|
@@ -71,6 +74,7 @@ export class NvmGroup extends ToolManagerGroup {
|
|
|
71
74
|
'opm nvm install',
|
|
72
75
|
'opm nvm upgrade',
|
|
73
76
|
'opm nvm dir',
|
|
77
|
+
'opm nvm list',
|
|
74
78
|
],
|
|
75
79
|
})
|
|
76
80
|
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* overlay 命令组 — 将本地开发源码覆盖到全局 npm 安装位置
|
|
3
|
+
*
|
|
4
|
+
* 用途:跳过发布流程,把最近修改的代码放到实际包安装位置用于实际测试。
|
|
5
|
+
*
|
|
6
|
+
* opm overlay 覆盖 cwd 包到全局安装
|
|
7
|
+
* opm overlay -f /path/to/pkg 指定源目录
|
|
8
|
+
* opm overlay -t /custom/node_modules 指定目标目录
|
|
9
|
+
* opm overlay --dry-run 预览将要复制的文件
|
|
10
|
+
*
|
|
11
|
+
* 逻辑:
|
|
12
|
+
* 1. 读取源目录 package.json 获取包名
|
|
13
|
+
* 2. 默认目标 = npm root -g,拼接 <globalRoot>/<pkgName>
|
|
14
|
+
* 3. 排除 node_modules/.git 等,逐文件复制(保留权限)
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import fs from 'node:fs'
|
|
18
|
+
import path from 'node:path'
|
|
19
|
+
import { execSync } from 'node:child_process'
|
|
20
|
+
import { parseFlags } from '../helpers/args.js'
|
|
21
|
+
import { output } from '../../formatter.js'
|
|
22
|
+
|
|
23
|
+
const EXCLUDE = new Set(['node_modules', '.git', '.DS_Store', 'Thumbs.db'])
|
|
24
|
+
|
|
25
|
+
export class OverlayGroup {
|
|
26
|
+
constructor() {
|
|
27
|
+
this.name = 'overlay'
|
|
28
|
+
this.desc = 'Overlay local package source onto global npm install (bypass publish)'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async run(argv) {
|
|
32
|
+
const parsed = parseFlags(argv)
|
|
33
|
+
|
|
34
|
+
if (parsed.flags.help === 'true' || parsed.flags.h === 'true' || parsed.positional[0] === 'help') {
|
|
35
|
+
this.printHelp()
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const dryRun = parsed.flags['dry-run'] === 'true'
|
|
40
|
+
|
|
41
|
+
const from = path.resolve(parsed.flags.f || parsed.flags.from || process.cwd())
|
|
42
|
+
if (!fs.existsSync(from) || !fs.statSync(from).isDirectory()) {
|
|
43
|
+
output({ error: 'Source directory does not exist or is not a directory', from })
|
|
44
|
+
process.exit(1)
|
|
45
|
+
}
|
|
46
|
+
const srcPkgPath = path.join(from, 'package.json')
|
|
47
|
+
if (!fs.existsSync(srcPkgPath)) {
|
|
48
|
+
output({ error: 'No package.json in source directory root (not an npm project)', from, hint: 'Use -f/--to to specify a directory containing package.json' })
|
|
49
|
+
process.exit(1)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const pkg = JSON.parse(fs.readFileSync(srcPkgPath, 'utf8'))
|
|
53
|
+
const pkgName = pkg.name
|
|
54
|
+
if (!pkgName) {
|
|
55
|
+
output({ error: 'package.json has no name field', from })
|
|
56
|
+
process.exit(1)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const to = parsed.flags.t || parsed.flags.to
|
|
60
|
+
let globalRoot
|
|
61
|
+
if (to) {
|
|
62
|
+
globalRoot = path.resolve(to)
|
|
63
|
+
if (path.basename(globalRoot) !== 'node_modules') {
|
|
64
|
+
output({ error: 'Target directory must end with "node_modules"', to: globalRoot, hint: 'Example: /usr/local/lib/node_modules' })
|
|
65
|
+
process.exit(1)
|
|
66
|
+
}
|
|
67
|
+
if (!fs.existsSync(globalRoot) || !fs.statSync(globalRoot).isDirectory()) {
|
|
68
|
+
output({ error: 'Target node_modules directory does not exist', to: globalRoot })
|
|
69
|
+
process.exit(1)
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
try {
|
|
73
|
+
globalRoot = execSync('npm root -g', { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }).trim()
|
|
74
|
+
} catch {
|
|
75
|
+
output({ error: 'Failed to determine npm global root', hint: 'Use -t/--to to specify target directory' })
|
|
76
|
+
process.exit(1)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const targetDir = path.join(globalRoot, pkgName)
|
|
81
|
+
if (!fs.existsSync(targetDir)) {
|
|
82
|
+
output({
|
|
83
|
+
error: 'Target package not found in global install',
|
|
84
|
+
package: pkgName,
|
|
85
|
+
target: targetDir,
|
|
86
|
+
hint: `Install first: npm install -g ${pkgName}`,
|
|
87
|
+
})
|
|
88
|
+
process.exit(1)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const files = this._collectFiles(from)
|
|
92
|
+
|
|
93
|
+
if (dryRun) {
|
|
94
|
+
output({
|
|
95
|
+
package: pkgName,
|
|
96
|
+
from,
|
|
97
|
+
to: targetDir,
|
|
98
|
+
dryRun: true,
|
|
99
|
+
fileCount: files.length,
|
|
100
|
+
files: files.map((f) => path.relative(from, f)),
|
|
101
|
+
})
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
let copied = 0
|
|
106
|
+
for (const srcPath of files) {
|
|
107
|
+
const rel = path.relative(from, srcPath)
|
|
108
|
+
const destPath = path.join(targetDir, rel)
|
|
109
|
+
fs.mkdirSync(path.dirname(destPath), { recursive: true })
|
|
110
|
+
const stat = fs.statSync(srcPath)
|
|
111
|
+
fs.copyFileSync(srcPath, destPath)
|
|
112
|
+
fs.chmodSync(destPath, stat.mode)
|
|
113
|
+
copied++
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
output({
|
|
117
|
+
package: pkgName,
|
|
118
|
+
from,
|
|
119
|
+
to: targetDir,
|
|
120
|
+
fileCount: copied,
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 递归收集源目录下所有文件(排除 EXCLUDE 集合)
|
|
126
|
+
* @param {string} dir
|
|
127
|
+
* @returns {string[]}
|
|
128
|
+
* @private
|
|
129
|
+
*/
|
|
130
|
+
_collectFiles(dir) {
|
|
131
|
+
const result = []
|
|
132
|
+
const walk = (d) => {
|
|
133
|
+
for (const entry of fs.readdirSync(d, { withFileTypes: true })) {
|
|
134
|
+
if (EXCLUDE.has(entry.name)) continue
|
|
135
|
+
const full = path.join(d, entry.name)
|
|
136
|
+
if (entry.isDirectory()) {
|
|
137
|
+
walk(full)
|
|
138
|
+
} else {
|
|
139
|
+
result.push(full)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
walk(dir)
|
|
144
|
+
return result
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
printHelp() {
|
|
148
|
+
console.log(`
|
|
149
|
+
Usage: opm overlay [options]
|
|
150
|
+
|
|
151
|
+
Overlay local package source onto the global npm install location.
|
|
152
|
+
Copies all files (except node_modules/.git) from source to target,
|
|
153
|
+
overwriting existing files. Useful for testing local changes without
|
|
154
|
+
publishing.
|
|
155
|
+
|
|
156
|
+
Options:
|
|
157
|
+
-f, --from <dir> Source package directory (default: current directory)
|
|
158
|
+
-t, --to <dir> Target node_modules directory (default: npm root -g)
|
|
159
|
+
--dry-run Preview files to copy without writing
|
|
160
|
+
-h, --help Show this help
|
|
161
|
+
|
|
162
|
+
Examples:
|
|
163
|
+
opm overlay Overlay cwd package to global install
|
|
164
|
+
opm overlay -f /path/to/package Overlay specific package
|
|
165
|
+
opm overlay -t /custom/node_modules Overlay to custom target
|
|
166
|
+
opm overlay --dry-run Preview what would be copied
|
|
167
|
+
`)
|
|
168
|
+
}
|
|
169
|
+
}
|