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.
- package/README.md +59 -20
- package/dist/analyze-script.d.mts +34 -0
- package/dist/analyze-script.mjs +53 -0
- package/dist/command-checker.mjs +527 -0
- package/dist/command-usage.mjs +413 -0
- package/dist/commands.mjs +639 -0
- package/dist/context.mjs +25 -0
- package/dist/fixes.d.mts +9 -0
- package/dist/fixes.mjs +354 -0
- package/dist/index.d.mts +6 -118
- package/dist/index.mjs +4 -3787
- package/dist/line-break-checker.mjs +104 -0
- package/dist/messages.mjs +38 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/array-difference.mjs +11 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/array-includes.mjs +8 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/array-intersection.mjs +13 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/array-is-subset.mjs +16 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/arrayify.mjs +7 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/sorted-array-insertion-index-with.mjs +33 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/sorted-array-insertion-index.mjs +10 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/iterable/sliding-window.mjs +30 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/map/map-get-or-insert-computed.mjs +42 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/map/map-get-or-insert.mjs +40 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/math/clamp.mjs +7 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/path/to-forward-slashes.mjs +8 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/predicate/is-array.mjs +39 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/semver/is-semver-in-range.mjs +5 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/semver/parse-semver.mjs +26 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/set/set-has.mjs +8 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/string/substring-after-last.mjs +24 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/string/substring-after.mjs +24 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/string/substring-before.mjs +24 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/string/truncate.mjs +46 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/ts/all-union-members.mjs +45 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/types/maybe-readonly-array.d.mts +17 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/value/is-equal.mjs +37 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/@antfu/utils/dist/index.mjs +5 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/_internal/globalThis.mjs +5 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/_internal/isUnsafeProperty.mjs +18 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/_internal/setOwnValue.mjs +23 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/_internal/toPropertyKey.mjs +16 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/array/differenceBy.mjs +40 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/array/differenceWith.mjs +37 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/array/intersectionWith.mjs +43 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/array/isSubsetWith.mjs +36 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/bigint/clamp.mjs +15 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/_internal/baseToString.mjs +26 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/_internal/getSymbols.mjs +5 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/_internal/getTag.mjs +13 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/_internal/hasOwn.mjs +13 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/_internal/isDeepKey.mjs +39 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/_internal/isIndex.mjs +10 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/_internal/regexMultiByte.mjs +10 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/_internal/tags.mjs +28 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/_internal/toKey.mjs +15 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/array/sortedIndex.mjs +36 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/array/sortedIndexBy.mjs +54 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/array/sortedLastIndex.mjs +34 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/array/sortedLastIndexBy.mjs +21 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/function/identity.mjs +5 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/object/cloneDeep.mjs +52 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/object/cloneDeepWith.mjs +179 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/object/get.mjs +67 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/object/has.mjs +53 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/object/property.mjs +26 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/predicate/isArguments.mjs +26 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/predicate/isBuffer.mjs +24 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/predicate/isMatch.mjs +34 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/predicate/isMatchWith.mjs +163 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/predicate/isNaN.mjs +18 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/predicate/isNil.mjs +24 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/predicate/isNumber.mjs +24 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/predicate/isObject.mjs +28 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/predicate/isObjectLike.mjs +28 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/predicate/isSymbol.mjs +19 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/predicate/isTypedArray.mjs +21 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/predicate/matches.mjs +36 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/predicate/matchesProperty.mjs +47 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/string/truncate.mjs +78 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/util/eq.mjs +18 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/util/iteratee.mjs +46 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/util/toPath.mjs +75 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/util/toString.mjs +23 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/function/identity.mjs +24 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/function/noop.mjs +12 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/math/clamp.mjs +23 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/predicate/isBuffer.mjs +24 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/predicate/isEqual.mjs +21 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/predicate/isEqualWith.mjs +150 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/predicate/isNil.mjs +24 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/predicate/isNull.mjs +25 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/predicate/isPlainObject.mjs +50 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/predicate/isPrimitive.mjs +26 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/predicate/isSymbol.mjs +28 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/predicate/isTypedArray.mjs +20 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/predicate/isUndefined.mjs +25 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/remeda/dist/binarySearchCutoffIndex-Bu-OMJ0Z.mjs +26 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/remeda/dist/isArray.mjs +18 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/remeda/dist/sortedIndexWith.mjs +7 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/ts-extras/distribution/array-includes.mjs +5 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/ts-extras/distribution/set-has.mjs +5 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/verkit/dist/comparison-CmVirWIW.mjs +108 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/verkit/dist/range-C5wjdo9a.mjs +164 -0
- package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/verkit/dist/set-BGFWKKE8.mjs +38 -0
- package/dist/platforms.d.mts +8 -0
- package/dist/platforms.mjs +26 -0
- package/dist/redirection-checker.mjs +169 -0
- package/dist/reporter.d.mts +32 -0
- package/dist/reporter.mjs +143 -0
- package/dist/runners.d.mts +21 -0
- package/dist/runners.mjs +199 -0
- package/dist/script-analyzer.mjs +853 -0
- package/dist/word-checker.mjs +573 -0
- package/dist/words.mjs +70 -0
- package/package.json +36 -30
package/dist/runners.mjs
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
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 { isSemverInRange } from "./node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/semver/is-semver-in-range.mjs";
|
|
6
|
+
import { parseSemver } from "./node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/semver/parse-semver.mjs";
|
|
7
|
+
import { setHas } from "./node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/set/set-has.mjs";
|
|
8
|
+
// src/runners.ts
|
|
9
|
+
const RUNNERS = allUnionMembers()([
|
|
10
|
+
"aube",
|
|
11
|
+
"node",
|
|
12
|
+
"npm",
|
|
13
|
+
"pnpm",
|
|
14
|
+
"pnpm-10",
|
|
15
|
+
"upm",
|
|
16
|
+
"yarn",
|
|
17
|
+
"yarn-classic"
|
|
18
|
+
]);
|
|
19
|
+
/** Runners that are package managers, i.e. all of them but `node` */
|
|
20
|
+
const PACKAGE_MANAGER_RUNNERS = arrayDifference(RUNNERS, ["node"]);
|
|
21
|
+
/** Scripts that any package manager may run by default */
|
|
22
|
+
const RUNNER_AGNOSTIC_SCRIPTS = /* @__PURE__ */ new Set([
|
|
23
|
+
"install",
|
|
24
|
+
"postinstall",
|
|
25
|
+
"preinstall",
|
|
26
|
+
"prepare"
|
|
27
|
+
]);
|
|
28
|
+
/**
|
|
29
|
+
* Checks whether any package manager may run a script.
|
|
30
|
+
* @param scriptName The script's name in `package.json`
|
|
31
|
+
* @param scripts `true` for all scripts, `false` for none, or whether each script is
|
|
32
|
+
* runner-agnostic, on top of the defaults
|
|
33
|
+
* @returns Whether the script is runner-agnostic
|
|
34
|
+
*/
|
|
35
|
+
const isRunnerAgnosticScript = (scriptName, scripts) => {
|
|
36
|
+
if (typeof scripts === "boolean") return scripts;
|
|
37
|
+
if (scriptName == null) return false;
|
|
38
|
+
return scripts != null && Object.hasOwn(scripts, scriptName) ? scripts[scriptName] === true : RUNNER_AGNOSTIC_SCRIPTS.has(scriptName);
|
|
39
|
+
};
|
|
40
|
+
const RUNNER_TRAITS = {
|
|
41
|
+
aube: { label: "aube" },
|
|
42
|
+
node: {
|
|
43
|
+
label: "`node --run`",
|
|
44
|
+
packageManagerVariables: /* @__PURE__ */ new Set()
|
|
45
|
+
},
|
|
46
|
+
npm: {
|
|
47
|
+
label: "npm",
|
|
48
|
+
setsHome: true
|
|
49
|
+
},
|
|
50
|
+
pnpm: { label: "pnpm" },
|
|
51
|
+
"pnpm-10": {
|
|
52
|
+
label: "pnpm v10",
|
|
53
|
+
setsHome: true
|
|
54
|
+
},
|
|
55
|
+
upm: {
|
|
56
|
+
label: "upm",
|
|
57
|
+
packageManagerVariables: /* @__PURE__ */ new Set([
|
|
58
|
+
"INIT_CWD",
|
|
59
|
+
"npm_lifecycle_event",
|
|
60
|
+
"npm_lifecycle_script",
|
|
61
|
+
"npm_package_json",
|
|
62
|
+
"npm_package_name",
|
|
63
|
+
"npm_package_version"
|
|
64
|
+
])
|
|
65
|
+
},
|
|
66
|
+
yarn: {
|
|
67
|
+
label: "Yarn",
|
|
68
|
+
portableShell: true
|
|
69
|
+
},
|
|
70
|
+
"yarn-classic": {
|
|
71
|
+
convertsSlashes: true,
|
|
72
|
+
label: "Yarn v1"
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
/** How pnpm runs the scripts with `shell-emulator` on, i.e. with Yarn's portable shell */
|
|
76
|
+
const SHELL_EMULATOR_TRAITS = {
|
|
77
|
+
pnpm: {
|
|
78
|
+
...RUNNER_TRAITS.pnpm,
|
|
79
|
+
portableShell: true
|
|
80
|
+
},
|
|
81
|
+
"pnpm-10": {
|
|
82
|
+
...RUNNER_TRAITS["pnpm-10"],
|
|
83
|
+
portableShell: true
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
/** Package managers whose runner always has the same name, i.e. all of them but pnpm and Yarn */
|
|
87
|
+
const SAME_NAME_RUNNERS = /* @__PURE__ */ new Set([
|
|
88
|
+
"aube",
|
|
89
|
+
"npm",
|
|
90
|
+
"upm"
|
|
91
|
+
]);
|
|
92
|
+
/** A version in a version range, e.g. `1.22` in `^1.22 || ^4` */
|
|
93
|
+
const RANGE_VERSIONS = /\d+(?:\.\d+){0,2}/g;
|
|
94
|
+
/** Maximum length of a version or a version range that is checked */
|
|
95
|
+
const MAX_VERSION_CHARACTERS = 256;
|
|
96
|
+
/**
|
|
97
|
+
* Gets major versions that a version or a version range matches, enough to tell whether it matches
|
|
98
|
+
* versions before a major version, and versions from it on.
|
|
99
|
+
* @param version A version, e.g. `1.22.22`, or a version range, e.g. `^1.22 || ^4`
|
|
100
|
+
* @param major The major version, e.g. `2`
|
|
101
|
+
* @returns The major versions, or none for an unknown version, e.g. `latest`
|
|
102
|
+
*/
|
|
103
|
+
const matchedMajors = (version, major) => {
|
|
104
|
+
if (version.length > MAX_VERSION_CHARACTERS) return [];
|
|
105
|
+
const exact = parseSemver(version);
|
|
106
|
+
if (exact) return [exact.major];
|
|
107
|
+
return [
|
|
108
|
+
[
|
|
109
|
+
0,
|
|
110
|
+
0,
|
|
111
|
+
0
|
|
112
|
+
],
|
|
113
|
+
[
|
|
114
|
+
major,
|
|
115
|
+
0,
|
|
116
|
+
0
|
|
117
|
+
],
|
|
118
|
+
...[...version.matchAll(RANGE_VERSIONS)].flatMap(([text]) => {
|
|
119
|
+
const [first = 0, second = 0, third = 0] = text.split(".").map(Number);
|
|
120
|
+
return [
|
|
121
|
+
[
|
|
122
|
+
first,
|
|
123
|
+
second,
|
|
124
|
+
third
|
|
125
|
+
],
|
|
126
|
+
[
|
|
127
|
+
first,
|
|
128
|
+
second,
|
|
129
|
+
third + 1
|
|
130
|
+
],
|
|
131
|
+
[
|
|
132
|
+
first,
|
|
133
|
+
second + 1,
|
|
134
|
+
0
|
|
135
|
+
],
|
|
136
|
+
[
|
|
137
|
+
first + 1,
|
|
138
|
+
0,
|
|
139
|
+
0
|
|
140
|
+
]
|
|
141
|
+
];
|
|
142
|
+
})
|
|
143
|
+
].filter((candidate) => isSemverInRange(candidate.join("."), version)).map(([candidateMajor = 0]) => candidateMajor);
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Gets the runner for a package manager, e.g. the one in the `packageManager` or
|
|
147
|
+
* `devEngines.packageManager` field of `package.json`.
|
|
148
|
+
* @param name Name of the package manager, e.g. `yarn`
|
|
149
|
+
* @param version Its version or version range, which tells Yarn v1 from Yarn v2+, and pnpm v10
|
|
150
|
+
* from later versions, e.g. `1.22.22`
|
|
151
|
+
* @returns The runner, or `undefined` if it's an unknown package manager or Yarn of an unknown
|
|
152
|
+
* version
|
|
153
|
+
*/
|
|
154
|
+
const getRunner = (name, version = "") => {
|
|
155
|
+
if (name === "pnpm") {
|
|
156
|
+
const majors = matchedMajors(version, 11);
|
|
157
|
+
return majors.length > 0 && majors.every((major) => major <= 10) ? "pnpm-10" : "pnpm";
|
|
158
|
+
}
|
|
159
|
+
if (name !== "yarn") return setHas(SAME_NAME_RUNNERS, name) ? name : void 0;
|
|
160
|
+
const majors = matchedMajors(version, 2);
|
|
161
|
+
const isClassic = majors.some((major) => major <= 1);
|
|
162
|
+
if (isClassic === majors.some((major) => major >= 2)) return;
|
|
163
|
+
return isClassic ? "yarn-classic" : "yarn";
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* Gets how a runner runs the scripts.
|
|
167
|
+
* @param runner What runs the scripts
|
|
168
|
+
* @param isShellEmulated Whether pnpm's `shell-emulator` setting is on
|
|
169
|
+
* @returns The runner's traits
|
|
170
|
+
*/
|
|
171
|
+
const runnerTraits = (runner, isShellEmulated) => isShellEmulated && SHELL_EMULATOR_TRAITS[runner] || RUNNER_TRAITS[runner];
|
|
172
|
+
/**
|
|
173
|
+
* Reads a runner's traits and remembers the values that were read.
|
|
174
|
+
* An analysis gives the same result for all runners with the same values of the traits it read, so
|
|
175
|
+
* it must read them only through this
|
|
176
|
+
*/
|
|
177
|
+
var TraitsReader = class {
|
|
178
|
+
#readValues = /* @__PURE__ */ new Map();
|
|
179
|
+
#traits;
|
|
180
|
+
constructor(traits) {
|
|
181
|
+
this.#traits = traits;
|
|
182
|
+
}
|
|
183
|
+
get(key) {
|
|
184
|
+
const value = this.#traits[key];
|
|
185
|
+
this.#readValues.set(key, value);
|
|
186
|
+
return value;
|
|
187
|
+
}
|
|
188
|
+
/** Checks whether other traits have the same values as the ones that were read */
|
|
189
|
+
matches(traits) {
|
|
190
|
+
return this.#readValues.entries().every(([key, value]) => traits[key] === value);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
194
|
+
* Formats runners as a list for people, e.g. "pnpm and Yarn v1".
|
|
195
|
+
* @param runners The runners to format
|
|
196
|
+
* @returns The formatted list
|
|
197
|
+
*/
|
|
198
|
+
const formatRunners = (runners) => listFormat.format(arrayIntersection(RUNNERS, runners).map((runner) => RUNNER_TRAITS[runner].label));
|
|
199
|
+
export { PACKAGE_MANAGER_RUNNERS, RUNNERS, RUNNER_AGNOSTIC_SCRIPTS, TraitsReader, formatRunners, getRunner, isRunnerAgnosticScript, runnerTraits };
|