@open-tomato/rafa 0.23.0 → 0.24.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.
@@ -4,7 +4,7 @@ import {
4
4
  commandSpelling,
5
5
  isRoutingWord,
6
6
  isTopLevel
7
- } from "./index-28jzpyks.js";
7
+ } from "./index-4fwgqveh.js";
8
8
  import {
9
9
  describeValue
10
10
  } from "./index-pmkgvtfe.js";
@@ -82,14 +82,23 @@ function shadowOf(words, find, subjects) {
82
82
  return;
83
83
  return find(subject.name, second);
84
84
  }
85
+ function typedAlias(alias) {
86
+ return alias.trim().split(/\s+/).join(" ");
87
+ }
85
88
  function indexAliases(commands, find, subjects) {
86
89
  const claimed = new Map;
87
90
  const aliases = [];
88
91
  for (const command of commands) {
89
92
  const spelling = commandSpelling(command);
93
+ const lasting = new Set((command.lastingAliases ?? []).map(typedAlias));
94
+ for (const kept of lasting) {
95
+ if (!(command.aliases ?? []).map(typedAlias).includes(kept)) {
96
+ throw new Error(`${REFUSAL}: command "${spelling}" has lasting alias "${kept}", which is not one of its aliases`);
97
+ }
98
+ }
90
99
  for (const alias of command.aliases ?? []) {
91
- const words = Object.freeze(alias.trim().split(/\s+/));
92
- const typed = words.join(" ");
100
+ const typed = typedAlias(alias);
101
+ const words = Object.freeze(typed.split(" "));
93
102
  if (!words.every(isRoutingWord)) {
94
103
  throw new Error(`${REFUSAL}: command "${spelling}" has alias ${describeValue(alias)},` + " expected words with no slash and no leading dash");
95
104
  }
@@ -103,7 +112,7 @@ function indexAliases(commands, find, subjects) {
103
112
  throw new Error(`${REFUSAL}: alias "${typed}" of "${spelling}" is spelled as command "${commandSpelling(shadow)}"`);
104
113
  }
105
114
  claimed.set(typed, command);
106
- aliases.push(Object.freeze({ words, command }));
115
+ aliases.push(Object.freeze({ words, command, lasting: lasting.has(typed) }));
107
116
  }
108
117
  }
109
118
  return Object.freeze(aliases.sort((a, b) => b.words.length - a.words.length));
@@ -189,7 +198,7 @@ function describeArg(arg) {
189
198
  function describeFlag(flag) {
190
199
  return { ...describeArg(flag), aliases: [...flag.aliases ?? []] };
191
200
  }
192
- function typedAlias(alias) {
201
+ function typedAlias2(alias) {
193
202
  return alias.trim().split(/\s+/).join(" ");
194
203
  }
195
204
  function describeCommand(command, name, module) {
@@ -202,7 +211,7 @@ function describeCommand(command, name, module) {
202
211
  flags: command.flags.map(describeFlag),
203
212
  examples: command.examples.map(({ cmd, note }) => ({ cmd, note })),
204
213
  outputs: [...command.outputs],
205
- aliases: module === null ? (command.aliases ?? []).map(typedAlias) : [],
214
+ aliases: module === null ? (command.aliases ?? []).map(typedAlias2) : [],
206
215
  deprecated: deprecated === undefined ? null : { since: deprecated.since, use: deprecated.use },
207
216
  module,
208
217
  spends: spends === undefined ? null : { ...spends }