package-json-scripts-portability 0.0.1 → 0.0.3

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 (115) hide show
  1. package/README.md +59 -20
  2. package/dist/analyze-script.d.mts +34 -0
  3. package/dist/analyze-script.mjs +53 -0
  4. package/dist/command-checker.mjs +527 -0
  5. package/dist/command-usage.mjs +413 -0
  6. package/dist/commands.mjs +639 -0
  7. package/dist/context.mjs +25 -0
  8. package/dist/fixes.d.mts +9 -0
  9. package/dist/fixes.mjs +354 -0
  10. package/dist/index.d.mts +6 -118
  11. package/dist/index.mjs +4 -3787
  12. package/dist/line-break-checker.mjs +104 -0
  13. package/dist/messages.mjs +38 -0
  14. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/array-difference.mjs +11 -0
  15. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/array-includes.mjs +8 -0
  16. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/array-intersection.mjs +13 -0
  17. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/array-is-subset.mjs +16 -0
  18. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/arrayify.mjs +7 -0
  19. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/sorted-array-insertion-index-with.mjs +33 -0
  20. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/sorted-array-insertion-index.mjs +10 -0
  21. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/iterable/sliding-window.mjs +30 -0
  22. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/map/map-get-or-insert-computed.mjs +42 -0
  23. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/map/map-get-or-insert.mjs +40 -0
  24. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/math/clamp.mjs +7 -0
  25. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/path/to-forward-slashes.mjs +8 -0
  26. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/predicate/is-array.mjs +39 -0
  27. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/semver/is-semver-in-range.mjs +5 -0
  28. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/semver/parse-semver.mjs +26 -0
  29. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/set/set-has.mjs +8 -0
  30. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/string/substring-after-last.mjs +24 -0
  31. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/string/substring-after.mjs +24 -0
  32. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/string/substring-before.mjs +24 -0
  33. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/string/truncate.mjs +46 -0
  34. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/ts/all-union-members.mjs +45 -0
  35. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/types/maybe-readonly-array.d.mts +17 -0
  36. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/value/is-equal.mjs +37 -0
  37. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/@antfu/utils/dist/index.mjs +5 -0
  38. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/_internal/globalThis.mjs +5 -0
  39. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/_internal/isUnsafeProperty.mjs +18 -0
  40. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/_internal/setOwnValue.mjs +23 -0
  41. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/_internal/toPropertyKey.mjs +16 -0
  42. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/array/differenceBy.mjs +40 -0
  43. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/array/differenceWith.mjs +37 -0
  44. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/array/intersectionWith.mjs +43 -0
  45. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/array/isSubsetWith.mjs +36 -0
  46. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/bigint/clamp.mjs +15 -0
  47. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/_internal/baseToString.mjs +26 -0
  48. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/_internal/getSymbols.mjs +5 -0
  49. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/_internal/getTag.mjs +13 -0
  50. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/_internal/hasOwn.mjs +13 -0
  51. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/_internal/isDeepKey.mjs +39 -0
  52. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/_internal/isIndex.mjs +10 -0
  53. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/_internal/regexMultiByte.mjs +10 -0
  54. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/_internal/tags.mjs +28 -0
  55. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/_internal/toKey.mjs +15 -0
  56. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/array/sortedIndex.mjs +36 -0
  57. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/array/sortedIndexBy.mjs +54 -0
  58. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/array/sortedLastIndex.mjs +34 -0
  59. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/array/sortedLastIndexBy.mjs +21 -0
  60. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/function/identity.mjs +5 -0
  61. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/object/cloneDeep.mjs +52 -0
  62. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/object/cloneDeepWith.mjs +179 -0
  63. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/object/get.mjs +67 -0
  64. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/object/has.mjs +53 -0
  65. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/object/property.mjs +26 -0
  66. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/predicate/isArguments.mjs +26 -0
  67. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/predicate/isBuffer.mjs +24 -0
  68. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/predicate/isMatch.mjs +34 -0
  69. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/predicate/isMatchWith.mjs +163 -0
  70. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/predicate/isNaN.mjs +18 -0
  71. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/predicate/isNil.mjs +24 -0
  72. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/predicate/isNumber.mjs +24 -0
  73. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/predicate/isObject.mjs +28 -0
  74. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/predicate/isObjectLike.mjs +28 -0
  75. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/predicate/isSymbol.mjs +19 -0
  76. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/predicate/isTypedArray.mjs +21 -0
  77. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/predicate/matches.mjs +36 -0
  78. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/predicate/matchesProperty.mjs +47 -0
  79. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/string/truncate.mjs +78 -0
  80. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/util/eq.mjs +18 -0
  81. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/util/iteratee.mjs +46 -0
  82. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/util/toPath.mjs +75 -0
  83. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/util/toString.mjs +23 -0
  84. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/function/identity.mjs +24 -0
  85. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/function/noop.mjs +12 -0
  86. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/math/clamp.mjs +23 -0
  87. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/predicate/isBuffer.mjs +24 -0
  88. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/predicate/isEqual.mjs +21 -0
  89. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/predicate/isEqualWith.mjs +150 -0
  90. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/predicate/isNil.mjs +24 -0
  91. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/predicate/isNull.mjs +25 -0
  92. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/predicate/isPlainObject.mjs +50 -0
  93. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/predicate/isPrimitive.mjs +26 -0
  94. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/predicate/isSymbol.mjs +28 -0
  95. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/predicate/isTypedArray.mjs +20 -0
  96. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/predicate/isUndefined.mjs +25 -0
  97. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/remeda/dist/binarySearchCutoffIndex-Bu-OMJ0Z.mjs +26 -0
  98. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/remeda/dist/isArray.mjs +18 -0
  99. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/remeda/dist/sortedIndexWith.mjs +7 -0
  100. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/ts-extras/distribution/array-includes.mjs +5 -0
  101. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/ts-extras/distribution/set-has.mjs +5 -0
  102. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/verkit/dist/comparison-CmVirWIW.mjs +108 -0
  103. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/verkit/dist/range-C5wjdo9a.mjs +164 -0
  104. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/verkit/dist/set-BGFWKKE8.mjs +38 -0
  105. package/dist/platforms.d.mts +8 -0
  106. package/dist/platforms.mjs +26 -0
  107. package/dist/redirection-checker.mjs +169 -0
  108. package/dist/reporter.d.mts +32 -0
  109. package/dist/reporter.mjs +143 -0
  110. package/dist/runners.d.mts +21 -0
  111. package/dist/runners.mjs +199 -0
  112. package/dist/script-analyzer.mjs +853 -0
  113. package/dist/word-checker.mjs +573 -0
  114. package/dist/words.mjs +70 -0
  115. package/package.json +36 -30
@@ -0,0 +1,104 @@
1
+ import { rangeInScript } from "./context.mjs";
2
+ import { joinLinesFix } from "./fixes.mjs";
3
+ import { slidingWindow } from "./node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/iterable/sliding-window.mjs";
4
+ import { sortedArrayInsertionIndexWith } from "./node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/sorted-array-insertion-index-with.mjs";
5
+ // src/line-break-checker.ts
6
+ const ONE_LINE_SUGGESTION = "Put the command on one line instead.";
7
+ /** Checks whether an issue was dropped, e.g. in a platform fallback, which leaves no platforms */
8
+ const isDropped = (issue) => issue.platforms.length === 0;
9
+ /** Checks line breaks, after which cmd.exe ignores the rest of the script */
10
+ var LineBreakChecker = class {
11
+ /**
12
+ * The issue of the last line break reported in each script, by where the script is and its
13
+ * source
14
+ */
15
+ #lastIssues = /* @__PURE__ */ new Map();
16
+ /** Reported line breaks sorted by where they start in the analyzed script */
17
+ #lineBreaks = [];
18
+ #reporter;
19
+ constructor(reporter) {
20
+ this.#reporter = reporter;
21
+ }
22
+ /**
23
+ * Reports a line break in a command, e.g. after a `\` line continuation or in a quoted string.
24
+ * @param node The command
25
+ * @param context Where the command is
26
+ */
27
+ checkCommandLineBreak(node, context) {
28
+ const newline = context.source.slice(node.pos, node.end).indexOf("\n");
29
+ if (newline === -1) return;
30
+ const position = node.pos + newline;
31
+ const isInWord = [
32
+ node.name,
33
+ ...node.prefix,
34
+ ...node.suffix
35
+ ].some((item) => item && item.pos <= position && position < item.end);
36
+ const isQuoted = isInWord && context.source[position - 1] !== "\\";
37
+ this.reportLineBreak(context, position, ONE_LINE_SUGGESTION, isInWord ? void 0 : joinLinesFix(context.source, position, position + 1), isQuoted);
38
+ }
39
+ /**
40
+ * Reports a line break after an operator of a list or pipeline, e.g. after `||`.
41
+ * @param commands The commands that the operators join
42
+ * @param context Where the commands are
43
+ */
44
+ checkOperatorLineBreaks(commands, context) {
45
+ for (const [command, next] of slidingWindow(commands, 2)) {
46
+ const between = context.source.slice(command.end, next.pos);
47
+ const newline = between.indexOf("\n");
48
+ if (newline !== -1) {
49
+ const position = command.end + newline;
50
+ this.reportLineBreak(context, position, ONE_LINE_SUGGESTION, between.includes("#") ? void 0 : joinLinesFix(context.source, position, next.pos));
51
+ return;
52
+ }
53
+ }
54
+ }
55
+ /**
56
+ * Reports a line break, after which cmd.exe ignores the rest of the script, once per source.
57
+ * @param context Where the line break is
58
+ * @param position Where the line break is in the source
59
+ * @param suggestion What to do instead
60
+ * @param fix A fix for the report
61
+ * @param isPortableSupported Whether Yarn's shell supports it, e.g. in quotes
62
+ */
63
+ reportLineBreak(context, position, suggestion, fix, isPortableSupported = false) {
64
+ const lineBreak = {
65
+ end: position + 1,
66
+ pos: position
67
+ };
68
+ const range = rangeInScript(context, lineBreak);
69
+ const scriptKey = `${context.offset} ${context.fixedRange?.pos ?? ""} ${context.source}`;
70
+ const lastIssue = this.#lastIssues.get(scriptKey);
71
+ if (lastIssue && !isDropped(lastIssue) || this.#isOverlapReported(range)) return;
72
+ const platforms = this.#reporter.reportSyntax(context, lineBreak, "posix", isPortableSupported, "unsupportedSyntax", {
73
+ suggestion,
74
+ syntax: "A multi-line script"
75
+ }, fix);
76
+ const issue = this.#reporter.issues.at(-1);
77
+ if (!issue || platforms.length === 0) return;
78
+ this.#lastIssues.set(scriptKey, issue);
79
+ this.#lineBreaks.splice(sortedArrayInsertionIndexWith(this.#lineBreaks, (reported) => reported.range.pos < range.pos), 0, {
80
+ issue,
81
+ range
82
+ });
83
+ }
84
+ /**
85
+ * Checks whether a reported line break overlaps a range, e.g. in `concurrently "a` + line break +
86
+ * `b"`, which is reported for the outer script.
87
+ * Dropped line breaks are removed on the way.
88
+ * @param range The range in the analyzed script
89
+ * @returns Whether one does
90
+ */
91
+ #isOverlapReported(range) {
92
+ const lineBreaks = this.#lineBreaks;
93
+ const end = sortedArrayInsertionIndexWith(lineBreaks, (reported) => reported.range.pos < range.end);
94
+ for (let index = end - 1; index >= 0; index--) {
95
+ const reported = lineBreaks[index];
96
+ if (!reported) break;
97
+ if (isDropped(reported.issue)) lineBreaks.splice(index, 1);
98
+ else if (range.pos < reported.range.end) return true;
99
+ else if (reported.range.pos < reported.range.end) return false;
100
+ }
101
+ return false;
102
+ }
103
+ };
104
+ export { LineBreakChecker };
@@ -0,0 +1,38 @@
1
+ import { originalText } from "./context.mjs";
2
+ import { truncate as truncate$2 } from "./node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/string/truncate.mjs";
3
+ // src/messages.ts
4
+ const BASH_4_SUGGESTION = "It needs Bash 4 or later, which macOS doesn't ship; use a Node.js script instead.";
5
+ const BASH_SUGGESTION = "Scripts run with `sh` (which isn't Bash on e.g. Debian/Ubuntu) or cmd.exe (on Windows).";
6
+ const CROSS_ENV_SUGGESTION = "Use `cross-env` instead.";
7
+ const CROSS_ENV_VARIABLE_SUGGESTION = "`cross-env` only replaces `$VAR` and `${VAR}` in all versions; use a Node.js script instead.";
8
+ const DEFAULT_SUGGESTION = "Use a cross-platform package or a Node.js script instead.";
9
+ const NODE_SCRIPT_SUGGESTION = "Use a Node.js script instead.";
10
+ const RIMRAF_SUGGESTION = "Use `rimraf` instead.";
11
+ const SHELL_SCRIPT_SUGGESTION = "Shell scripts require a POSIX shell; use a Node.js script instead.";
12
+ const VARIABLE_SUGGESTION = "Use `cross-env` or a Node.js script instead.";
13
+ /** Joins names for people, e.g. "macOS, Linux, and Windows" */
14
+ const listFormat = new Intl.ListFormat("en");
15
+ /** Maximum length of script text in a report message */
16
+ const MAX_SNIPPET_CHARACTERS = 40;
17
+ const WHITESPACE = /\s+/g;
18
+ /**
19
+ * Shortens script text for a report message.
20
+ * @param text Text from the script
21
+ * @returns The text on a single line, cut off at the maximum length
22
+ */
23
+ const truncate = (text) => truncate$2(text.replaceAll(WHITESPACE, " "), { length: MAX_SNIPPET_CHARACTERS });
24
+ /**
25
+ * Gets the text of a node for a report message, as the script has it.
26
+ * @param context The piece of the script that the node is in
27
+ * @param node The node
28
+ * @returns The shortened text
29
+ */
30
+ const snippet = (context, node) => truncate(originalText(context, node));
31
+ /**
32
+ * Describes a fix that replaces script text, e.g. "Replace `rm -rf` with `rimraf`.".
33
+ * @param original The replaced text
34
+ * @param replacement The text that replaces it
35
+ * @returns The description
36
+ */
37
+ const describeReplacement = (original, replacement) => `Replace \`${truncate(original)}\` with \`${truncate(replacement)}\`.`;
38
+ export { BASH_4_SUGGESTION, BASH_SUGGESTION, CROSS_ENV_SUGGESTION, CROSS_ENV_VARIABLE_SUGGESTION, DEFAULT_SUGGESTION, NODE_SCRIPT_SUGGESTION, RIMRAF_SUGGESTION, SHELL_SCRIPT_SUGGESTION, VARIABLE_SUGGESTION, describeReplacement, listFormat, snippet, truncate };
@@ -0,0 +1,11 @@
1
+ import { differenceBy } from "../vendor/es-toolkit/dist/array/differenceBy.mjs";
2
+ import { differenceWith } from "../vendor/es-toolkit/dist/array/differenceWith.mjs";
3
+ // node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/array-difference.mjs
4
+ function arrayDifference(firstArray, secondArray, fn) {
5
+ if (!fn) {
6
+ const secondSet = new Set(secondArray);
7
+ return firstArray.filter((item) => !secondSet.has(item));
8
+ }
9
+ return fn.length === 2 ? differenceWith(firstArray, secondArray, fn) : differenceBy(firstArray, secondArray, fn);
10
+ }
11
+ export { arrayDifference };
@@ -0,0 +1,8 @@
1
+ import { arrayIncludes as arrayIncludes$1 } from "../vendor/ts-extras/distribution/array-includes.mjs";
2
+ // node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/array-includes.mjs
3
+ /**
4
+ * Checks whether an array has a value, like `Array.prototype.includes`, but as a type guard: when
5
+ * it returns `true`, the value is narrowed to the element type of the array
6
+ */
7
+ const arrayIncludes = arrayIncludes$1;
8
+ export { arrayIncludes };
@@ -0,0 +1,13 @@
1
+ import { intersectionWith } from "../vendor/es-toolkit/dist/array/intersectionWith.mjs";
2
+ // node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/array-intersection.mjs
3
+ function arrayIntersection(firstArray, secondArray, fn) {
4
+ if (!fn) {
5
+ const secondSet = new Set(secondArray);
6
+ return firstArray.filter((item) => secondSet.has(item));
7
+ }
8
+ if (fn.length === 2) return intersectionWith(firstArray, secondArray, fn);
9
+ const mapper = fn;
10
+ const secondKeys = new Set(secondArray.map((item) => mapper(item)));
11
+ return firstArray.filter((item) => secondKeys.has(mapper(item)));
12
+ }
13
+ export { arrayIntersection };
@@ -0,0 +1,16 @@
1
+ import { isSubsetWith } from "../vendor/es-toolkit/dist/array/isSubsetWith.mjs";
2
+ // node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/array-is-subset.mjs
3
+ function arrayIsSubset(superset, subset, fn) {
4
+ if (!fn) {
5
+ const supersetSet = new Set(superset);
6
+ return subset.every((item) => supersetSet.has(item));
7
+ }
8
+ if (fn.length === 2) {
9
+ const areItemsEqual = fn;
10
+ return isSubsetWith(superset, subset, (subsetItem, supersetItem) => areItemsEqual(supersetItem, subsetItem));
11
+ }
12
+ const mapper = fn;
13
+ const mappedSuperset = new Set(superset.map((item) => mapper(item)));
14
+ return subset.every((item) => mappedSuperset.has(mapper(item)));
15
+ }
16
+ export { arrayIsSubset };
@@ -0,0 +1,7 @@
1
+ import { isArray } from "../predicate/is-array.mjs";
2
+ // node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/arrayify.mjs
3
+ function arrayify(value, shouldWrapNullish = false) {
4
+ if (value == null) return shouldWrapNullish ? [value] : [];
5
+ return isArray(value) ? value : [value];
6
+ }
7
+ export { arrayify };
@@ -0,0 +1,33 @@
1
+ import { sortedIndexWith } from "../vendor/remeda/dist/sortedIndexWith.mjs";
2
+ // node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/sorted-array-insertion-index-with.mjs
3
+ /**
4
+ * Finds an insertion index into an already-sorted `sortedArray` using a binary
5
+ * search driven by a `predicate`.
6
+ * The predicate must return `true` for every element that should come *before*
7
+ * the insertion point and `false` from there on (i.e. it must be monotonic over
8
+ * the sorted array); the returned index is the first position at which it
9
+ * becomes `false`, in the range `0..sortedArray.length`.
10
+ *
11
+ * This is the most general member of the `sortedArrayInsertionIndex*` family:
12
+ * unlike `sortedArrayInsertionIndex` it takes no search value and is not
13
+ * limited to `number`/`string` keys, so it can locate a boundary for any
14
+ * comparable condition.
15
+ * @param sortedArray - The already-sorted array to search.
16
+ * Not mutated.
17
+ * @param predicate - Returns `true` for elements before the insertion point.
18
+ * Receives the value, its index, and the array.
19
+ * @returns The first index at which `predicate` returns `false`, in `0..sortedArray.length`.
20
+ * @example
21
+ * // First index whose value is not less than 2
22
+ * sortedArrayInsertionIndexWith([1, 2, 2, 3], (value) => value < 2);
23
+ * // 1
24
+ * @example
25
+ * // Boundary by a derived key
26
+ * sortedArrayInsertionIndexWith(
27
+ * [{age: 10}, {age: 20}, {age: 30}],
28
+ * (item) => item.age < 25,
29
+ * );
30
+ * // 2
31
+ */
32
+ const sortedArrayInsertionIndexWith = (sortedArray, predicate) => sortedIndexWith(sortedArray, predicate);
33
+ export { sortedArrayInsertionIndexWith };
@@ -0,0 +1,10 @@
1
+ import { sortedIndexBy } from "../vendor/es-toolkit/dist/compat/array/sortedIndexBy.mjs";
2
+ import { sortedIndex } from "../vendor/es-toolkit/dist/compat/array/sortedIndex.mjs";
3
+ import { sortedLastIndex } from "../vendor/es-toolkit/dist/compat/array/sortedLastIndex.mjs";
4
+ import { sortedLastIndexBy } from "../vendor/es-toolkit/dist/compat/array/sortedLastIndexBy.mjs";
5
+ // node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/sorted-array-insertion-index.mjs
6
+ function sortedArrayInsertionIndex(sortedArray, value, { iteratee, rightmost = false } = {}) {
7
+ if (iteratee) return rightmost ? sortedLastIndexBy(sortedArray, value, iteratee) : sortedIndexBy(sortedArray, value, iteratee);
8
+ return rightmost ? sortedLastIndex(sortedArray, value) : sortedIndex(sortedArray, value);
9
+ }
10
+ export { sortedArrayInsertionIndex };
@@ -0,0 +1,30 @@
1
+ // node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/iterable/sliding-window.mjs
2
+ function* generateWindows(iterable, size, step, shouldYieldPartialWindows) {
3
+ const buffer = [];
4
+ let skip = 0;
5
+ for (const item of iterable) {
6
+ if (skip > 0) {
7
+ skip--;
8
+ continue;
9
+ }
10
+ buffer.push(item);
11
+ if (buffer.length !== size) continue;
12
+ yield buffer.slice();
13
+ if (step >= size) {
14
+ buffer.length = 0;
15
+ skip = step - size;
16
+ } else buffer.splice(0, step);
17
+ }
18
+ if (!shouldYieldPartialWindows || buffer.length === 0) return;
19
+ yield buffer.slice();
20
+ while (buffer.length > step) {
21
+ buffer.splice(0, step);
22
+ yield buffer.slice();
23
+ }
24
+ }
25
+ function slidingWindow(iterable, size, step = 1, { partialWindows = false } = {}) {
26
+ if (!Number.isSafeInteger(size) || size < 1) throw new Error("`size` must be a positive integer.");
27
+ if (!Number.isSafeInteger(step) || step < 1) throw new Error("`step` must be a positive integer.");
28
+ return generateWindows(iterable, size, step, partialWindows);
29
+ }
30
+ export { slidingWindow };
@@ -0,0 +1,42 @@
1
+ // node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/map/map-get-or-insert-computed.mjs
2
+ /**
3
+ * Returns the value stored under `key`, first inserting the result of `computeDefaultValue` when
4
+ * the key is not present.
5
+ *
6
+ * The lazy counterpart of `mapGetOrInsert`: `computeDefaultValue` runs only on a miss, so it suits
7
+ * defaults that are expensive to build, must not be shared between keys, or have side effects.
8
+ * An already present value is never overwritten, and a stored `undefined` counts as present.
9
+ *
10
+ * Calls the native `Map#getOrInsertComputed` when the map has it, which doesn't call the `has`,
11
+ * `get` and `set` methods of the map: a `Map` subclass that overrides them should override
12
+ * `getOrInsertComputed` too.
13
+ * @param map - The map to read from.
14
+ * Mutated only when `key` is not present.
15
+ * @param key - The key to look up.
16
+ * @param computeDefaultValue - Produces the value to insert.
17
+ * Called with `key`, and only when `key` is not present.
18
+ * @returns The value already stored under `key`, or the computed value when it has just been
19
+ * inserted.
20
+ * @example
21
+ * // Grouping entries by key: every miss gets its own array
22
+ * const entriesByPackageId = new Map<string, Entry[]>();
23
+ * mapGetOrInsertComputed(entriesByPackageId, packageId, () => []).push(newEntry);
24
+ * @example
25
+ * // The looked-up key is passed to the factory
26
+ * const messagesByChannel = new Map<string, string[]>();
27
+ * mapGetOrInsertComputed(messagesByChannel, 'general', (channel) => [`joined ${channel}`]);
28
+ * // ['joined general']
29
+ * @example
30
+ * // Nothing is computed for a key that is already there
31
+ * mapGetOrInsertComputed(new Map([['alice', 10]]), 'alice', () => expensiveDefault());
32
+ * // 10, `expensiveDefault` never runs
33
+ */
34
+ const mapGetOrInsertComputed = (map, key, computeDefaultValue) => {
35
+ const nativeMap = map;
36
+ if (nativeMap.getOrInsertComputed) return nativeMap.getOrInsertComputed(key, computeDefaultValue);
37
+ if (map.has(key)) return map.get(key);
38
+ const defaultValue = computeDefaultValue(key);
39
+ map.set(key, defaultValue);
40
+ return defaultValue;
41
+ };
42
+ export { mapGetOrInsertComputed };
@@ -0,0 +1,40 @@
1
+ // node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/map/map-get-or-insert.mjs
2
+ /**
3
+ * Returns the value stored under `key`, first inserting `defaultValue` when the key is not present.
4
+ *
5
+ * The return type is not optional, unlike `Map#get`, so the result is directly usable, which
6
+ * collapses the usual "look up, create when missing, then use" dance into a single expression.
7
+ * An already present value is never overwritten, and a stored `undefined` counts as present.
8
+ *
9
+ * `defaultValue` is evaluated by the caller on every call, even when `key` is already present.
10
+ * Use `mapGetOrInsertComputed` when producing it is expensive or has side effects.
11
+ *
12
+ * Calls the native `Map#getOrInsert` when the map has it, which doesn't call the `has`, `get` and
13
+ * `set` methods of the map: a `Map` subclass that overrides them should override `getOrInsert` too.
14
+ * @param map - The map to read from.
15
+ * Mutated only when `key` is not present.
16
+ * @param key - The key to look up.
17
+ * @param defaultValue - The value to insert and return when `key` is not present.
18
+ * @returns The value already stored under `key`, or `defaultValue` when it has just been inserted.
19
+ * @example
20
+ * // Appending to an array-valued map without a separate existence check
21
+ * const tagsByPostId = new Map<string, string[]>();
22
+ * mapGetOrInsert(tagsByPostId, 'post-1', []).push('typescript');
23
+ * // Map { 'post-1' => ['typescript'] }
24
+ * @example
25
+ * // An existing value is returned as-is
26
+ * mapGetOrInsert(new Map([['alice', 10]]), 'alice', 0);
27
+ * // 10
28
+ * @example
29
+ * // A stored `undefined` is a value, not a miss
30
+ * mapGetOrInsert(new Map<string, number | undefined>([['a', undefined]]), 'a', 42);
31
+ * // undefined
32
+ */
33
+ const mapGetOrInsert = (map, key, defaultValue) => {
34
+ const nativeMap = map;
35
+ if (nativeMap.getOrInsert) return nativeMap.getOrInsert(key, defaultValue);
36
+ if (map.has(key)) return map.get(key);
37
+ map.set(key, defaultValue);
38
+ return defaultValue;
39
+ };
40
+ export { mapGetOrInsert };
@@ -0,0 +1,7 @@
1
+ import { clamp as clamp$1 } from "../vendor/es-toolkit/dist/bigint/clamp.mjs";
2
+ import { clamp as clamp$2 } from "../vendor/es-toolkit/dist/math/clamp.mjs";
3
+ // node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/math/clamp.mjs
4
+ function clamp(value, bound1, bound2) {
5
+ return typeof value === "bigint" ? clamp$1(value, bound1, bound2) : clamp$2(value, bound1, bound2);
6
+ }
7
+ export { clamp };
@@ -0,0 +1,8 @@
1
+ import { slash } from "../vendor/@antfu/utils/dist/index.mjs";
2
+ // node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/path/to-forward-slashes.mjs
3
+ /**
4
+ * Replaces every backslash in a path with a forward slash, turning a Windows path into the form
5
+ * that URLs, glob patterns and POSIX tools expect
6
+ */
7
+ const toForwardSlashes = slash;
8
+ export { toForwardSlashes };
@@ -0,0 +1,39 @@
1
+ import { isArray as isArray$1 } from "../vendor/remeda/dist/isArray.mjs";
2
+ // node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/predicate/is-array.mjs
3
+ /**
4
+ * Checks whether a value is an array, like `Array.isArray`, but also narrows readonly arrays.
5
+ *
6
+ * `Array.isArray` narrows to `any[]`, and a readonly array is not assignable to it.
7
+ * So for a `T | readonly T[]` value, it gives `any[]` when `true` and keeps `readonly T[]` when
8
+ * `false`.
9
+ * This guard narrows to the array members of the value's type (or to `readonly unknown[]` if
10
+ * there are none) when `true`, and removes them when `false`.
11
+ * @param data - The value to check.
12
+ * @returns `true` if `data` is an array, `false` otherwise.
13
+ * @example
14
+ * declare const paths: string | readonly string[];
15
+ *
16
+ * if (isArray(paths)) {
17
+ * paths; // readonly string[]
18
+ * } else {
19
+ * paths; // string
20
+ * }
21
+ * @example
22
+ * // Mutable arrays and tuples keep their types
23
+ * declare const size: number | [width: number, height: number];
24
+ *
25
+ * const [width, height] = isArray(size) ? size : [size, size];
26
+ * @example
27
+ * // Narrows `unknown` to a readonly array, so its elements can't be modified by mistake
28
+ * declare const value: unknown;
29
+ *
30
+ * if (isArray(value)) {
31
+ * value; // readonly unknown[]
32
+ * }
33
+ * @example
34
+ * isArray([1, 2, 3]); // true
35
+ * isArray(new Set([1, 2, 3])); // false
36
+ * isArray({length: 0}); // false
37
+ */
38
+ const isArray = isArray$1;
39
+ export { isArray };
@@ -0,0 +1,5 @@
1
+ import { f as satisfies } from "../vendor/verkit/dist/range-C5wjdo9a.mjs";
2
+ // node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/semver/is-semver-in-range.mjs
3
+ /** Checks whether a semantic version satisfies an npm-style version range */
4
+ const isSemverInRange = satisfies;
5
+ export { isSemverInRange };
@@ -0,0 +1,26 @@
1
+ import { S as tryParse } from "../vendor/verkit/dist/comparison-CmVirWIW.mjs";
2
+ // node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/semver/parse-semver.mjs
3
+ /**
4
+ * Parses a semantic version string into its parts.
5
+ * A leading `v` and surrounding whitespace are allowed; build metadata (after
6
+ * `+`) is split by dots, and numeric prerelease identifiers become numbers.
7
+ *
8
+ * Returns `undefined` for an invalid version, including incomplete ones like
9
+ * `'1.2'`.
10
+ * Pass `{loose: true}` to also accept common mistakes, like a leading `=` or a
11
+ * missing `-` before the prerelease (`'1.2.3beta'`).
12
+ * @param version - The version string to parse.
13
+ * @param options - Options.
14
+ * @param options.loose - Accept common syntax mistakes (defaults to `false`).
15
+ * @returns The version parts, or `undefined` if the version is invalid.
16
+ * @example
17
+ * parseSemver('1.2.3-rc.1+sha.abc');
18
+ * // {major: 1, minor: 2, patch: 3, prerelease: ['rc', 1], build: ['sha', 'abc']}
19
+ * parseSemver('v2.0.0');
20
+ * // {major: 2, minor: 0, patch: 0}
21
+ * @example
22
+ * parseSemver('1.2');
23
+ * // undefined
24
+ */
25
+ const parseSemver = (version, options) => tryParse(version, options) || void 0;
26
+ export { parseSemver };
@@ -0,0 +1,8 @@
1
+ import { setHas as setHas$1 } from "../vendor/ts-extras/distribution/set-has.mjs";
2
+ // node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/set/set-has.mjs
3
+ /**
4
+ * Checks whether a set has a value, like `Set.prototype.has`, but as a type guard: when it returns
5
+ * `true`, the value is narrowed to the element type of the set
6
+ */
7
+ const setHas = setHas$1;
8
+ export { setHas };
@@ -0,0 +1,24 @@
1
+ // node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/string/substring-after-last.mjs
2
+ /**
3
+ * Gets the part of a string after the last occurrence of a delimiter.
4
+ * When the delimiter is missing, returns `fallback`, which defaults to the
5
+ * whole string.
6
+ * @param text - The string to search.
7
+ * @param delimiter - The substring to search for.
8
+ * @param fallback - What to return when the delimiter is missing (defaults to `text`).
9
+ * @returns The part after the last delimiter, or `fallback`.
10
+ * @example
11
+ * substringAfterLast('src/utils/index.ts', '/');
12
+ * // 'index.ts'
13
+ * @example
14
+ * // File extension, empty when there is none
15
+ * substringAfterLast('index.test.ts', '.', '');
16
+ * // 'ts'
17
+ * substringAfterLast('Makefile', '.', '');
18
+ * // ''
19
+ */
20
+ const substringAfterLast = (text, delimiter, fallback = text) => {
21
+ const index = text.lastIndexOf(delimiter);
22
+ return index === -1 ? fallback : text.slice(index + delimiter.length);
23
+ };
24
+ export { substringAfterLast };
@@ -0,0 +1,24 @@
1
+ // node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/string/substring-after.mjs
2
+ /**
3
+ * Gets the part of a string after the first occurrence of a delimiter.
4
+ * When the delimiter is missing, returns `fallback`, which defaults to the
5
+ * whole string.
6
+ * @param text - The string to search.
7
+ * @param delimiter - The substring to search for.
8
+ * @param fallback - What to return when the delimiter is missing (defaults to `text`).
9
+ * @returns The part after the first delimiter, or `fallback`.
10
+ * @example
11
+ * substringAfter('index.test.ts', '.');
12
+ * // 'test.ts'
13
+ * substringAfter('https://example.com/a?b=1', '?');
14
+ * // 'b=1'
15
+ * @example
16
+ * // A different result for a missing delimiter
17
+ * substringAfter('https://example.com', '?', '');
18
+ * // ''
19
+ */
20
+ const substringAfter = (text, delimiter, fallback = text) => {
21
+ const index = text.indexOf(delimiter);
22
+ return index === -1 ? fallback : text.slice(index + delimiter.length);
23
+ };
24
+ export { substringAfter };
@@ -0,0 +1,24 @@
1
+ // node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/string/substring-before.mjs
2
+ /**
3
+ * Gets the part of a string before the first occurrence of a delimiter.
4
+ * When the delimiter is missing, returns `fallback`, which defaults to the
5
+ * whole string.
6
+ * @param text - The string to search.
7
+ * @param delimiter - The substring to search for.
8
+ * @param fallback - What to return when the delimiter is missing (defaults to `text`).
9
+ * @returns The part before the first delimiter, or `fallback`.
10
+ * @example
11
+ * substringBefore('index.test.ts', '.');
12
+ * // 'index'
13
+ * substringBefore('README', '.');
14
+ * // 'README'
15
+ * @example
16
+ * // A different result for a missing delimiter
17
+ * substringBefore('no-scheme', '://', '');
18
+ * // ''
19
+ */
20
+ const substringBefore = (text, delimiter, fallback = text) => {
21
+ const index = text.indexOf(delimiter);
22
+ return index === -1 ? fallback : text.slice(0, index);
23
+ };
24
+ export { substringBefore };
@@ -0,0 +1,46 @@
1
+ import { truncate as truncate$1 } from "../vendor/es-toolkit/dist/compat/string/truncate.mjs";
2
+ // node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/string/truncate.mjs
3
+ /**
4
+ * Shortens a string to a maximum length, replacing the removed part with an
5
+ * omission (`'...'` by default).
6
+ * Strings that fit are returned as is.
7
+ * The length is counted in code points, so emoji are never split in half.
8
+ *
9
+ * The removed part is at the end by default; pass `position: 'start'` to keep
10
+ * the end (like the end of a long path), or `'middle'` to keep both ends (like
11
+ * a file name with its extension).
12
+ * With the default `'end'` position, a `separator` makes the cut happen before
13
+ * its last match within the limit, to avoid cutting a word in half.
14
+ * When a match starts right at the limit, the string is cut there.
15
+ * When `length` is shorter than the omission, a string that doesn't fit becomes
16
+ * the omission alone, which is longer than `length`.
17
+ * @param text - The string to truncate.
18
+ * @param options - `length` (`30` by default), `omission` (`'...'` by default), `position` (`'end'`
19
+ * by default) and `separator`.
20
+ * @returns The string, shortened if needed.
21
+ * @example
22
+ * truncate('hi-diddly-ho there, neighborino');
23
+ * // 'hi-diddly-ho there, neighbo...'
24
+ * truncate('hi-diddly-ho there, neighborino', {length: 24, separator: ' '});
25
+ * // 'hi-diddly-ho there,...'
26
+ * @example
27
+ * // Keep the end or both ends
28
+ * truncate('/home/user/projects/utilery/src/index.ts', {length: 20, position: 'start'});
29
+ * // '...lery/src/index.ts'
30
+ * truncate('a-very-long-file-name.tar.gz', {length: 16, position: 'middle'});
31
+ * // 'a-very-...tar.gz'
32
+ */
33
+ const truncate = (text, options = {}) => {
34
+ const { length = 30, omission = "...", position = "end", separator } = options;
35
+ if (position === "end") return truncate$1(text, {
36
+ length,
37
+ omission,
38
+ ...separator != null && { separator }
39
+ });
40
+ const characters = [...text];
41
+ if (characters.length <= length) return text;
42
+ const keptLength = Math.max(Math.floor(length) - [...omission].length, 0) || 0;
43
+ const headLength = position === "middle" ? Math.ceil(keptLength / 2) : 0;
44
+ return characters.slice(0, headLength).join("") + omission + characters.slice(characters.length - (keptLength - headLength)).join("");
45
+ };
46
+ export { truncate };
@@ -0,0 +1,45 @@
1
+ // node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/ts/all-union-members.mjs
2
+ /**
3
+ * Builds a compile-time guard that a tuple lists every member of `Union`
4
+ * exactly once: no missing members, no extras and no duplicates.
5
+ * It is meant to keep a runtime list in sync with a union type: whenever the
6
+ * union changes, the tuple stops type-checking until it is updated to match.
7
+ *
8
+ * Because TypeScript cannot infer one type argument while another is given
9
+ * explicitly, the union is passed to the outer call and the tuple is inferred
10
+ * by the returned function.
11
+ * At runtime the returned function is the identity function: all of the work
12
+ * happens in the type system.
13
+ * An invalid tuple fails to type-check with a message that names the missing,
14
+ * extra or duplicated members (see {@link AllUnionMembers}).
15
+ *
16
+ * By default the result is widened to a mutable tuple; pass `{readonly: true}`
17
+ * as the second type argument to preserve the `readonly` tuple type instead.
18
+ * @returns A function that accepts the tuple and returns it unchanged, typed as
19
+ * the tuple of `Union`'s members (mutable by default, `readonly` on request).
20
+ * @example
21
+ * type Fruit = 'apple' | 'banana' | 'cherry';
22
+ *
23
+ * // OK: lists every member exactly once
24
+ * const fruits = allUnionMembers<Fruit>()(['apple', 'banana', 'cherry']);
25
+ * // type: ['apple', 'banana', 'cherry']
26
+ * @example
27
+ * // Error: "...is missing these union members": "cherry"
28
+ * allUnionMembers<Fruit>()(['apple', 'banana']);
29
+ * @example
30
+ * // Error: 'apple' is duplicated
31
+ * allUnionMembers<Fruit>()(['apple', 'banana', 'cherry', 'apple']);
32
+ * @example
33
+ * // Error: 'date' is not a member of `Fruit`
34
+ * allUnionMembers<Fruit>()(['apple', 'banana', 'cherry', 'date']);
35
+ * @example
36
+ * // Keep the tuple `readonly`
37
+ * const readonlyFruits = allUnionMembers<Fruit, {readonly: true}>()([
38
+ * 'apple',
39
+ * 'banana',
40
+ * 'cherry',
41
+ * ]);
42
+ * // type: readonly ['apple', 'banana', 'cherry']
43
+ */
44
+ const allUnionMembers = () => (members) => members;
45
+ export { allUnionMembers };