@meshy3d/cli
v1.0.1
Published
Meshy3D CLI — distributed via npm with prebuilt Go binaries
Readme
@meshy3d/cli
A CLI written in Go, distributed through npm.
采用 esbuild / Biome 同款的 optionalDependencies 模式:安装时零编译、零运行期下载,
npm 只把匹配你当前操作系统/CPU 的那一个预编译二进制装到本地。
安装与使用
# 全局安装
npm install -g @meshy3d/cli
meshy3d hello --name world
meshy3d version
# 或者免安装直接跑
npx @meshy3d/cli hello --name Alice --shout输出示例:
$ meshy3d version
meshy3d 1.0.0 (darwin/arm64)
$ meshy3d hello --name Alice
Hello, Alice! — from a Go binary delivered via npm.工作原理
npm install -g @meshy3d/cli
│
▼
下载主包 @meshy3d/cli(只有一个 JS launcher,无二进制)
│
▼
主包声明了 5 个 optionalDependencies:
@meshy3d/cli-darwin-arm64 (os: darwin, cpu: arm64)
@meshy3d/cli-darwin-x64 (os: darwin, cpu: x64)
@meshy3d/cli-linux-arm64 (os: linux, cpu: arm64)
@meshy3d/cli-linux-x64 (os: linux, cpu: x64)
@meshy3d/cli-win32-x64 (os: win32, cpu: x64)
│
▼
npm 按 os/cpu 字段匹配 → 只装当前平台那一个,其余静默跳过
│
▼
运行 `meshy3d` → bin/cli.js (launcher)
│ require.resolve("@meshy3d/cli-<platform>/bin/meshy3d")
▼
spawnSync 调起对应的 Go 二进制,参数/stdio/退出码全透传要点:
- 零 postinstall 脚本、零运行期网络下载 —— 二进制是 npm 包内容的一部分,
因此在
--ignore-scripts、离线缓存、企业内网等场景下都稳定。 - 每个平台子包通过
package.json的os/cpu字段声明适用平台, npm 会自动跳过不匹配的可选依赖且不报错。 - launcher 用
require.resolve定位二进制,再用child_process.spawnSync以stdio: "inherit"调起,退出码原样返回。
支持的平台
| OS | Arch | npm 子包 |
| ------- | ----- | ---------------------------- |
| macOS | arm64 | @meshy3d/cli-darwin-arm64 |
| macOS | x64 | @meshy3d/cli-darwin-x64 |
| Linux | arm64 | @meshy3d/cli-linux-arm64 |
| Linux | x64 | @meshy3d/cli-linux-x64 |
| Windows | x64 | @meshy3d/cli-win32-x64 |
如果你的网络/工具链跳过了可选依赖,运行
meshy3d会给出明确的排查提示。 也可用环境变量MESHY3D_BINARY=/path/to/binary meshy3d ...指定二进制(调试用)。
License
MIT
