@linguacode/cli 1.4.1 → 1.5.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 (3) hide show
  1. package/LICENSE +1 -1
  2. package/bin/lingua.cjs +204 -118
  3. package/package.json +1 -1
package/LICENSE CHANGED
@@ -66,7 +66,7 @@ contributor collaboration. It is NOT distributed under an open-source license.
66
66
 
67
67
  6. Commercial licensing
68
68
 
69
- Public launch tiers (Free, Monthly, Pro, Education) and their
69
+ Public tiers (Free, Monthly, Pro, Team, Education) and their
70
70
  entitlements are documented at `linguacode.dev/pricing`. Commercial
71
71
  and production use requires a valid commercial license.
72
72
 
package/bin/lingua.cjs CHANGED
@@ -44,11 +44,23 @@ var CLI_EXIT_CODES = {
44
44
  internal: 4
45
45
  };
46
46
 
47
- // src/shared/runCapsule.ts
48
- var MAX_CAPSULE_BYTES = 4194304;
47
+ // src/shared/utf8.ts
48
+ var encoder = new TextEncoder();
49
+ var decoder = new TextDecoder("utf-8", { fatal: false, ignoreBOM: true });
49
50
  function utf8ByteLength(value) {
50
- return new TextEncoder().encode(value).byteLength;
51
+ return encoder.encode(value).byteLength;
51
52
  }
53
+ function truncateUtf8(value, maxBytes) {
54
+ if (maxBytes <= 0) return "";
55
+ const bytes = encoder.encode(value);
56
+ if (bytes.byteLength <= maxBytes) return value;
57
+ let end = maxBytes;
58
+ while (end > 0 && (bytes[end] & 192) === 128) end -= 1;
59
+ return decoder.decode(bytes.subarray(0, end));
60
+ }
61
+
62
+ // src/shared/runCapsule.ts
63
+ var MAX_CAPSULE_BYTES = 4194304;
52
64
  function isRecord(value) {
53
65
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
54
66
  }
@@ -685,7 +697,7 @@ var CappedOutput = class {
685
697
  return chunk;
686
698
  }
687
699
  const remainingBytes = Math.max(0, payloadCap - currentBytes);
688
- const prefix = utf8Prefix(chunk, remainingBytes);
700
+ const prefix = truncateUtf8(chunk, remainingBytes);
689
701
  const accepted = `${prefix}${OUTPUT_TRUNCATION_MARKER}`;
690
702
  this.value += accepted;
691
703
  this.truncated = true;
@@ -696,14 +708,6 @@ function forwardOutput(output, chunk, listener) {
696
708
  const accepted = output.append(chunk);
697
709
  if (accepted) listener?.(accepted);
698
710
  }
699
- function utf8Prefix(value, maxBytes) {
700
- if (maxBytes <= 0) return "";
701
- const bytes = Buffer.from(value, "utf8");
702
- if (bytes.length <= maxBytes) return value;
703
- let end = maxBytes;
704
- while (end > 0 && (bytes[end] & 192) === 128) end -= 1;
705
- return bytes.subarray(0, end).toString("utf8");
706
- }
707
711
  function asErrno(error) {
708
712
  return error instanceof Error ? error : new Error(String(error));
709
713
  }
@@ -741,7 +745,7 @@ function killProcessTree(child, signal) {
741
745
  var import_node_fs = require("node:fs");
742
746
  var import_promises2 = require("node:fs/promises");
743
747
  var import_node_os = __toESM(require("node:os"));
744
- var import_node_path2 = __toESM(require("node:path"));
748
+ var import_node_path3 = __toESM(require("node:path"));
745
749
  var import_node_sea = require("node:sea");
746
750
 
747
751
  // node_modules/acorn/dist/acorn.mjs
@@ -1019,6 +1023,9 @@ var defaultOptions = {
1019
1023
  // Can be either `"script"`, `"module"` or `"commonjs"`. This influences global
1020
1024
  // strict mode and parsing of `import` and `export` declarations.
1021
1025
  sourceType: "script",
1026
+ // When set to true, enable strict parsing mode even if `sourceType`
1027
+ // is `"script"`.
1028
+ strict: false,
1022
1029
  // `onInsertedSemicolon` can be a callback that will be called when
1023
1030
  // a semicolon is automatically inserted. It will be passed the
1024
1031
  // position of the inserted semicolon as an offset, and if
@@ -1060,6 +1067,11 @@ var defaultOptions = {
1060
1067
  // line being 1-based and column 0-based) will be attached to the
1061
1068
  // nodes.
1062
1069
  locations: false,
1070
+ // Pass an optional `{line, column}` object to use for the start of
1071
+ // the parse. This is mostly useful when using `parseExpressionAt`
1072
+ // with `locations: true`, to prevent the parser from having to
1073
+ // determine the line position at the start position.
1074
+ startLocation: null,
1063
1075
  // A function can be passed as `onToken` option, which will
1064
1076
  // cause Acorn to call that function with object in the same
1065
1077
  // format as tokens returned from `tokenizer().getToken()`. Note
@@ -1196,13 +1208,18 @@ var Parser = function Parser2(options, input, startPos) {
1196
1208
  this.reservedWordsStrictBind = wordsRegexp(reservedStrict + " " + reservedWords.strictBind);
1197
1209
  this.input = String(input);
1198
1210
  this.containsEsc = false;
1199
- if (startPos) {
1200
- this.pos = startPos;
1211
+ this.pos = startPos || 0;
1212
+ this.curLine = 1;
1213
+ if (options.startLocation) {
1214
+ this.lineStart = this.pos - options.startLocation.column;
1215
+ this.curLine = options.startLocation.line;
1216
+ } else if (startPos) {
1201
1217
  this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
1202
- this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
1218
+ if (this.options.locations) {
1219
+ this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
1220
+ }
1203
1221
  } else {
1204
- this.pos = this.lineStart = 0;
1205
- this.curLine = 1;
1222
+ this.lineStart = 0;
1206
1223
  }
1207
1224
  this.type = types$1.eof;
1208
1225
  this.value = null;
@@ -1213,7 +1230,7 @@ var Parser = function Parser2(options, input, startPos) {
1213
1230
  this.context = this.initialContext();
1214
1231
  this.exprAllowed = true;
1215
1232
  this.inModule = options.sourceType === "module";
1216
- this.strict = this.inModule || this.strictDirective(this.pos);
1233
+ this.strict = this.inModule || options.strict === true || this.strictDirective(this.pos);
1217
1234
  this.potentialArrowAt = -1;
1218
1235
  this.potentialArrowInForAwait = false;
1219
1236
  this.yieldPos = this.awaitPos = this.awaitIdentPos = 0;
@@ -1231,9 +1248,12 @@ var Parser = function Parser2(options, input, startPos) {
1231
1248
  };
1232
1249
  var prototypeAccessors = { inFunction: { configurable: true }, inGenerator: { configurable: true }, inAsync: { configurable: true }, canAwait: { configurable: true }, allowReturn: { configurable: true }, allowSuper: { configurable: true }, allowDirectSuper: { configurable: true }, treatFunctionsAsVar: { configurable: true }, allowNewDotTarget: { configurable: true }, allowUsing: { configurable: true }, inClassStaticBlock: { configurable: true } };
1233
1250
  Parser.prototype.parse = function parse() {
1251
+ var this$1$1 = this;
1234
1252
  var node = this.options.program || this.startNode();
1235
1253
  this.nextToken();
1236
- return this.parseTopLevel(node);
1254
+ return this.catchStackOverflow(function() {
1255
+ return this$1$1.parseTopLevel(node);
1256
+ });
1237
1257
  };
1238
1258
  prototypeAccessors.inFunction.get = function() {
1239
1259
  return (this.currentVarScope().flags & SCOPE_FUNCTION) > 0;
@@ -1367,6 +1387,17 @@ pp$9.eatContextual = function(name) {
1367
1387
  this.next();
1368
1388
  return true;
1369
1389
  };
1390
+ pp$9.catchStackOverflow = function(f) {
1391
+ try {
1392
+ return f();
1393
+ } catch (e) {
1394
+ if (e instanceof Error && (/\bstack\b.*\b(exceeded|overflow)\b/i.test(e.message) || /\btoo much recursion\b/i.test(e.message))) {
1395
+ this.raise(this.start, "Not enough stack space to parse input");
1396
+ } else {
1397
+ throw e;
1398
+ }
1399
+ }
1400
+ };
1370
1401
  pp$9.expectContextual = function(name) {
1371
1402
  if (!this.eatContextual(name)) {
1372
1403
  this.unexpected();
@@ -1452,12 +1483,12 @@ pp$9.isSimpleAssignTarget = function(expr) {
1452
1483
  };
1453
1484
  var pp$8 = Parser.prototype;
1454
1485
  pp$8.parseTopLevel = function(node) {
1455
- var exports2 = /* @__PURE__ */ Object.create(null);
1486
+ var exports$1 = /* @__PURE__ */ Object.create(null);
1456
1487
  if (!node.body) {
1457
1488
  node.body = [];
1458
1489
  }
1459
1490
  while (this.type !== types$1.eof) {
1460
- var stmt = this.parseStatement(null, true, exports2);
1491
+ var stmt = this.parseStatement(null, true, exports$1);
1461
1492
  node.body.push(stmt);
1462
1493
  }
1463
1494
  if (this.inModule) {
@@ -1547,9 +1578,18 @@ pp$8.isUsingKeyword = function(isAwaitUsing, isFor) {
1547
1578
  return true;
1548
1579
  }
1549
1580
  var id = this.input.slice(idStart, next);
1550
- if (keywordRelationalOperator.test(id) || isFor && id === "of") {
1581
+ if (keywordRelationalOperator.test(id)) {
1551
1582
  return false;
1552
1583
  }
1584
+ if (isFor && !isAwaitUsing && id === "of") {
1585
+ skipWhiteSpace.lastIndex = next;
1586
+ var skipAfterOf = skipWhiteSpace.exec(this.input);
1587
+ next = next + skipAfterOf[0].length;
1588
+ if (this.input.charCodeAt(next) !== 61 || // Check for ==, === and => operators
1589
+ (ch = this.input.charCodeAt(next + 1)) === 61 || ch === 62) {
1590
+ return false;
1591
+ }
1592
+ }
1553
1593
  return true;
1554
1594
  };
1555
1595
  pp$8.isAwaitUsing = function(isFor) {
@@ -1558,7 +1598,7 @@ pp$8.isAwaitUsing = function(isFor) {
1558
1598
  pp$8.isUsing = function(isFor) {
1559
1599
  return this.isUsingKeyword(false, isFor);
1560
1600
  };
1561
- pp$8.parseStatement = function(context, topLevel, exports2) {
1601
+ pp$8.parseStatement = function(context, topLevel, exports$1) {
1562
1602
  var starttype = this.type, node = this.startNode(), kind;
1563
1603
  if (this.isLet(context)) {
1564
1604
  starttype = types$1._var;
@@ -1627,7 +1667,7 @@ pp$8.parseStatement = function(context, topLevel, exports2) {
1627
1667
  this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'");
1628
1668
  }
1629
1669
  }
1630
- return starttype === types$1._import ? this.parseImport(node) : this.parseExport(node, exports2);
1670
+ return starttype === types$1._import ? this.parseImport(node) : this.parseExport(node, exports$1);
1631
1671
  // If the statement does not start with a statement keyword or a
1632
1672
  // brace, it's an ExpressionStatement or LabeledStatement. We
1633
1673
  // simply start parsing an expression, and afterwards, if the
@@ -1646,6 +1686,9 @@ pp$8.parseStatement = function(context, topLevel, exports2) {
1646
1686
  if (!this.allowUsing) {
1647
1687
  this.raise(this.start, "Using declaration cannot appear in the top level when source type is `script` or in the bare case statement");
1648
1688
  }
1689
+ if (context) {
1690
+ this.raise(this.start, "Using declaration is not allowed in single-statement positions");
1691
+ }
1649
1692
  if (usingKind === "await using") {
1650
1693
  if (!this.canAwait) {
1651
1694
  this.raise(this.start, "Await using cannot appear outside of async function");
@@ -1780,14 +1823,15 @@ pp$8.parseForStatement = function(node) {
1780
1823
  };
1781
1824
  pp$8.parseForAfterInit = function(node, init, awaitAt) {
1782
1825
  if ((this.type === types$1._in || this.options.ecmaVersion >= 6 && this.isContextual("of")) && init.declarations.length === 1) {
1783
- if (this.options.ecmaVersion >= 9) {
1784
- if (this.type === types$1._in) {
1785
- if (awaitAt > -1) {
1786
- this.unexpected(awaitAt);
1787
- }
1788
- } else {
1789
- node.await = awaitAt > -1;
1826
+ if (this.type === types$1._in) {
1827
+ if ((init.kind === "using" || init.kind === "await using") && !init.declarations[0].init) {
1828
+ this.raise(this.start, "Using declaration is not allowed in for-in loops");
1829
+ }
1830
+ if (this.options.ecmaVersion >= 9 && awaitAt > -1) {
1831
+ this.unexpected(awaitAt);
1790
1832
  }
1833
+ } else if (this.options.ecmaVersion >= 9) {
1834
+ node.await = awaitAt > -1;
1791
1835
  }
1792
1836
  return this.parseForIn(node, init);
1793
1837
  }
@@ -2305,11 +2349,11 @@ function checkKeyName(node, name) {
2305
2349
  var key = node.key;
2306
2350
  return !computed && (key.type === "Identifier" && key.name === name || key.type === "Literal" && key.value === name);
2307
2351
  }
2308
- pp$8.parseExportAllDeclaration = function(node, exports2) {
2352
+ pp$8.parseExportAllDeclaration = function(node, exports$1) {
2309
2353
  if (this.options.ecmaVersion >= 11) {
2310
2354
  if (this.eatContextual("as")) {
2311
2355
  node.exported = this.parseModuleExportName();
2312
- this.checkExport(exports2, node.exported, this.lastTokStart);
2356
+ this.checkExport(exports$1, node.exported, this.lastTokStart);
2313
2357
  } else {
2314
2358
  node.exported = null;
2315
2359
  }
@@ -2325,22 +2369,22 @@ pp$8.parseExportAllDeclaration = function(node, exports2) {
2325
2369
  this.semicolon();
2326
2370
  return this.finishNode(node, "ExportAllDeclaration");
2327
2371
  };
2328
- pp$8.parseExport = function(node, exports2) {
2372
+ pp$8.parseExport = function(node, exports$1) {
2329
2373
  this.next();
2330
2374
  if (this.eat(types$1.star)) {
2331
- return this.parseExportAllDeclaration(node, exports2);
2375
+ return this.parseExportAllDeclaration(node, exports$1);
2332
2376
  }
2333
2377
  if (this.eat(types$1._default)) {
2334
- this.checkExport(exports2, "default", this.lastTokStart);
2378
+ this.checkExport(exports$1, "default", this.lastTokStart);
2335
2379
  node.declaration = this.parseExportDefaultDeclaration();
2336
2380
  return this.finishNode(node, "ExportDefaultDeclaration");
2337
2381
  }
2338
2382
  if (this.shouldParseExportStatement()) {
2339
2383
  node.declaration = this.parseExportDeclaration(node);
2340
2384
  if (node.declaration.type === "VariableDeclaration") {
2341
- this.checkVariableExport(exports2, node.declaration.declarations);
2385
+ this.checkVariableExport(exports$1, node.declaration.declarations);
2342
2386
  } else {
2343
- this.checkExport(exports2, node.declaration.id, node.declaration.id.start);
2387
+ this.checkExport(exports$1, node.declaration.id, node.declaration.id.start);
2344
2388
  }
2345
2389
  node.specifiers = [];
2346
2390
  node.source = null;
@@ -2349,7 +2393,7 @@ pp$8.parseExport = function(node, exports2) {
2349
2393
  }
2350
2394
  } else {
2351
2395
  node.declaration = null;
2352
- node.specifiers = this.parseExportSpecifiers(exports2);
2396
+ node.specifiers = this.parseExportSpecifiers(exports$1);
2353
2397
  if (this.eatContextual("from")) {
2354
2398
  if (this.type !== types$1.string) {
2355
2399
  this.unexpected();
@@ -2397,66 +2441,66 @@ pp$8.parseExportDefaultDeclaration = function() {
2397
2441
  return declaration;
2398
2442
  }
2399
2443
  };
2400
- pp$8.checkExport = function(exports2, name, pos) {
2401
- if (!exports2) {
2444
+ pp$8.checkExport = function(exports$1, name, pos) {
2445
+ if (!exports$1) {
2402
2446
  return;
2403
2447
  }
2404
2448
  if (typeof name !== "string") {
2405
2449
  name = name.type === "Identifier" ? name.name : name.value;
2406
2450
  }
2407
- if (hasOwn(exports2, name)) {
2451
+ if (hasOwn(exports$1, name)) {
2408
2452
  this.raiseRecoverable(pos, "Duplicate export '" + name + "'");
2409
2453
  }
2410
- exports2[name] = true;
2454
+ exports$1[name] = true;
2411
2455
  };
2412
- pp$8.checkPatternExport = function(exports2, pat) {
2456
+ pp$8.checkPatternExport = function(exports$1, pat) {
2413
2457
  var type = pat.type;
2414
2458
  if (type === "Identifier") {
2415
- this.checkExport(exports2, pat, pat.start);
2459
+ this.checkExport(exports$1, pat, pat.start);
2416
2460
  } else if (type === "ObjectPattern") {
2417
2461
  for (var i2 = 0, list2 = pat.properties; i2 < list2.length; i2 += 1) {
2418
2462
  var prop = list2[i2];
2419
- this.checkPatternExport(exports2, prop);
2463
+ this.checkPatternExport(exports$1, prop);
2420
2464
  }
2421
2465
  } else if (type === "ArrayPattern") {
2422
2466
  for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) {
2423
2467
  var elt = list$1[i$1];
2424
2468
  if (elt) {
2425
- this.checkPatternExport(exports2, elt);
2469
+ this.checkPatternExport(exports$1, elt);
2426
2470
  }
2427
2471
  }
2428
2472
  } else if (type === "Property") {
2429
- this.checkPatternExport(exports2, pat.value);
2473
+ this.checkPatternExport(exports$1, pat.value);
2430
2474
  } else if (type === "AssignmentPattern") {
2431
- this.checkPatternExport(exports2, pat.left);
2475
+ this.checkPatternExport(exports$1, pat.left);
2432
2476
  } else if (type === "RestElement") {
2433
- this.checkPatternExport(exports2, pat.argument);
2477
+ this.checkPatternExport(exports$1, pat.argument);
2434
2478
  }
2435
2479
  };
2436
- pp$8.checkVariableExport = function(exports2, decls) {
2437
- if (!exports2) {
2480
+ pp$8.checkVariableExport = function(exports$1, decls) {
2481
+ if (!exports$1) {
2438
2482
  return;
2439
2483
  }
2440
2484
  for (var i2 = 0, list2 = decls; i2 < list2.length; i2 += 1) {
2441
2485
  var decl = list2[i2];
2442
- this.checkPatternExport(exports2, decl.id);
2486
+ this.checkPatternExport(exports$1, decl.id);
2443
2487
  }
2444
2488
  };
2445
2489
  pp$8.shouldParseExportStatement = function() {
2446
2490
  return this.type.keyword === "var" || this.type.keyword === "const" || this.type.keyword === "class" || this.type.keyword === "function" || this.isLet() || this.isAsyncFunction();
2447
2491
  };
2448
- pp$8.parseExportSpecifier = function(exports2) {
2492
+ pp$8.parseExportSpecifier = function(exports$1) {
2449
2493
  var node = this.startNode();
2450
2494
  node.local = this.parseModuleExportName();
2451
2495
  node.exported = this.eatContextual("as") ? this.parseModuleExportName() : node.local;
2452
2496
  this.checkExport(
2453
- exports2,
2497
+ exports$1,
2454
2498
  node.exported,
2455
2499
  node.exported.start
2456
2500
  );
2457
2501
  return this.finishNode(node, "ExportSpecifier");
2458
2502
  };
2459
- pp$8.parseExportSpecifiers = function(exports2) {
2503
+ pp$8.parseExportSpecifiers = function(exports$1) {
2460
2504
  var nodes = [], first = true;
2461
2505
  this.expect(types$1.braceL);
2462
2506
  while (!this.eat(types$1.braceR)) {
@@ -2468,7 +2512,7 @@ pp$8.parseExportSpecifiers = function(exports2) {
2468
2512
  } else {
2469
2513
  first = false;
2470
2514
  }
2471
- nodes.push(this.parseExportSpecifier(exports2));
2515
+ nodes.push(this.parseExportSpecifier(exports$1));
2472
2516
  }
2473
2517
  return nodes;
2474
2518
  };
@@ -3036,17 +3080,20 @@ pp$5.checkPropClash = function(prop, propHash, refDestructuringErrors) {
3036
3080
  other[kind] = true;
3037
3081
  };
3038
3082
  pp$5.parseExpression = function(forInit, refDestructuringErrors) {
3039
- var startPos = this.start, startLoc = this.startLoc;
3040
- var expr = this.parseMaybeAssign(forInit, refDestructuringErrors);
3041
- if (this.type === types$1.comma) {
3042
- var node = this.startNodeAt(startPos, startLoc);
3043
- node.expressions = [expr];
3044
- while (this.eat(types$1.comma)) {
3045
- node.expressions.push(this.parseMaybeAssign(forInit, refDestructuringErrors));
3083
+ var this$1$1 = this;
3084
+ return this.catchStackOverflow(function() {
3085
+ var startPos = this$1$1.start, startLoc = this$1$1.startLoc;
3086
+ var expr = this$1$1.parseMaybeAssign(forInit, refDestructuringErrors);
3087
+ if (this$1$1.type === types$1.comma) {
3088
+ var node = this$1$1.startNodeAt(startPos, startLoc);
3089
+ node.expressions = [expr];
3090
+ while (this$1$1.eat(types$1.comma)) {
3091
+ node.expressions.push(this$1$1.parseMaybeAssign(forInit, refDestructuringErrors));
3092
+ }
3093
+ return this$1$1.finishNode(node, "SequenceExpression");
3046
3094
  }
3047
- return this.finishNode(node, "SequenceExpression");
3048
- }
3049
- return expr;
3095
+ return expr;
3096
+ });
3050
3097
  };
3051
3098
  pp$5.parseMaybeAssign = function(forInit, refDestructuringErrors, afterLeftParse) {
3052
3099
  if (this.isContextual("yield")) {
@@ -3118,7 +3165,7 @@ pp$5.parseMaybeConditional = function(forInit, refDestructuringErrors) {
3118
3165
  if (this.checkExpressionErrors(refDestructuringErrors)) {
3119
3166
  return expr;
3120
3167
  }
3121
- if (this.eat(types$1.question)) {
3168
+ if (!(expr.type === "ArrowFunctionExpression" && expr.start === startPos) && this.eat(types$1.question)) {
3122
3169
  var node = this.startNodeAt(startPos, startLoc);
3123
3170
  node.test = expr;
3124
3171
  node.consequent = this.parseMaybeAssign();
@@ -3213,7 +3260,7 @@ pp$5.parseMaybeUnary = function(refDestructuringErrors, sawUnary, incDec, forIni
3213
3260
  expr = this.finishNode(node$1, "UpdateExpression");
3214
3261
  }
3215
3262
  }
3216
- if (!incDec && this.eat(types$1.starstar)) {
3263
+ if (!incDec && !(expr.type === "ArrowFunctionExpression" && expr.start === startPos) && this.eat(types$1.starstar)) {
3217
3264
  if (sawUnary) {
3218
3265
  this.unexpected(this.lastTokStart);
3219
3266
  } else {
@@ -3617,6 +3664,9 @@ pp$5.parseNew = function() {
3617
3664
  }
3618
3665
  var startPos = this.start, startLoc = this.startLoc;
3619
3666
  node.callee = this.parseSubscripts(this.parseExprAtom(null, false, true), startPos, startLoc, true, false);
3667
+ if (node.callee.type === "Super") {
3668
+ this.raiseRecoverable(startPos, "Invalid use of 'super'");
3669
+ }
3620
3670
  if (this.eat(types$1.parenL)) {
3621
3671
  node.arguments = this.parseExprList(types$1.parenR, this.options.ecmaVersion >= 8, false);
3622
3672
  } else {
@@ -6369,7 +6419,7 @@ pp.readWord = function() {
6369
6419
  }
6370
6420
  return this.finishToken(type, word);
6371
6421
  };
6372
- var version = "8.16.0";
6422
+ var version = "8.18.0";
6373
6423
  Parser.acorn = {
6374
6424
  Parser,
6375
6425
  version,
@@ -6439,6 +6489,48 @@ function sourceRequiresModuleInput(source) {
6439
6489
  }
6440
6490
  }
6441
6491
 
6492
+ // src/shared/python/interpreter.ts
6493
+ var import_node_path2 = __toESM(require("node:path"));
6494
+ function pythonCommandCandidates(platform) {
6495
+ return platform === "win32" ? ["python", "py", "python3"] : ["python3", "python"];
6496
+ }
6497
+ function pythonVenvRelativePaths(platform) {
6498
+ const pathApi = platform === "win32" ? import_node_path2.default.win32 : import_node_path2.default.posix;
6499
+ return platform === "win32" ? [
6500
+ pathApi.join(".venv", "Scripts", "python.exe"),
6501
+ pathApi.join("venv", "Scripts", "python.exe")
6502
+ ] : [pathApi.join(".venv", "bin", "python"), pathApi.join("venv", "bin", "python")];
6503
+ }
6504
+ function pythonInterpreterCandidates(options) {
6505
+ const { startDirectory, platform, env, walkUp = false, respectPythonEnv = false } = options;
6506
+ const pathApi = platform === "win32" ? import_node_path2.default.win32 : import_node_path2.default.posix;
6507
+ const relatives = pythonVenvRelativePaths(platform);
6508
+ const candidates = [];
6509
+ let current2 = startDirectory;
6510
+ for (; ; ) {
6511
+ for (const relative of relatives) {
6512
+ candidates.push({ command: pathApi.join(current2, relative), source: "venv" });
6513
+ }
6514
+ if (!walkUp) break;
6515
+ const parent = pathApi.dirname(current2);
6516
+ if (parent === current2) break;
6517
+ current2 = parent;
6518
+ }
6519
+ const pythonEnv = respectPythonEnv ? env?.PYTHON : void 0;
6520
+ if (pythonEnv) candidates.push({ command: pythonEnv, source: "python-env" });
6521
+ for (const name of pythonCommandCandidates(platform)) {
6522
+ candidates.push({ command: name, source: "path" });
6523
+ }
6524
+ return candidates;
6525
+ }
6526
+ async function resolvePythonInterpreter(options, probe) {
6527
+ for (const candidate of pythonInterpreterCandidates(options)) {
6528
+ const resolved = await probe(candidate);
6529
+ if (resolved !== null) return resolved;
6530
+ }
6531
+ return null;
6532
+ }
6533
+
6442
6534
  // src/cli/runtime/targets.ts
6443
6535
  var ExecutionTargetError = class extends Error {
6444
6536
  constructor(reason, message) {
@@ -6449,7 +6541,7 @@ var ExecutionTargetError = class extends Error {
6449
6541
  reason;
6450
6542
  };
6451
6543
  async function resolveExecutionTarget(target, programArgs, env = process.env) {
6452
- const absolute = import_node_path2.default.resolve(target);
6544
+ const absolute = import_node_path3.default.resolve(target);
6453
6545
  let targetStat;
6454
6546
  try {
6455
6547
  targetStat = await (0, import_promises2.stat)(absolute);
@@ -6517,7 +6609,7 @@ async function resolveCapsuleSource(input, programArgs, env = process.env) {
6517
6609
  }
6518
6610
  }
6519
6611
  async function planProject(root, displayTarget, programArgs, env) {
6520
- const packageJson = import_node_path2.default.join(root, "package.json");
6612
+ const packageJson = import_node_path3.default.join(root, "package.json");
6521
6613
  if (await exists(packageJson)) {
6522
6614
  let manifest;
6523
6615
  try {
@@ -6539,18 +6631,18 @@ async function planProject(root, displayTarget, programArgs, env) {
6539
6631
  ]);
6540
6632
  }
6541
6633
  if (isRecord2(manifest) && typeof manifest.main === "string") {
6542
- const mainPath = import_node_path2.default.resolve(root, manifest.main);
6634
+ const mainPath = import_node_path3.default.resolve(root, manifest.main);
6543
6635
  if (await isFile(mainPath)) return planFile(mainPath, displayTarget, programArgs, env);
6544
6636
  }
6545
6637
  }
6546
- if (await exists(import_node_path2.default.join(root, "go.mod"))) {
6638
+ if (await exists(import_node_path3.default.join(root, "go.mod"))) {
6547
6639
  return singleStep(displayTarget, "go-project", root, commandName("go"), [
6548
6640
  "run",
6549
6641
  ".",
6550
6642
  ...programArgs
6551
6643
  ]);
6552
6644
  }
6553
- if (await exists(import_node_path2.default.join(root, "Cargo.toml"))) {
6645
+ if (await exists(import_node_path3.default.join(root, "Cargo.toml"))) {
6554
6646
  return singleStep(displayTarget, "cargo", root, commandName("cargo"), [
6555
6647
  "run",
6556
6648
  "--quiet",
@@ -6559,7 +6651,7 @@ async function planProject(root, displayTarget, programArgs, env) {
6559
6651
  ]);
6560
6652
  }
6561
6653
  for (const candidate of PROJECT_ENTRY_CANDIDATES) {
6562
- const entry = import_node_path2.default.join(root, candidate);
6654
+ const entry = import_node_path3.default.join(root, candidate);
6563
6655
  if (await isFile(entry)) return planFile(entry, displayTarget, programArgs, env);
6564
6656
  }
6565
6657
  throw new ExecutionTargetError(
@@ -6586,8 +6678,8 @@ var PROJECT_ENTRY_CANDIDATES = [
6586
6678
  "src/index.ts"
6587
6679
  ];
6588
6680
  async function planFile(absolute, displayTarget, programArgs, env) {
6589
- const cwd = import_node_path2.default.dirname(absolute);
6590
- const extension = import_node_path2.default.extname(absolute).toLowerCase();
6681
+ const cwd = import_node_path3.default.dirname(absolute);
6682
+ const extension = import_node_path3.default.extname(absolute).toLowerCase();
6591
6683
  switch (extension) {
6592
6684
  case ".js":
6593
6685
  case ".mjs":
@@ -6623,8 +6715,8 @@ async function planFile(absolute, displayTarget, programArgs, env) {
6623
6715
  case ".lua":
6624
6716
  return singleStep(displayTarget, "lua", cwd, commandName("lua"), [absolute, ...programArgs]);
6625
6717
  case ".rs": {
6626
- const temporaryRoot = await (0, import_promises2.mkdtemp)(import_node_path2.default.join(import_node_os.default.tmpdir(), "lingua-cli-rust-"));
6627
- const binary = import_node_path2.default.join(
6718
+ const temporaryRoot = await (0, import_promises2.mkdtemp)(import_node_path3.default.join(import_node_os.default.tmpdir(), "lingua-cli-rust-"));
6719
+ const binary = import_node_path3.default.join(
6628
6720
  temporaryRoot,
6629
6721
  process.platform === "win32" ? "program.exe" : "program"
6630
6722
  );
@@ -6651,8 +6743,8 @@ async function planFile(absolute, displayTarget, programArgs, env) {
6651
6743
  }
6652
6744
  }
6653
6745
  async function stageCompiledSource(displayTarget, language, filename, source, programArgs) {
6654
- const temporaryRoot = await (0, import_promises2.mkdtemp)(import_node_path2.default.join(import_node_os.default.tmpdir(), `lingua-cli-${language}-`));
6655
- const sourcePath = import_node_path2.default.join(temporaryRoot, filename);
6746
+ const temporaryRoot = await (0, import_promises2.mkdtemp)(import_node_path3.default.join(import_node_os.default.tmpdir(), `lingua-cli-${language}-`));
6747
+ const sourcePath = import_node_path3.default.join(temporaryRoot, filename);
6656
6748
  await (0, import_promises2.writeFile)(sourcePath, source, "utf8");
6657
6749
  if (language === "go") {
6658
6750
  return {
@@ -6669,7 +6761,7 @@ async function stageCompiledSource(displayTarget, language, filename, source, pr
6669
6761
  ]
6670
6762
  };
6671
6763
  }
6672
- const binary = import_node_path2.default.join(temporaryRoot, process.platform === "win32" ? "program.exe" : "program");
6764
+ const binary = import_node_path3.default.join(temporaryRoot, process.platform === "win32" ? "program.exe" : "program");
6673
6765
  return {
6674
6766
  displayTarget,
6675
6767
  runtime: "rust",
@@ -6733,34 +6825,28 @@ function planJavaScriptCapsule(displayTarget, cwd, input, programArgs, typescrip
6733
6825
  `Capsule runtime mode ${JSON.stringify(input.runtimeMode)} is not replayable by the CLI for ${typescript ? "TypeScript" : "JavaScript"}; supported modes are worker and node.`
6734
6826
  );
6735
6827
  }
6736
- function pythonCommandCandidates(platform = process.platform) {
6737
- return platform === "win32" ? ["python", "py", "python3"] : ["python3", "python"];
6738
- }
6739
6828
  function nodeRuntimeExecutable(options) {
6740
6829
  const sea = options?.sea ?? (0, import_node_sea.isSea)();
6741
6830
  return sea ? commandName("node") : options?.execPath ?? process.execPath;
6742
6831
  }
6743
- async function findPython(startDirectory, env = process.env) {
6744
- let current2 = startDirectory;
6745
- while (true) {
6746
- const local = process.platform === "win32" ? import_node_path2.default.join(current2, ".venv", "Scripts", "python.exe") : import_node_path2.default.join(current2, ".venv", "bin", "python");
6747
- if (await isFile(local)) return local;
6748
- const parent = import_node_path2.default.dirname(current2);
6749
- if (parent === current2) break;
6750
- current2 = parent;
6751
- }
6752
- if (env.PYTHON) return env.PYTHON;
6753
- const candidates = pythonCommandCandidates();
6754
- for (const candidate of candidates) {
6755
- if (await executableIsOnPath(candidate, process.platform, env)) return commandName(candidate);
6756
- }
6757
- return commandName(candidates[0]);
6832
+ async function findPython(startDirectory, env = process.env, platform = process.platform) {
6833
+ const resolved = await resolvePythonInterpreter(
6834
+ { startDirectory, platform, env, walkUp: true, respectPythonEnv: true },
6835
+ async (candidate) => {
6836
+ if (candidate.source === "path") {
6837
+ return await executableIsOnPath(candidate.command, platform, env) ? commandName(candidate.command) : null;
6838
+ }
6839
+ if (candidate.source === "python-env") return candidate.command;
6840
+ return await isFile(candidate.command) ? candidate.command : null;
6841
+ }
6842
+ );
6843
+ return resolved ?? commandName(pythonCommandCandidates(platform)[0]);
6758
6844
  }
6759
6845
  async function executableIsOnPath(executable, platform = process.platform, env = process.env) {
6760
6846
  const pathValue = env.PATH ?? env.Path ?? env.path;
6761
6847
  if (!pathValue) return false;
6762
6848
  const windows = platform === "win32";
6763
- const pathApi = windows ? import_node_path2.default.win32 : import_node_path2.default.posix;
6849
+ const pathApi = windows ? import_node_path3.default.win32 : import_node_path3.default.posix;
6764
6850
  const delimiter = windows ? ";" : ":";
6765
6851
  const extensions = windows ? (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean).map((extension) => extension.toLowerCase()) : [""];
6766
6852
  const hasExtension = pathApi.extname(executable).length > 0;
@@ -7090,7 +7176,7 @@ function errorMessage3(error) {
7090
7176
  var import_node_fs2 = require("node:fs");
7091
7177
  var import_promises3 = require("node:fs/promises");
7092
7178
  var import_node_os2 = __toESM(require("node:os"));
7093
- var import_node_path3 = __toESM(require("node:path"));
7179
+ var import_node_path4 = __toESM(require("node:path"));
7094
7180
 
7095
7181
  // src/cli/commandModel.ts
7096
7182
  var CLI_COLOR_MODES = ["auto", "always", "never"];
@@ -7505,29 +7591,29 @@ var defaultDependencies = {
7505
7591
  };
7506
7592
  function shellFromExecutable(executablePath) {
7507
7593
  if (!executablePath) return void 0;
7508
- const name = import_node_path3.default.basename(executablePath);
7594
+ const name = import_node_path4.default.basename(executablePath);
7509
7595
  return CLI_COMPLETION_SHELLS.includes(name) ? name : void 0;
7510
7596
  }
7511
7597
  function completionPathForShell(shell, io, dependencies) {
7512
7598
  const home = io.getEnvironmentValue("HOME") || dependencies.homedir();
7513
7599
  switch (shell) {
7514
7600
  case "bash": {
7515
- const dataHome = io.getEnvironmentValue("XDG_DATA_HOME") || import_node_path3.default.join(home, ".local/share");
7601
+ const dataHome = io.getEnvironmentValue("XDG_DATA_HOME") || import_node_path4.default.join(home, ".local/share");
7516
7602
  return {
7517
- completionPath: import_node_path3.default.join(dataHome, "bash-completion/completions/lingua")
7603
+ completionPath: import_node_path4.default.join(dataHome, "bash-completion/completions/lingua")
7518
7604
  };
7519
7605
  }
7520
7606
  case "zsh": {
7521
7607
  const zshHome = io.getEnvironmentValue("ZDOTDIR") || home;
7522
7608
  return {
7523
- completionPath: import_node_path3.default.join(zshHome, ".zfunc/_lingua"),
7524
- activationPath: import_node_path3.default.join(zshHome, ".zshrc")
7609
+ completionPath: import_node_path4.default.join(zshHome, ".zfunc/_lingua"),
7610
+ activationPath: import_node_path4.default.join(zshHome, ".zshrc")
7525
7611
  };
7526
7612
  }
7527
7613
  case "fish": {
7528
- const configHome = io.getEnvironmentValue("XDG_CONFIG_HOME") || import_node_path3.default.join(home, ".config");
7614
+ const configHome = io.getEnvironmentValue("XDG_CONFIG_HOME") || import_node_path4.default.join(home, ".config");
7529
7615
  return {
7530
- completionPath: import_node_path3.default.join(configHome, "fish/completions/lingua.fish")
7616
+ completionPath: import_node_path4.default.join(configHome, "fish/completions/lingua.fish")
7531
7617
  };
7532
7618
  }
7533
7619
  }
@@ -7537,9 +7623,9 @@ async function resolveExecutable(shell, io, dependencies) {
7537
7623
  if (shellFromExecutable(currentShellPath) === shell && currentShellPath !== void 0 && await dependencies.isExecutable(currentShellPath)) {
7538
7624
  return currentShellPath;
7539
7625
  }
7540
- const pathEntries = (io.getEnvironmentValue("PATH") || "").split(import_node_path3.default.delimiter).filter(Boolean);
7626
+ const pathEntries = (io.getEnvironmentValue("PATH") || "").split(import_node_path4.default.delimiter).filter(Boolean);
7541
7627
  for (const directory of pathEntries) {
7542
- const candidate = import_node_path3.default.join(directory, shell);
7628
+ const candidate = import_node_path4.default.join(directory, shell);
7543
7629
  if (await dependencies.isExecutable(candidate)) return candidate;
7544
7630
  }
7545
7631
  return void 0;
@@ -7622,7 +7708,7 @@ async function runCompletionInstallCommand(options, io, dependencies = defaultDe
7622
7708
  }
7623
7709
  }
7624
7710
  for (const target of targets) {
7625
- await dependencies.mkdir(import_node_path3.default.dirname(target.completionPath));
7711
+ await dependencies.mkdir(import_node_path4.default.dirname(target.completionPath));
7626
7712
  await dependencies.writeFile(target.completionPath, renderCompletion(target.shell));
7627
7713
  if (target.shell === "zsh" && target.activationPath) {
7628
7714
  await ensureZshActivation(target.activationPath, dependencies);
@@ -10449,8 +10535,8 @@ function createDefaultIo() {
10449
10535
  writeStderr(text) {
10450
10536
  process.stderr.write(text);
10451
10537
  },
10452
- async readFile(path4) {
10453
- return (0, import_promises4.readFile)(path4, "utf8");
10538
+ async readFile(path5) {
10539
+ return (0, import_promises4.readFile)(path5, "utf8");
10454
10540
  },
10455
10541
  async readStdin() {
10456
10542
  if (process.stdin.isTTY) {
@@ -10921,8 +11007,8 @@ function assertSingleTarget(command, positionals, help, label) {
10921
11007
 
10922
11008
  // src/cli/lingua.ts
10923
11009
  function resolveCliVersion() {
10924
- if ("1.4.1".length > 0) {
10925
- return "1.4.1";
11010
+ if ("1.5.1".length > 0) {
11011
+ return "1.5.1";
10926
11012
  }
10927
11013
  return "0.0.0-dev";
10928
11014
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linguacode/cli",
3
- "version": "1.4.1",
3
+ "version": "1.5.1",
4
4
  "description": "Headless offline CLI for Lingua utilities, local runners, and Run Capsules",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "homepage": "https://linguacode.dev",