@youdie006/swapdex 0.28.0 → 0.31.0

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/bin/swapdex.js CHANGED
@@ -1,17 +1,48 @@
1
1
  #!/usr/bin/env node
2
- // Thin shim: exec the prebuilt binary that install.js placed next to this file,
3
- // forwarding argv, stdio, and the exit code.
2
+ // Resolve the prebuilt binary from the platform-specific optionalDependency and
3
+ // exec it, forwarding argv, stdio, and the exit code. There is NO install
4
+ // script: npm installs only the optionalDependency whose `os`/`cpu` match this
5
+ // machine (the esbuild / @biomejs distribution pattern), so nothing runs at
6
+ // install time and there is no allow-scripts prompt.
4
7
 
5
- const path = require("path");
6
8
  const { spawnSync } = require("child_process");
7
9
 
8
- const bin = path.join(__dirname, "swapdex");
10
+ // swapdex is a Unix tool (Linux, WSL, macOS) - it manages 0600 credential files.
11
+ const PKGS = {
12
+ "darwin arm64": "@youdie006/swapdex-darwin-arm64",
13
+ "darwin x64": "@youdie006/swapdex-darwin-x64",
14
+ "linux x64": "@youdie006/swapdex-linux-x64",
15
+ "linux arm64": "@youdie006/swapdex-linux-arm64",
16
+ };
9
17
 
10
- const result = spawnSync(bin, process.argv.slice(2), { stdio: "inherit" });
18
+ function binaryPath() {
19
+ const pkg = PKGS[`${process.platform} ${process.arch}`];
20
+ if (!pkg) return null;
21
+ try {
22
+ // The platform package ships the binary at bin/swapdex; require.resolve
23
+ // finds that exact file inside the installed optional dependency.
24
+ return require.resolve(`${pkg}/bin/swapdex`);
25
+ } catch {
26
+ return null;
27
+ }
28
+ }
29
+
30
+ const bin = binaryPath();
31
+ if (!bin) {
32
+ console.error(
33
+ `swapdex: no prebuilt binary for ${process.platform} ${process.arch} ` +
34
+ "(swapdex supports Linux, WSL, and macOS on x64/arm64). " +
35
+ "If your platform is supported, the optional dependency failed to install - " +
36
+ "reinstall, or use `cargo install swapdex`."
37
+ );
38
+ process.exit(1);
39
+ }
11
40
 
41
+ const result = spawnSync(bin, process.argv.slice(2), { stdio: "inherit" });
12
42
  if (result.error) {
13
43
  console.error(
14
- "swapdex: prebuilt binary not found. Reinstall the package, or use `cargo install swapdex`."
44
+ `swapdex: failed to run the prebuilt binary (${result.error.message}). ` +
45
+ "Try `cargo install swapdex`."
15
46
  );
16
47
  process.exit(1);
17
48
  }
package/package.json CHANGED
@@ -1,19 +1,20 @@
1
1
  {
2
2
  "name": "@youdie006/swapdex",
3
- "version": "0.28.0",
3
+ "version": "0.31.0",
4
4
  "description": "Switch between multiple Claude Code, Codex, Gemini, and Antigravity login accounts, locally and safely.",
5
5
  "bin": {
6
6
  "swapdex": "bin/swapdex.js"
7
7
  },
8
- "scripts": {
9
- "postinstall": "node install.js",
10
- "prepublishOnly": "cp ../README.md ./README.md"
11
- },
12
8
  "files": [
13
9
  "README.md",
14
- "bin/swapdex.js",
15
- "install.js"
10
+ "bin/swapdex.js"
16
11
  ],
12
+ "optionalDependencies": {
13
+ "@youdie006/swapdex-darwin-arm64": "0.31.0",
14
+ "@youdie006/swapdex-darwin-x64": "0.31.0",
15
+ "@youdie006/swapdex-linux-x64": "0.31.0",
16
+ "@youdie006/swapdex-linux-arm64": "0.31.0"
17
+ },
17
18
  "keywords": [
18
19
  "cli",
19
20
  "claude",
package/install.js DELETED
@@ -1,75 +0,0 @@
1
- #!/usr/bin/env node
2
- // Postinstall: download the prebuilt swapdex binary for this platform from the
3
- // matching GitHub release and place it next to the JS shim. Never fails the npm
4
- // install hard - on any problem it prints a hint to use `cargo install swapdex`
5
- // and exits 0, so the package install does not break.
6
-
7
- const fs = require("fs");
8
- const os = require("os");
9
- const path = require("path");
10
- const https = require("https");
11
- const { execFileSync } = require("child_process");
12
-
13
- const version = require("./package.json").version;
14
-
15
- // swapdex is a Unix tool (Linux, WSL, macOS) - it manages 0600 credential files.
16
- const TARGETS = {
17
- "darwin arm64": "aarch64-apple-darwin",
18
- "darwin x64": "x86_64-apple-darwin",
19
- "linux x64": "x86_64-unknown-linux-musl",
20
- "linux arm64": "aarch64-unknown-linux-musl",
21
- };
22
-
23
- const key = `${process.platform} ${process.arch}`;
24
- const target = TARGETS[key];
25
- const binDir = path.join(__dirname, "bin");
26
- const binName = "swapdex";
27
-
28
- function bail(msg) {
29
- console.error(`swapdex: ${msg} Try \`cargo install swapdex\` instead.`);
30
- process.exit(0); // do not break the whole npm install
31
- }
32
-
33
- if (!target) bail(`no prebuilt binary for ${key} (swapdex supports Linux, WSL, and macOS).`);
34
-
35
- const ext = "tar.gz";
36
- const url = `https://github.com/youdie006/swapdex/releases/download/v${version}/swapdex-${target}.${ext}`;
37
-
38
- function download(u, dest, cb, redirects = 0) {
39
- https
40
- .get(u, { headers: { "User-Agent": "swapdex-npm" } }, (res) => {
41
- if (
42
- [301, 302, 307, 308].includes(res.statusCode) &&
43
- res.headers.location &&
44
- redirects < 5
45
- ) {
46
- res.resume();
47
- return download(res.headers.location, dest, cb, redirects + 1);
48
- }
49
- if (res.statusCode !== 200) {
50
- return cb(new Error(`HTTP ${res.statusCode}`));
51
- }
52
- const f = fs.createWriteStream(dest);
53
- res.pipe(f);
54
- f.on("finish", () => f.close(() => cb(null)));
55
- f.on("error", cb);
56
- })
57
- .on("error", cb);
58
- }
59
-
60
- fs.mkdirSync(binDir, { recursive: true });
61
- const archive = path.join(os.tmpdir(), `swapdex-${target}.${ext}`);
62
-
63
- download(url, archive, (err) => {
64
- if (err) bail(`could not download the prebuilt binary (${err.message}).`);
65
- try {
66
- execFileSync("tar", ["-xzf", archive, "-C", binDir], { stdio: "ignore" });
67
- const bin = path.join(binDir, binName);
68
- if (!fs.existsSync(bin)) bail("the downloaded archive did not contain the binary.");
69
- fs.chmodSync(bin, 0o755);
70
- fs.unlinkSync(archive);
71
- console.log(`swapdex: installed prebuilt binary (${target}).`);
72
- } catch (e) {
73
- bail(`failed to extract the binary (${e.message}).`);
74
- }
75
- });