package-json-scripts-portability 0.0.0 → 0.0.2

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 (66) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +235 -45
  3. package/dist/analyze-script.d.mts +34 -0
  4. package/dist/analyze-script.mjs +48 -0
  5. package/dist/command-checker.mjs +295 -0
  6. package/dist/command-usage.mjs +364 -0
  7. package/dist/commands.mjs +520 -0
  8. package/dist/context.mjs +18 -0
  9. package/dist/fixes.d.mts +9 -0
  10. package/dist/fixes.mjs +210 -0
  11. package/dist/index.d.mts +6 -0
  12. package/dist/index.mjs +5 -0
  13. package/dist/line-break-checker.mjs +71 -0
  14. package/dist/messages.mjs +30 -0
  15. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/array-difference.mjs +11 -0
  16. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/array-includes.mjs +8 -0
  17. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/array-intersection.mjs +13 -0
  18. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/array-is-subset.mjs +16 -0
  19. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/arrayify.mjs +7 -0
  20. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/iterable/sliding-window.mjs +30 -0
  21. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/map/map-get-or-insert-computed.mjs +42 -0
  22. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/map/map-get-or-insert.mjs +40 -0
  23. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/math/clamp.mjs +7 -0
  24. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/path/to-forward-slashes.mjs +8 -0
  25. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/predicate/is-array.mjs +39 -0
  26. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/set/set-has.mjs +8 -0
  27. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/string/substring-after-last.mjs +24 -0
  28. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/string/substring-before.mjs +24 -0
  29. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/string/truncate.mjs +46 -0
  30. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/ts/all-union-members.mjs +45 -0
  31. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/types/maybe-readonly-array.d.mts +17 -0
  32. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/value/is-equal.mjs +37 -0
  33. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/@antfu/utils/dist/index.mjs +5 -0
  34. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/_internal/globalThis.mjs +5 -0
  35. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/array/differenceBy.mjs +40 -0
  36. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/array/differenceWith.mjs +37 -0
  37. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/array/intersectionWith.mjs +43 -0
  38. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/array/isSubsetWith.mjs +36 -0
  39. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/bigint/clamp.mjs +15 -0
  40. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/_internal/getSymbols.mjs +5 -0
  41. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/_internal/getTag.mjs +13 -0
  42. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/_internal/regexMultiByte.mjs +10 -0
  43. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/_internal/tags.mjs +27 -0
  44. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/predicate/isObject.mjs +28 -0
  45. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/string/truncate.mjs +78 -0
  46. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/util/eq.mjs +18 -0
  47. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/function/noop.mjs +12 -0
  48. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/math/clamp.mjs +23 -0
  49. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/predicate/isBuffer.mjs +24 -0
  50. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/predicate/isEqual.mjs +21 -0
  51. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/predicate/isEqualWith.mjs +151 -0
  52. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/predicate/isPlainObject.mjs +50 -0
  53. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/remeda/dist/isArray.mjs +18 -0
  54. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/ts-extras/distribution/array-includes.mjs +5 -0
  55. package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/ts-extras/distribution/set-has.mjs +5 -0
  56. package/dist/platforms.d.mts +8 -0
  57. package/dist/platforms.mjs +26 -0
  58. package/dist/redirection-checker.mjs +117 -0
  59. package/dist/reporter.d.mts +32 -0
  60. package/dist/reporter.mjs +98 -0
  61. package/dist/runners.d.mts +24 -0
  62. package/dist/runners.mjs +118 -0
  63. package/dist/script-analyzer.mjs +551 -0
  64. package/dist/word-checker.mjs +444 -0
  65. package/dist/words.mjs +43 -0
  66. package/package.json +118 -6
@@ -0,0 +1,151 @@
1
+ import { getSymbols } from "../compat/_internal/getSymbols.mjs";
2
+ import { getTag } from "../compat/_internal/getTag.mjs";
3
+ import { arrayBufferTag, arrayTag, bigInt64ArrayTag, bigUint64ArrayTag, booleanTag, dataViewTag, dateTag, errorTag, float32ArrayTag, float64ArrayTag, functionTag, int16ArrayTag, int32ArrayTag, int8ArrayTag, mapTag, numberTag, objectTag, regexpTag, setTag, stringTag, symbolTag, uint16ArrayTag, uint32ArrayTag, uint8ArrayTag, uint8ClampedArrayTag } from "../compat/_internal/tags.mjs";
4
+ import { isBuffer } from "./isBuffer.mjs";
5
+ import { isPlainObject } from "./isPlainObject.mjs";
6
+ import { eq } from "../compat/util/eq.mjs";
7
+ // node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/predicate/isEqualWith.mjs
8
+ /**
9
+ * Compares two values for equality using a custom comparison function.
10
+ *
11
+ * The custom function allows for fine-tuned control over the comparison process. If it returns a boolean, that result determines the equality. If it returns undefined, the function falls back to the default equality comparison.
12
+ *
13
+ * This function also uses the custom equality function to compare values inside objects,
14
+ * arrays, maps, sets, and other complex structures, ensuring a deep comparison.
15
+ *
16
+ * This approach provides flexibility in handling complex comparisons while maintaining efficient default behavior for simpler cases.
17
+ *
18
+ * The custom comparison function can take up to six parameters:
19
+ * - `x`: The value from the first object `a`.
20
+ * - `y`: The value from the second object `b`.
21
+ * - `property`: The property key used to get `x` and `y`.
22
+ * - `xParent`: The parent of the first value `x`.
23
+ * - `yParent`: The parent of the second value `y`.
24
+ * - `stack`: An internal stack (Map) to handle circular references.
25
+ *
26
+ * @param a - The first value to compare.
27
+ * @param b - The second value to compare.
28
+ * @param areValuesEqual - A function to customize the comparison.
29
+ * If it returns a boolean, that result will be used. If it returns undefined,
30
+ * the default equality comparison will be used.
31
+ * @returns `true` if the values are equal according to the customizer, otherwise `false`.
32
+ *
33
+ * @example
34
+ * const customizer = (a, b) => {
35
+ * if (typeof a === 'string' && typeof b === 'string') {
36
+ * return a.toLowerCase() === b.toLowerCase();
37
+ * }
38
+ * };
39
+ * isEqualWith('Hello', 'hello', customizer); // true
40
+ * isEqualWith({ a: 'Hello' }, { a: 'hello' }, customizer); // true
41
+ * isEqualWith([1, 2, 3], [1, 2, 3], customizer); // true
42
+ */
43
+ function isEqualWith(a, b, areValuesEqual) {
44
+ return isEqualWithImpl(a, b, void 0, void 0, void 0, void 0, areValuesEqual);
45
+ }
46
+ function isEqualWithImpl(a, b, property, aParent, bParent, stack, areValuesEqual) {
47
+ const result = areValuesEqual(a, b, property, aParent, bParent, stack);
48
+ if (result !== void 0) return result;
49
+ if (typeof a === typeof b) switch (typeof a) {
50
+ case "bigint":
51
+ case "string":
52
+ case "boolean":
53
+ case "symbol":
54
+ case "undefined": return a === b;
55
+ case "number": return a === b || Object.is(a, b);
56
+ case "function": return a === b;
57
+ case "object": return areObjectsEqual(a, b, stack, areValuesEqual);
58
+ }
59
+ return areObjectsEqual(a, b, stack, areValuesEqual);
60
+ }
61
+ function areObjectsEqual(a, b, stack, areValuesEqual) {
62
+ if (Object.is(a, b)) return true;
63
+ let aTag = getTag(a);
64
+ let bTag = getTag(b);
65
+ if (aTag === "[object Arguments]") aTag = objectTag;
66
+ if (bTag === "[object Arguments]") bTag = objectTag;
67
+ if (aTag !== bTag) return false;
68
+ switch (aTag) {
69
+ case stringTag: return a.toString() === b.toString();
70
+ case numberTag: {
71
+ const x = a.valueOf();
72
+ const y = b.valueOf();
73
+ return eq(x, y);
74
+ }
75
+ case booleanTag:
76
+ case dateTag:
77
+ case symbolTag: return Object.is(a.valueOf(), b.valueOf());
78
+ case regexpTag: return a.source === b.source && a.flags === b.flags;
79
+ case functionTag: return a === b;
80
+ }
81
+ stack = stack ?? /* @__PURE__ */ new Map();
82
+ const aStack = stack.get(a);
83
+ const bStack = stack.get(b);
84
+ if (aStack != null && bStack != null) return aStack === b;
85
+ stack.set(a, b);
86
+ stack.set(b, a);
87
+ try {
88
+ switch (aTag) {
89
+ case mapTag:
90
+ if (a.size !== b.size) return false;
91
+ for (const [key, value] of a.entries()) if (!b.has(key) || !isEqualWithImpl(value, b.get(key), key, a, b, stack, areValuesEqual)) return false;
92
+ return true;
93
+ case setTag: {
94
+ if (a.size !== b.size) return false;
95
+ const aValues = Array.from(a.values());
96
+ const bValues = Array.from(b.values());
97
+ for (let i = 0; i < aValues.length; i++) {
98
+ const aValue = aValues[i];
99
+ const index = bValues.findIndex((bValue) => {
100
+ return isEqualWithImpl(aValue, bValue, void 0, a, b, stack, areValuesEqual);
101
+ });
102
+ if (index === -1) return false;
103
+ bValues.splice(index, 1);
104
+ }
105
+ return true;
106
+ }
107
+ case arrayTag:
108
+ case uint8ArrayTag:
109
+ case uint8ClampedArrayTag:
110
+ case uint16ArrayTag:
111
+ case uint32ArrayTag:
112
+ case bigUint64ArrayTag:
113
+ case int8ArrayTag:
114
+ case int16ArrayTag:
115
+ case int32ArrayTag:
116
+ case bigInt64ArrayTag:
117
+ case float32ArrayTag:
118
+ case float64ArrayTag:
119
+ if (isBuffer(a) !== isBuffer(b)) return false;
120
+ if (a.length !== b.length) return false;
121
+ for (let i = 0; i < a.length; i++) if (!isEqualWithImpl(a[i], b[i], i, a, b, stack, areValuesEqual)) return false;
122
+ return true;
123
+ case arrayBufferTag:
124
+ if (a.byteLength !== b.byteLength) return false;
125
+ return areObjectsEqual(new Uint8Array(a), new Uint8Array(b), stack, areValuesEqual);
126
+ case dataViewTag:
127
+ if (a.byteLength !== b.byteLength || a.byteOffset !== b.byteOffset) return false;
128
+ return areObjectsEqual(new Uint8Array(a), new Uint8Array(b), stack, areValuesEqual);
129
+ case errorTag: return a.name === b.name && a.message === b.message;
130
+ case objectTag: {
131
+ if (!(areObjectsEqual(a.constructor, b.constructor, stack, areValuesEqual) || isPlainObject(a) && isPlainObject(b))) return false;
132
+ const aKeys = [...Object.keys(a), ...getSymbols(a)];
133
+ const bKeys = [...Object.keys(b), ...getSymbols(b)];
134
+ if (aKeys.length !== bKeys.length) return false;
135
+ for (let i = 0; i < aKeys.length; i++) {
136
+ const propKey = aKeys[i];
137
+ const aProp = a[propKey];
138
+ if (!Object.hasOwn(b, propKey)) return false;
139
+ const bProp = b[propKey];
140
+ if (!isEqualWithImpl(aProp, bProp, propKey, a, b, stack, areValuesEqual)) return false;
141
+ }
142
+ return true;
143
+ }
144
+ default: return false;
145
+ }
146
+ } finally {
147
+ stack.delete(a);
148
+ stack.delete(b);
149
+ }
150
+ }
151
+ export { isEqualWith };
@@ -0,0 +1,50 @@
1
+ // node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/predicate/isPlainObject.mjs
2
+ /**
3
+ * Checks if a given value is a plain object.
4
+ *
5
+ * @param value - The value to check.
6
+ * @returns True if the value is a plain object, otherwise false.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * // ✅👇 True
11
+ *
12
+ * isPlainObject({ }); // ✅
13
+ * isPlainObject({ key: 'value' }); // ✅
14
+ * isPlainObject({ key: new Date() }); // ✅
15
+ * isPlainObject(new Object()); // ✅
16
+ * isPlainObject(Object.create(null)); // ✅
17
+ * isPlainObject({ nested: { key: true} }); // ✅
18
+ * isPlainObject(new Proxy({}, {})); // ✅
19
+ * isPlainObject({ [Symbol('tag')]: 'A' }); // ✅
20
+ *
21
+ * // ✅👇 (cross-realms, node context, workers, ...)
22
+ * const runInNewContext = await import('node:vm').then(
23
+ * (mod) => mod.runInNewContext
24
+ * );
25
+ * isPlainObject(runInNewContext('({})')); // ✅
26
+ *
27
+ * // ❌👇 False
28
+ *
29
+ * class Test { };
30
+ * isPlainObject(new Test()) // ❌
31
+ * isPlainObject(10); // ❌
32
+ * isPlainObject(null); // ❌
33
+ * isPlainObject('hello'); // ❌
34
+ * isPlainObject([]); // ❌
35
+ * isPlainObject(new Date()); // ❌
36
+ * isPlainObject(new Uint8Array([1])); // ❌
37
+ * isPlainObject(Buffer.from('ABC')); // ❌
38
+ * isPlainObject(Promise.resolve({})); // ❌
39
+ * isPlainObject(Object.create({})); // ❌
40
+ * isPlainObject(new (class Cls {})); // ❌
41
+ * isPlainObject(globalThis); // ❌,
42
+ * ```
43
+ */
44
+ function isPlainObject(value) {
45
+ if (!value || typeof value !== "object") return false;
46
+ const proto = Object.getPrototypeOf(value);
47
+ if (!(proto === null || proto === Object.prototype || Object.getPrototypeOf(proto) === null)) return false;
48
+ return Object.prototype.toString.call(value) === "[object Object]";
49
+ }
50
+ export { isPlainObject };
@@ -0,0 +1,18 @@
1
+ // node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/remeda/dist/isArray.mjs
2
+ /**
3
+ * A function that checks if the passed parameter is an Array and narrows its type accordingly.
4
+ *
5
+ * @param data - The variable to check.
6
+ * @returns True if the passed input is an Array, false otherwise.
7
+ * @signature
8
+ * isArray(data)
9
+ * @example
10
+ * isArray([5]) //=> true
11
+ * isArray([]) //=> true
12
+ * isArray('somethingElse') //=> false
13
+ * @category Guard
14
+ */
15
+ function isArray(data) {
16
+ return Array.isArray(data);
17
+ }
18
+ export { isArray };
@@ -0,0 +1,5 @@
1
+ // node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/ts-extras/distribution/array-includes.mjs
2
+ function arrayIncludes(array, item, fromIndex) {
3
+ return array.includes(item, fromIndex);
4
+ }
5
+ export { arrayIncludes };
@@ -0,0 +1,5 @@
1
+ // node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/ts-extras/distribution/set-has.mjs
2
+ function setHas(set, item) {
3
+ return set.has(item);
4
+ }
5
+ export { setHas };
@@ -0,0 +1,8 @@
1
+ export type Platform = 'darwin' | 'linux' | 'win32';
2
+ export declare const PLATFORMS: readonly Platform[];
3
+ /**
4
+ * Formats platforms as a list for people, e.g. "macOS, Linux, and Windows".
5
+ * @param platforms The platforms to format
6
+ * @returns The formatted list
7
+ */
8
+ export declare const formatPlatforms: (platforms: readonly Platform[]) => string;
@@ -0,0 +1,26 @@
1
+ import { listFormat } from "./messages.mjs";
2
+ import { arrayIntersection } from "./node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/array-intersection.mjs";
3
+ // src/platforms.ts
4
+ const PLATFORMS = [
5
+ "darwin",
6
+ "linux",
7
+ "win32"
8
+ ];
9
+ const POSIX_PLATFORMS = ["darwin", "linux"];
10
+ const MACOS_PLATFORMS = ["darwin"];
11
+ const LINUX_PLATFORMS = ["linux"];
12
+ const WINDOWS_PLATFORMS = ["win32"];
13
+ const NOT_LINUX_OR_WINDOWS = ["linux", "win32"];
14
+ const NOT_MACOS_OR_WINDOWS = ["darwin", "win32"];
15
+ const PLATFORM_NAMES = {
16
+ darwin: "macOS",
17
+ linux: "Linux",
18
+ win32: "Windows"
19
+ };
20
+ /**
21
+ * Formats platforms as a list for people, e.g. "macOS, Linux, and Windows".
22
+ * @param platforms The platforms to format
23
+ * @returns The formatted list
24
+ */
25
+ const formatPlatforms = (platforms) => listFormat.format(arrayIntersection(PLATFORMS, platforms).map((platform) => PLATFORM_NAMES[platform]));
26
+ export { LINUX_PLATFORMS, MACOS_PLATFORMS, NOT_LINUX_OR_WINDOWS, NOT_MACOS_OR_WINDOWS, PLATFORMS, POSIX_PLATFORMS, WINDOWS_PLATFORMS, formatPlatforms };
@@ -0,0 +1,117 @@
1
+ import { bashLabel } from "./context.mjs";
2
+ import { removal, replacement } from "./fixes.mjs";
3
+ import { BASH_SUGGESTION, NODE_SCRIPT_SUGGESTION, describeReplacement, truncate } from "./messages.mjs";
4
+ import { POSIX_PLATFORMS } from "./platforms.mjs";
5
+ import { mapGetOrInsert } from "./node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/map/map-get-or-insert.mjs";
6
+ import { setHas } from "./node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/set/set-has.mjs";
7
+ import { POSIX_PATH, WHITESPACE, staticValue } from "./words.mjs";
8
+ // src/redirection-checker.ts
9
+ /** The target of a redirection that duplicates or closes a file descriptor, e.g. `1` or `-` */
10
+ const DESCRIPTOR = /^(?:\d+|-)$/;
11
+ /** Device names, which cmd.exe treats as the device in any directory */
12
+ const WINDOWS_DEVICES = /* @__PURE__ */ new Set([
13
+ "aux",
14
+ "con",
15
+ "nul",
16
+ "prn"
17
+ ]);
18
+ /** Checks redirections, e.g. for Bash-specific operators and device files */
19
+ var RedirectionChecker = class {
20
+ /** End offsets of here-documents, by the source that they're in */
21
+ hereDocumentEnds = /* @__PURE__ */ new Map();
22
+ #reporter;
23
+ #words;
24
+ constructor(reporter, words) {
25
+ this.#reporter = reporter;
26
+ this.#words = words;
27
+ }
28
+ checkEchoToFile(node, context) {
29
+ const doesWriteFile = node.redirects.some((redirect) => redirect.type === "Redirect" && (redirect.operator === ">" || redirect.operator === ">>") && redirect.descriptor == null && !POSIX_PATH.test(redirect.target?.value || "") && !setHas(WINDOWS_DEVICES, redirect.target?.value.toLowerCase()));
30
+ const quoted = node.args.find((argument) => argument.type === "Word" && argument.parts?.some((part) => part.type === "DoubleQuoted"));
31
+ if (doesWriteFile && quoted) this.#reporter.reportSyntax(context, quoted, "posix", true, "inconsistentBehavior", {
32
+ reason: "cmd.exe's `echo` writes the quotes into the file",
33
+ suggestion: NODE_SCRIPT_SUGGESTION,
34
+ syntax: "Writing a double-quoted string with `echo`"
35
+ });
36
+ }
37
+ /**
38
+ * Checks a redirection and its target.
39
+ * @param redirection Redirection to check, e.g. `> out.log`
40
+ * @param context Where the redirection is
41
+ * @param isWholeCommand Whether the redirection is the whole command, e.g. `>log` in `tsc | >log`
42
+ */
43
+ checkRedirection(redirection, context, isWholeCommand = false) {
44
+ const text = context.source.slice(redirection.pos, redirection.end);
45
+ switch (redirection.type) {
46
+ case "HereDoc":
47
+ this.#reporter.reportSyntax(context, redirection, "posix", false, "unsupportedSyntax", {
48
+ suggestion: NODE_SCRIPT_SUGGESTION,
49
+ syntax: `The here-document \`${redirection.operator}\``
50
+ });
51
+ if (redirection.closing) mapGetOrInsert(this.hereDocumentEnds, context.source, []).push(redirection.closing.end);
52
+ return;
53
+ case "HereString":
54
+ this.#reporter.reportSyntax(context, redirection, "bash", true, "unsupportedSyntax", {
55
+ suggestion: "Pipe the value into the command instead.",
56
+ syntax: "The Bash-specific here-string `<<<`"
57
+ });
58
+ break;
59
+ case "Redirect": {
60
+ const { descriptor, operator } = redirection;
61
+ if (descriptor?.type === "FileDescriptorVariable") this.#reporter.reportSyntax(context, descriptor, "bash", false, "unsupportedSyntax", {
62
+ suggestion: BASH_SUGGESTION,
63
+ syntax: `The Bash-specific file descriptor variable \`{${descriptor.name}}\``
64
+ });
65
+ const separator = redirection.pos > 0 && !WHITESPACE.test(context.source.charAt(redirection.pos - 1)) ? " " : "";
66
+ const redirectionFix = (fixed) => ({
67
+ description: describeReplacement(text, fixed),
68
+ edits: [{
69
+ end: redirection.end,
70
+ pos: redirection.pos,
71
+ text: `${separator}${fixed}`
72
+ }]
73
+ });
74
+ if (operator === "&>" || operator === "&>>") {
75
+ const kind = operator === "&>" ? "bash" : "bash4";
76
+ this.#reporter.reportSyntax(context, redirection, kind, false, "unsupportedSyntax", {
77
+ suggestion: `Use \`${operator.slice(1)} file 2>&1\` instead.`,
78
+ syntax: `The ${bashLabel(kind)} \`${operator}\` redirection`
79
+ }, redirection.target && redirectionFix(`${operator.slice(1)} ${redirection.target.text} 2>&1`));
80
+ } else if (operator === ">|" || operator === "<>") {
81
+ const position = context.source.indexOf(operator, descriptor?.end || redirection.pos);
82
+ this.#reporter.reportSyntax(context, redirection, "posix", false, "unsupportedSyntax", {
83
+ suggestion: operator === ">|" ? "Use `>` instead." : NODE_SCRIPT_SUGGESTION,
84
+ syntax: `The \`${operator}\` redirection`
85
+ }, operator === ">|" ? replacement({
86
+ end: position + operator.length,
87
+ pos: position
88
+ }, operator, ">") : void 0);
89
+ }
90
+ if (redirection.target && (operator === ">&" || operator === "<&")) {
91
+ const target = staticValue(redirection.target);
92
+ if (target != null && DESCRIPTOR.test(target)) return;
93
+ if (operator === ">&" && target != null) this.#reporter.reportSyntax(context, redirection, "bash", false, "unsupportedSyntax", {
94
+ suggestion: `Use \`> ${truncate(target)} 2>&1\` instead.`,
95
+ syntax: "The Bash-specific `>&` redirection to a file"
96
+ }, descriptor ? void 0 : redirectionFix(`> ${redirection.target.text} 2>&1`));
97
+ }
98
+ break;
99
+ }
100
+ }
101
+ if (!redirection.target) return;
102
+ const target = staticValue(redirection.target);
103
+ if (target != null && WINDOWS_DEVICES.has(target.toLowerCase())) this.#reporter.report(context, redirection.target, "inconsistentBehavior", {
104
+ reason: `POSIX shells create a file named \`${target}\` instead`,
105
+ suggestion: "Remove the redirection or use a Node.js script instead.",
106
+ syntax: `The redirection to \`${target}\``
107
+ }, POSIX_PLATFORMS);
108
+ this.#words.checkWord(redirection.target, context, { redirectTarget: true });
109
+ if (target == null || target === "/dev/null" && context.portable) return;
110
+ const doesDiscardOutput = !isWholeCommand && redirection.type === "Redirect" && (redirection.operator === ">" || redirection.operator === ">>") && target === "/dev/null";
111
+ this.#words.checkPosixPath(redirection.target, target, context, doesDiscardOutput ? {
112
+ description: `Remove \`${truncate(text)}\`.`,
113
+ edits: [removal(context.source, redirection.pos, redirection.end)]
114
+ } : void 0);
115
+ }
116
+ };
117
+ export { RedirectionChecker };
@@ -0,0 +1,32 @@
1
+ import { Platform } from "./platforms.mjs";
2
+ import { Runner } from "./runners.mjs";
3
+ export type ScriptIssueMessageId = 'inconsistentBehavior' | 'unsupportedCommand' | 'unsupportedSyntax' | 'unsupportedUsage';
4
+ export interface ScriptEdit {
5
+ /** End offset (exclusive) of the replaced text in the script */
6
+ end: number;
7
+ /** Start offset of the replaced text in the script */
8
+ pos: number;
9
+ /** The replacement */
10
+ text: string;
11
+ }
12
+ export interface ScriptFix {
13
+ /** Describes the fix for people, e.g. "Prefix the command with `cross-env`." */
14
+ description: string;
15
+ /** Replacements that don't overlap */
16
+ edits: ScriptEdit[];
17
+ }
18
+ export interface ScriptIssue {
19
+ /** Message data, apart from `platforms` */
20
+ data: Record<string, string>;
21
+ /** End offset (exclusive) of the issue in the script */
22
+ end: number;
23
+ /** A fix for the issue, if it has an obvious one */
24
+ fix?: ScriptFix;
25
+ messageId: ScriptIssueMessageId;
26
+ /** Platforms on which the script doesn't work as intended */
27
+ platforms: Platform[];
28
+ /** Start offset of the issue in the script */
29
+ pos: number;
30
+ /** Runners with which the script has the issue */
31
+ runners: Runner[];
32
+ }
@@ -0,0 +1,98 @@
1
+ import { rangeInScript } from "./context.mjs";
2
+ import { MACOS_PLATFORMS, NOT_LINUX_OR_WINDOWS, PLATFORMS, WINDOWS_PLATFORMS } from "./platforms.mjs";
3
+ import { clamp } from "./node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/math/clamp.mjs";
4
+ // src/reporter.ts
5
+ /**
6
+ * Gets what identifies an issue, apart from the platforms and the runners that it's found for.
7
+ * @param issue The issue
8
+ * @returns A string that is the same for the same issues
9
+ */
10
+ const issueKey = (issue) => JSON.stringify([
11
+ issue.messageId,
12
+ issue.pos,
13
+ issue.end,
14
+ issue.data
15
+ ]);
16
+ /** Platforms on which each kind of syntax doesn't work, by the shell that runs it */
17
+ const SYNTAX_PLATFORMS = {
18
+ bash: {
19
+ bash: [],
20
+ native: NOT_LINUX_OR_WINDOWS,
21
+ sh: NOT_LINUX_OR_WINDOWS
22
+ },
23
+ bash4: {
24
+ bash: MACOS_PLATFORMS,
25
+ native: PLATFORMS,
26
+ sh: PLATFORMS
27
+ },
28
+ bashNonPosix: {
29
+ bash: [],
30
+ native: PLATFORMS,
31
+ sh: PLATFORMS
32
+ },
33
+ posix: {
34
+ bash: [],
35
+ native: WINDOWS_PLATFORMS,
36
+ sh: []
37
+ }
38
+ };
39
+ var Reporter = class {
40
+ issues = [];
41
+ /**
42
+ * Length of the analyzed script, which unbash's positions can exceed, e.g. after a trailing `\`
43
+ */
44
+ #length;
45
+ #seen = /* @__PURE__ */ new Set();
46
+ constructor(length) {
47
+ this.#length = length;
48
+ }
49
+ /**
50
+ * Maps a fix's positions to the analyzed script.
51
+ * @param context Where the fix is
52
+ * @param fix The fix, with positions relative to the context's source
53
+ * @returns The mapped fix, or `undefined` if it can't be applied in the context
54
+ */
55
+ #mapFix(context, fix) {
56
+ if (!fix || context.fixedRange) return;
57
+ const edits = fix.edits.map(({ end, pos, text }) => ({
58
+ end: context.offset + end,
59
+ pos: context.offset + pos,
60
+ text
61
+ }));
62
+ return edits.every(({ end, pos, text }) => pos >= 0 && pos <= end && end <= this.#length && context.fixExclusions.every((exclusion) => !exclusion.test(text))) ? {
63
+ description: fix.description,
64
+ edits
65
+ } : void 0;
66
+ }
67
+ report(context, node, messageId, data, platforms, fix) {
68
+ const remaining = platforms.filter((platform) => !context.covered.has(platform));
69
+ if (remaining.length > 0) {
70
+ const range = rangeInScript(context, node);
71
+ const pos = clamp(range.pos, 0, this.#length);
72
+ const end = clamp(range.end, pos, this.#length);
73
+ const key = issueKey({
74
+ data,
75
+ end,
76
+ messageId,
77
+ pos
78
+ });
79
+ if (!this.#seen.has(key)) {
80
+ this.#seen.add(key);
81
+ this.issues.push({
82
+ data,
83
+ end,
84
+ fix: this.#mapFix(context, fix),
85
+ messageId,
86
+ platforms: remaining,
87
+ pos
88
+ });
89
+ }
90
+ }
91
+ return remaining;
92
+ }
93
+ reportSyntax(context, node, kind, isPortableSupported, messageId, data, fix) {
94
+ const platforms = context.portable ? isPortableSupported ? [] : PLATFORMS : SYNTAX_PLATFORMS[kind][context.shell];
95
+ return this.report(context, node, messageId, data, platforms, fix);
96
+ }
97
+ };
98
+ export { Reporter, issueKey };
@@ -0,0 +1,24 @@
1
+ /** What can run the scripts: a package manager, or `node` for `node --run` */
2
+ export type Runner = 'aube' | 'node' | 'npm' | 'pnpm' | 'pnpm-10' | 'upm' | 'yarn' | 'yarn-classic';
3
+ export declare const RUNNERS: readonly Runner[];
4
+ /**
5
+ * Scripts that run with any package manager by default, as they run on the machine of whoever
6
+ * installs the package: install scripts, and `prepare`, which runs when it's installed from git
7
+ */
8
+ export declare const RUNNER_AGNOSTIC_SCRIPTS: ReadonlySet<string>;
9
+ /**
10
+ * Gets the runner for a package manager, e.g. the one in the `packageManager` or
11
+ * `devEngines.packageManager` field of package.json.
12
+ * @param name Name of the package manager, e.g. `yarn`
13
+ * @param version Its version or version range, which tells Yarn v1 from Yarn v2+, and pnpm v10
14
+ * from later versions, e.g. `1.22.22`
15
+ * @returns The runner, or `undefined` if it's an unknown package manager or Yarn of an unknown
16
+ * version
17
+ */
18
+ export declare const getRunner: (name: string, version?: string) => Runner | undefined;
19
+ /**
20
+ * Formats runners as a list for people, e.g. "pnpm and Yarn v1".
21
+ * @param runners The runners to format
22
+ * @returns The formatted list
23
+ */
24
+ export declare const formatRunners: (runners: readonly Runner[]) => string;
@@ -0,0 +1,118 @@
1
+ import { listFormat } from "./messages.mjs";
2
+ import { allUnionMembers } from "./node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/ts/all-union-members.mjs";
3
+ import { arrayDifference } from "./node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/array-difference.mjs";
4
+ import { arrayIntersection } from "./node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/array-intersection.mjs";
5
+ import { setHas } from "./node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/set/set-has.mjs";
6
+ // src/runners.ts
7
+ const RUNNERS = allUnionMembers()([
8
+ "aube",
9
+ "node",
10
+ "npm",
11
+ "pnpm",
12
+ "pnpm-10",
13
+ "upm",
14
+ "yarn",
15
+ "yarn-classic"
16
+ ]);
17
+ /** Runners that are package managers: all of them but `node`, which doesn't install packages */
18
+ const PACKAGE_MANAGER_RUNNERS = arrayDifference(RUNNERS, ["node"]);
19
+ /**
20
+ * Scripts that run with any package manager by default, as they run on the machine of whoever
21
+ * installs the package: install scripts, and `prepare`, which runs when it's installed from git
22
+ */
23
+ const RUNNER_AGNOSTIC_SCRIPTS = /* @__PURE__ */ new Set([
24
+ "install",
25
+ "postinstall",
26
+ "preinstall",
27
+ "prepare"
28
+ ]);
29
+ /**
30
+ * Checks whether any package manager may run a script.
31
+ * @param scriptName The script's name in package.json
32
+ * @param scripts `true` for all scripts, `false` for none, or whether each script is
33
+ * runner-agnostic, on top of the defaults
34
+ * @returns Whether the script is runner-agnostic
35
+ */
36
+ const isRunnerAgnosticScript = (scriptName, scripts = {}) => {
37
+ if (typeof scripts === "boolean") return scripts;
38
+ if (scriptName == null) return false;
39
+ return Object.hasOwn(scripts, scriptName) ? scripts[scriptName] === true : RUNNER_AGNOSTIC_SCRIPTS.has(scriptName);
40
+ };
41
+ const RUNNER_TRAITS = {
42
+ aube: { label: "aube" },
43
+ node: {
44
+ label: "`node --run`",
45
+ packageManagerVariables: /* @__PURE__ */ new Set()
46
+ },
47
+ npm: {
48
+ label: "npm",
49
+ setsHome: true
50
+ },
51
+ pnpm: { label: "pnpm" },
52
+ "pnpm-10": {
53
+ label: "pnpm v10",
54
+ setsHome: true
55
+ },
56
+ upm: {
57
+ label: "upm",
58
+ packageManagerVariables: /* @__PURE__ */ new Set([
59
+ "INIT_CWD",
60
+ "npm_lifecycle_event",
61
+ "npm_lifecycle_script",
62
+ "npm_package_json",
63
+ "npm_package_name",
64
+ "npm_package_version"
65
+ ])
66
+ },
67
+ yarn: {
68
+ label: "Yarn",
69
+ portableShell: true
70
+ },
71
+ "yarn-classic": {
72
+ convertsSlashes: true,
73
+ label: "Yarn v1"
74
+ }
75
+ };
76
+ /** Package managers whose runner always has the same name, i.e. all of them but pnpm and Yarn */
77
+ const SAME_NAME_RUNNERS = /* @__PURE__ */ new Set([
78
+ "aube",
79
+ "npm",
80
+ "upm"
81
+ ]);
82
+ /** The first number of a version or a version range, e.g. `1` in `^1.22.0` */
83
+ const MAJOR_VERSION = /\d+/;
84
+ /** A version range without an upper bound, e.g. `>=10`, which includes later major versions */
85
+ const UNBOUNDED_RANGE = /^\s*>/;
86
+ /**
87
+ * Gets the runner for a package manager, e.g. the one in the `packageManager` or
88
+ * `devEngines.packageManager` field of package.json.
89
+ * @param name Name of the package manager, e.g. `yarn`
90
+ * @param version Its version or version range, which tells Yarn v1 from Yarn v2+, and pnpm v10
91
+ * from later versions, e.g. `1.22.22`
92
+ * @returns The runner, or `undefined` if it's an unknown package manager or Yarn of an unknown
93
+ * version
94
+ */
95
+ const getRunner = (name, version = "") => {
96
+ const major = Number(MAJOR_VERSION.exec(version)?.[0]);
97
+ if (name === "pnpm") return major <= 10 && !UNBOUNDED_RANGE.test(version) ? "pnpm-10" : "pnpm";
98
+ if (name !== "yarn") return setHas(SAME_NAME_RUNNERS, name) ? name : void 0;
99
+ if (major === 1) return "yarn-classic";
100
+ return major >= 2 ? "yarn" : void 0;
101
+ };
102
+ /**
103
+ * Gets how a runner runs the scripts.
104
+ * @param runner What runs the scripts
105
+ * @param isShellEmulated Whether pnpm's `shell-emulator` setting is on
106
+ * @returns The runner's traits
107
+ */
108
+ const runnerTraits = (runner, isShellEmulated) => isShellEmulated && (runner === "pnpm" || runner === "pnpm-10") ? {
109
+ ...RUNNER_TRAITS[runner],
110
+ portableShell: true
111
+ } : RUNNER_TRAITS[runner];
112
+ /**
113
+ * Formats runners as a list for people, e.g. "pnpm and Yarn v1".
114
+ * @param runners The runners to format
115
+ * @returns The formatted list
116
+ */
117
+ const formatRunners = (runners) => listFormat.format(arrayIntersection(RUNNERS, runners).map((runner) => RUNNER_TRAITS[runner].label));
118
+ export { PACKAGE_MANAGER_RUNNERS, RUNNERS, RUNNER_AGNOSTIC_SCRIPTS, formatRunners, getRunner, isRunnerAgnosticScript, runnerTraits };