package-json-scripts-portability 0.0.2 → 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 +58 -19
- package/dist/analyze-script.d.mts +3 -3
- package/dist/analyze-script.mjs +19 -14
- package/dist/command-checker.mjs +331 -99
- package/dist/command-usage.mjs +85 -36
- package/dist/commands.mjs +124 -5
- package/dist/context.mjs +8 -1
- package/dist/fixes.d.mts +1 -1
- package/dist/fixes.mjs +193 -49
- package/dist/line-break-checker.mjs +40 -7
- package/dist/messages.mjs +9 -1
- 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/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/string/substring-after.mjs +24 -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/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/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/tags.mjs +2 -1
- 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/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/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/predicate/isEqualWith.mjs +1 -2
- 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/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/sortedIndexWith.mjs +7 -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/redirection-checker.mjs +76 -24
- package/dist/reporter.mjs +63 -18
- package/dist/runners.d.mts +2 -5
- package/dist/runners.mjs +103 -22
- package/dist/script-analyzer.mjs +457 -155
- package/dist/word-checker.mjs +232 -103
- package/dist/words.mjs +34 -7
- package/package.json +25 -21
package/dist/fixes.mjs
CHANGED
|
@@ -1,16 +1,51 @@
|
|
|
1
|
+
import { CMD_BUILTINS, OS_COMMANDS, SHELL_STATE_COMMANDS } from "./commands.mjs";
|
|
1
2
|
import { describeReplacement, truncate } from "./messages.mjs";
|
|
2
|
-
import {
|
|
3
|
+
import { substringAfter } from "./node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/string/substring-after.mjs";
|
|
4
|
+
import { toForwardSlashes } from "./node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/path/to-forward-slashes.mjs";
|
|
5
|
+
import { ASSIGNMENT, GLOB_PART_TYPES, isPlainAssignment, isPlainWord, nestedSource, staticValue } from "./words.mjs";
|
|
3
6
|
// src/fixes.ts
|
|
4
7
|
const LINE_WHITESPACE = /[\t ]/;
|
|
5
8
|
const LINE_BREAK = /^\r?\n/;
|
|
9
|
+
const BACKSLASH_CODE_POINT = 92;
|
|
6
10
|
/** Options of `rm` that `rimraf` doesn't need, e.g. `-rf` */
|
|
7
11
|
const RM_OPTION = /^(?:-[Rfr]+|--force|--recursive)$/;
|
|
12
|
+
/** One of these options that makes `rm` delete directories, e.g. `-rf` */
|
|
13
|
+
const RM_RECURSIVE_OPTION = /^(?:-f*[Rr]|--recursive)/;
|
|
14
|
+
/** One of these options that makes `rm` ignore missing paths, e.g. `-rf` */
|
|
15
|
+
const RM_FORCE_OPTION = /^(?:-[Rr]*f|--force)/;
|
|
8
16
|
/** A binary of a dependency, which package managers add to `PATH` */
|
|
9
17
|
const DEPENDENCY_BINARY = /^(?:\.\/)?node_modules\/\.bin\/([^/]+)$/;
|
|
10
|
-
|
|
18
|
+
/** Commands that run instead of a dependency's binary with the same name, e.g. cmd.exe's `del` */
|
|
19
|
+
const SHADOWING_COMMANDS = OS_COMMANDS.union(CMD_BUILTINS).union(SHELL_STATE_COMMANDS);
|
|
20
|
+
/** Characters that `rimraf --glob` treats as glob syntax, e.g. `[` */
|
|
21
|
+
const GLOB_SYNTAX = /[(*?[\\\]{}]|^!/;
|
|
11
22
|
/** A brace expansion of plain alternatives, e.g. `{a,b}` */
|
|
12
23
|
const SIMPLE_BRACE_EXPANSION = /^\{([\w+\-./@]*(?:,[\w+\-./@]*)+)\}$/;
|
|
13
24
|
const PLAIN_TEXT = /^[\w+\-./:=@]*$/;
|
|
25
|
+
const JOIN_LINES_DESCRIPTION = "Join the lines.";
|
|
26
|
+
/**
|
|
27
|
+
* Text that `cross-env` changes in the words of its command: it removes `'`, and `\` before `$`,
|
|
28
|
+
* `"`, `\` or `'`
|
|
29
|
+
*/
|
|
30
|
+
const CROSS_ENV_CHANGED_TEXT = /'|\\["$'\\]/;
|
|
31
|
+
/**
|
|
32
|
+
* Values that `cross-env` changes, e.g. by removing their quotes or replacing variables, or only
|
|
33
|
+
* reads up to a line break, or with `~` at the start or after `:`, which shells expand in
|
|
34
|
+
* assignments, but not in arguments
|
|
35
|
+
*/
|
|
36
|
+
const CROSS_ENV_CHANGED_VALUE = /[\n\r$\\]|:~|^["'~]/;
|
|
37
|
+
/** Parts of a value that shells don't split or expand as globs in an argument either */
|
|
38
|
+
const UNSPLIT_PART_TYPES = /* @__PURE__ */ new Set([
|
|
39
|
+
"DoubleQuoted",
|
|
40
|
+
"Literal",
|
|
41
|
+
"SingleQuoted"
|
|
42
|
+
]);
|
|
43
|
+
const QUOTES_OR_BACKSLASH = /["'\\]/;
|
|
44
|
+
/**
|
|
45
|
+
* Checks whether a file that `.` runs is a dotfile without a slash, e.g. `.env`, which shells look
|
|
46
|
+
* for in `PATH`, but where it's unlikely to be, unlike e.g. conda's `activate`
|
|
47
|
+
*/
|
|
48
|
+
const isDotfileName = (file) => file.startsWith(".") && !file.includes("/");
|
|
14
49
|
/** Creates a fix that replaces a piece of the script */
|
|
15
50
|
const replacement = (node, original, text) => ({
|
|
16
51
|
description: describeReplacement(original, text),
|
|
@@ -33,6 +68,57 @@ const quoting = (word, description) => ({
|
|
|
33
68
|
text: "\""
|
|
34
69
|
}]
|
|
35
70
|
});
|
|
71
|
+
/** Gets the value of a word, with placeholders for its expansions */
|
|
72
|
+
const maskedValue = (word) => word.parts ? nestedSource(word.parts) : word.value;
|
|
73
|
+
/**
|
|
74
|
+
* Gets the edits that keep the value of an assignment the same in an argument of `cross-env`.
|
|
75
|
+
* @param value The value
|
|
76
|
+
* @returns The edits, e.g. ones that quote `./bin:$PATH`, which shells split in arguments, or
|
|
77
|
+
* `undefined` if no edits can keep it
|
|
78
|
+
*/
|
|
79
|
+
const crossEnvValueEdits = (value) => {
|
|
80
|
+
const parts = value.parts || [];
|
|
81
|
+
if (CROSS_ENV_CHANGED_VALUE.test(maskedValue(value)) || parts.some((part) => part.type === "BraceExpansion")) return;
|
|
82
|
+
if (parts.every((part) => UNSPLIT_PART_TYPES.has(part.type))) return [];
|
|
83
|
+
return QUOTES_OR_BACKSLASH.test(value.text) ? void 0 : quoting(value, "").edits;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Checks whether `cross-env` runs a command with the same words as the shell, e.g. not with
|
|
87
|
+
* `console.log('a')`, whose quotes it removes, or with `""`, which it drops.
|
|
88
|
+
* @param words The command's name and arguments
|
|
89
|
+
* @returns Whether it does
|
|
90
|
+
*/
|
|
91
|
+
const isCrossEnvCommandSafe = (words) => words.every((word) => {
|
|
92
|
+
const value = maskedValue(word);
|
|
93
|
+
return value.length > 0 && !CROSS_ENV_CHANGED_TEXT.test(value);
|
|
94
|
+
});
|
|
95
|
+
/**
|
|
96
|
+
* Gets the edits that keep a command the same when `cross-env` sets its variables.
|
|
97
|
+
* @param assignments The items that become the arguments of `cross-env` before the command
|
|
98
|
+
* @param commandWords The command's name and arguments
|
|
99
|
+
* @returns The edits, or `undefined` if `cross-env` would run something else
|
|
100
|
+
*/
|
|
101
|
+
const crossEnvEdits = (assignments, commandWords) => {
|
|
102
|
+
const edits = [];
|
|
103
|
+
return isCrossEnvCommandSafe(commandWords) && assignments.every((item) => {
|
|
104
|
+
const valueEdits = isPlainAssignment(item) ? crossEnvValueEdits(item.value) : void 0;
|
|
105
|
+
edits.push(...valueEdits || []);
|
|
106
|
+
return valueEdits;
|
|
107
|
+
}) ? edits : void 0;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Finds the `\` line continuation before a line, e.g. in `a \` + line break + `b`.
|
|
111
|
+
* @param source The script
|
|
112
|
+
* @param lineStart Where the line starts
|
|
113
|
+
* @returns Where the `\` is, or -1 if the line doesn't continue the previous one
|
|
114
|
+
*/
|
|
115
|
+
const lineContinuationStart = (source, lineStart) => {
|
|
116
|
+
if (source[lineStart - 1] !== "\n") return -1;
|
|
117
|
+
const lineEnd = lineStart - (source[lineStart - 2] === "\r" ? 2 : 1);
|
|
118
|
+
let backslashes = 0;
|
|
119
|
+
while (source.codePointAt(lineEnd - backslashes - 1) === BACKSLASH_CODE_POINT) backslashes++;
|
|
120
|
+
return backslashes % 2 === 1 ? lineEnd - 1 : -1;
|
|
121
|
+
};
|
|
36
122
|
/**
|
|
37
123
|
* Creates an edit that removes a piece of a script, along with the whitespace that separates it.
|
|
38
124
|
* @param source The script
|
|
@@ -44,7 +130,11 @@ const removal = (source, pos, end) => {
|
|
|
44
130
|
let start = pos;
|
|
45
131
|
let stop = end;
|
|
46
132
|
while (start > 0 && LINE_WHITESPACE.test(source.charAt(start - 1))) start--;
|
|
47
|
-
|
|
133
|
+
const continuation = lineContinuationStart(source, start);
|
|
134
|
+
if (continuation !== -1) {
|
|
135
|
+
start = continuation;
|
|
136
|
+
while (start > 0 && LINE_WHITESPACE.test(source.charAt(start - 1))) start--;
|
|
137
|
+
} else if (start === 0 || source[start - 1] === "\n") {
|
|
48
138
|
while (stop < source.length && LINE_WHITESPACE.test(source.charAt(stop))) stop++;
|
|
49
139
|
const lineBreak = LINE_BREAK.exec(source.slice(stop))?.[0];
|
|
50
140
|
if (lineBreak) stop += lineBreak.length;
|
|
@@ -67,12 +157,16 @@ const removal = (source, pos, end) => {
|
|
|
67
157
|
const commandFix = (name, nameWord, argumentWords, source) => {
|
|
68
158
|
const first = argumentWords.at(0);
|
|
69
159
|
switch (name) {
|
|
70
|
-
case "env":
|
|
160
|
+
case "env": {
|
|
161
|
+
const commandIndex = argumentWords.findIndex((word) => !ASSIGNMENT.test(word.text));
|
|
162
|
+
return commandIndex > 0 && argumentWords.slice(0, commandIndex).every((word) => !CROSS_ENV_CHANGED_VALUE.test(substringAfter(maskedValue(word), "="))) && isCrossEnvCommandSafe(argumentWords.slice(commandIndex)) ? replacement(nameWord, nameWord.text, "cross-env") : void 0;
|
|
163
|
+
}
|
|
71
164
|
case "rm": {
|
|
72
165
|
const optionCount = argumentWords.findIndex((word) => !RM_OPTION.test(staticValue(word) || ""));
|
|
73
166
|
const paths = optionCount === -1 ? [] : argumentWords.slice(optionCount);
|
|
167
|
+
const options = argumentWords.slice(0, optionCount).map((word) => staticValue(word) || "");
|
|
74
168
|
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;
|
|
169
|
+
if (paths.length === 0 || options.every((option) => !RM_RECURSIVE_OPTION.test(option)) || options.every((option) => !RM_FORCE_OPTION.test(option)) || paths.some((word) => staticValue(word)?.startsWith("-") && word.text !== "--") || globs.some((word) => !isPlainWord(word, GLOB_PART_TYPES)) || globs.some((word) => word.text.includes("**")) || globs.length > 0 && paths.some((word) => !globs.includes(word) && GLOB_SYNTAX.test(staticValue(word) ?? "*"))) return;
|
|
76
170
|
const end = argumentWords[optionCount - 1]?.end || nameWord.end;
|
|
77
171
|
const original = source.slice(nameWord.pos, end);
|
|
78
172
|
return globs.length === 0 ? replacement({
|
|
@@ -94,28 +188,41 @@ const commandFix = (name, nameWord, argumentWords, source) => {
|
|
|
94
188
|
end: first.end,
|
|
95
189
|
pos: nameWord.pos
|
|
96
190
|
};
|
|
97
|
-
return replacement(range, source.slice(range.pos, range.end), `. ${file
|
|
191
|
+
return replacement(range, source.slice(range.pos, range.end), `. ${isDotfileName(file) ? "./" : ""}${first.text}`);
|
|
98
192
|
}
|
|
99
193
|
default: return;
|
|
100
194
|
}
|
|
101
195
|
};
|
|
102
196
|
/**
|
|
103
|
-
* Gets a fix for running a command by its path, e.g. `
|
|
197
|
+
* Gets a fix for running a command by its path, e.g. `tsc` for `./node_modules/.bin/tsc`.
|
|
104
198
|
* @param name Path that the command was invoked with
|
|
105
199
|
* @param nameWord Word that the path comes from
|
|
106
|
-
* @
|
|
200
|
+
* @param isDirectoryChanged Whether a command before it changed the directory, e.g. `cd`
|
|
201
|
+
* @returns The fix, if the path is a dependency's binary
|
|
107
202
|
*/
|
|
108
|
-
const pathCommandFix = (name, nameWord) => {
|
|
203
|
+
const pathCommandFix = (name, nameWord, isDirectoryChanged) => {
|
|
109
204
|
const binary = DEPENDENCY_BINARY.exec(name)?.[1];
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
205
|
+
return binary && !isDirectoryChanged && !SHADOWING_COMMANDS.has(binary.toLowerCase()) ? replacement(nameWord, nameWord.text, binary) : void 0;
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* Gets a fix that replaces the backslashes of a Windows path with slashes.
|
|
209
|
+
* @param word The word with the path, e.g. `--config=configs\app.json`
|
|
210
|
+
* @param original The word's text as the script has it
|
|
211
|
+
* @param shouldQuote Whether to also quote the path, e.g. `src\**\*.js`
|
|
212
|
+
* @returns The fix, which only replaces the path
|
|
213
|
+
*/
|
|
214
|
+
const backslashPathFix = (word, original, shouldQuote) => {
|
|
215
|
+
const start = word.text.lastIndexOf("=") + 1;
|
|
216
|
+
const path = toForwardSlashes(word.text.slice(start));
|
|
217
|
+
const text = shouldQuote ? `"${path}"` : path;
|
|
218
|
+
return {
|
|
219
|
+
description: describeReplacement(original, `${original.slice(0, start)}${text}`),
|
|
113
220
|
edits: [{
|
|
114
|
-
end:
|
|
115
|
-
pos:
|
|
116
|
-
text
|
|
221
|
+
end: word.end,
|
|
222
|
+
pos: word.pos + start,
|
|
223
|
+
text
|
|
117
224
|
}]
|
|
118
|
-
}
|
|
225
|
+
};
|
|
119
226
|
};
|
|
120
227
|
/**
|
|
121
228
|
* Gets a fix that expands a brace expansion, e.g. `dist/a dist/b` for `dist/{a,b}`.
|
|
@@ -131,67 +238,104 @@ const braceExpansionFix = (word, part) => {
|
|
|
131
238
|
const suffix = word.text.slice(part.end - word.pos);
|
|
132
239
|
return replacement(word, word.text, alternatives.map((alternative) => `${prefix}${alternative}${suffix}`).join(" "));
|
|
133
240
|
};
|
|
241
|
+
const hasAlternatives = ({ command }) => command.type === "AndOr" && command.operators.includes("||");
|
|
242
|
+
/** Checks whether a command is only a word with the given text, e.g. `\` */
|
|
243
|
+
const isLoneWord = (node, text) => node?.type === "Command" && node.prefix.length === 0 && node.name?.text === text && node.suffix.length === 0;
|
|
244
|
+
/** Checks whether a statement is a lone `\` at the end of the script, which can't follow `&&` */
|
|
245
|
+
const isTrailingBackslash = ({ command }) => isLoneWord(command, "\\");
|
|
246
|
+
/**
|
|
247
|
+
* Checks whether a statement ends with a command that is only a carriage return, e.g. after `&&`
|
|
248
|
+
* and before a line feed, whose fix removes it
|
|
249
|
+
*/
|
|
250
|
+
const doesEndWithCarriageReturn = ({ command }) => {
|
|
251
|
+
const last = command.type === "AndOr" ? command.commands.at(-1) : command;
|
|
252
|
+
return isLoneWord(last?.type === "Pipeline" ? last.commands.at(-1) : last, "\r");
|
|
253
|
+
};
|
|
134
254
|
/**
|
|
135
|
-
* Checks whether joining
|
|
136
|
-
*
|
|
255
|
+
* Checks whether joining two statements with `&&` keeps the logic the same, apart from stopping
|
|
256
|
+
* after a failure.
|
|
257
|
+
* @param statement The first statement
|
|
137
258
|
* @param next The statement that follows
|
|
138
259
|
* @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
|
|
260
|
+
* `c` when `a` fails, or for `a || b; c`, which cmd.exe would read as `a || (b && c)`
|
|
140
261
|
*/
|
|
141
|
-
const canChain = (next) => !next.background && !(
|
|
262
|
+
const canChain = (statement, next) => !next.background && !hasAlternatives(statement) && !hasAlternatives(next) && !isTrailingBackslash(next);
|
|
142
263
|
/**
|
|
143
|
-
* Gets a fix for a line break that separates
|
|
144
|
-
* @param
|
|
145
|
-
* @param
|
|
264
|
+
* Gets a fix for a line break that separates statements.
|
|
265
|
+
* @param source The source that the statements are in
|
|
266
|
+
* @param gapStart Where the text between the statements starts, after the bodies of the first
|
|
267
|
+
* statement's here-documents
|
|
268
|
+
* @param statement The statement before the line break
|
|
146
269
|
* @param next The statement that follows it
|
|
147
270
|
* @returns The fix, if the text is only whitespace and the rest of the logic stays the same
|
|
148
271
|
*/
|
|
149
|
-
const lineBreakFix = (gapStart,
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
272
|
+
const lineBreakFix = (source, gapStart, statement, next) => {
|
|
273
|
+
const gap = source.slice(gapStart, next.pos);
|
|
274
|
+
if (gap.trim().length > 0 || gapStart !== statement.end || lineContinuationStart(source, gapStart + gap.indexOf("\n") + 1) !== -1 || doesEndWithCarriageReturn(statement)) return;
|
|
275
|
+
if (statement.background) return {
|
|
276
|
+
description: JOIN_LINES_DESCRIPTION,
|
|
277
|
+
edits: [{
|
|
278
|
+
end: next.pos,
|
|
279
|
+
pos: gapStart,
|
|
280
|
+
text: " "
|
|
281
|
+
}]
|
|
282
|
+
};
|
|
283
|
+
return canChain(statement, next) ? {
|
|
284
|
+
description: "Replace the line break with `&&`, which stops at the first failing command.",
|
|
285
|
+
edits: [{
|
|
286
|
+
end: next.pos,
|
|
287
|
+
pos: gapStart,
|
|
288
|
+
text: " && "
|
|
289
|
+
}]
|
|
290
|
+
} : void 0;
|
|
291
|
+
};
|
|
157
292
|
/**
|
|
158
293
|
* Gets a fix that joins the lines of a command, e.g. after `||` or a `\` line continuation.
|
|
159
294
|
* @param source The source that the command is in
|
|
160
295
|
* @param position Where the line break is
|
|
161
|
-
* @param end Where the
|
|
162
|
-
* @returns The fix, which keeps the command the same in POSIX shells
|
|
296
|
+
* @param end Where the text after the line break ends, e.g. the indentation of the next line
|
|
297
|
+
* @returns The fix, which keeps the command the same in POSIX shells, if it only removes whitespace
|
|
298
|
+
* or a `\` line continuation
|
|
163
299
|
*/
|
|
164
300
|
const joinLinesFix = (source, position, end) => {
|
|
165
|
-
return {
|
|
166
|
-
description:
|
|
167
|
-
edits: [
|
|
301
|
+
if (source[position - 1] === "\\") return {
|
|
302
|
+
description: JOIN_LINES_DESCRIPTION,
|
|
303
|
+
edits: [{
|
|
168
304
|
end: position + 1,
|
|
169
305
|
pos: position - 1,
|
|
170
306
|
text: ""
|
|
171
|
-
}
|
|
307
|
+
}]
|
|
308
|
+
};
|
|
309
|
+
return source.slice(position, end).trim().length === 0 ? {
|
|
310
|
+
description: JOIN_LINES_DESCRIPTION,
|
|
311
|
+
edits: [{
|
|
172
312
|
end,
|
|
173
313
|
pos: position,
|
|
174
314
|
text: " "
|
|
175
315
|
}]
|
|
176
|
-
};
|
|
316
|
+
} : void 0;
|
|
177
317
|
};
|
|
178
318
|
/**
|
|
179
319
|
* Gets a fix for a `;` that separates commands.
|
|
180
320
|
* @param range Where the `;` is
|
|
181
321
|
* @param gap The text between the commands, including the `;`
|
|
322
|
+
* @param statement The statement before it
|
|
182
323
|
* @param next The statement that follows it, if any
|
|
183
|
-
* @returns The fix, unless
|
|
324
|
+
* @returns The fix, unless a statement has alternatives (`||`) or the next one runs in the
|
|
184
325
|
* background
|
|
185
326
|
*/
|
|
186
|
-
const semicolonFix = (range, gap, next) => {
|
|
187
|
-
if (!next)
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
327
|
+
const semicolonFix = (range, gap, statement, next) => {
|
|
328
|
+
if (!next) {
|
|
329
|
+
const text = gap[gap.indexOf(";") + 1] === "#" ? " " : "";
|
|
330
|
+
return {
|
|
331
|
+
description: "Remove the `;`.",
|
|
332
|
+
edits: [{
|
|
333
|
+
...range,
|
|
334
|
+
text
|
|
335
|
+
}]
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
return gap.trim() === ";" && canChain(statement, next) ? {
|
|
195
339
|
description: "Replace `;` with `&&`, which stops at the first failing command.",
|
|
196
340
|
edits: [{
|
|
197
341
|
end: next.pos,
|
|
@@ -207,4 +351,4 @@ const semicolonFix = (range, gap, next) => {
|
|
|
207
351
|
* @returns The fixed script
|
|
208
352
|
*/
|
|
209
353
|
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 };
|
|
354
|
+
export { DEPENDENCY_BINARY, applyFix, backslashPathFix, braceExpansionFix, commandFix, crossEnvEdits, isDotfileName, joinLinesFix, lineBreakFix, pathCommandFix, quoting, removal, replacement, semicolonFix };
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { rangeInScript } from "./context.mjs";
|
|
2
2
|
import { joinLinesFix } from "./fixes.mjs";
|
|
3
3
|
import { slidingWindow } from "./node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/iterable/sliding-window.mjs";
|
|
4
|
+
import { sortedArrayInsertionIndexWith } from "./node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/sorted-array-insertion-index-with.mjs";
|
|
4
5
|
// src/line-break-checker.ts
|
|
5
6
|
const ONE_LINE_SUGGESTION = "Put the command on one line instead.";
|
|
7
|
+
/** Checks whether an issue was dropped, e.g. in a platform fallback, which leaves no platforms */
|
|
8
|
+
const isDropped = (issue) => issue.platforms.length === 0;
|
|
6
9
|
/** Checks line breaks, after which cmd.exe ignores the rest of the script */
|
|
7
10
|
var LineBreakChecker = class {
|
|
8
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* The issue of the last line break reported in each script, by where the script is and its
|
|
13
|
+
* source
|
|
14
|
+
*/
|
|
15
|
+
#lastIssues = /* @__PURE__ */ new Map();
|
|
16
|
+
/** Reported line breaks sorted by where they start in the analyzed script */
|
|
9
17
|
#lineBreaks = [];
|
|
10
|
-
#multilineSources = /* @__PURE__ */ new Set();
|
|
11
18
|
#reporter;
|
|
12
19
|
constructor(reporter) {
|
|
13
20
|
this.#reporter = reporter;
|
|
@@ -59,13 +66,39 @@ var LineBreakChecker = class {
|
|
|
59
66
|
pos: position
|
|
60
67
|
};
|
|
61
68
|
const range = rangeInScript(context, lineBreak);
|
|
62
|
-
|
|
63
|
-
|
|
69
|
+
const scriptKey = `${context.offset} ${context.fixedRange?.pos ?? ""} ${context.source}`;
|
|
70
|
+
const lastIssue = this.#lastIssues.get(scriptKey);
|
|
71
|
+
if (lastIssue && !isDropped(lastIssue) || this.#isOverlapReported(range)) return;
|
|
72
|
+
const platforms = this.#reporter.reportSyntax(context, lineBreak, "posix", isPortableSupported, "unsupportedSyntax", {
|
|
64
73
|
suggestion,
|
|
65
74
|
syntax: "A multi-line script"
|
|
66
|
-
}, fix)
|
|
67
|
-
this.#
|
|
68
|
-
|
|
75
|
+
}, fix);
|
|
76
|
+
const issue = this.#reporter.issues.at(-1);
|
|
77
|
+
if (!issue || platforms.length === 0) return;
|
|
78
|
+
this.#lastIssues.set(scriptKey, issue);
|
|
79
|
+
this.#lineBreaks.splice(sortedArrayInsertionIndexWith(this.#lineBreaks, (reported) => reported.range.pos < range.pos), 0, {
|
|
80
|
+
issue,
|
|
81
|
+
range
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Checks whether a reported line break overlaps a range, e.g. in `concurrently "a` + line break +
|
|
86
|
+
* `b"`, which is reported for the outer script.
|
|
87
|
+
* Dropped line breaks are removed on the way.
|
|
88
|
+
* @param range The range in the analyzed script
|
|
89
|
+
* @returns Whether one does
|
|
90
|
+
*/
|
|
91
|
+
#isOverlapReported(range) {
|
|
92
|
+
const lineBreaks = this.#lineBreaks;
|
|
93
|
+
const end = sortedArrayInsertionIndexWith(lineBreaks, (reported) => reported.range.pos < range.end);
|
|
94
|
+
for (let index = end - 1; index >= 0; index--) {
|
|
95
|
+
const reported = lineBreaks[index];
|
|
96
|
+
if (!reported) break;
|
|
97
|
+
if (isDropped(reported.issue)) lineBreaks.splice(index, 1);
|
|
98
|
+
else if (range.pos < reported.range.end) return true;
|
|
99
|
+
else if (reported.range.pos < reported.range.end) return false;
|
|
100
|
+
}
|
|
101
|
+
return false;
|
|
69
102
|
}
|
|
70
103
|
};
|
|
71
104
|
export { LineBreakChecker };
|
package/dist/messages.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { originalText } from "./context.mjs";
|
|
1
2
|
import { truncate as truncate$2 } from "./node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/string/truncate.mjs";
|
|
2
3
|
// src/messages.ts
|
|
3
4
|
const BASH_4_SUGGESTION = "It needs Bash 4 or later, which macOS doesn't ship; use a Node.js script instead.";
|
|
@@ -21,10 +22,17 @@ const WHITESPACE = /\s+/g;
|
|
|
21
22
|
*/
|
|
22
23
|
const truncate = (text) => truncate$2(text.replaceAll(WHITESPACE, " "), { length: MAX_SNIPPET_CHARACTERS });
|
|
23
24
|
/**
|
|
25
|
+
* Gets the text of a node for a report message, as the script has it.
|
|
26
|
+
* @param context The piece of the script that the node is in
|
|
27
|
+
* @param node The node
|
|
28
|
+
* @returns The shortened text
|
|
29
|
+
*/
|
|
30
|
+
const snippet = (context, node) => truncate(originalText(context, node));
|
|
31
|
+
/**
|
|
24
32
|
* Describes a fix that replaces script text, e.g. "Replace `rm -rf` with `rimraf`.".
|
|
25
33
|
* @param original The replaced text
|
|
26
34
|
* @param replacement The text that replaces it
|
|
27
35
|
* @returns The description
|
|
28
36
|
*/
|
|
29
37
|
const describeReplacement = (original, replacement) => `Replace \`${truncate(original)}\` with \`${truncate(replacement)}\`.`;
|
|
30
|
-
export { BASH_4_SUGGESTION, BASH_SUGGESTION, CROSS_ENV_SUGGESTION, CROSS_ENV_VARIABLE_SUGGESTION, DEFAULT_SUGGESTION, NODE_SCRIPT_SUGGESTION, RIMRAF_SUGGESTION, SHELL_SCRIPT_SUGGESTION, VARIABLE_SUGGESTION, describeReplacement, listFormat, truncate };
|
|
38
|
+
export { BASH_4_SUGGESTION, BASH_SUGGESTION, CROSS_ENV_SUGGESTION, CROSS_ENV_VARIABLE_SUGGESTION, DEFAULT_SUGGESTION, NODE_SCRIPT_SUGGESTION, RIMRAF_SUGGESTION, SHELL_SCRIPT_SUGGESTION, VARIABLE_SUGGESTION, describeReplacement, listFormat, snippet, truncate };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { sortedIndexWith } from "../vendor/remeda/dist/sortedIndexWith.mjs";
|
|
2
|
+
// node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/sorted-array-insertion-index-with.mjs
|
|
3
|
+
/**
|
|
4
|
+
* Finds an insertion index into an already-sorted `sortedArray` using a binary
|
|
5
|
+
* search driven by a `predicate`.
|
|
6
|
+
* The predicate must return `true` for every element that should come *before*
|
|
7
|
+
* the insertion point and `false` from there on (i.e. it must be monotonic over
|
|
8
|
+
* the sorted array); the returned index is the first position at which it
|
|
9
|
+
* becomes `false`, in the range `0..sortedArray.length`.
|
|
10
|
+
*
|
|
11
|
+
* This is the most general member of the `sortedArrayInsertionIndex*` family:
|
|
12
|
+
* unlike `sortedArrayInsertionIndex` it takes no search value and is not
|
|
13
|
+
* limited to `number`/`string` keys, so it can locate a boundary for any
|
|
14
|
+
* comparable condition.
|
|
15
|
+
* @param sortedArray - The already-sorted array to search.
|
|
16
|
+
* Not mutated.
|
|
17
|
+
* @param predicate - Returns `true` for elements before the insertion point.
|
|
18
|
+
* Receives the value, its index, and the array.
|
|
19
|
+
* @returns The first index at which `predicate` returns `false`, in `0..sortedArray.length`.
|
|
20
|
+
* @example
|
|
21
|
+
* // First index whose value is not less than 2
|
|
22
|
+
* sortedArrayInsertionIndexWith([1, 2, 2, 3], (value) => value < 2);
|
|
23
|
+
* // 1
|
|
24
|
+
* @example
|
|
25
|
+
* // Boundary by a derived key
|
|
26
|
+
* sortedArrayInsertionIndexWith(
|
|
27
|
+
* [{age: 10}, {age: 20}, {age: 30}],
|
|
28
|
+
* (item) => item.age < 25,
|
|
29
|
+
* );
|
|
30
|
+
* // 2
|
|
31
|
+
*/
|
|
32
|
+
const sortedArrayInsertionIndexWith = (sortedArray, predicate) => sortedIndexWith(sortedArray, predicate);
|
|
33
|
+
export { sortedArrayInsertionIndexWith };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { sortedIndexBy } from "../vendor/es-toolkit/dist/compat/array/sortedIndexBy.mjs";
|
|
2
|
+
import { sortedIndex } from "../vendor/es-toolkit/dist/compat/array/sortedIndex.mjs";
|
|
3
|
+
import { sortedLastIndex } from "../vendor/es-toolkit/dist/compat/array/sortedLastIndex.mjs";
|
|
4
|
+
import { sortedLastIndexBy } from "../vendor/es-toolkit/dist/compat/array/sortedLastIndexBy.mjs";
|
|
5
|
+
// node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/array/sorted-array-insertion-index.mjs
|
|
6
|
+
function sortedArrayInsertionIndex(sortedArray, value, { iteratee, rightmost = false } = {}) {
|
|
7
|
+
if (iteratee) return rightmost ? sortedLastIndexBy(sortedArray, value, iteratee) : sortedIndexBy(sortedArray, value, iteratee);
|
|
8
|
+
return rightmost ? sortedLastIndex(sortedArray, value) : sortedIndex(sortedArray, value);
|
|
9
|
+
}
|
|
10
|
+
export { sortedArrayInsertionIndex };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { f as satisfies } from "../vendor/verkit/dist/range-C5wjdo9a.mjs";
|
|
2
|
+
// node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/semver/is-semver-in-range.mjs
|
|
3
|
+
/** Checks whether a semantic version satisfies an npm-style version range */
|
|
4
|
+
const isSemverInRange = satisfies;
|
|
5
|
+
export { isSemverInRange };
|
package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/semver/parse-semver.mjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { S as tryParse } from "../vendor/verkit/dist/comparison-CmVirWIW.mjs";
|
|
2
|
+
// node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/semver/parse-semver.mjs
|
|
3
|
+
/**
|
|
4
|
+
* Parses a semantic version string into its parts.
|
|
5
|
+
* A leading `v` and surrounding whitespace are allowed; build metadata (after
|
|
6
|
+
* `+`) is split by dots, and numeric prerelease identifiers become numbers.
|
|
7
|
+
*
|
|
8
|
+
* Returns `undefined` for an invalid version, including incomplete ones like
|
|
9
|
+
* `'1.2'`.
|
|
10
|
+
* Pass `{loose: true}` to also accept common mistakes, like a leading `=` or a
|
|
11
|
+
* missing `-` before the prerelease (`'1.2.3beta'`).
|
|
12
|
+
* @param version - The version string to parse.
|
|
13
|
+
* @param options - Options.
|
|
14
|
+
* @param options.loose - Accept common syntax mistakes (defaults to `false`).
|
|
15
|
+
* @returns The version parts, or `undefined` if the version is invalid.
|
|
16
|
+
* @example
|
|
17
|
+
* parseSemver('1.2.3-rc.1+sha.abc');
|
|
18
|
+
* // {major: 1, minor: 2, patch: 3, prerelease: ['rc', 1], build: ['sha', 'abc']}
|
|
19
|
+
* parseSemver('v2.0.0');
|
|
20
|
+
* // {major: 2, minor: 0, patch: 0}
|
|
21
|
+
* @example
|
|
22
|
+
* parseSemver('1.2');
|
|
23
|
+
* // undefined
|
|
24
|
+
*/
|
|
25
|
+
const parseSemver = (version, options) => tryParse(version, options) || void 0;
|
|
26
|
+
export { parseSemver };
|
package/dist/node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/string/substring-after.mjs
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/string/substring-after.mjs
|
|
2
|
+
/**
|
|
3
|
+
* Gets the part of a string after the first occurrence of a delimiter.
|
|
4
|
+
* When the delimiter is missing, returns `fallback`, which defaults to the
|
|
5
|
+
* whole string.
|
|
6
|
+
* @param text - The string to search.
|
|
7
|
+
* @param delimiter - The substring to search for.
|
|
8
|
+
* @param fallback - What to return when the delimiter is missing (defaults to `text`).
|
|
9
|
+
* @returns The part after the first delimiter, or `fallback`.
|
|
10
|
+
* @example
|
|
11
|
+
* substringAfter('index.test.ts', '.');
|
|
12
|
+
* // 'test.ts'
|
|
13
|
+
* substringAfter('https://example.com/a?b=1', '?');
|
|
14
|
+
* // 'b=1'
|
|
15
|
+
* @example
|
|
16
|
+
* // A different result for a missing delimiter
|
|
17
|
+
* substringAfter('https://example.com', '?', '');
|
|
18
|
+
* // ''
|
|
19
|
+
*/
|
|
20
|
+
const substringAfter = (text, delimiter, fallback = text) => {
|
|
21
|
+
const index = text.indexOf(delimiter);
|
|
22
|
+
return index === -1 ? fallback : text.slice(index + delimiter.length);
|
|
23
|
+
};
|
|
24
|
+
export { substringAfter };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/_internal/isUnsafeProperty.mjs
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a property key is unsafe to access or copy directly.
|
|
4
|
+
*
|
|
5
|
+
* This function is used in functions like `get` and `merge` to prevent
|
|
6
|
+
* prototype pollution attacks by identifying `__proto__`, which modifies the object's
|
|
7
|
+
* prototype chain. `constructor` and `prototype` stay accessible here because lodash
|
|
8
|
+
* keeps reads of them unrestricted; write paths use `isUnsafeToWriteProperty` instead,
|
|
9
|
+
* which also blocks those keys.
|
|
10
|
+
*
|
|
11
|
+
* @param key - The property key to check
|
|
12
|
+
* @returns `true` if the property is unsafe to access directly, `false` otherwise
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
function isUnsafeProperty(key) {
|
|
16
|
+
return key === "__proto__";
|
|
17
|
+
}
|
|
18
|
+
export { isUnsafeProperty };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { toPropertyKey } from "./toPropertyKey.mjs";
|
|
2
|
+
// node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/_internal/setOwnValue.mjs
|
|
3
|
+
/**
|
|
4
|
+
* Sets `object[key]` to `value` as an own property.
|
|
5
|
+
*
|
|
6
|
+
* Unlike an assignment, it doesn't replace the prototype of `object` when `key` is `__proto__`,
|
|
7
|
+
* which data parsed with `JSON.parse` can have as an own key, also when `key` only converts to it.
|
|
8
|
+
*
|
|
9
|
+
* @param object - The object to set the property on.
|
|
10
|
+
* @param key - The property key.
|
|
11
|
+
* @param value - The property value.
|
|
12
|
+
*/
|
|
13
|
+
function setOwnValue(object, key, value) {
|
|
14
|
+
key = toPropertyKey(key);
|
|
15
|
+
if (key === "__proto__") Object.defineProperty(object, key, {
|
|
16
|
+
value,
|
|
17
|
+
writable: true,
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true
|
|
20
|
+
});
|
|
21
|
+
else object[key] = value;
|
|
22
|
+
}
|
|
23
|
+
export { setOwnValue };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/_internal/toPropertyKey.mjs
|
|
2
|
+
/**
|
|
3
|
+
* Converts `key` to the property key that an access like `object[key]` uses, so that a check on
|
|
4
|
+
* the result sees the key the access gets. Only objects need converting: `['__proto__']`,
|
|
5
|
+
* `new String('__proto__')` or an object whose `toString` returns `'__proto__'` all access
|
|
6
|
+
* `__proto__`, while a check like `key === '__proto__'` misses them. The conversion runs once, so
|
|
7
|
+
* a `toString` can't return one key to the check and another to the access.
|
|
8
|
+
*
|
|
9
|
+
* @param key - The key to convert.
|
|
10
|
+
* @returns The string or symbol that an access with `key` uses, or `key` itself if it isn't an object.
|
|
11
|
+
*/
|
|
12
|
+
function toPropertyKey(key) {
|
|
13
|
+
if (typeof key === "object" && key !== null || typeof key === "function") return Reflect.ownKeys({ [key]: void 0 })[0];
|
|
14
|
+
return key;
|
|
15
|
+
}
|
|
16
|
+
export { toPropertyKey };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { isSymbol } from "../predicate/isSymbol.mjs";
|
|
2
|
+
// node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/_internal/baseToString.mjs
|
|
3
|
+
/**
|
|
4
|
+
* Converts `value` to a string like Lodash's `baseToString`.
|
|
5
|
+
*
|
|
6
|
+
* Unlike `toString`, `null` and `undefined` are not special-cased, so `null` becomes `'null'`.
|
|
7
|
+
*
|
|
8
|
+
* @param value - The value to convert.
|
|
9
|
+
* @returns The converted string.
|
|
10
|
+
*/
|
|
11
|
+
function baseToString(value) {
|
|
12
|
+
if (typeof value === "string") return value;
|
|
13
|
+
if (Array.isArray(value)) {
|
|
14
|
+
let result = "";
|
|
15
|
+
for (let i = 0; i < value.length; i++) {
|
|
16
|
+
if (i > 0) result += ",";
|
|
17
|
+
result += baseToString(value[i]);
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
if (isSymbol(value)) return value.toString();
|
|
22
|
+
const result = value + "";
|
|
23
|
+
if (result === "0" && Object.is(Number(value), -0)) return "-0";
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
export { baseToString };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// node_modules/.pnpm/utilery@0.4.0/node_modules/utilery/dist/vendor/es-toolkit/dist/compat/_internal/hasOwn.mjs
|
|
2
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
3
|
+
/**
|
|
4
|
+
* Checks if `key` is an own property of `object`, like `Object.hasOwn`, which is not available on ES2015 engines.
|
|
5
|
+
*
|
|
6
|
+
* @param object - The object to inspect.
|
|
7
|
+
* @param key - The key to check.
|
|
8
|
+
* @returns `true` if `key` is an own property of `object`, otherwise `false`.
|
|
9
|
+
*/
|
|
10
|
+
function hasOwn(object, key) {
|
|
11
|
+
return hasOwnProperty.call(object, key);
|
|
12
|
+
}
|
|
13
|
+
export { hasOwn };
|