@sh-renjian/sw 0.1.0-rc.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.
package/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # @sh-renjian/sw
2
+
3
+ `@sh-renjian/sw` 是 `sw` CLI 的 npm 入口包。
4
+
5
+ 安装后会按当前平台自动选择对应的预编译二进制:
6
+
7
+ ```sh
8
+ npx @sh-renjian/sw --version
9
+ ```
10
+
11
+ 或:
12
+
13
+ ```sh
14
+ npm install -g @sh-renjian/sw
15
+ sw --version
16
+ ```
17
+
18
+ 支持的平台以发布说明为准。
package/bin/sw.js ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawnSync } from "node:child_process";
4
+
5
+ import { installedBinaryPath } from "../lib/platform.mjs";
6
+
7
+ try {
8
+ const binaryPath = installedBinaryPath();
9
+ const result = spawnSync(binaryPath, process.argv.slice(2), {
10
+ stdio: "inherit"
11
+ });
12
+ if (result.error) {
13
+ throw result.error;
14
+ }
15
+ process.exit(result.status ?? 1);
16
+ } catch (error) {
17
+ const detail = error instanceof Error ? error.message : String(error);
18
+ console.error(`Unable to locate the installed @sh-renjian/sw binary for ${process.platform}/${process.arch}: ${detail}`);
19
+ process.exit(1);
20
+ }
@@ -0,0 +1,45 @@
1
+ import path from "node:path";
2
+ import { createRequire } from "node:module";
3
+
4
+ const supportedTargets = new Set([
5
+ "darwin/arm64",
6
+ "darwin/x64",
7
+ "linux/arm64",
8
+ "linux/x64",
9
+ "win32/x64",
10
+ ]);
11
+
12
+ function assertSupportedTarget(platform, arch) {
13
+ if (!supportedTargets.has(`${platform}/${arch}`)) {
14
+ throw new Error(`unsupported platform/arch: ${platform}/${arch}`);
15
+ }
16
+ }
17
+
18
+ function binaryFileName(platform) {
19
+ return platform === "win32" ? "sw.exe" : "sw";
20
+ }
21
+
22
+ export function platformPackageName(packageName, platform, arch) {
23
+ assertSupportedTarget(platform, arch);
24
+ return `${packageName}-${platform}-${arch}`;
25
+ }
26
+
27
+ export function resolveBinaryPath({ packageName = "@sh-renjian/sw", platform, arch, packageRoot }) {
28
+ return path.join(packageRoot, "bin", binaryFileName(platform, arch));
29
+ }
30
+
31
+ export function installedBinaryPath({
32
+ packageName = "@sh-renjian/sw",
33
+ platform = process.platform,
34
+ arch = process.arch,
35
+ requireResolve,
36
+ } = {}) {
37
+ const resolve = requireResolve ?? createRequire(import.meta.url).resolve;
38
+ const packageJsonPath = resolve(`${platformPackageName(packageName, platform, arch)}/package.json`);
39
+ return resolveBinaryPath({
40
+ packageName,
41
+ platform,
42
+ arch,
43
+ packageRoot: path.dirname(packageJsonPath),
44
+ });
45
+ }
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@sh-renjian/sw",
3
+ "version": "0.1.0-rc.1",
4
+ "description": "sansi Worker Platform CLI entry package",
5
+ "license": "UNLICENSED",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://git.sansi.net:6101/renjian/sansi-cloudflare-worker-platform.git"
9
+ },
10
+ "homepage": "https://git.sansi.net:6101/renjian/sansi-cloudflare-worker-platform",
11
+ "bugs": {
12
+ "url": "https://git.sansi.net:6101/renjian/sansi-cloudflare-worker-platform/-/issues"
13
+ },
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "files": [
18
+ "bin/",
19
+ "lib/",
20
+ "README.md"
21
+ ],
22
+ "type": "module",
23
+ "bin": {
24
+ "sw": "bin/sw.js",
25
+ "sh-renjian-sw": "bin/sw.js"
26
+ },
27
+ "optionalDependencies": {
28
+ "@sh-renjian/sw-darwin-arm64": "0.1.0-rc.1",
29
+ "@sh-renjian/sw-darwin-x64": "0.1.0-rc.1",
30
+ "@sh-renjian/sw-linux-arm64": "0.1.0-rc.1",
31
+ "@sh-renjian/sw-linux-x64": "0.1.0-rc.1",
32
+ "@sh-renjian/sw-win32-x64": "0.1.0-rc.1"
33
+ }
34
+ }