fauxnix-cli 0.13.0 → 2.0.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.
@@ -0,0 +1,22 @@
1
+ import { readFileSync } from 'node:fs';
2
+ // Keep diagnostics and the entrypoint aligned with the install contract.
3
+ const metadata = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
4
+ export const nodeEngineRange = metadata.engines?.node;
5
+ const minimum = /^>=(\d+)\.(\d+)\.(\d+)$/.exec(nodeEngineRange);
6
+ if (!minimum)
7
+ throw new Error('fauxnix: unsupported package.json Node engine range');
8
+ const required = minimum.slice(1).map(Number);
9
+ /** This package uses one inclusive stable-version floor, not general semver ranges. */
10
+ export function supportsNode(version) {
11
+ const match = /^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\+[\w.-]+)?$/.exec(version);
12
+ if (!match)
13
+ return false;
14
+ const actual = match.slice(1, 4).map(Number);
15
+ if (!actual.every(Number.isSafeInteger))
16
+ return false;
17
+ for (let i = 0; i < 3; i++) {
18
+ if (actual[i] !== required[i])
19
+ return actual[i] > required[i];
20
+ }
21
+ return true;
22
+ }
@@ -50,7 +50,8 @@ export declare function pathExpr(s: string): string;
50
50
  /**
51
51
  * Convert a Word to a PowerShell string expression.
52
52
  * Literal words become single-quoted strings; dynamic ones become
53
- * double-quoted strings with $(...) interpolation.
53
+ * double-quoted strings with $(...) interpolation, concatenating command
54
+ * substitutions outside those strings so their scriptblocks parse independently.
54
55
  */
55
56
  export declare function exprOfWord(w: Word, opts?: {
56
57
  preserveCmdSub?: boolean;
@@ -279,7 +279,7 @@ export function varExpr(name, index, param, length = false, extra) {
279
279
  case 'HOME':
280
280
  return '$HOME';
281
281
  case 'PWD':
282
- return '$PWD.Path';
282
+ return 'fx-posix([string]$PWD.Path)';
283
283
  case 'USER':
284
284
  case 'LOGNAME':
285
285
  return '$env:USERNAME';
@@ -290,7 +290,7 @@ export function varExpr(name, index, param, length = false, extra) {
290
290
  case 'TERM':
291
291
  return "'xterm-256color'";
292
292
  case 'OLDPWD':
293
- return '$env:FAUXNIX_OLDPWD';
293
+ return 'fx-posix([string]$env:FAUXNIX_OLDPWD)';
294
294
  case '?':
295
295
  return '[string]$fx_prev';
296
296
  case '$':
@@ -366,7 +366,8 @@ export function pathExpr(s) {
366
366
  /**
367
367
  * Convert a Word to a PowerShell string expression.
368
368
  * Literal words become single-quoted strings; dynamic ones become
369
- * double-quoted strings with $(...) interpolation.
369
+ * double-quoted strings with $(...) interpolation, concatenating command
370
+ * substitutions outside those strings so their scriptblocks parse independently.
370
371
  */
371
372
  export function exprOfWord(w, opts) {
372
373
  // tilde expansion (unquoted leading ~)
@@ -399,35 +400,59 @@ export function exprOfWord(w, opts) {
399
400
  const text = expanded.map((p) => p.text).join('');
400
401
  return pathExpr(normalizeLiteralPath(text));
401
402
  }
402
- // dynamic — build a PS double-quoted string with interpolation
403
- let out = '"';
403
+ return interpolatedWordExpr(expanded, opts?.preserveCmdSub === true);
404
+ }
405
+ function containsCmdSub(parts) {
406
+ return parts.some((part) => part.kind === 'CmdSub' ||
407
+ ((part.kind === 'DoubleQuoted' || part.kind === 'Arith') && containsCmdSub(part.parts)));
408
+ }
409
+ /** Keep generated scriptblocks out of PowerShell's expandable-string lexer. */
410
+ function interpolatedWordExpr(parts, preserveCmdSub) {
411
+ const expressions = [];
412
+ let text = '';
413
+ const flushText = () => {
414
+ if (text)
415
+ expressions.push('"' + text + '"');
416
+ text = '';
417
+ };
404
418
  const emitPart = (p, quoted) => {
405
419
  switch (p.kind) {
406
420
  case 'Text':
407
- out += escapeDq(p.text);
408
- break;
409
421
  case 'SingleQuoted':
410
- out += escapeDq(p.text);
422
+ text += escapeDq(p.text);
411
423
  break;
412
424
  case 'DoubleQuoted':
413
425
  for (const q of p.parts)
414
426
  emitPart(q, true);
415
427
  break;
416
428
  case 'Var':
417
- out += '$(' + varExpr(p.name, p.index, p.param, p.length === true, varExtraOf(p)) + ')';
429
+ text += '$(' + varExpr(p.name, p.index, p.param, p.length === true, varExtraOf(p)) + ')';
418
430
  break;
419
431
  case 'CmdSub':
420
- out += '$(' + translateCmdSub(p.cmd, quoted || opts?.preserveCmdSub === true) + ')';
432
+ flushText();
433
+ // fx-csub returns one string. Preserve an empty result and prevent '+'
434
+ // from acquiring array/numeric semantics when this starts a mixed word.
435
+ expressions.push('[string](' + translateCmdSub(p.cmd, quoted || preserveCmdSub) + ')');
421
436
  break;
422
437
  case 'Arith':
423
- out += arithExpr(p.parts);
438
+ if (containsCmdSub(p.parts)) {
439
+ flushText();
440
+ expressions.push('[string](' + arithExpr(p.parts) + ')');
441
+ }
442
+ else {
443
+ text += arithExpr(p.parts);
444
+ }
424
445
  break;
425
446
  }
426
447
  };
427
- for (const p of expanded)
448
+ for (const p of parts)
428
449
  emitPart(p, false);
429
- out += '"';
430
- return out;
450
+ flushText();
451
+ if (expressions.length === 0)
452
+ return '""';
453
+ if (expressions.length === 1)
454
+ return expressions[0];
455
+ return '(' + expressions.join(' + ') + ')';
431
456
  }
432
457
  let arithHelperPreamble = '';
433
458
  /** Registered by sysinfo so wrapScript can emit fx-arith without a circular import. */
@@ -458,32 +483,7 @@ function arithSourceExpr(parts) {
458
483
  if (parts.every((p) => p.kind === 'Text')) {
459
484
  return psStr(parts.map((p) => p.text).join(''));
460
485
  }
461
- let out = '"';
462
- const emit = (p) => {
463
- switch (p.kind) {
464
- case 'Text':
465
- case 'SingleQuoted':
466
- out += escapeDq(p.text);
467
- break;
468
- case 'DoubleQuoted':
469
- for (const q of p.parts)
470
- emit(q);
471
- break;
472
- case 'Var':
473
- out += '$(' + varExpr(p.name, p.index, p.param, p.length === true, varExtraOf(p)) + ')';
474
- break;
475
- case 'CmdSub':
476
- out += '$(' + translateCmdSub(p.cmd, true) + ')';
477
- break;
478
- case 'Arith':
479
- out += arithExpr(p.parts);
480
- break;
481
- }
482
- };
483
- for (const p of parts)
484
- emit(p);
485
- out += '"';
486
- return out;
486
+ return interpolatedWordExpr(parts, true);
487
487
  }
488
488
  /** Literal text of a word when it contains no interpolation, else null. */
489
489
  export function literalOfWord(w) {
@@ -1275,6 +1275,7 @@ const WRAP_HELPER_ORDER = [
1275
1275
  'fx-winargv',
1276
1276
  'fx-cmdargv',
1277
1277
  'fx-native',
1278
+ 'fx-posix',
1278
1279
  ];
1279
1280
  const WRAP_HELPER_DEPS = {
1280
1281
  'fx-readlines': [],
@@ -1301,6 +1302,7 @@ const WRAP_HELPER_DEPS = {
1301
1302
  'fx-winargv': [],
1302
1303
  'fx-cmdargv': ['fx-winargv'],
1303
1304
  'fx-native': ['fx-cmdargv'],
1305
+ 'fx-posix': [],
1304
1306
  };
1305
1307
  /** Helpers the body calls that wrapScript still has to emit (not already defined there). */
1306
1308
  function wrapHelpersNeeded(body) {
@@ -1538,12 +1540,12 @@ export function wrapScript(body, opts = {}) {
1538
1540
  ' if ($fx_pair.Substring(0, $fx_eq) -ceq $n) { return (fx-svdec $fx_pair.Substring($fx_eq + 1)) }',
1539
1541
  ' }',
1540
1542
  " if ($n -ceq 'HOME') { return [string]$HOME }",
1541
- " if ($n -ceq 'PWD') { return [string]$PWD.Path }",
1543
+ " if ($n -ceq 'PWD') { return fx-posix([string]$PWD.Path) }",
1542
1544
  " if ($n -ceq 'USER' -or $n -ceq 'LOGNAME') { return [string]$env:USERNAME }",
1543
1545
  " if ($n -ceq 'PATH') { return [string]$env:PATH }",
1544
1546
  " if ($n -ceq 'SHELL') { return 'powershell' }",
1545
1547
  " if ($n -ceq 'TERM') { return 'xterm-256color' }",
1546
- " if ($n -ceq 'OLDPWD') { return $(if ($env:FAUXNIX_OLDPWD) { [string]$env:FAUXNIX_OLDPWD } else { $null }) }",
1548
+ " if ($n -ceq 'OLDPWD') { return $(if ($env:FAUXNIX_OLDPWD) { fx-posix([string]$env:FAUXNIX_OLDPWD) } else { $null }) }",
1547
1549
  " if ($n -ceq 'HOSTNAME') { return [string]$env:COMPUTERNAME }",
1548
1550
  ' $ev = Get-ChildItem Env: | Where-Object { $_.Name -ceq $n } | Select-Object -First 1',
1549
1551
  ' if ($ev) { return [string]$ev.Value }',
@@ -1655,6 +1657,13 @@ export function wrapScript(body, opts = {}) {
1655
1657
  ' return $false',
1656
1658
  '}',
1657
1659
  ],
1660
+ 'fx-posix': [
1661
+ 'function fx-posix($p) {',
1662
+ ' $p = ([string]$p).Replace(\'\\\', \'/\')',
1663
+ " if ($p -match '^[A-Za-z]:') { return '/' + $p.Substring(0, 1).ToLower() + $p.Substring(2) }",
1664
+ ' return $p',
1665
+ '}',
1666
+ ],
1658
1667
  'fx-subst': [
1659
1668
  'function fx-subst($s, $pat, $repl, $all) {',
1660
1669
  ' if ($null -eq $s) { return \'\' }',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fauxnix-cli",
3
- "version": "0.13.0",
3
+ "version": "2.0.0",
4
4
  "description": "Fauxnix — run Linux-style commands on Windows via deterministic PowerShell translation. No VM, no WSL. MCP server + CLI for AI agents.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -12,16 +12,18 @@
12
12
  "LICENSE"
13
13
  ],
14
14
  "scripts": {
15
+ "prebuild": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
15
16
  "build": "tsc",
16
17
  "prepare": "npm run build",
17
- "prepublishOnly": "npm run release:check -- --require-tag && npm run typecheck && npm test && npm run test:package",
18
+ "prepublishOnly": "npm run release:check -- --require-tag && npm run typecheck && npm run typecheck:test && npm test && npm run test:package",
18
19
  "release:check": "node scripts/release-check.mjs",
19
20
  "test": "vitest run",
20
21
  "test:package": "node scripts/package-smoke.mjs",
21
22
  "benchmark:mcp-batch": "npm run build && node scripts/benchmark-mcp-batch.mjs",
22
23
  "test:watch": "vitest",
23
24
  "typecheck": "tsc --noEmit",
24
- "dev": "tsx src/index.ts"
25
+ "dev": "tsx src/index.ts",
26
+ "typecheck:test": "tsc --project tsconfig.test.json"
25
27
  },
26
28
  "keywords": [
27
29
  "bash",
@@ -42,7 +44,7 @@
42
44
  "utf8"
43
45
  ],
44
46
  "engines": {
45
- "node": ">=18"
47
+ "node": ">=22.20.0"
46
48
  },
47
49
  "license": "MIT",
48
50
  "repository": {