package-json-scripts-portability 0.0.1 → 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.
- package/README.md +1 -1
- package/dist/analyze-script.d.mts +34 -0
- package/dist/analyze-script.mjs +48 -0
- package/dist/command-checker.mjs +295 -0
- package/dist/command-usage.mjs +364 -0
- package/dist/commands.mjs +520 -0
- package/dist/context.mjs +18 -0
- package/dist/fixes.d.mts +9 -0
- package/dist/fixes.mjs +210 -0
- package/dist/index.d.mts +6 -118
- package/dist/index.mjs +4 -3787
- package/dist/line-break-checker.mjs +71 -0
- package/dist/messages.mjs +30 -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/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/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-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/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/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/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 +27 -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/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/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 +151 -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/remeda/dist/isArray.mjs +18 -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/platforms.d.mts +8 -0
- package/dist/platforms.mjs +26 -0
- package/dist/redirection-checker.mjs +117 -0
- package/dist/reporter.d.mts +32 -0
- package/dist/reporter.mjs +98 -0
- package/dist/runners.d.mts +24 -0
- package/dist/runners.mjs +118 -0
- package/dist/script-analyzer.mjs +551 -0
- package/dist/word-checker.mjs +444 -0
- package/dist/words.mjs +43 -0
- package/package.json +22 -20
package/dist/fixes.mjs
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { describeReplacement, truncate } from "./messages.mjs";
|
|
2
|
+
import { ASSIGNMENT, GLOB_PART_TYPES, isPlainWord, staticValue } from "./words.mjs";
|
|
3
|
+
// src/fixes.ts
|
|
4
|
+
const LINE_WHITESPACE = /[\t ]/;
|
|
5
|
+
const LINE_BREAK = /^\r?\n/;
|
|
6
|
+
/** Options of `rm` that `rimraf` doesn't need, e.g. `-rf` */
|
|
7
|
+
const RM_OPTION = /^(?:-[Rfr]+|--force|--recursive)$/;
|
|
8
|
+
/** A binary of a dependency, which package managers add to `PATH` */
|
|
9
|
+
const DEPENDENCY_BINARY = /^(?:\.\/)?node_modules\/\.bin\/([^/]+)$/;
|
|
10
|
+
const JAVASCRIPT_FILE = /\.[cm]?js$/;
|
|
11
|
+
/** A brace expansion of plain alternatives, e.g. `{a,b}` */
|
|
12
|
+
const SIMPLE_BRACE_EXPANSION = /^\{([\w+\-./@]*(?:,[\w+\-./@]*)+)\}$/;
|
|
13
|
+
const PLAIN_TEXT = /^[\w+\-./:=@]*$/;
|
|
14
|
+
/** Creates a fix that replaces a piece of the script */
|
|
15
|
+
const replacement = (node, original, text) => ({
|
|
16
|
+
description: describeReplacement(original, text),
|
|
17
|
+
edits: [{
|
|
18
|
+
end: node.end,
|
|
19
|
+
pos: node.pos,
|
|
20
|
+
text
|
|
21
|
+
}]
|
|
22
|
+
});
|
|
23
|
+
/** Creates a fix that wraps a word in double quotes */
|
|
24
|
+
const quoting = (word, description) => ({
|
|
25
|
+
description,
|
|
26
|
+
edits: [{
|
|
27
|
+
end: word.pos,
|
|
28
|
+
pos: word.pos,
|
|
29
|
+
text: "\""
|
|
30
|
+
}, {
|
|
31
|
+
end: word.end,
|
|
32
|
+
pos: word.end,
|
|
33
|
+
text: "\""
|
|
34
|
+
}]
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* Creates an edit that removes a piece of a script, along with the whitespace that separates it.
|
|
38
|
+
* @param source The script
|
|
39
|
+
* @param pos Start offset of the piece
|
|
40
|
+
* @param end End offset (exclusive) of the piece
|
|
41
|
+
* @returns The edit
|
|
42
|
+
*/
|
|
43
|
+
const removal = (source, pos, end) => {
|
|
44
|
+
let start = pos;
|
|
45
|
+
let stop = end;
|
|
46
|
+
while (start > 0 && LINE_WHITESPACE.test(source.charAt(start - 1))) start--;
|
|
47
|
+
if (start === 0 || source[start - 1] === "\n") {
|
|
48
|
+
while (stop < source.length && LINE_WHITESPACE.test(source.charAt(stop))) stop++;
|
|
49
|
+
const lineBreak = LINE_BREAK.exec(source.slice(stop))?.[0];
|
|
50
|
+
if (lineBreak) stop += lineBreak.length;
|
|
51
|
+
else if (stop === source.length && start > 0) start -= source[start - 2] === "\r" ? 2 : 1;
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
end: stop,
|
|
55
|
+
pos: start,
|
|
56
|
+
text: ""
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Gets a fix for a command that isn't available on all platforms, e.g. `rimraf` for `rm -rf`.
|
|
61
|
+
* @param name Name that the command was invoked with, e.g. `rm`
|
|
62
|
+
* @param nameWord Word that the name comes from
|
|
63
|
+
* @param argumentWords The words that follow it
|
|
64
|
+
* @param source The source that node positions refer to
|
|
65
|
+
* @returns The fix, if there's a replacement that works the same
|
|
66
|
+
*/
|
|
67
|
+
const commandFix = (name, nameWord, argumentWords, source) => {
|
|
68
|
+
const first = argumentWords.at(0);
|
|
69
|
+
switch (name) {
|
|
70
|
+
case "env": return first && ASSIGNMENT.test(first.text) && argumentWords.some((word) => !ASSIGNMENT.test(word.text)) ? replacement(nameWord, nameWord.text, "cross-env") : void 0;
|
|
71
|
+
case "rm": {
|
|
72
|
+
const optionCount = argumentWords.findIndex((word) => !RM_OPTION.test(staticValue(word) || ""));
|
|
73
|
+
const paths = optionCount === -1 ? [] : argumentWords.slice(optionCount);
|
|
74
|
+
const globs = paths.filter((word) => word.parts?.some((part) => GLOB_PART_TYPES.includes(part.type)));
|
|
75
|
+
if (paths.length === 0 || paths.some((word) => staticValue(word)?.startsWith("-") && word.text !== "--") || globs.some((word) => !isPlainWord(word, GLOB_PART_TYPES))) return;
|
|
76
|
+
const end = argumentWords[optionCount - 1]?.end || nameWord.end;
|
|
77
|
+
const original = source.slice(nameWord.pos, end);
|
|
78
|
+
return globs.length === 0 ? replacement({
|
|
79
|
+
end,
|
|
80
|
+
pos: nameWord.pos
|
|
81
|
+
}, original, "rimraf") : {
|
|
82
|
+
description: `Replace \`${truncate(original)}\` with \`rimraf --glob\`, and quote the globs.`,
|
|
83
|
+
edits: [{
|
|
84
|
+
end,
|
|
85
|
+
pos: nameWord.pos,
|
|
86
|
+
text: "rimraf --glob"
|
|
87
|
+
}, ...globs.flatMap((word) => quoting(word, "").edits)]
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
case "source": {
|
|
91
|
+
const file = first && staticValue(first);
|
|
92
|
+
if (!first || file == null) return;
|
|
93
|
+
const range = {
|
|
94
|
+
end: first.end,
|
|
95
|
+
pos: nameWord.pos
|
|
96
|
+
};
|
|
97
|
+
return replacement(range, source.slice(range.pos, range.end), `. ${file.includes("/") ? "" : "./"}${first.text}`);
|
|
98
|
+
}
|
|
99
|
+
default: return;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Gets a fix for running a command by its path, e.g. `node ./build.js` for `./build.js`.
|
|
104
|
+
* @param name Path that the command was invoked with
|
|
105
|
+
* @param nameWord Word that the path comes from
|
|
106
|
+
* @returns The fix, if the path is a dependency's binary or a JavaScript file
|
|
107
|
+
*/
|
|
108
|
+
const pathCommandFix = (name, nameWord) => {
|
|
109
|
+
const binary = DEPENDENCY_BINARY.exec(name)?.[1];
|
|
110
|
+
if (binary) return replacement(nameWord, nameWord.text, binary);
|
|
111
|
+
return JAVASCRIPT_FILE.test(name) ? {
|
|
112
|
+
description: "Run the file with `node`.",
|
|
113
|
+
edits: [{
|
|
114
|
+
end: nameWord.pos,
|
|
115
|
+
pos: nameWord.pos,
|
|
116
|
+
text: "node "
|
|
117
|
+
}]
|
|
118
|
+
} : void 0;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Gets a fix that expands a brace expansion, e.g. `dist/a dist/b` for `dist/{a,b}`.
|
|
122
|
+
* @param word The word that contains the brace expansion
|
|
123
|
+
* @param part Brace expansion in the word, e.g. `{a,b}`
|
|
124
|
+
* @returns The fix, if the word only consists of plain text and the brace expansion
|
|
125
|
+
*/
|
|
126
|
+
const braceExpansionFix = (word, part) => {
|
|
127
|
+
const alternatives = SIMPLE_BRACE_EXPANSION.exec(part.text)?.[1]?.split(",");
|
|
128
|
+
const isPlain = (word.parts || []).every((other) => other === part || other.type === "Literal" && PLAIN_TEXT.test(other.text));
|
|
129
|
+
if (!alternatives || !isPlain) return;
|
|
130
|
+
const prefix = word.text.slice(0, part.pos - word.pos);
|
|
131
|
+
const suffix = word.text.slice(part.end - word.pos);
|
|
132
|
+
return replacement(word, word.text, alternatives.map((alternative) => `${prefix}${alternative}${suffix}`).join(" "));
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Checks whether joining a statement to the previous one with `&&` keeps the logic the same,
|
|
136
|
+
* apart from stopping after a failure.
|
|
137
|
+
* @param next The statement that follows
|
|
138
|
+
* @returns Whether the rest of the logic stays the same, e.g. not for `a; b || c`, which would run
|
|
139
|
+
* `c` when `a` fails
|
|
140
|
+
*/
|
|
141
|
+
const canChain = (next) => !next.background && !(next.command.type === "AndOr" && next.command.operators.includes("||"));
|
|
142
|
+
/**
|
|
143
|
+
* Gets a fix for a line break that separates commands.
|
|
144
|
+
* @param gapStart Where the text between the commands starts
|
|
145
|
+
* @param gap The text between the commands, including the line break
|
|
146
|
+
* @param next The statement that follows it
|
|
147
|
+
* @returns The fix, if the text is only whitespace and the rest of the logic stays the same
|
|
148
|
+
*/
|
|
149
|
+
const lineBreakFix = (gapStart, gap, next) => gap.trim().length === 0 && canChain(next) ? {
|
|
150
|
+
description: "Replace the line break with `&&`, which stops at the first failing command.",
|
|
151
|
+
edits: [{
|
|
152
|
+
end: next.pos,
|
|
153
|
+
pos: gapStart,
|
|
154
|
+
text: " && "
|
|
155
|
+
}]
|
|
156
|
+
} : void 0;
|
|
157
|
+
/**
|
|
158
|
+
* Gets a fix that joins the lines of a command, e.g. after `||` or a `\` line continuation.
|
|
159
|
+
* @param source The source that the command is in
|
|
160
|
+
* @param position Where the line break is
|
|
161
|
+
* @param end Where the whitespace after the line break ends
|
|
162
|
+
* @returns The fix, which keeps the command the same in POSIX shells
|
|
163
|
+
*/
|
|
164
|
+
const joinLinesFix = (source, position, end) => {
|
|
165
|
+
return {
|
|
166
|
+
description: "Join the lines.",
|
|
167
|
+
edits: [source[position - 1] === "\\" ? {
|
|
168
|
+
end: position + 1,
|
|
169
|
+
pos: position - 1,
|
|
170
|
+
text: ""
|
|
171
|
+
} : {
|
|
172
|
+
end,
|
|
173
|
+
pos: position,
|
|
174
|
+
text: " "
|
|
175
|
+
}]
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Gets a fix for a `;` that separates commands.
|
|
180
|
+
* @param range Where the `;` is
|
|
181
|
+
* @param gap The text between the commands, including the `;`
|
|
182
|
+
* @param next The statement that follows it, if any
|
|
183
|
+
* @returns The fix, unless the statement that follows has alternatives (`||`) or runs in the
|
|
184
|
+
* background
|
|
185
|
+
*/
|
|
186
|
+
const semicolonFix = (range, gap, next) => {
|
|
187
|
+
if (!next) return {
|
|
188
|
+
description: "Remove the `;`.",
|
|
189
|
+
edits: [{
|
|
190
|
+
...range,
|
|
191
|
+
text: ""
|
|
192
|
+
}]
|
|
193
|
+
};
|
|
194
|
+
return gap.trim() === ";" && canChain(next) ? {
|
|
195
|
+
description: "Replace `;` with `&&`, which stops at the first failing command.",
|
|
196
|
+
edits: [{
|
|
197
|
+
end: next.pos,
|
|
198
|
+
pos: range.pos - gap.indexOf(";"),
|
|
199
|
+
text: " && "
|
|
200
|
+
}]
|
|
201
|
+
} : void 0;
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* Applies a fix to the script that it was found in.
|
|
205
|
+
* @param script Text of the script to change
|
|
206
|
+
* @param fix A fix from `analyzeScript`
|
|
207
|
+
* @returns The fixed script
|
|
208
|
+
*/
|
|
209
|
+
const applyFix = (script, fix) => fix.edits.toSorted((left, right) => right.pos - left.pos).reduce((result, { end, pos, text }) => result.slice(0, pos) + text + result.slice(end), script);
|
|
210
|
+
export { DEPENDENCY_BINARY, applyFix, braceExpansionFix, commandFix, joinLinesFix, lineBreakFix, pathCommandFix, quoting, removal, replacement, semicolonFix };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,118 +1,6 @@
|
|
|
1
|
-
import "
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* @returns The formatted list
|
|
8
|
-
*/
|
|
9
|
-
export declare const formatPlatforms: (platforms: readonly Platform[]) => string;
|
|
10
|
-
/** What can run the scripts: a package manager, or `node` for `node --run` */
|
|
11
|
-
type Runner = 'aube' | 'node' | 'npm' | 'pnpm' | 'pnpm-10' | 'upm' | 'yarn' | 'yarn-classic';
|
|
12
|
-
export declare const RUNNERS: readonly Runner[];
|
|
13
|
-
/**
|
|
14
|
-
* Scripts that run with any package manager by default, as they run on the machine of whoever
|
|
15
|
-
* installs the package: install scripts, and `prepare`, which runs when it's installed from git
|
|
16
|
-
*/
|
|
17
|
-
export declare const RUNNER_AGNOSTIC_SCRIPTS: ReadonlySet<string>;
|
|
18
|
-
/**
|
|
19
|
-
* Gets the runner for a package manager, e.g. the one in the `packageManager` or
|
|
20
|
-
* `devEngines.packageManager` field of package.json.
|
|
21
|
-
* @param name Name of the package manager, e.g. `yarn`
|
|
22
|
-
* @param version Its version or version range, which tells Yarn v1 from Yarn v2+, and pnpm v10
|
|
23
|
-
* from later versions, e.g. `1.22.22`
|
|
24
|
-
* @returns The runner, or `undefined` if it's an unknown package manager or Yarn of an unknown
|
|
25
|
-
* version
|
|
26
|
-
*/
|
|
27
|
-
export declare const getRunner: (name: string, version?: string) => "aube" | "node" | "npm" | "pnpm" | "pnpm-10" | "upm" | "yarn" | "yarn-classic" | undefined;
|
|
28
|
-
/**
|
|
29
|
-
* Formats runners as a list for people, e.g. "pnpm and Yarn v1".
|
|
30
|
-
* @param runners The runners to format
|
|
31
|
-
* @returns The formatted list
|
|
32
|
-
*/
|
|
33
|
-
export declare const formatRunners: (runners: readonly Runner[]) => string;
|
|
34
|
-
/**
|
|
35
|
-
* A value or a readonly array of such values: `T | readonly T[]`.
|
|
36
|
-
*
|
|
37
|
-
* Unlike `MaybeArray`, it also accepts readonly arrays and tuples (like `as const` literals), so
|
|
38
|
-
* it fits parameters and options that only read the array.
|
|
39
|
-
* To tell the two cases apart, use `isArray`: unlike `Array.isArray`, it narrows this type in
|
|
40
|
-
* both branches.
|
|
41
|
-
* @example
|
|
42
|
-
* const watch = (paths: MaybeReadonlyArray<string>) => {
|
|
43
|
-
* const list = isArray(paths) ? paths : [paths]; // readonly string[]
|
|
44
|
-
* // ...
|
|
45
|
-
* };
|
|
46
|
-
*
|
|
47
|
-
* watch('src');
|
|
48
|
-
* watch(['src', 'test'] as const); // an error with `MaybeArray<string>`
|
|
49
|
-
*/
|
|
50
|
-
type MaybeReadonlyArray<T> = T | readonly T[];
|
|
51
|
-
type ScriptIssueMessageId = 'inconsistentBehavior' | 'unsupportedCommand' | 'unsupportedSyntax' | 'unsupportedUsage';
|
|
52
|
-
interface ScriptEdit {
|
|
53
|
-
/** End offset (exclusive) of the replaced text in the script */
|
|
54
|
-
end: number;
|
|
55
|
-
/** Start offset of the replaced text in the script */
|
|
56
|
-
pos: number;
|
|
57
|
-
/** The replacement */
|
|
58
|
-
text: string;
|
|
59
|
-
}
|
|
60
|
-
interface ScriptFix {
|
|
61
|
-
/** Describes the fix for people, e.g. "Prefix the command with `cross-env`." */
|
|
62
|
-
description: string;
|
|
63
|
-
/** Replacements that don't overlap */
|
|
64
|
-
edits: ScriptEdit[];
|
|
65
|
-
}
|
|
66
|
-
interface ScriptIssue {
|
|
67
|
-
/** Message data, apart from `platforms` */
|
|
68
|
-
data: Record<string, string>;
|
|
69
|
-
/** End offset (exclusive) of the issue in the script */
|
|
70
|
-
end: number;
|
|
71
|
-
/** A fix that the rule suggests, if the issue has an obvious one */
|
|
72
|
-
fix?: ScriptFix;
|
|
73
|
-
messageId: ScriptIssueMessageId;
|
|
74
|
-
/** Platforms on which the script doesn't work as intended */
|
|
75
|
-
platforms: Platform[];
|
|
76
|
-
/** Start offset of the issue in the script */
|
|
77
|
-
pos: number;
|
|
78
|
-
/** Runners with which the script has the issue */
|
|
79
|
-
runners: Runner[];
|
|
80
|
-
}
|
|
81
|
-
interface AnalyzeScriptOptions {
|
|
82
|
-
/** Names of the package's dependencies, e.g. to detect del-cli's `del` alias */
|
|
83
|
-
dependencies?: readonly string[];
|
|
84
|
-
/** Commands that shouldn't be reported */
|
|
85
|
-
ignoreCommands?: readonly string[];
|
|
86
|
-
/**
|
|
87
|
-
* What runs the script: a package manager, or `node` for `node --run`.
|
|
88
|
-
* It decides e.g. which shell runs the script and which environment variables it gets.
|
|
89
|
-
* Several runners report what breaks with any of them.
|
|
90
|
-
* Defaults to `npm`
|
|
91
|
-
*/
|
|
92
|
-
runner?: MaybeReadonlyArray<Runner>;
|
|
93
|
-
/**
|
|
94
|
-
* Scripts that any package manager may run, which are checked with all of them instead of
|
|
95
|
-
* `runner`: `true` for all scripts, `false` for none, or whether each script is, by name, on
|
|
96
|
-
* top of the defaults (`preinstall`, `install`, `postinstall` and `prepare`)
|
|
97
|
-
*/
|
|
98
|
-
runnerAgnosticScripts?: boolean | Readonly<Record<string, boolean>>;
|
|
99
|
-
/** The script's name in package.json, e.g. `postinstall`, to tell if it's runner-agnostic */
|
|
100
|
-
scriptName?: string;
|
|
101
|
-
/** Whether pnpm's `shell-emulator` setting is on, so that it runs the script with Yarn's shell */
|
|
102
|
-
shellEmulator?: boolean;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Analyzes a package.json script for constructs that don't work (the same) on all platforms.
|
|
106
|
-
* @param script The script's source
|
|
107
|
-
* @param options Analysis options
|
|
108
|
-
* @returns The issues found, with offsets relative to the script
|
|
109
|
-
*/
|
|
110
|
-
export declare const analyzeScript: (script: string, options?: AnalyzeScriptOptions) => ScriptIssue[];
|
|
111
|
-
/**
|
|
112
|
-
* Applies a fix to the script that it was found in.
|
|
113
|
-
* @param script Text of the script to change
|
|
114
|
-
* @param fix A fix from `analyzeScript`
|
|
115
|
-
* @returns The fixed script
|
|
116
|
-
*/
|
|
117
|
-
export declare const applyFix: (script: string, fix: ScriptFix) => string;
|
|
118
|
-
export type { AnalyzeScriptOptions, Platform, Runner, ScriptEdit, ScriptFix, ScriptIssue, ScriptIssueMessageId };
|
|
1
|
+
import { AnalyzeScriptOptions, analyzeScript } from "./analyze-script.mjs";
|
|
2
|
+
import { applyFix } from "./fixes.mjs";
|
|
3
|
+
import { PLATFORMS, Platform, formatPlatforms } from "./platforms.mjs";
|
|
4
|
+
import { ScriptEdit, ScriptFix, ScriptIssue, ScriptIssueMessageId } from "./reporter.mjs";
|
|
5
|
+
import { RUNNERS, RUNNER_AGNOSTIC_SCRIPTS, Runner, formatRunners, getRunner } from "./runners.mjs";
|
|
6
|
+
export { type AnalyzeScriptOptions, PLATFORMS, type Platform, RUNNERS, RUNNER_AGNOSTIC_SCRIPTS, type Runner, type ScriptEdit, type ScriptFix, type ScriptIssue, type ScriptIssueMessageId, analyzeScript, applyFix, formatPlatforms, formatRunners, getRunner };
|