Skip to content

Commit 3966d7f

Browse files
committed
Use more Array.from
1 parent 1826217 commit 3966d7f

8 files changed

Lines changed: 18 additions & 16 deletions

File tree

src/commands/fix/npm-fix.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ export async function npmFix(
166166
// Process the workspace root last since it will add an override to package.json.
167167
pkgEnvDetails.editablePkgJson.filename!,
168168
]
169-
const sortedInfoEntries = [...infoByPartialPurl.entries()].sort((a, b) =>
170-
naturalCompare(a[0], b[0]),
169+
const sortedInfoEntries = Array.from(infoByPartialPurl.entries()).sort(
170+
(a, b) => naturalCompare(a[0], b[0]),
171171
)
172172

173173
const cleanupInfoEntriesLoop = () => {
@@ -197,7 +197,7 @@ export async function npmFix(
197197
const partialPurlObj = getPurlObject(infoEntry[0])
198198
const name = resolvePackageName(partialPurlObj)
199199

200-
const infos = [...infoEntry[1].values()]
200+
const infos = Array.from(infoEntry[1].values())
201201
if (!infos.length) {
202202
continue infoEntriesLoop
203203
}

src/commands/fix/open-pr.mts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ export async function cleanupOpenPrs(
213213

214214
if (cachesToSave.size) {
215215
await Promise.allSettled(
216-
[...cachesToSave].map(({ 0: key, 1: data }) => writeCache(key, data)),
216+
Array.from(cachesToSave).map(({ 0: key, 1: data }) =>
217+
writeCache(key, data),
218+
),
217219
)
218220
}
219221

src/commands/fix/pnpm-fix.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ export async function pnpmFix(
242242
// Process the workspace root last since it will add an override to package.json.
243243
pkgEnvDetails.editablePkgJson.filename!,
244244
]
245-
const sortedInfoEntries = [...infoByPartialPurl.entries()].sort((a, b) =>
246-
naturalCompare(a[0], b[0]),
245+
const sortedInfoEntries = Array.from(infoByPartialPurl.entries()).sort(
246+
(a, b) => naturalCompare(a[0], b[0]),
247247
)
248248

249249
const cleanupInfoEntriesLoop = () => {
@@ -273,7 +273,7 @@ export async function pnpmFix(
273273
const partialPurlObj = getPurlObject(infoEntry[0])
274274
const name = resolvePackageName(partialPurlObj)
275275

276-
const infos = [...infoEntry[1].values()]
276+
const infos = Array.from(infoEntry[1].values())
277277
if (!infos.length) {
278278
continue infoEntriesLoop
279279
}

src/commands/optimize/ls-by-agent.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function cleanupQueryStdout(stdout: string): string {
3030
names.add(resolvedName)
3131
}
3232
}
33-
return JSON.stringify([...names], null, 2)
33+
return JSON.stringify(Array.from(names), null, 2)
3434
}
3535

3636
function parsableToQueryStdout(stdout: string) {
@@ -41,7 +41,7 @@ function parsableToQueryStdout(stdout: string) {
4141
// The matchAll regexp looks for a forward (posix) or backward (win32) slash
4242
// and matches one or more non-slashes until the newline.
4343
const names = new Set(stdout.matchAll(/(?<=[/\\])[^/\\]+(?=\n)/g))
44-
return JSON.stringify([...names], null, 2)
44+
return JSON.stringify(Array.from(names), null, 2)
4545
}
4646

4747
async function npmQuery(npmExecPath: string, cwd: string): Promise<string> {

src/shadow/npm/arborist-helpers.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export async function getAlertsMapFromArborist(
201201
)?.overrides?.children
202202
if (overridesMap) {
203203
overrides = Object.fromEntries(
204-
[...overridesMap.entries()].map(([key, overrideSet]) => {
204+
Array.from(overridesMap.entries()).map(([key, overrideSet]) => {
205205
return [key, overrideSet.value!]
206206
}),
207207
)

src/utils/pnpm.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export async function extractPurlsFromPnpmLockfile(
4949
for (const pkgPath of Object.keys(packages)) {
5050
visit(pkgPath)
5151
}
52-
return [...seen].map(p =>
52+
return Array.from(seen).map(p =>
5353
idToNpmPurl(stripPnpmPeerSuffix(stripLeadingPnpmDepPathSlash(p))),
5454
)
5555
}

src/utils/semver.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function applyRange(
3535
case 'preserve': {
3636
const range = new semver.Range(refRange)
3737
const { raw } = range
38-
const comparators = [...range.set].flat()
38+
const comparators = range.set.flat()
3939
const { length } = comparators
4040
if (length === 1) {
4141
const char = /^[<>]=?/.exec(raw)?.[0]

src/utils/socket-package-alert.mts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,10 @@ export async function addArtifactToAlertsMap<T extends AlertsByPurl>(
261261
}
262262
sockPkgAlerts = [
263263
// Sort CVE alerts by severity: critical, high, middle, then low.
264-
...[...highestForCve.values()]
264+
...Array.from(highestForCve.values())
265265
.map(d => d.alert)
266266
.sort(alertSeverityComparator),
267-
...[...highestForUpgrade.values()].map(d => d.alert),
267+
...Array.from(highestForUpgrade.values()).map(d => d.alert),
268268
...unfixableAlerts,
269269
]
270270
} else {
@@ -448,7 +448,7 @@ export function logAlertsMap(
448448
} as LogAlertsMapOptions
449449

450450
const translations = getTranslations()
451-
const sortedEntries = [...alertsMap.entries()].sort(
451+
const sortedEntries = Array.from(alertsMap.entries()).sort(
452452
(a, b) => getAlertsSeverityOrder(a[1]) - getAlertsSeverityOrder(b[1]),
453453
)
454454

@@ -522,7 +522,7 @@ export function logAlertsMap(
522522
for (
523523
let i = 0,
524524
prevAboveTheFold = true,
525-
entries = [...viewableAlertsByPurl.entries()],
525+
entries = Array.from(viewableAlertsByPurl.entries()),
526526
{ length } = entries;
527527
i < length;
528528
i += 1

0 commit comments

Comments
 (0)