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,413 @@
1
+ import { NO_LONG_OPTIONS_ON_MACOS, TIMEOUT_VALUE_OPTIONS } from "./commands.mjs";
2
+ import { isDotfileName } from "./fixes.mjs";
3
+ import { CROSS_ENV_SUGGESTION, NODE_SCRIPT_SUGGESTION, RIMRAF_SUGGESTION, describeReplacement, truncate } from "./messages.mjs";
4
+ import { LINUX_PLATFORMS, MACOS_PLATFORMS, NOT_MACOS_OR_WINDOWS, PLATFORMS, POSIX_PLATFORMS, WINDOWS_PLATFORMS } from "./platforms.mjs";
5
+ import { setHas } from "./node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/set/set-has.mjs";
6
+ import { substringBefore } from "./node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/string/substring-before.mjs";
7
+ import { ASSIGNMENT, isShortOptionCluster } from "./words.mjs";
8
+ // src/command-usage.ts
9
+ /** Commands that also exist in cmd.exe, whose names are case-insensitive there */
10
+ const CMD_COMMANDS = /* @__PURE__ */ new Set([
11
+ "exit",
12
+ "mkdir",
13
+ "rmdir",
14
+ "set",
15
+ "sort",
16
+ "timeout"
17
+ ]);
18
+ /** Bash's pseudo-signals for `trap`, which dash doesn't support */
19
+ const BASH_TRAP_CONDITIONS = /* @__PURE__ */ new Set([
20
+ "DEBUG",
21
+ "ERR",
22
+ "RETURN"
23
+ ]);
24
+ const DASH = "dash, the `sh` of Debian/Ubuntu,";
25
+ /** GNU `find` primaries that BSD `find` doesn't support */
26
+ const GNU_FIND_PRIMARIES = /* @__PURE__ */ new Set([
27
+ "-executable",
28
+ "-fprintf",
29
+ "-printf",
30
+ "-readable",
31
+ "-regextype",
32
+ "-writable",
33
+ "-xtype"
34
+ ]);
35
+ /** BSD `find` options, which come before the starting paths */
36
+ const BSD_FIND_OPTIONS = /^-[EHLPXdsx]+$/;
37
+ /**
38
+ * GNU regex escapes that BSD `sed` doesn't support, e.g. `\s`, but not after an escaped backslash,
39
+ * e.g. in `\\s`
40
+ */
41
+ const GNU_SED_ESCAPE = /(?<!\\)(?:\\\\)*(\\[<>bsw])/i;
42
+ /** The same, in basic regexes only */
43
+ const GNU_SED_BASIC_ESCAPE = /(?<!\\)(?:\\\\)*(\\[+?])/;
44
+ /** GNU `xargs` options that BSD `xargs` doesn't support, e.g. `-d` */
45
+ const GNU_XARGS_OPTION = /^(?:-[0prtx]*[adil]|--(?:arg-file|delimiter|max-lines|replace)\b)/;
46
+ const LONG_OPTION = /^--[^-]/;
47
+ /** Long options that some BSD utilities on macOS do support, by utility */
48
+ const BSD_LONG_OPTIONS = /* @__PURE__ */ new Map([["df", ["--libxo", "--si"]], ["du", ["--libxo", "--si"]]]);
49
+ /** Any option, e.g. `-p` */
50
+ const POSIX_OPTION = /^-./;
51
+ /**
52
+ * Switches of cmd.exe's `dir`, also combined or turned off with `-`, e.g. `/b`, `/a:-d`, `/o-n` or
53
+ * `/b/s`, unlike paths like `/usr/lib`
54
+ */
55
+ const DIR_CMD_OPTION = /^(?:\/-?(?:[4bcdlnp-swx]|a:?(?:-?[adhilors])*|o:?(?:-?[degns])*|t:?[acw]?))+$/i;
56
+ /** Including combined switches, e.g. `/s/q` */
57
+ const RMDIR_CMD_OPTION = /^(?:\/[qs])+$/i;
58
+ const EXIT_CMD_OPTION = /^\/b$/i;
59
+ /** Options of cmd.exe's `timeout`, which are case-insensitive, e.g. `/T` */
60
+ const TIMEOUT_CMD_OPTION = /^\/(?:nobreak|t)$/i;
61
+ const ECHO_OPTIONS = /^-[Een]+$/;
62
+ const HEAD_COUNT_OPTION = /^-[cn]$/;
63
+ /** e.g. `-n-1` */
64
+ const HEAD_NEGATIVE_COUNT_OPTION = /^-[cn]-\d/;
65
+ const NEGATIVE_NUMBER = /^-\d/;
66
+ /**
67
+ * `-E` or `-r`, also in a cluster like `-nE`, but not after an option that takes the rest of the
68
+ * cluster as its value, like `-e` (a script) or `-i` (a backup suffix)
69
+ */
70
+ const SED_EXTENDED_OPTION = /^-(?:(?![Iefil])[A-Za-z])*[Er]/;
71
+ /** `-i` without a suffix, also in a cluster like `-ni`, but not as the value of `-e`, like in `-ei` */
72
+ const SED_IN_PLACE_OPTION = /^-(?:(?![Iefil])[A-Za-z])*[Ii]$/;
73
+ /** Options of `sed` that take the next argument as their value, e.g. `-e` or `-ne` */
74
+ const SED_VALUE_OPTION = /^(?:-(?:(?![Iefil])[A-Za-z])*[ef]|--(?:expression|file))$/;
75
+ /** `-P`, also in a cluster like `-oP`, but not as the value of an option, like in `-eP` */
76
+ const GREP_PERL_OPTION = /^(?:-(?:(?![A-DPd-fm])[A-Za-z])*P[A-Za-z]*|--perl-regexp)$/;
77
+ /** Options of `grep` that take the next argument as their value, e.g. `-e` or `-ie` */
78
+ const GREP_VALUE_OPTION = /^(?:-(?:(?![A-Dd-fm])[A-Za-z])*[A-Dd-fm]|--(?:after-context|before-context|binary-files|context|devices|directories|exclude|exclude-dir|exclude-from|file|include|label|max-count|regexp))$/;
79
+ /** `set -o`, possibly after other options, e.g. `set -euo` */
80
+ const SET_NAMED_OPTION = /^-[a-z]*o$/i;
81
+ const SET_SHELL_OPTIONS = /^[+-][a-z]+$/i;
82
+ /** Including attached values, e.g. `-f%z` */
83
+ const STAT_FORMAT_OPTION = /^-[cf]/;
84
+ /**
85
+ * Checks a command's options for ones that don't work (the same) on all platforms, e.g. `sed -i`.
86
+ * @param name Name that the command was invoked with, e.g. `sed`
87
+ * @param values Values of the words that follow the command name, or `undefined` for the ones that
88
+ * depend on expansions
89
+ * @param words The words themselves
90
+ * @param options Where the command runs, and where its options end
91
+ * @returns The issues found
92
+ */
93
+ const checkCommandUsage = (name, values, words, options) => {
94
+ const { bash, native, optionsEnd, portable } = options;
95
+ const textOf = (index) => words[index]?.text || "";
96
+ const issues = [];
97
+ const optionIndex = (isMatch) => values.findIndex((value, index) => index < optionsEnd && value != null && isMatch(value, index));
98
+ /**
99
+ * Gets the arguments that are values of options, which aren't options themselves, e.g. `-P` in
100
+ * `grep -e -P`.
101
+ * @param valueOption Options that take the next argument as their value
102
+ * @returns Indexes of the values
103
+ */
104
+ const optionValueIndexes = (valueOption) => values.reduce((indexes, value, index) => {
105
+ if (value != null && index < optionsEnd && !indexes.has(index) && valueOption.test(value)) indexes.add(index + 1);
106
+ return indexes;
107
+ }, /* @__PURE__ */ new Set());
108
+ const report = (index, platforms, data, fix) => {
109
+ if (data.syntax) issues.push({
110
+ argumentIndex: index,
111
+ data,
112
+ fix,
113
+ messageId: "inconsistentBehavior",
114
+ platforms
115
+ });
116
+ else {
117
+ const usage = data.usage || `${name} ${truncate(values[index] ?? textOf(index))}`;
118
+ issues.push({
119
+ argumentIndex: index,
120
+ data: {
121
+ ...data,
122
+ usage
123
+ },
124
+ fix,
125
+ messageId: "unsupportedUsage",
126
+ platforms
127
+ });
128
+ }
129
+ };
130
+ const reportOption = (isMatch, platforms, data) => {
131
+ const index = optionIndex(isMatch);
132
+ if (index !== -1) report(index, platforms, data);
133
+ };
134
+ /** Creates a fix that replaces an argument's source text */
135
+ const replaceArgument = (index, text) => ({
136
+ argumentIndex: index,
137
+ description: describeReplacement(textOf(index), text),
138
+ text
139
+ });
140
+ const reportCommand = (platforms, suggestion) => {
141
+ issues.push({
142
+ argumentIndex: void 0,
143
+ data: {
144
+ command: name,
145
+ suggestion
146
+ },
147
+ messageId: "unsupportedCommand",
148
+ platforms
149
+ });
150
+ };
151
+ if (NO_LONG_OPTIONS_ON_MACOS.has(name)) {
152
+ const index = optionIndex((value) => LONG_OPTION.test(value) && !BSD_LONG_OPTIONS.get(name)?.includes(substringBefore(value, "=")));
153
+ if (index !== -1) report(index, MACOS_PLATFORMS, {
154
+ reason: `BSD \`${name}\` doesn't support GNU-style long options`,
155
+ suggestion: "Use short options instead.",
156
+ usage: `${name} ${substringBefore(values[index] || "", "=")}`
157
+ });
158
+ }
159
+ const lowerCaseName = name.toLowerCase();
160
+ const isDash = !bash && !portable;
161
+ switch (CMD_COMMANDS.has(lowerCaseName) ? lowerCaseName : name) {
162
+ case ".": {
163
+ const [file] = values;
164
+ if (isDash && file != null && !file.includes("/")) report(0, LINUX_PLATFORMS, {
165
+ reason: "dash only looks for the file in `PATH`, not in the current directory",
166
+ suggestion: `Use \`. ./${truncate(file)}\` instead.`
167
+ }, isDotfileName(file) ? replaceArgument(0, `./${textOf(0)}`) : void 0);
168
+ break;
169
+ }
170
+ case "[":
171
+ case "test": {
172
+ const index = words.findIndex(({ text }) => text === "==");
173
+ if (isDash && index !== -1) report(index, LINUX_PLATFORMS, {
174
+ reason: `${DASH} only supports \`=\` for comparing strings`,
175
+ suggestion: "Use `=` instead.",
176
+ usage: name === "[" ? "[ ... == ... ]" : "test ... == ..."
177
+ }, replaceArgument(index, "="));
178
+ break;
179
+ }
180
+ case "bash":
181
+ case "shopt": {
182
+ const option = name === "bash" ? "-O" : "-s";
183
+ const index = optionIndex((value, valueIndex) => value === "globstar" && values.slice(0, valueIndex).includes(option));
184
+ if (index !== -1) report(index, MACOS_PLATFORMS, {
185
+ reason: "macOS ships Bash 3.2, which doesn't have the `globstar` option",
186
+ suggestion: "Quote globs with escaped double quotes (`\\\"`) and let the tool expand them instead.",
187
+ usage: `${name} ${option} globstar`
188
+ });
189
+ break;
190
+ }
191
+ case "cp":
192
+ reportOption((value) => isShortOptionCluster(value, "t"), MACOS_PLATFORMS, {
193
+ reason: "BSD `cp` doesn't support `-t`",
194
+ suggestion: "Put the target directory last instead."
195
+ });
196
+ break;
197
+ case "date":
198
+ reportOption((value) => value.startsWith("-d"), MACOS_PLATFORMS, {
199
+ reason: "BSD `date` uses `-j -f` to parse dates",
200
+ suggestion: NODE_SCRIPT_SUGGESTION
201
+ });
202
+ break;
203
+ case "dir": {
204
+ const index = optionIndex((value) => DIR_CMD_OPTION.test(value));
205
+ if (index !== -1) report(index, LINUX_PLATFORMS, {
206
+ reason: `\`${values[index] || ""}\` is a cmd.exe option`,
207
+ suggestion: NODE_SCRIPT_SUGGESTION
208
+ });
209
+ break;
210
+ }
211
+ case "du":
212
+ reportOption((value) => isShortOptionCluster(value, "b"), MACOS_PLATFORMS, {
213
+ reason: "BSD `du` doesn't support `-b`",
214
+ suggestion: NODE_SCRIPT_SUGGESTION
215
+ });
216
+ break;
217
+ case "echo": {
218
+ const [first] = values;
219
+ if (isDash && first != null && ECHO_OPTIONS.test(first)) {
220
+ const doesInterpretEscapes = first.toLowerCase().includes("e");
221
+ report(0, doesInterpretEscapes ? PLATFORMS : NOT_MACOS_OR_WINDOWS, {
222
+ reason: doesInterpretEscapes ? "`sh`'s `echo` on macOS and Debian/Ubuntu, and cmd.exe's `echo` print the option literally" : "`sh`'s `echo` on macOS and cmd.exe's `echo` print the option literally",
223
+ suggestion: NODE_SCRIPT_SUGGESTION,
224
+ syntax: `\`echo ${first}\``
225
+ });
226
+ }
227
+ break;
228
+ }
229
+ case "exit": {
230
+ const [option = ""] = values;
231
+ if (EXIT_CMD_OPTION.test(option)) report(0, POSIX_PLATFORMS, {
232
+ reason: `\`${option}\` is a cmd.exe option`,
233
+ suggestion: `Remove \`${option}\` instead.`
234
+ });
235
+ break;
236
+ }
237
+ case "find": {
238
+ const start = values.findIndex((value) => value == null || !BSD_FIND_OPTIONS.test(value));
239
+ const primary = values.findIndex((value) => setHas(GNU_FIND_PRIMARIES, value));
240
+ if (values[start]?.startsWith("-")) report(start, MACOS_PLATFORMS, {
241
+ reason: "BSD `find` requires a starting path",
242
+ suggestion: "Add `.` before the expression.",
243
+ usage: `find ${values[start] || ""}`
244
+ }, {
245
+ argumentIndex: start,
246
+ description: "Add `.` before the expression.",
247
+ text: `. ${textOf(start)}`
248
+ });
249
+ else if (primary !== -1) report(primary, MACOS_PLATFORMS, {
250
+ reason: `BSD \`find\` doesn't support \`${values[primary] || ""}\``,
251
+ suggestion: NODE_SCRIPT_SUGGESTION
252
+ });
253
+ break;
254
+ }
255
+ case "fuser":
256
+ reportOption((value) => isShortOptionCluster(value, "k"), MACOS_PLATFORMS, {
257
+ reason: "macOS' `fuser` doesn't support `-k`",
258
+ suggestion: NODE_SCRIPT_SUGGESTION
259
+ });
260
+ break;
261
+ case "grep": {
262
+ const optionValues = optionValueIndexes(GREP_VALUE_OPTION);
263
+ reportOption((value, index) => !optionValues.has(index) && GREP_PERL_OPTION.test(value), MACOS_PLATFORMS, {
264
+ reason: "BSD `grep` doesn't support Perl-compatible regular expressions",
265
+ suggestion: "Use `grep -E` or a Node.js script instead."
266
+ });
267
+ break;
268
+ }
269
+ case "head": {
270
+ const index = optionIndex((value, valueIndex) => HEAD_NEGATIVE_COUNT_OPTION.test(value) || HEAD_COUNT_OPTION.test(value) && NEGATIVE_NUMBER.test(values[valueIndex + 1] || ""));
271
+ if (index !== -1) {
272
+ const countIndex = HEAD_COUNT_OPTION.test(values[index] || "") ? index + 1 : index;
273
+ report(countIndex, MACOS_PLATFORMS, {
274
+ reason: "BSD `head` doesn't support negative counts",
275
+ suggestion: NODE_SCRIPT_SUGGESTION,
276
+ usage: `head ${values.slice(index, countIndex + 1).join(" ")}`
277
+ });
278
+ }
279
+ break;
280
+ }
281
+ case "ln":
282
+ reportOption((value) => isShortOptionCluster(value, "r"), MACOS_PLATFORMS, {
283
+ reason: "BSD `ln` doesn't support `-r`",
284
+ suggestion: NODE_SCRIPT_SUGGESTION
285
+ });
286
+ break;
287
+ case "mkdir":
288
+ case "rmdir": {
289
+ const suggestion = lowerCaseName === "mkdir" ? NODE_SCRIPT_SUGGESTION : RIMRAF_SUGGESTION;
290
+ if (portable) {
291
+ reportCommand(WINDOWS_PLATFORMS, suggestion);
292
+ break;
293
+ }
294
+ const windowsOption = optionIndex((value) => RMDIR_CMD_OPTION.test(value));
295
+ if (lowerCaseName === "rmdir" && windowsOption !== -1) {
296
+ report(windowsOption, POSIX_PLATFORMS, {
297
+ reason: `\`${values[windowsOption] || ""}\` is a cmd.exe option`,
298
+ suggestion
299
+ });
300
+ break;
301
+ }
302
+ const posixOption = optionIndex((value) => POSIX_OPTION.test(value));
303
+ if (posixOption !== -1) {
304
+ report(posixOption, WINDOWS_PLATFORMS, {
305
+ reason: `cmd.exe's \`${name}\` doesn't support POSIX options`,
306
+ suggestion
307
+ });
308
+ break;
309
+ }
310
+ const pathWithSlash = values.findIndex((value, index) => value != null && !value.startsWith("-") && value.includes("/") && !textOf(index).startsWith("\""));
311
+ if (pathWithSlash !== -1) report(pathWithSlash, WINDOWS_PLATFORMS, {
312
+ reason: `cmd.exe's \`${name}\` treats \`/\` as an option prefix`,
313
+ suggestion
314
+ });
315
+ break;
316
+ }
317
+ case "sed": {
318
+ const isExtended = optionIndex((value) => SED_EXTENDED_OPTION.test(value) || value === "--regexp-extended") !== -1;
319
+ const findEscape = (value) => value == null || value.startsWith("-") ? void 0 : (GNU_SED_ESCAPE.exec(value) || (isExtended ? null : GNU_SED_BASIC_ESCAPE.exec(value)))?.[1];
320
+ const escapeIndex = values.findIndex((value) => findEscape(value) != null);
321
+ if (escapeIndex !== -1) report(escapeIndex, MACOS_PLATFORMS, {
322
+ reason: "BSD `sed` doesn't support it, so the pattern doesn't match",
323
+ suggestion: "Use POSIX regex syntax (e.g. `[[:space:]]`, or `+` with `sed -E`) instead.",
324
+ syntax: `The GNU regex escape \`${findEscape(values[escapeIndex]) || ""}\``
325
+ });
326
+ const optionValues = optionValueIndexes(SED_VALUE_OPTION);
327
+ const index = optionIndex((value, valueIndex) => !optionValues.has(valueIndex) && SED_IN_PLACE_OPTION.test(value));
328
+ if (index === -1) break;
329
+ if (values[index + 1]?.length === 0) report(index + 1, LINUX_PLATFORMS, {
330
+ reason: "GNU `sed` treats the empty backup suffix as the script",
331
+ suggestion: "Use an attached suffix (e.g. `-i.bak`) or a Node.js script instead.",
332
+ usage: `sed ${values[index] || ""} ''`
333
+ });
334
+ else report(index, MACOS_PLATFORMS, {
335
+ reason: "BSD `sed` requires a backup suffix argument after `-i`",
336
+ suggestion: "Use an attached suffix (e.g. `-i.bak`) or a Node.js script instead."
337
+ });
338
+ break;
339
+ }
340
+ case "set": {
341
+ const [first] = values;
342
+ if (portable) {
343
+ reportCommand(PLATFORMS, first != null && ASSIGNMENT.test(first) ? CROSS_ENV_SUGGESTION : NODE_SCRIPT_SUGGESTION);
344
+ break;
345
+ }
346
+ const pipefail = optionIndex((value, index) => value === "pipefail" && SET_NAMED_OPTION.test(values[index - 1] || ""));
347
+ if (isDash && pipefail !== -1) report(pipefail, LINUX_PLATFORMS, {
348
+ reason: `${DASH} doesn't support \`pipefail\``,
349
+ suggestion: "Remove it or use a Node.js script instead.",
350
+ usage: "set -o pipefail"
351
+ });
352
+ if (first == null) break;
353
+ if (native && SET_SHELL_OPTIONS.test(first)) report(0, WINDOWS_PLATFORMS, {
354
+ reason: "cmd.exe's `set` manages environment variables instead of shell options",
355
+ suggestion: "Remove it or use a Node.js script instead."
356
+ });
357
+ else if (ASSIGNMENT.test(first)) report(0, POSIX_PLATFORMS, {
358
+ reason: "POSIX shells don't set environment variables with `set`",
359
+ suggestion: CROSS_ENV_SUGGESTION,
360
+ syntax: `\`set ${truncate(textOf(0))}\``
361
+ });
362
+ break;
363
+ }
364
+ case "sort":
365
+ reportOption((value) => POSIX_OPTION.test(value), WINDOWS_PLATFORMS, {
366
+ reason: "Windows' `sort` command uses `/` options",
367
+ suggestion: NODE_SCRIPT_SUGGESTION
368
+ });
369
+ break;
370
+ case "stat": {
371
+ const index = optionIndex((value) => STAT_FORMAT_OPTION.test(value));
372
+ if (index === -1) break;
373
+ if (values[index]?.startsWith("-c")) report(index, MACOS_PLATFORMS, {
374
+ reason: "BSD `stat` uses `-f` to specify the format",
375
+ suggestion: NODE_SCRIPT_SUGGESTION
376
+ });
377
+ else report(index, LINUX_PLATFORMS, {
378
+ reason: "GNU `stat -f` displays file system status instead of formatting the output",
379
+ suggestion: NODE_SCRIPT_SUGGESTION,
380
+ syntax: "`stat -f`"
381
+ });
382
+ break;
383
+ }
384
+ case "timeout": {
385
+ const duration = values.findIndex((value, index) => value == null || !POSIX_OPTION.test(value) && !TIMEOUT_VALUE_OPTIONS.includes(values[index - 1] || ""));
386
+ if (TIMEOUT_CMD_OPTION.test(values[0] || "")) report(0, POSIX_PLATFORMS, {
387
+ reason: `\`${values[0] || ""}\` is an option of Windows' \`timeout\` command`,
388
+ suggestion: NODE_SCRIPT_SUGGESTION
389
+ });
390
+ else if (duration !== -1 && duration === values.length - 1) report(duration, POSIX_PLATFORMS, {
391
+ reason: "only Windows' `timeout` works without a command",
392
+ suggestion: NODE_SCRIPT_SUGGESTION
393
+ });
394
+ else reportCommand(NOT_MACOS_OR_WINDOWS, "Older macOS versions don't have it, and Windows' `timeout` only waits; use a Node.js script instead.");
395
+ break;
396
+ }
397
+ case "trap": {
398
+ const index = values.findIndex((value, valueIndex) => valueIndex > 0 && setHas(BASH_TRAP_CONDITIONS, value));
399
+ if (isDash && index !== -1) report(index, LINUX_PLATFORMS, {
400
+ reason: `${DASH} doesn't support the \`${values[index] || ""}\` condition`,
401
+ suggestion: NODE_SCRIPT_SUGGESTION,
402
+ usage: `trap ... ${values[index] || ""}`
403
+ });
404
+ break;
405
+ }
406
+ case "xargs": reportOption((value) => GNU_XARGS_OPTION.test(value), MACOS_PLATFORMS, {
407
+ reason: "BSD `xargs` doesn't support this GNU option",
408
+ suggestion: NODE_SCRIPT_SUGGESTION
409
+ });
410
+ }
411
+ return issues;
412
+ };
413
+ export { checkCommandUsage };