@just-every/code 0.2.42 → 0.2.43

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/coder.js CHANGED
@@ -3,8 +3,6 @@
3
3
 
4
4
  import path from "path";
5
5
  import { fileURLToPath } from "url";
6
- import { realpathSync, accessSync, constants } from "fs";
7
- import { spawnSync } from "child_process";
8
6
 
9
7
  // __dirname equivalent in ESM
10
8
  const __filename = fileURLToPath(import.meta.url);
@@ -12,55 +10,9 @@ const __dirname = path.dirname(__filename);
12
10
 
13
11
  const { platform, arch } = process;
14
12
 
15
- // If invoked as "code" and another "code" exists in PATH that is not
16
- // this package's launcher, delegate to it (e.g., VS Code's CLI).
17
- // This avoids hijacking users who already have VS Code installed.
18
- const maybeDelegateToOtherCode = () => {
19
- try {
20
- const invoked = process.env._ || "";
21
- const invokedBase = path.basename(invoked);
22
- if (invokedBase !== "code") return false;
23
-
24
- const ourScriptReal = realpathSync(process.argv[1]);
25
-
26
- const which = spawnSync("bash", ["-lc", "which -a code 2>/dev/null"], {
27
- encoding: "utf8",
28
- stdio: ["ignore", "pipe", "ignore"],
29
- });
30
- if (which.status !== 0 || !which.stdout) return false;
31
-
32
- const candidates = which.stdout
33
- .split(/\r?\n/)
34
- .map((s) => s.trim())
35
- .filter(Boolean);
36
-
37
- for (const c of candidates) {
38
- // Skip the path that was used to invoke us
39
- if (c === invoked) continue;
40
- try {
41
- const real = realpathSync(c);
42
- // Skip if it resolves to our own script (same file inside our package)
43
- if (real === ourScriptReal) continue;
44
-
45
- // Ensure it's executable; if so, exec and mirror exit code
46
- accessSync(c, constants.X_OK);
47
- const run = spawnSync(c, process.argv.slice(2), {
48
- stdio: "inherit",
49
- });
50
- // If it executed (even with non-zero), we consider delegation done.
51
- const code = run.status == null ? 1 : run.status;
52
- process.exit(code);
53
- } catch {
54
- // Try next candidate
55
- }
56
- }
57
- } catch {
58
- // Fall through to our own binary
59
- }
60
- return false;
61
- };
62
-
63
- maybeDelegateToOtherCode();
13
+ // Important: Never delegate to another system's `code` binary (e.g., VS Code).
14
+ // When users run via `npx @just-every/code`, we must always execute our
15
+ // packaged native binary by absolute path to avoid PATH collisions.
64
16
 
65
17
  const isWSL = () => {
66
18
  if (platform !== "linux") return false;
@@ -130,6 +82,7 @@ if (!existsSync(binaryPath)) {
130
82
 
131
83
  // Check if binary exists and try to fix permissions if needed
132
84
  import { existsSync, chmodSync, statSync, openSync, readSync, closeSync } from "fs";
85
+ import { spawnSync } from "child_process";
133
86
  if (existsSync(binaryPath)) {
134
87
  try {
135
88
  // Ensure binary is executable on Unix-like systems
@@ -200,6 +153,33 @@ if (!validation.ok) {
200
153
  process.exit(1);
201
154
  }
202
155
 
156
+ // If running under npx/npm, emit a concise notice about which binary path is used
157
+ try {
158
+ const ua = process.env.npm_config_user_agent || "";
159
+ const isNpx = ua.includes("npx");
160
+ if (isNpx && process.stderr && process.stderr.isTTY) {
161
+ // Best-effort discovery of another 'code' on PATH for user clarity
162
+ let otherCode = "";
163
+ try {
164
+ const cmd = process.platform === "win32" ? "where code" : "command -v code || which code || true";
165
+ const out = spawnSync(process.platform === "win32" ? "cmd" : "bash", [
166
+ process.platform === "win32" ? "/c" : "-lc",
167
+ cmd,
168
+ ], { encoding: "utf8" });
169
+ const line = (out.stdout || "").split(/\r?\n/).map((s) => s.trim()).filter(Boolean)[0];
170
+ if (line && !line.includes("@just-every/code")) {
171
+ otherCode = line;
172
+ }
173
+ } catch {}
174
+ if (otherCode) {
175
+ console.error(`@just-every/code: running bundled binary -> ${binaryPath}`);
176
+ console.error(`Note: a different 'code' exists at ${otherCode}; not delegating.`);
177
+ } else {
178
+ console.error(`@just-every/code: running bundled binary -> ${binaryPath}`);
179
+ }
180
+ }
181
+ } catch {}
182
+
203
183
  // Use an asynchronous spawn instead of spawnSync so that Node is able to
204
184
  // respond to signals (e.g. Ctrl-C / SIGINT) while the native binary is
205
185
  // executing. This allows us to forward those signals to the child process
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@just-every/code",
3
- "version": "0.2.42",
3
+ "version": "0.2.43",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Lightweight coding agent that runs in your terminal - fork of OpenAI Codex",
6
6
  "bin": {
@@ -35,10 +35,10 @@
35
35
  "prettier": "^3.3.3"
36
36
  },
37
37
  "optionalDependencies": {
38
- "@just-every/code-darwin-arm64": "0.2.42",
39
- "@just-every/code-darwin-x64": "0.2.42",
40
- "@just-every/code-linux-x64-musl": "0.2.42",
41
- "@just-every/code-linux-arm64-musl": "0.2.42",
42
- "@just-every/code-win32-x64": "0.2.42"
38
+ "@just-every/code-darwin-arm64": "0.2.43",
39
+ "@just-every/code-darwin-x64": "0.2.43",
40
+ "@just-every/code-linux-x64-musl": "0.2.43",
41
+ "@just-every/code-linux-arm64-musl": "0.2.43",
42
+ "@just-every/code-win32-x64": "0.2.43"
43
43
  }
44
44
  }
package/postinstall.js CHANGED
@@ -364,20 +364,32 @@ async function main() {
364
364
 
365
365
  const ourShim = join(globalBin || '', isWindows ? 'code.cmd' : 'code');
366
366
 
367
- // Resolve which 'code' is currently on PATH
368
- const resolveOnPath = (cmd) => {
367
+ // Resolve all 'code' candidates on PATH (so we detect collisions even if
368
+ // our npm global bin currently appears first).
369
+ const resolveAllOnPath = () => {
369
370
  try {
370
371
  if (isWindows) {
371
- const out = execSync(`where ${cmd}`, { stdio: ['ignore', 'pipe', 'ignore'] }).toString().split(/\r?\n/)[0]?.trim();
372
- return out || '';
373
- } else {
374
- return execSync(`command -v ${cmd}`, { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim();
372
+ const out = execSync('where code', { stdio: ['ignore', 'pipe', 'ignore'] }).toString();
373
+ return out.split(/\r?\n/).map(s => s.trim()).filter(Boolean);
374
+ }
375
+ // Prefer 'which -a' if available; fall back to 'command -v'
376
+ let out = '';
377
+ try {
378
+ out = execSync('bash -lc "which -a code 2>/dev/null"', { stdio: ['ignore', 'pipe', 'ignore'] }).toString();
379
+ } catch {
380
+ try {
381
+ out = execSync('command -v code || true', { stdio: ['ignore', 'pipe', 'ignore'] }).toString();
382
+ } catch { out = ''; }
375
383
  }
376
- } catch { return ''; }
384
+ return out.split(/\r?\n/).map(s => s.trim()).filter(Boolean);
385
+ } catch {
386
+ return [];
387
+ }
377
388
  };
378
389
 
379
- const codeResolved = resolveOnPath('code');
380
- const collision = codeResolved && ourShim && codeResolved !== ourShim;
390
+ const candidates = resolveAllOnPath();
391
+ const others = candidates.filter(p => p && ourShim && p !== ourShim);
392
+ const collision = others.length > 0;
381
393
 
382
394
  const ensureWrapper = (name, args) => {
383
395
  if (!globalBin) return;
@@ -402,26 +414,22 @@ async function main() {
402
414
  ensureWrapper('code-exec', 'exec');
403
415
 
404
416
  if (collision) {
405
- console.log('⚠ Detected an existing `code` command on your PATH (likely VS Code).');
417
+ console.log('⚠ Detected existing `code` on PATH:');
418
+ for (const p of others) console.log(` - ${p}`);
406
419
  if (globalBin) {
407
- // Create a 'coder' shim that forwards to our installed 'code' in the same dir
420
+ // Remove our global `code` shim to avoid shadowing editors like VS Code
408
421
  try {
409
- const coderShim = join(globalBin, isWindows ? 'coder.cmd' : 'coder');
410
- if (isWindows) {
411
- const content = `@echo off\r\n"%~dp0code" %*\r\n`;
412
- writeFileSync(coderShim, content);
413
- } else {
414
- const content = `#!/bin/sh\nexec "$(dirname \"$0\")/code" "$@"\n`;
415
- writeFileSync(coderShim, content);
416
- chmodSync(coderShim, 0o755);
422
+ if (existsSync(ourShim)) {
423
+ unlinkSync(ourShim);
424
+ console.log(`✓ Skipped global 'code' shim (removed ${ourShim})`);
417
425
  }
418
- console.log(`✓ Created fallback command \`coder\` -> our \`code\``);
419
426
  } catch (e) {
420
- console.log(`⚠ Failed to create 'coder' fallback: ${e.message}`);
427
+ console.log(`⚠ Could not remove npm shim '${ourShim}': ${e.message}`);
421
428
  }
422
429
 
423
430
  // Offer to create a 'vscode' alias that points to the existing system VS Code
424
- if (isTTY && codeResolved) {
431
+ const primaryOther = others[0];
432
+ if (isTTY && primaryOther) {
425
433
  const prompt = (msg) => {
426
434
  process.stdout.write(msg);
427
435
  try {
@@ -436,10 +444,10 @@ async function main() {
436
444
  try {
437
445
  const vscodeShim = join(globalBin, isWindows ? 'vscode.cmd' : 'vscode');
438
446
  if (isWindows) {
439
- const content = `@echo off\r\n"${codeResolved}" %*\r\n`;
447
+ const content = `@echo off\r\n"${primaryOther}" %*\r\n`;
440
448
  writeFileSync(vscodeShim, content);
441
449
  } else {
442
- const content = `#!/bin/sh\nexec "${codeResolved}" "$@"\n`;
450
+ const content = `#!/bin/sh\nexec "${primaryOther}" "$@"\n`;
443
451
  writeFileSync(vscodeShim, content);
444
452
  chmodSync(vscodeShim, 0o755);
445
453
  }
@@ -451,7 +459,6 @@ async function main() {
451
459
  console.log('Skipping creation of `vscode` alias.');
452
460
  }
453
461
  }
454
-
455
462
  console.log('→ Use `coder` to run this tool, and `vscode` (if created) for your editor.');
456
463
  } else {
457
464
  console.log('Note: could not determine npm global bin; skipping alias creation.');