@inventeer.tech/apex 0.9.0 → 0.10.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/install.js +87 -1
  2. package/package.json +1 -1
package/install.js CHANGED
@@ -22,6 +22,88 @@ function getArch() {
22
22
  throw new Error("Unsupported arch: " + a);
23
23
  }
24
24
 
25
+ function getGlobalPrefix() {
26
+ const envPrefix = process.env.npm_config_prefix;
27
+ if (envPrefix) return envPrefix;
28
+ try {
29
+ return execSync("npm prefix -g", { encoding: "utf8" }).trim();
30
+ } catch (e) {
31
+ return null;
32
+ }
33
+ }
34
+
35
+ function safeUnlink(target) {
36
+ try {
37
+ fs.unlinkSync(target);
38
+ } catch (e) {
39
+ if (e.code !== "ENOENT") throw e;
40
+ }
41
+ }
42
+
43
+ function writeWindowsShims(prefix, binaryPath) {
44
+ const cmdPath = path.join(prefix, "apex.cmd");
45
+ const cmdBody =
46
+ "@ECHO OFF\r\n" +
47
+ '"' + binaryPath + '" %*\r\n';
48
+ fs.writeFileSync(cmdPath, cmdBody);
49
+
50
+ const ps1Path = path.join(prefix, "apex.ps1");
51
+ const ps1Target = binaryPath.replace(/'/g, "''");
52
+ const ps1Body =
53
+ "#!/usr/bin/env pwsh\n" +
54
+ "$exe = '" + ps1Target + "'\n" +
55
+ "& $exe @args\n" +
56
+ "exit $LASTEXITCODE\n";
57
+ fs.writeFileSync(ps1Path, ps1Body);
58
+
59
+ const shPath = path.join(prefix, "apex");
60
+ const shTarget = binaryPath.replace(/\\/g, "/");
61
+ const shBody =
62
+ "#!/bin/sh\n" +
63
+ 'exec "' + shTarget + '" "$@"\n';
64
+ fs.writeFileSync(shPath, shBody);
65
+ try {
66
+ fs.chmodSync(shPath, 0o755);
67
+ } catch (e) {
68
+ // chmod is a no-op on most Windows filesystems; ignore failures.
69
+ }
70
+ }
71
+
72
+ function linkPosix(prefix, binaryPath) {
73
+ const binDir = path.join(prefix, "bin");
74
+ if (!fs.existsSync(binDir)) fs.mkdirSync(binDir, { recursive: true });
75
+ const linkPath = path.join(binDir, "apex");
76
+ safeUnlink(linkPath);
77
+ fs.symlinkSync(binaryPath, linkPath);
78
+ }
79
+
80
+ function installGlobalLink(binaryPath) {
81
+ if (process.env.npm_config_global !== "true") return;
82
+
83
+ const prefix = getGlobalPrefix();
84
+ if (!prefix) {
85
+ console.warn(
86
+ "apex: could not resolve npm global prefix; skipping PATH link.",
87
+ );
88
+ return;
89
+ }
90
+
91
+ try {
92
+ if (process.platform === "win32") {
93
+ writeWindowsShims(prefix, binaryPath);
94
+ } else {
95
+ linkPosix(prefix, binaryPath);
96
+ }
97
+ } catch (e) {
98
+ console.warn(
99
+ "apex: failed to link binary into PATH (" + e.message + ").",
100
+ );
101
+ console.warn(
102
+ " You can re-link manually: see " + PKG.homepage + "#install.",
103
+ );
104
+ }
105
+ }
106
+
25
107
  async function main() {
26
108
  const platform = getPlatform();
27
109
  const arch = getArch();
@@ -74,8 +156,12 @@ async function main() {
74
156
  fs.rmSync(extractDir, { recursive: true, force: true });
75
157
  }
76
158
 
77
- fs.chmodSync(path.join(BIN_DIR, binaryName), 0o755);
159
+ const binaryPath = path.join(BIN_DIR, binaryName);
160
+ fs.chmodSync(binaryPath, 0o755);
78
161
  fs.rmSync(tmp, { force: true });
162
+
163
+ installGlobalLink(binaryPath);
164
+
79
165
  console.log("apex installed successfully.");
80
166
  }
81
167
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inventeer.tech/apex",
3
- "version": "0.9.0",
3
+ "version": "0.10.1",
4
4
  "description": "AI-powered software delivery agent",
5
5
  "bin": {
6
6
  "apex": "./bin/apex"