@optique/core 1.2.12 → 1.2.13

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.
@@ -1,5 +1,6 @@
1
1
  import { lineBreak, message, optionName, text, value } from "./message.js";
2
2
  import { extractCommandNames, extractOptionNames, isSuggestionHidden } from "./usage.js";
3
+ import { mergeJoinedFileSuggestions } from "./internal/joined-file-suggestion.js";
3
4
 
4
5
  //#region src/suggestion.ts
5
6
  /**
@@ -322,22 +323,27 @@ function appendValueHint(base, input, candidates, options) {
322
323
  *
323
324
  * For literal suggestions, the text itself is used as the key.
324
325
  * For file suggestions, a composite key is created from the type,
325
- * extensions, and pattern.
326
+ * extensions, pattern, and insertion prefix.
326
327
  *
327
328
  * @param suggestion The suggestion to create a key for
328
329
  * @returns A string key that uniquely identifies this suggestion
329
330
  * @internal
330
331
  */
331
332
  function getSuggestionKey(suggestion) {
332
- if (suggestion.kind === "literal") return suggestion.text;
333
- return `__FILE__:${suggestion.type}:${suggestion.extensions?.toSorted().join(",") ?? ""}:${suggestion.pattern ?? ""}`;
333
+ if (suggestion.kind === "literal") return `literal:${suggestion.text}`;
334
+ return `file:${JSON.stringify([
335
+ suggestion.type,
336
+ suggestion.extensions?.toSorted().join(",") ?? "",
337
+ suggestion.pattern ?? "",
338
+ suggestion.prefix ?? ""
339
+ ])}`;
334
340
  }
335
341
  /**
336
342
  * Removes duplicate suggestions from an array while preserving order.
337
343
  *
338
344
  * Suggestions are considered duplicates if they have the same key:
339
345
  * - Literal suggestions: same text
340
- * - File suggestions: same type, extensions, and pattern
346
+ * - File suggestions: same type, extensions, pattern, and insertion prefix
341
347
  *
342
348
  * The first occurrence of each unique suggestion is kept. For file
343
349
  * suggestions, `includeHidden` is merged across duplicates: if any
@@ -370,7 +376,8 @@ function deduplicateSuggestions(suggestions) {
370
376
  if (existing == null) {
371
377
  entries.set(key, suggestion);
372
378
  order.push(key);
373
- } else if (suggestion.kind === "file" && existing.kind === "file" && suggestion.includeHidden === true && existing.includeHidden !== true) entries.set(key, {
379
+ } else if (suggestion.kind === "literal" && existing.kind === "literal") mergeJoinedFileSuggestions(existing, suggestion);
380
+ else if (suggestion.kind === "file" && existing.kind === "file" && suggestion.includeHidden === true && existing.includeHidden !== true) entries.set(key, {
374
381
  ...existing,
375
382
  includeHidden: true
376
383
  });
@@ -895,7 +895,8 @@ function prefixKeyValueSuggestion(suggestion, prefix, suffix = "") {
895
895
  const text$1 = `${prefix}${textValue}${suffix}`;
896
896
  if (suggestion.kind === "file" && suffix === "") return {
897
897
  ...suggestion,
898
- pattern: text$1
898
+ pattern: text$1,
899
+ prefix: `${prefix}${suggestion.prefix ?? ""}`
899
900
  };
900
901
  return suggestion.description == null ? {
901
902
  kind: "literal",
@@ -895,7 +895,8 @@ function prefixKeyValueSuggestion(suggestion, prefix, suffix = "") {
895
895
  const text$1 = `${prefix}${textValue}${suffix}`;
896
896
  if (suggestion.kind === "file" && suffix === "") return {
897
897
  ...suggestion,
898
- pattern: text$1
898
+ pattern: text$1,
899
+ prefix: `${prefix}${suggestion.prefix ?? ""}`
899
900
  };
900
901
  return suggestion.description == null ? {
901
902
  kind: "literal",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.2.12",
3
+ "version": "1.2.13",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",
@@ -221,7 +221,7 @@
221
221
  },
222
222
  "sideEffects": false,
223
223
  "devDependencies": {
224
- "@optique/env": "1.2.12",
224
+ "@optique/env": "1.2.13",
225
225
  "@types/node": "^24.0.0",
226
226
  "fast-check": "^4.7.0",
227
227
  "tsdown": "^0.13.0",