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
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
import { BASH_4_SUGGESTION, BASH_SUGGESTION, CROSS_ENV_SUGGESTION, DEFAULT_SUGGESTION, RIMRAF_SUGGESTION, SHELL_SCRIPT_SUGGESTION } from "./messages.mjs";
|
|
2
|
+
import { LINUX_PLATFORMS, MACOS_PLATFORMS, NOT_LINUX_OR_WINDOWS, NOT_MACOS_OR_WINDOWS, PLATFORMS, POSIX_PLATFORMS, WINDOWS_PLATFORMS } from "./platforms.mjs";
|
|
3
|
+
// src/commands.ts
|
|
4
|
+
/** POSIX shells, which don't exist on Windows */
|
|
5
|
+
const SHELLS = [
|
|
6
|
+
"bash",
|
|
7
|
+
"csh",
|
|
8
|
+
"dash",
|
|
9
|
+
"fish",
|
|
10
|
+
"ksh",
|
|
11
|
+
"sh",
|
|
12
|
+
"tcsh",
|
|
13
|
+
"zsh"
|
|
14
|
+
];
|
|
15
|
+
const COMMAND_GROUPS = [
|
|
16
|
+
[
|
|
17
|
+
["rm"],
|
|
18
|
+
WINDOWS_PLATFORMS,
|
|
19
|
+
RIMRAF_SUGGESTION
|
|
20
|
+
],
|
|
21
|
+
[
|
|
22
|
+
["env", "export"],
|
|
23
|
+
WINDOWS_PLATFORMS,
|
|
24
|
+
CROSS_ENV_SUGGESTION
|
|
25
|
+
],
|
|
26
|
+
[
|
|
27
|
+
["true", ":"],
|
|
28
|
+
WINDOWS_PLATFORMS,
|
|
29
|
+
"Use `exit 0` instead (e.g. `command || exit 0`)."
|
|
30
|
+
],
|
|
31
|
+
[
|
|
32
|
+
["false"],
|
|
33
|
+
WINDOWS_PLATFORMS,
|
|
34
|
+
"Use `exit 1` instead."
|
|
35
|
+
],
|
|
36
|
+
[
|
|
37
|
+
["find"],
|
|
38
|
+
WINDOWS_PLATFORMS,
|
|
39
|
+
"Windows ships an unrelated `find` command; use a Node.js script instead."
|
|
40
|
+
],
|
|
41
|
+
[
|
|
42
|
+
["date"],
|
|
43
|
+
WINDOWS_PLATFORMS,
|
|
44
|
+
"cmd.exe's `date` sets the system date; use a Node.js script instead."
|
|
45
|
+
],
|
|
46
|
+
[
|
|
47
|
+
SHELLS,
|
|
48
|
+
WINDOWS_PLATFORMS,
|
|
49
|
+
SHELL_SCRIPT_SUGGESTION
|
|
50
|
+
],
|
|
51
|
+
[[
|
|
52
|
+
".",
|
|
53
|
+
"[",
|
|
54
|
+
"alias",
|
|
55
|
+
"awk",
|
|
56
|
+
"base64",
|
|
57
|
+
"basename",
|
|
58
|
+
"bg",
|
|
59
|
+
"bzip2",
|
|
60
|
+
"cat",
|
|
61
|
+
"chgrp",
|
|
62
|
+
"chmod",
|
|
63
|
+
"chown",
|
|
64
|
+
"clear",
|
|
65
|
+
"cmp",
|
|
66
|
+
"column",
|
|
67
|
+
"comm",
|
|
68
|
+
"command",
|
|
69
|
+
"cp",
|
|
70
|
+
"crontab",
|
|
71
|
+
"cut",
|
|
72
|
+
"df",
|
|
73
|
+
"diff",
|
|
74
|
+
"dirname",
|
|
75
|
+
"du",
|
|
76
|
+
"egrep",
|
|
77
|
+
"eval",
|
|
78
|
+
"exec",
|
|
79
|
+
"expr",
|
|
80
|
+
"fg",
|
|
81
|
+
"fgrep",
|
|
82
|
+
"file",
|
|
83
|
+
"fmt",
|
|
84
|
+
"fold",
|
|
85
|
+
"fuser",
|
|
86
|
+
"getopts",
|
|
87
|
+
"grep",
|
|
88
|
+
"gunzip",
|
|
89
|
+
"gzip",
|
|
90
|
+
"hash",
|
|
91
|
+
"head",
|
|
92
|
+
"hexdump",
|
|
93
|
+
"iconv",
|
|
94
|
+
"id",
|
|
95
|
+
"install",
|
|
96
|
+
"jobs",
|
|
97
|
+
"join",
|
|
98
|
+
"kill",
|
|
99
|
+
"killall",
|
|
100
|
+
"less",
|
|
101
|
+
"ln",
|
|
102
|
+
"local",
|
|
103
|
+
"ls",
|
|
104
|
+
"lsof",
|
|
105
|
+
"md5sum",
|
|
106
|
+
"mktemp",
|
|
107
|
+
"mv",
|
|
108
|
+
"nice",
|
|
109
|
+
"nl",
|
|
110
|
+
"nohup",
|
|
111
|
+
"od",
|
|
112
|
+
"paste",
|
|
113
|
+
"patch",
|
|
114
|
+
"pgrep",
|
|
115
|
+
"pkill",
|
|
116
|
+
"printenv",
|
|
117
|
+
"printf",
|
|
118
|
+
"ps",
|
|
119
|
+
"pwd",
|
|
120
|
+
"read",
|
|
121
|
+
"readlink",
|
|
122
|
+
"readonly",
|
|
123
|
+
"realpath",
|
|
124
|
+
"return",
|
|
125
|
+
"rev",
|
|
126
|
+
"rsync",
|
|
127
|
+
"sed",
|
|
128
|
+
"seq",
|
|
129
|
+
"sha1sum",
|
|
130
|
+
"sha224sum",
|
|
131
|
+
"sha256sum",
|
|
132
|
+
"sha384sum",
|
|
133
|
+
"sha512sum",
|
|
134
|
+
"shasum",
|
|
135
|
+
"shift",
|
|
136
|
+
"sleep",
|
|
137
|
+
"split",
|
|
138
|
+
"stat",
|
|
139
|
+
"stdbuf",
|
|
140
|
+
"strings",
|
|
141
|
+
"su",
|
|
142
|
+
"sudo",
|
|
143
|
+
"tail",
|
|
144
|
+
"tee",
|
|
145
|
+
"test",
|
|
146
|
+
"time",
|
|
147
|
+
"touch",
|
|
148
|
+
"tput",
|
|
149
|
+
"tr",
|
|
150
|
+
"trap",
|
|
151
|
+
"truncate",
|
|
152
|
+
"ulimit",
|
|
153
|
+
"umask",
|
|
154
|
+
"uname",
|
|
155
|
+
"uniq",
|
|
156
|
+
"unset",
|
|
157
|
+
"unzip",
|
|
158
|
+
"wait",
|
|
159
|
+
"wc",
|
|
160
|
+
"which",
|
|
161
|
+
"xargs",
|
|
162
|
+
"xxd",
|
|
163
|
+
"yes",
|
|
164
|
+
"zcat",
|
|
165
|
+
"zip"
|
|
166
|
+
], WINDOWS_PLATFORMS],
|
|
167
|
+
[[
|
|
168
|
+
"apk",
|
|
169
|
+
"apt",
|
|
170
|
+
"apt-get",
|
|
171
|
+
"b2sum",
|
|
172
|
+
"dnf",
|
|
173
|
+
"dpkg",
|
|
174
|
+
"free",
|
|
175
|
+
"gawk",
|
|
176
|
+
"inotifywait",
|
|
177
|
+
"ip",
|
|
178
|
+
"journalctl",
|
|
179
|
+
"ldconfig",
|
|
180
|
+
"ldd",
|
|
181
|
+
"lsblk",
|
|
182
|
+
"notify-send",
|
|
183
|
+
"nproc",
|
|
184
|
+
"pacman",
|
|
185
|
+
"rpm",
|
|
186
|
+
"sensible-browser",
|
|
187
|
+
"service",
|
|
188
|
+
"setsid",
|
|
189
|
+
"shred",
|
|
190
|
+
"snap",
|
|
191
|
+
"ss",
|
|
192
|
+
"strace",
|
|
193
|
+
"systemctl",
|
|
194
|
+
"tac",
|
|
195
|
+
"taskset",
|
|
196
|
+
"unxz",
|
|
197
|
+
"wget",
|
|
198
|
+
"wl-copy",
|
|
199
|
+
"wl-paste",
|
|
200
|
+
"xclip",
|
|
201
|
+
"xdg-open",
|
|
202
|
+
"xdotool",
|
|
203
|
+
"xsel",
|
|
204
|
+
"xz",
|
|
205
|
+
"yum",
|
|
206
|
+
"zypper"
|
|
207
|
+
], NOT_MACOS_OR_WINDOWS],
|
|
208
|
+
[[
|
|
209
|
+
"afplay",
|
|
210
|
+
"agvtool",
|
|
211
|
+
"caffeinate",
|
|
212
|
+
"codesign",
|
|
213
|
+
"defaults",
|
|
214
|
+
"diskutil",
|
|
215
|
+
"ditto",
|
|
216
|
+
"hdiutil",
|
|
217
|
+
"install_name_tool",
|
|
218
|
+
"launchctl",
|
|
219
|
+
"lipo",
|
|
220
|
+
"md5",
|
|
221
|
+
"mdfind",
|
|
222
|
+
"networksetup",
|
|
223
|
+
"open",
|
|
224
|
+
"osacompile",
|
|
225
|
+
"osascript",
|
|
226
|
+
"pbcopy",
|
|
227
|
+
"pbpaste",
|
|
228
|
+
"pkgutil",
|
|
229
|
+
"plutil",
|
|
230
|
+
"pmset",
|
|
231
|
+
"qlmanage",
|
|
232
|
+
"say",
|
|
233
|
+
"scutil",
|
|
234
|
+
"security",
|
|
235
|
+
"sw_vers",
|
|
236
|
+
"tccutil",
|
|
237
|
+
"xcodebuild",
|
|
238
|
+
"xcrun",
|
|
239
|
+
"xed"
|
|
240
|
+
], NOT_LINUX_OR_WINDOWS],
|
|
241
|
+
[
|
|
242
|
+
["del"],
|
|
243
|
+
POSIX_PLATFORMS,
|
|
244
|
+
"Use `rimraf` instead (del-cli's `del` alias is shadowed by cmd.exe's builtin on Windows)."
|
|
245
|
+
],
|
|
246
|
+
[
|
|
247
|
+
["erase", "rd"],
|
|
248
|
+
POSIX_PLATFORMS,
|
|
249
|
+
RIMRAF_SUGGESTION
|
|
250
|
+
],
|
|
251
|
+
[
|
|
252
|
+
["setx"],
|
|
253
|
+
POSIX_PLATFORMS,
|
|
254
|
+
CROSS_ENV_SUGGESTION
|
|
255
|
+
],
|
|
256
|
+
[
|
|
257
|
+
["rem"],
|
|
258
|
+
POSIX_PLATFORMS,
|
|
259
|
+
"Remove the comment instead."
|
|
260
|
+
],
|
|
261
|
+
[["dir"], MACOS_PLATFORMS],
|
|
262
|
+
[[
|
|
263
|
+
"assoc",
|
|
264
|
+
"attrib",
|
|
265
|
+
"call",
|
|
266
|
+
"certutil",
|
|
267
|
+
"chcp",
|
|
268
|
+
"chdir",
|
|
269
|
+
"choice",
|
|
270
|
+
"clip",
|
|
271
|
+
"cls",
|
|
272
|
+
"cmd",
|
|
273
|
+
"copy",
|
|
274
|
+
"cscript",
|
|
275
|
+
"endlocal",
|
|
276
|
+
"explorer",
|
|
277
|
+
"findstr",
|
|
278
|
+
"ftype",
|
|
279
|
+
"goto",
|
|
280
|
+
"icacls",
|
|
281
|
+
"md",
|
|
282
|
+
"mklink",
|
|
283
|
+
"move",
|
|
284
|
+
"msiexec",
|
|
285
|
+
"netsh",
|
|
286
|
+
"pause",
|
|
287
|
+
"powershell",
|
|
288
|
+
"reg",
|
|
289
|
+
"ren",
|
|
290
|
+
"rename",
|
|
291
|
+
"robocopy",
|
|
292
|
+
"rundll32",
|
|
293
|
+
"schtasks",
|
|
294
|
+
"setlocal",
|
|
295
|
+
"start",
|
|
296
|
+
"systeminfo",
|
|
297
|
+
"taskkill",
|
|
298
|
+
"tasklist",
|
|
299
|
+
"title",
|
|
300
|
+
"ver",
|
|
301
|
+
"where",
|
|
302
|
+
"wmic",
|
|
303
|
+
"wscript",
|
|
304
|
+
"wsl",
|
|
305
|
+
"xcopy"
|
|
306
|
+
], POSIX_PLATFORMS]
|
|
307
|
+
];
|
|
308
|
+
/** Bash builtins that POSIX `sh` (e.g. dash on Debian/Ubuntu) and cmd.exe don't have */
|
|
309
|
+
const BASH_BUILTINS = [
|
|
310
|
+
[[
|
|
311
|
+
"bind",
|
|
312
|
+
"builtin",
|
|
313
|
+
"caller",
|
|
314
|
+
"compgen",
|
|
315
|
+
"complete",
|
|
316
|
+
"declare",
|
|
317
|
+
"dirs",
|
|
318
|
+
"disown",
|
|
319
|
+
"enable",
|
|
320
|
+
"help",
|
|
321
|
+
"history",
|
|
322
|
+
"let",
|
|
323
|
+
"logout",
|
|
324
|
+
"shopt",
|
|
325
|
+
"source",
|
|
326
|
+
"suspend",
|
|
327
|
+
"typeset"
|
|
328
|
+
], NOT_LINUX_OR_WINDOWS],
|
|
329
|
+
[["popd", "pushd"], LINUX_PLATFORMS],
|
|
330
|
+
[
|
|
331
|
+
["mapfile", "readarray"],
|
|
332
|
+
PLATFORMS,
|
|
333
|
+
BASH_4_SUGGESTION
|
|
334
|
+
]
|
|
335
|
+
];
|
|
336
|
+
const COMMANDS = new Map([...COMMAND_GROUPS.flatMap(([names, platforms, suggestion = DEFAULT_SUGGESTION]) => names.map((name) => [name, {
|
|
337
|
+
platforms,
|
|
338
|
+
suggestion
|
|
339
|
+
}])), ...BASH_BUILTINS.flatMap(([names, platforms, suggestion = BASH_SUGGESTION]) => names.map((name) => [name, {
|
|
340
|
+
bashBuiltin: true,
|
|
341
|
+
platforms,
|
|
342
|
+
suggestion
|
|
343
|
+
}]))]);
|
|
344
|
+
/** cmd.exe builtins (rather than executables), which Yarn's portable shell can't run on Windows */
|
|
345
|
+
const CMD_BUILTINS = /* @__PURE__ */ new Set([
|
|
346
|
+
"assoc",
|
|
347
|
+
"call",
|
|
348
|
+
"chdir",
|
|
349
|
+
"cls",
|
|
350
|
+
"copy",
|
|
351
|
+
"del",
|
|
352
|
+
"dir",
|
|
353
|
+
"endlocal",
|
|
354
|
+
"erase",
|
|
355
|
+
"ftype",
|
|
356
|
+
"goto",
|
|
357
|
+
"md",
|
|
358
|
+
"mklink",
|
|
359
|
+
"move",
|
|
360
|
+
"pause",
|
|
361
|
+
"rd",
|
|
362
|
+
"rem",
|
|
363
|
+
"ren",
|
|
364
|
+
"rename",
|
|
365
|
+
"setlocal",
|
|
366
|
+
"start",
|
|
367
|
+
"title",
|
|
368
|
+
"ver"
|
|
369
|
+
]);
|
|
370
|
+
/** Builtins of Yarn's portable shell, which work on all platforms */
|
|
371
|
+
const PORTABLE_SHELL_BUILTINS = /* @__PURE__ */ new Set([
|
|
372
|
+
":",
|
|
373
|
+
"cd",
|
|
374
|
+
"echo",
|
|
375
|
+
"exit",
|
|
376
|
+
"false",
|
|
377
|
+
"pwd",
|
|
378
|
+
"sleep",
|
|
379
|
+
"true",
|
|
380
|
+
"unset"
|
|
381
|
+
]);
|
|
382
|
+
/** BSD utilities on macOS that don't support GNU-style long options */
|
|
383
|
+
const NO_LONG_OPTIONS_ON_MACOS = /* @__PURE__ */ new Set([
|
|
384
|
+
"basename",
|
|
385
|
+
"cat",
|
|
386
|
+
"chmod",
|
|
387
|
+
"chown",
|
|
388
|
+
"cp",
|
|
389
|
+
"cut",
|
|
390
|
+
"date",
|
|
391
|
+
"df",
|
|
392
|
+
"dirname",
|
|
393
|
+
"du",
|
|
394
|
+
"install",
|
|
395
|
+
"ln",
|
|
396
|
+
"mkdir",
|
|
397
|
+
"mv",
|
|
398
|
+
"readlink",
|
|
399
|
+
"realpath",
|
|
400
|
+
"rm",
|
|
401
|
+
"rmdir",
|
|
402
|
+
"sed",
|
|
403
|
+
"stat",
|
|
404
|
+
"tee",
|
|
405
|
+
"touch",
|
|
406
|
+
"tr",
|
|
407
|
+
"truncate",
|
|
408
|
+
"uname",
|
|
409
|
+
"wc"
|
|
410
|
+
]);
|
|
411
|
+
/** OS commands rather than npm packages, including those that exist everywhere */
|
|
412
|
+
const OS_COMMANDS = /* @__PURE__ */ new Set([
|
|
413
|
+
...COMMANDS.keys(),
|
|
414
|
+
"cd",
|
|
415
|
+
"echo",
|
|
416
|
+
"mkdir",
|
|
417
|
+
"rmdir",
|
|
418
|
+
"sort",
|
|
419
|
+
"timeout"
|
|
420
|
+
]);
|
|
421
|
+
/** Package manager subcommands that run the command given as their arguments */
|
|
422
|
+
const EXEC_SUBCOMMANDS = {
|
|
423
|
+
aube: ["dlx", "exec"],
|
|
424
|
+
bun: ["x"],
|
|
425
|
+
npm: ["exec", "x"],
|
|
426
|
+
pnpm: ["dlx", "exec"],
|
|
427
|
+
upm: ["exec"],
|
|
428
|
+
yarn: ["dlx", "exec"]
|
|
429
|
+
};
|
|
430
|
+
/** Options of package managers (before the subcommand) that take a value */
|
|
431
|
+
const PACKAGE_MANAGER_VALUE_OPTIONS = [
|
|
432
|
+
"--cd",
|
|
433
|
+
"--cwd",
|
|
434
|
+
"--dir",
|
|
435
|
+
"--filter",
|
|
436
|
+
"--filter-prod",
|
|
437
|
+
"--prefix",
|
|
438
|
+
"--workspace",
|
|
439
|
+
"-C",
|
|
440
|
+
"-F"
|
|
441
|
+
];
|
|
442
|
+
/** Options of package managers' exec subcommands that take a value */
|
|
443
|
+
const EXEC_VALUE_OPTIONS = ["--package", "-p"];
|
|
444
|
+
/** Commands whose arguments are often patterns rather than paths */
|
|
445
|
+
const PATTERN_COMMANDS = /* @__PURE__ */ new Set([
|
|
446
|
+
"awk",
|
|
447
|
+
"echo",
|
|
448
|
+
"egrep",
|
|
449
|
+
"findstr",
|
|
450
|
+
"grep",
|
|
451
|
+
"printf",
|
|
452
|
+
"sed"
|
|
453
|
+
]);
|
|
454
|
+
/** Commands that run the command given as their arguments, with their options that take a value */
|
|
455
|
+
const WRAPPER_VALUE_OPTIONS = /* @__PURE__ */ new Map([
|
|
456
|
+
["aubx", EXEC_VALUE_OPTIONS],
|
|
457
|
+
["bunx", EXEC_VALUE_OPTIONS],
|
|
458
|
+
["command", []],
|
|
459
|
+
["env", [
|
|
460
|
+
"--chdir",
|
|
461
|
+
"--split-string",
|
|
462
|
+
"--unset",
|
|
463
|
+
"-C",
|
|
464
|
+
"-S",
|
|
465
|
+
"-u"
|
|
466
|
+
]],
|
|
467
|
+
["exec", ["-a"]],
|
|
468
|
+
["nice", ["--adjustment", "-n"]],
|
|
469
|
+
["nohup", []],
|
|
470
|
+
["npx", EXEC_VALUE_OPTIONS],
|
|
471
|
+
["pnpx", EXEC_VALUE_OPTIONS],
|
|
472
|
+
["sudo", [
|
|
473
|
+
"-C",
|
|
474
|
+
"-D",
|
|
475
|
+
"-g",
|
|
476
|
+
"-h",
|
|
477
|
+
"-p",
|
|
478
|
+
"-r",
|
|
479
|
+
"-t",
|
|
480
|
+
"-U",
|
|
481
|
+
"-u"
|
|
482
|
+
]],
|
|
483
|
+
["time", ["-f", "-o"]],
|
|
484
|
+
["upx", EXEC_VALUE_OPTIONS],
|
|
485
|
+
["xargs", [
|
|
486
|
+
"-a",
|
|
487
|
+
"-d",
|
|
488
|
+
"-E",
|
|
489
|
+
"-I",
|
|
490
|
+
"-L",
|
|
491
|
+
"-n",
|
|
492
|
+
"-P",
|
|
493
|
+
"-s"
|
|
494
|
+
]]
|
|
495
|
+
]);
|
|
496
|
+
/**
|
|
497
|
+
* Builtins that change the shell's state.
|
|
498
|
+
* In a subshell, the change doesn't reach the commands that follow
|
|
499
|
+
*/
|
|
500
|
+
const SHELL_STATE_COMMANDS = /* @__PURE__ */ new Set([
|
|
501
|
+
".",
|
|
502
|
+
"alias",
|
|
503
|
+
"cd",
|
|
504
|
+
"exit",
|
|
505
|
+
"export",
|
|
506
|
+
"popd",
|
|
507
|
+
"pushd",
|
|
508
|
+
"read",
|
|
509
|
+
"readonly",
|
|
510
|
+
"return",
|
|
511
|
+
"set",
|
|
512
|
+
"shift",
|
|
513
|
+
"source",
|
|
514
|
+
"trap",
|
|
515
|
+
"ulimit",
|
|
516
|
+
"umask",
|
|
517
|
+
"unalias",
|
|
518
|
+
"unset"
|
|
519
|
+
]);
|
|
520
|
+
export { CMD_BUILTINS, COMMANDS, EXEC_SUBCOMMANDS, EXEC_VALUE_OPTIONS, NO_LONG_OPTIONS_ON_MACOS, OS_COMMANDS, PACKAGE_MANAGER_VALUE_OPTIONS, PATTERN_COMMANDS, PORTABLE_SHELL_BUILTINS, SHELLS, SHELL_STATE_COMMANDS, WRAPPER_VALUE_OPTIONS };
|
package/dist/context.mjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/context.ts
|
|
2
|
+
/**
|
|
3
|
+
* Gets where a node of a piece of the script is in the analyzed script.
|
|
4
|
+
* @param context The piece that the node is in
|
|
5
|
+
* @param node The node, with positions relative to the piece's source
|
|
6
|
+
* @returns The range in the analyzed script, or the piece's fixed range
|
|
7
|
+
*/
|
|
8
|
+
const rangeInScript = (context, node) => context.fixedRange || {
|
|
9
|
+
end: context.offset + node.end,
|
|
10
|
+
pos: context.offset + node.pos
|
|
11
|
+
};
|
|
12
|
+
const withCovered = (context, platforms) => platforms.every((platform) => context.covered.has(platform)) ? context : {
|
|
13
|
+
...context,
|
|
14
|
+
covered: /* @__PURE__ */ new Set([...context.covered, ...platforms])
|
|
15
|
+
};
|
|
16
|
+
/** Gets how reports name Bash syntax of a kind, e.g. "Bash 4" for Bash 4 syntax */
|
|
17
|
+
const bashLabel = (kind) => kind === "bash4" ? "Bash 4" : "Bash-specific";
|
|
18
|
+
export { bashLabel, rangeInScript, withCovered };
|
package/dist/fixes.d.mts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ScriptFix } from "./reporter.mjs";
|
|
2
|
+
import "unbash";
|
|
3
|
+
/**
|
|
4
|
+
* Applies a fix to the script that it was found in.
|
|
5
|
+
* @param script Text of the script to change
|
|
6
|
+
* @param fix A fix from `analyzeScript`
|
|
7
|
+
* @returns The fixed script
|
|
8
|
+
*/
|
|
9
|
+
export declare const applyFix: (script: string, fix: ScriptFix) => string;
|