spec-controller 0.1.80 → 0.1.82

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 (2) hide show
  1. package/dist/cli.js +54 -18
  2. package/package.json +2 -2
package/dist/cli.js CHANGED
@@ -12934,31 +12934,62 @@ function nextToken(text, at, word) {
12934
12934
  }
12935
12935
  return plain(text, at);
12936
12936
  }
12937
- function simpleCommands(text) {
12938
- const source = text.replace(JOINED_LINE, " ");
12937
+ function pastBody(text, from, { delimiter, tabs }) {
12938
+ const lines = text.slice(from).split("\n");
12939
+ const last = lines.findIndex((line) => (tabs ? line.replace(/^\t*/, "") : line) === delimiter);
12940
+ return last === -1 ? text.length : from + lines.slice(0, last + 1).join("\n").length;
12941
+ }
12942
+ function commandList() {
12939
12943
  const commands = [];
12944
+ const opens = [];
12945
+ let closed;
12946
+ const read = (token, char) => {
12947
+ if (token.kind === "break")
12948
+ return;
12949
+ if (token.kind === "separator" && token.pipe && closed !== void 0) {
12950
+ commands.splice(closed, Infinity, ...commands.slice(closed).map((command) => ({ ...command, piped: true })));
12951
+ }
12952
+ if (char === "(")
12953
+ opens.push(commands.length);
12954
+ closed = char === ")" ? opens.pop() : void 0;
12955
+ };
12956
+ return { commands, push: (command) => commands.push(command), read };
12957
+ }
12958
+ function commentLineEnd(text, source, at, word) {
12959
+ if (comment(source, at, word) === void 0)
12960
+ return source;
12961
+ const end = text.indexOf("\n", at);
12962
+ return source[end] === text[end] ? source : `${source.slice(0, end)}
12963
+ ${source.slice(end + 1)}`;
12964
+ }
12965
+ function simpleCommands(text) {
12966
+ let source = text.replace(JOINED_LINE, (joined, pairs) => pairs.padEnd(joined.length));
12967
+ const { commands, push, read } = commandList();
12968
+ const bodies = [];
12940
12969
  let words = [];
12941
12970
  let word;
12942
12971
  let quoted = false;
12943
- let target = false;
12972
+ let target;
12944
12973
  const endWord = () => {
12945
- if (word !== void 0) {
12946
- if (!target)
12947
- words.push(word);
12948
- target = false;
12949
- }
12974
+ if (word === void 0)
12975
+ return;
12976
+ if (target === void 0)
12977
+ words.push(word);
12978
+ else if (target.kind === "heredoc")
12979
+ bodies.push({ delimiter: word, tabs: target.tabs, quoted });
12980
+ target = void 0;
12950
12981
  word = void 0;
12951
12982
  quoted = false;
12952
12983
  };
12953
12984
  const endCommand = (piped) => {
12954
12985
  endWord();
12955
- target = false;
12986
+ target = void 0;
12956
12987
  if (words.length > 0)
12957
- commands.push({ words, piped });
12988
+ push({ words, piped });
12958
12989
  words = [];
12959
12990
  };
12960
- let at = 0;
12961
- while (at < source.length) {
12991
+ for (let at = 0; at < source.length; ) {
12992
+ source = commentLineEnd(text, source, at, word);
12962
12993
  const token = nextToken(source, at, word);
12963
12994
  if (token.kind === "part") {
12964
12995
  word = (word ?? "") + token.value;
@@ -12966,12 +12997,14 @@ function simpleCommands(text) {
12966
12997
  } else if (token.kind === "separator")
12967
12998
  endCommand(token.pipe);
12968
12999
  else {
12969
- if (token.kind === "redirection" && !quoted && FILE_DESCRIPTOR.test(word ?? ""))
13000
+ if (token.kind !== "break" && !quoted && FILE_DESCRIPTOR.test(word ?? ""))
12970
13001
  word = void 0;
12971
13002
  endWord();
12972
- target ||= token.kind === "redirection";
13003
+ if (token.kind !== "break")
13004
+ target = token;
12973
13005
  }
12974
- at = token.end;
13006
+ read(token, source.charAt(at));
13007
+ at = source[at] === "\n" ? bodies.splice(0).reduce((from, body) => pastBody(body.quoted ? text : source, from, body), token.end) : token.end;
12975
13008
  }
12976
13009
  endCommand(false);
12977
13010
  return commands;
@@ -13132,9 +13165,9 @@ var init_commandRuns = __esm({
13132
13165
  return words.some((_, at) => opensAt(words, invocation, at));
13133
13166
  };
13134
13167
  pastAssignments = (words) => words.slice(words.findIndex((word) => !ASSIGNMENT.test(word)));
13135
- JOINED_LINE = /\\\r?\n/g;
13168
+ JOINED_LINE = /(?<!\\)((?:\\\\)*)\\\r?\n/g;
13136
13169
  SEPARATORS = "&|;()\n";
13137
- REDIRECTION = /&>|[<>]&|>>|[<>]/y;
13170
+ REDIRECTION = /<<<|<<-?|&>|[<>]&|>>|[<>]/y;
13138
13171
  FILE_DESCRIPTOR = /^\d+$/;
13139
13172
  PLAIN = /[^\s&|;()<>'"\\`$]+/y;
13140
13173
  ESCAPED_IN_DOUBLE_QUOTES = '"\\$`';
@@ -13172,7 +13205,10 @@ var init_commandRuns = __esm({
13172
13205
  redirection = (text, at) => {
13173
13206
  REDIRECTION.lastIndex = at;
13174
13207
  const operator = REDIRECTION.exec(text)?.[0];
13175
- return operator === void 0 ? void 0 : { kind: "redirection", end: at + operator.length };
13208
+ if (operator === void 0)
13209
+ return void 0;
13210
+ const end = at + operator.length;
13211
+ return operator === "<<" || operator === "<<-" ? { kind: "heredoc", tabs: operator === "<<-", end } : { kind: "redirection", end };
13176
13212
  };
13177
13213
  separator = (text, at) => {
13178
13214
  const char = text.charAt(at);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spec-controller",
3
- "version": "0.1.80",
3
+ "version": "0.1.82",
4
4
  "description": "Reconcile the behaviour your scenarios name against the evidence that actually ran — the deterministic `balance` CLI.",
5
5
  "keywords": [
6
6
  "reconciliation",
@@ -25,7 +25,7 @@
25
25
  "esbuild": "0.28.1",
26
26
  "fast-xml-parser": "^5.11.2",
27
27
  "yaml": "^2.9.0",
28
- "@3f-consulting/spec-controller-core": "0.1.80"
28
+ "@3f-consulting/spec-controller-core": "0.1.82"
29
29
  },
30
30
  "publishConfig": {
31
31
  "access": "public"