@optique/core 1.1.12 → 1.1.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 { message, optionName, text } 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
  /**
@@ -257,22 +258,27 @@ function createErrorWithSuggestions(baseError, invalidInput, usage, type = "both
257
258
  *
258
259
  * For literal suggestions, the text itself is used as the key.
259
260
  * For file suggestions, a composite key is created from the type,
260
- * extensions, and pattern.
261
+ * extensions, pattern, and insertion prefix.
261
262
  *
262
263
  * @param suggestion The suggestion to create a key for
263
264
  * @returns A string key that uniquely identifies this suggestion
264
265
  * @internal
265
266
  */
266
267
  function getSuggestionKey(suggestion) {
267
- if (suggestion.kind === "literal") return suggestion.text;
268
- return `__FILE__:${suggestion.type}:${suggestion.extensions?.toSorted().join(",") ?? ""}:${suggestion.pattern ?? ""}`;
268
+ if (suggestion.kind === "literal") return `literal:${suggestion.text}`;
269
+ return `file:${JSON.stringify([
270
+ suggestion.type,
271
+ suggestion.extensions?.toSorted().join(",") ?? "",
272
+ suggestion.pattern ?? "",
273
+ suggestion.prefix ?? ""
274
+ ])}`;
269
275
  }
270
276
  /**
271
277
  * Removes duplicate suggestions from an array while preserving order.
272
278
  *
273
279
  * Suggestions are considered duplicates if they have the same key:
274
280
  * - Literal suggestions: same text
275
- * - File suggestions: same type, extensions, and pattern
281
+ * - File suggestions: same type, extensions, pattern, and insertion prefix
276
282
  *
277
283
  * The first occurrence of each unique suggestion is kept. For file
278
284
  * suggestions, `includeHidden` is merged across duplicates: if any
@@ -305,7 +311,8 @@ function deduplicateSuggestions(suggestions) {
305
311
  if (existing == null) {
306
312
  entries.set(key, suggestion);
307
313
  order.push(key);
308
- } else if (suggestion.kind === "file" && existing.kind === "file" && suggestion.includeHidden === true && existing.includeHidden !== true) entries.set(key, {
314
+ } else if (suggestion.kind === "literal" && existing.kind === "literal") mergeJoinedFileSuggestions(existing, suggestion);
315
+ else if (suggestion.kind === "file" && existing.kind === "file" && suggestion.includeHidden === true && existing.includeHidden !== true) entries.set(key, {
309
316
  ...existing,
310
317
  includeHidden: true
311
318
  });
@@ -602,7 +602,8 @@ function prefixKeyValueSuggestion(suggestion, prefix, suffix = "") {
602
602
  const text$1 = `${prefix}${textValue}${suffix}`;
603
603
  if (suggestion.kind === "file" && suffix === "") return {
604
604
  ...suggestion,
605
- pattern: text$1
605
+ pattern: text$1,
606
+ prefix: `${prefix}${suggestion.prefix ?? ""}`
606
607
  };
607
608
  return suggestion.description == null ? {
608
609
  kind: "literal",
@@ -602,7 +602,8 @@ function prefixKeyValueSuggestion(suggestion, prefix, suffix = "") {
602
602
  const text$1 = `${prefix}${textValue}${suffix}`;
603
603
  if (suggestion.kind === "file" && suffix === "") return {
604
604
  ...suggestion,
605
- pattern: text$1
605
+ pattern: text$1,
606
+ prefix: `${prefix}${suggestion.prefix ?? ""}`
606
607
  };
607
608
  return suggestion.description == null ? {
608
609
  kind: "literal",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.1.12",
3
+ "version": "1.1.13",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",
@@ -196,7 +196,7 @@
196
196
  },
197
197
  "sideEffects": false,
198
198
  "devDependencies": {
199
- "@optique/env": "1.1.12",
199
+ "@optique/env": "1.1.13",
200
200
  "@types/node": "^24.0.0",
201
201
  "fast-check": "^4.7.0",
202
202
  "tsdown": "^0.13.0",