@ut-protocol/utp 0.5.2-beta.1

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.
Files changed (2) hide show
  1. package/bin/utp +42 -0
  2. package/package.json +20 -0
package/bin/utp ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env node
2
+ // 主包入口:按当前平台找到对应子包里的原生二进制,透传参数与 stdio 执行。
3
+ // Scope 从主包 package.json 的 name 字段动态读取(内网 @ali、公网 @ucp-b2b)。
4
+ "use strict";
5
+
6
+ const { execFileSync } = require("child_process");
7
+ const path = require("path");
8
+
9
+ // scope 从主包的 name 字段读取(如 @ali/utp → @ali, @ucp-b2b/utp → @ucp-b2b)
10
+ const mainPkg = require(path.resolve(__dirname, "../package.json"));
11
+ const scope = mainPkg.name.split("/")[0] || "@ali";
12
+
13
+ const PKG_BY_PLATFORM = {
14
+ "darwin-arm64": `${scope}/utp-darwin-arm64`,
15
+ "darwin-x64": `${scope}/utp-darwin-x64`,
16
+ "linux-x64": `${scope}/utp-linux-x64`,
17
+ "win32-x64": `${scope}/utp-win32-x64`,
18
+ };
19
+
20
+ const key = `${process.platform}-${process.arch}`; // 如 darwin-arm64 / linux-x64
21
+ const pkg = PKG_BY_PLATFORM[key];
22
+ if (!pkg) {
23
+ console.error(`[utp] 不支持的平台: ${key}`);
24
+ process.exit(1);
25
+ }
26
+
27
+ const binName = process.platform === "win32" ? "utp.exe" : "utp";
28
+ let binPath;
29
+ try {
30
+ binPath = path.join(path.dirname(require.resolve(`${pkg}/package.json`)), binName);
31
+ } catch (e) {
32
+ console.error(`[utp] 缺少平台二进制包 ${pkg},请重新安装: npm i -g ${scope}/utp`);
33
+ process.exit(1);
34
+ }
35
+
36
+ try {
37
+ execFileSync(binPath, process.argv.slice(2), { stdio: "inherit" });
38
+ } catch (e) {
39
+ if (typeof e.status === "number") process.exit(e.status); // 透传子进程退出码
40
+ console.error(e.message);
41
+ process.exit(1);
42
+ }
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@ut-protocol/utp",
3
+ "version": "0.5.2-beta.1",
4
+ "description": "UTP Protocol CLI - Universal Commerce Protocol client",
5
+ "bin": {
6
+ "utp": "bin/utp"
7
+ },
8
+ "optionalDependencies": {
9
+ "@ut-protocol/utp-darwin-arm64": "0.5.2-beta.1",
10
+ "@ut-protocol/utp-darwin-x64": "0.5.2-beta.1",
11
+ "@ut-protocol/utp-linux-x64": "0.5.2-beta.1",
12
+ "@ut-protocol/utp-win32-x64": "0.5.2-beta.1"
13
+ },
14
+ "files": [
15
+ "bin/utp"
16
+ ],
17
+ "publishConfig": {
18
+ "registry": "https://registry.npmjs.org"
19
+ }
20
+ }