@staff0rd/assist 0.513.0 → 0.514.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.
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import { Command } from "commander";
6
6
  // package.json
7
7
  var package_default = {
8
8
  name: "@staff0rd/assist",
9
- version: "0.513.0",
9
+ version: "0.514.1",
10
10
  type: "module",
11
11
  main: "dist/index.js",
12
12
  bin: {
@@ -15358,15 +15358,39 @@ function consumeRedirect(tokens, opIndex, current) {
15358
15358
  error: `redirect target '${target}' is outside the OS temp directory`
15359
15359
  };
15360
15360
  }
15361
+ popFdPrefix(current);
15362
+ return { ok: true, nextIndex: opIndex + 1 };
15363
+ }
15364
+ function popFdPrefix(current) {
15361
15365
  if (current.length > 0 && /^\d$/.test(current[current.length - 1])) {
15362
15366
  current.pop();
15363
15367
  }
15368
+ }
15369
+
15370
+ // src/shared/consumeHeredoc.ts
15371
+ function consumeHeredoc(tokens, opIndex, current) {
15372
+ const delimiter = tokens[opIndex + 2];
15373
+ if (typeof delimiter !== "string") {
15374
+ return { ok: false, error: "unable to parse" };
15375
+ }
15376
+ popFdPrefix(current);
15377
+ return { ok: true, nextIndex: opIndex + 2 };
15378
+ }
15379
+
15380
+ // src/shared/consumeInputRedirect.ts
15381
+ function consumeInputRedirect(tokens, opIndex, current) {
15382
+ const source = tokens[opIndex + 1];
15383
+ if (typeof source !== "string") {
15384
+ return { ok: false, error: "unable to parse" };
15385
+ }
15386
+ popFdPrefix(current);
15364
15387
  return { ok: true, nextIndex: opIndex + 1 };
15365
15388
  }
15366
15389
 
15367
15390
  // src/shared/groupByOperator.ts
15368
15391
  var SEPARATOR_OPS = /* @__PURE__ */ new Set(["|", "&&", "||", ";"]);
15369
15392
  var OUTPUT_REDIRECT_OPS = /* @__PURE__ */ new Set([">", ">>"]);
15393
+ var INPUT_REDIRECT_OP = "<";
15370
15394
  var UNPARSEABLE = { ok: false, error: "unable to parse" };
15371
15395
  function groupByOperator(tokens) {
15372
15396
  const groups = [[]];
@@ -15392,6 +15416,10 @@ function handleToken(tokens, i, groups) {
15392
15416
  if (OUTPUT_REDIRECT_OPS.has(op)) {
15393
15417
  return consumeRedirect(tokens, i, groups[groups.length - 1]);
15394
15418
  }
15419
+ if (op === INPUT_REDIRECT_OP) {
15420
+ const current = groups[groups.length - 1];
15421
+ return getOp(tokens[i + 1]) === INPUT_REDIRECT_OP ? consumeHeredoc(tokens, i, current) : consumeInputRedirect(tokens, i, current);
15422
+ }
15395
15423
  return UNPARSEABLE;
15396
15424
  }
15397
15425
  function appendWord(token, groups, i) {
@@ -15413,6 +15441,90 @@ function hasUnquotedBackticks(command) {
15413
15441
  return false;
15414
15442
  }
15415
15443
 
15444
+ // src/shared/separateCommandLines.ts
15445
+ var ESCAPE_OR_QUOTED_OR_NEWLINE_RE = /\\[\s\S]|'[^']*'|"[^"]*"|(\n)/g;
15446
+ function separateCommandLines(command) {
15447
+ if (!command.includes("\n")) return command;
15448
+ return command.replace(
15449
+ ESCAPE_OR_QUOTED_OR_NEWLINE_RE,
15450
+ (match, newline) => newline === void 0 ? match : ";"
15451
+ );
15452
+ }
15453
+
15454
+ // src/shared/matchHeredocHeader.ts
15455
+ var HEADER_RE = /^<<-?[ \t]*(?:'([^']*)'|"([^"]*)"|([^\s;|&<>()'"$`]+))/;
15456
+ function matchHeredocHeader(command, start3) {
15457
+ let end = start3;
15458
+ while (command[end] === "<") end++;
15459
+ const angles = command.slice(start3, end);
15460
+ if (angles.length !== 2) return { text: angles };
15461
+ const match = HEADER_RE.exec(command.slice(start3));
15462
+ if (!match) return { text: angles };
15463
+ return { text: match[0], delimiter: match[1] ?? match[2] ?? match[3] };
15464
+ }
15465
+
15466
+ // src/shared/skipHeredocBodies.ts
15467
+ function skipHeredocBodies(command, start3, delimiters) {
15468
+ let i = start3;
15469
+ for (const delimiter of delimiters) i = skipBody(command, i, delimiter);
15470
+ return i;
15471
+ }
15472
+ function skipBody(command, start3, delimiter) {
15473
+ let i = start3;
15474
+ while (i < command.length) {
15475
+ const newline = command.indexOf("\n", i);
15476
+ const line = command.slice(i, newline === -1 ? command.length : newline);
15477
+ i = newline === -1 ? command.length : newline + 1;
15478
+ if (line.trim() === delimiter) return i;
15479
+ }
15480
+ return i;
15481
+ }
15482
+
15483
+ // src/shared/stripHeredocBodies.ts
15484
+ function stripHeredocBodies(command) {
15485
+ if (!command.includes("<<")) return command;
15486
+ let out = "";
15487
+ let pending = [];
15488
+ let quote;
15489
+ let i = 0;
15490
+ while (i < command.length) {
15491
+ const char = command[i];
15492
+ if (char === "\\" && quote !== "'" && i + 1 < command.length) {
15493
+ out += command.slice(i, i + 2);
15494
+ i += 2;
15495
+ continue;
15496
+ }
15497
+ if (quote) {
15498
+ if (char === quote) quote = void 0;
15499
+ out += char;
15500
+ i++;
15501
+ continue;
15502
+ }
15503
+ if (char === "'" || char === '"') {
15504
+ quote = char;
15505
+ out += char;
15506
+ i++;
15507
+ continue;
15508
+ }
15509
+ if (char === "\n" && pending.length > 0) {
15510
+ out += char;
15511
+ i = skipHeredocBodies(command, i + 1, pending);
15512
+ pending = [];
15513
+ continue;
15514
+ }
15515
+ if (char === "<") {
15516
+ const header = matchHeredocHeader(command, i);
15517
+ if (header.delimiter !== void 0) pending.push(header.delimiter);
15518
+ out += header.text;
15519
+ i += header.text.length;
15520
+ continue;
15521
+ }
15522
+ out += char;
15523
+ i++;
15524
+ }
15525
+ return out;
15526
+ }
15527
+
15416
15528
  // src/shared/splitCompound.ts
15417
15529
  var FD_REDIRECT_RE = /\d+>&\d+/g;
15418
15530
  var FD_DEVNULL_RE = /\d*>(?:\/dev\/null|\$null)/g;
@@ -15422,12 +15534,12 @@ function splitCompound(command) {
15422
15534
  if (!tokens) return UNPARSEABLE2;
15423
15535
  const grouped = groupByOperator(tokens);
15424
15536
  if (!grouped.ok) return grouped;
15425
- const parts = grouped.groups.map((g) => stripEnvPrefix(g).join(" ")).filter((cmd) => cmd !== "");
15537
+ const parts = grouped.groups.map((g) => stripEnvPrefix(g.filter((word) => word !== "")).join(" ")).filter((cmd) => cmd !== "");
15426
15538
  if (parts.length === 0) return UNPARSEABLE2;
15427
15539
  return { ok: true, parts };
15428
15540
  }
15429
15541
  function tokenizeCommand(command) {
15430
- const trimmed = command.trim().replace(FD_DEVNULL_RE, "").replace(FD_REDIRECT_RE, "");
15542
+ const trimmed = separateCommandLines(stripHeredocBodies(command.trim())).replace(FD_DEVNULL_RE, "").replace(FD_REDIRECT_RE, "");
15431
15543
  if (!trimmed) return void 0;
15432
15544
  if (hasUnquotedBackticks(trimmed)) return void 0;
15433
15545
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@staff0rd/assist",
3
- "version": "0.513.0",
3
+ "version": "0.514.1",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {