sphere-cli 0.2.5 → 0.2.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sphere-cli",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "SPHERE CLI — synthetic data generation, evaluation, and certification (sealed native binary)",
5
5
  "keywords": [
6
6
  "synthetic-data",
@@ -24,7 +24,7 @@ const VERSION = PKG.version;
24
24
  const REPO = 'statzihuai/sphere-cli';
25
25
  // Binary release tag — decoupled from the npm package version so JS-only patch
26
26
  // releases reuse the same prebuilt/notarized binaries without re-uploading them.
27
- const BINARY_RELEASE = 'v0.2.5';
27
+ const BINARY_RELEASE = 'v0.2.6';
28
28
 
29
29
  const PLATFORM = process.platform; // 'darwin' | 'linux'
30
30
  const ARCH = process.arch; // 'arm64' | 'x64'
@@ -126,8 +126,60 @@ try {
126
126
  } catch (_) { /* best-effort; user just pays the scan on first run */ }
127
127
  }
128
128
 
129
+ setupGlobalPath();
130
+
129
131
  log(`installed sealed binary for ${KEY} ✓`);
130
132
  } catch (e) {
131
133
  fail(`failed to install binary: ${e.message}\n` +
132
134
  `You can retry with: npm rebuild sphere-cli`);
133
135
  }
136
+
137
+ // ── Make `sphere` callable without manual PATH editing ──────────────────────
138
+ // For a GLOBAL install whose prefix/bin is not already on PATH (common on HPC,
139
+ // where users point `npm config set prefix` at a roomy shared dir like $OAK so
140
+ // the install survives across login/compute nodes), append the bin dir to the
141
+ // user's shell rc. Because the rc lives in the shared home dir, the `sphere`
142
+ // command then works in every future session on every node — no reinstall.
143
+ // Idempotent; skipped when already on PATH; opt out with SPHERE_NO_PATH_SETUP=1.
144
+ function setupGlobalPath() {
145
+ try {
146
+ if (process.env.SPHERE_NO_PATH_SETUP === '1') return;
147
+ if (PLATFORM === 'win32') return;
148
+ const isGlobal = process.env.npm_config_global === 'true'
149
+ || /[\\/]lib[\\/]node_modules[\\/]sphere-cli$/.test(PKG_ROOT);
150
+ if (!isGlobal) return; // local installs run via `npx sphere` — no PATH needed
151
+
152
+ const prefix = process.env.npm_config_prefix
153
+ || path.resolve(PKG_ROOT, '..', '..', '..'); // <prefix>/lib/node_modules/sphere-cli
154
+ const binDir = path.join(prefix, 'bin');
155
+ const parts = (process.env.PATH || '').split(path.delimiter);
156
+ if (parts.includes(binDir)) return; // already callable — nothing to do
157
+
158
+ const os = require('os');
159
+ const home = os.homedir();
160
+ const block = `\n# added by sphere-cli — makes the \`sphere\` command available\n`
161
+ + `export PATH="${binDir}:$PATH"\n`;
162
+
163
+ const targets = [];
164
+ for (const f of ['.bashrc', '.zshrc']) {
165
+ const p = path.join(home, f);
166
+ if (fs.existsSync(p)) targets.push(p);
167
+ }
168
+ if (targets.length === 0) targets.push(path.join(home, '.bashrc')); // create one
169
+
170
+ const wrote = [];
171
+ for (const rc of targets) {
172
+ let cur = '';
173
+ try { cur = fs.readFileSync(rc, 'utf8'); } catch (_) {}
174
+ if (cur.includes(binDir)) continue; // idempotent
175
+ try { fs.appendFileSync(rc, block); wrote.push(path.basename(rc)); } catch (_) {}
176
+ }
177
+
178
+ if (wrote.length) {
179
+ log(`PATH: added ${binDir} to ${wrote.join(', ')} — \`sphere\` will work in new shells (and on every node, since home is shared).`);
180
+ log(`for THIS shell now: export PATH="${binDir}:$PATH"`);
181
+ } else {
182
+ log(`to run \`sphere\`, add to your shell rc: export PATH="${binDir}:$PATH"`);
183
+ }
184
+ } catch (_) { /* best-effort; never fail the install over PATH setup */ }
185
+ }