Skip to content

Commit a74106b

Browse files
committed
Use more objectEntries and objectFromEntries
1 parent 7959ab1 commit a74106b

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

src/cli.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import path from 'node:path'
44
import { pathToFileURL } from 'node:url'
55

6+
import {
7+
objectEntries,
8+
objectFromEntries
9+
} from '@socketsecurity/registry/lib/objects'
610
import chalk from 'chalk'
711
import { messageWithCauses, stackWithCauses } from 'pony-cause'
812
import updateNotifier from 'tiny-updater'
@@ -18,9 +22,10 @@ const rootPkgJsonPath = path.join(rootPath, 'package.json')
1822

1923
const rootPkgJson = require(rootPkgJsonPath)
2024

21-
const formattedCliCommands = Object.fromEntries(
22-
Object.entries(cliCommands).map(entry => {
23-
entry[0] = camelToHyphen(entry[0])
25+
const formattedCliCommands = objectFromEntries(
26+
objectEntries(cliCommands).map(entry => {
27+
const key = entry[0]
28+
entry[0] = typeof key === 'string' ? camelToHyphen(key) : key
2429
return entry
2530
})
2631
)

src/commands/cdxgen.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { existsSync, promises as fs } from 'node:fs'
22
import path from 'node:path'
33

44
import spawn from '@npmcli/promise-spawn'
5+
import { objectEntries } from '@socketsecurity/registry/lib/objects'
56
import chalk from 'chalk'
67
import yargsParse from 'yargs-parser'
78

@@ -129,18 +130,18 @@ function argvToArray(argv: {
129130
}): string[] {
130131
if (argv['help']) return ['--help']
131132
const result = []
132-
for (const { 0: key, 1: value } of Object.entries(argv)) {
133+
for (const { 0: key, 1: value } of objectEntries(argv)) {
133134
if (key === '_' || key === '--') continue
134135
if (key === 'babel' || key === 'install-deps' || key === 'validate') {
135136
// cdxgen documents no-babel, no-install-deps, and no-validate flags so
136137
// use them when relevant.
137138
result.push(`--${value ? key : `no-${key}`}`)
138139
} else if (value === true) {
139-
result.push(`--${key}`)
140+
result.push(`--${String(key)}`)
140141
} else if (typeof value === 'string') {
141-
result.push(`--${key}`, String(value))
142+
result.push(`--${String(key)}`, String(value))
142143
} else if (Array.isArray(value)) {
143-
result.push(`--${key}`, ...value.map(String))
144+
result.push(`--${String(key)}`, ...value.map(String))
144145
}
145146
}
146147
if (argv['--']) {

src/commands/optimize.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,26 @@ import path from 'node:path'
44
import spawn from '@npmcli/promise-spawn'
55
import EditablePackageJson from '@npmcli/package-json'
66
import { getManifestData } from '@socketsecurity/registry'
7-
//import cacache from 'cacache'
7+
import {
8+
hasOwn,
9+
objectFromEntries,
10+
toSortedObject
11+
} from '@socketsecurity/registry/lib/objects'
12+
import { fetchPackageManifest } from '@socketsecurity/registry/lib/packages'
13+
import { pEach } from '@socketsecurity/registry/lib/promises'
14+
import { escapeRegExp } from '@socketsecurity/registry/lib/regexps'
15+
import { isNonEmptyString } from '@socketsecurity/registry/lib/strings'
816
import meow from 'meow'
917
import npa from 'npm-package-arg'
1018
import ora from 'ora'
1119
import semver from 'semver'
1220
import { glob as tinyGlob } from 'tinyglobby'
1321
import { parse as yamlParse } from 'yaml'
1422

15-
import { fetchPackageManifest } from '@socketsecurity/registry/lib/packages'
1623
import { commonFlags } from '../flags'
1724
import { printFlagList } from '../utils/formatting'
1825
import { existsSync } from '../utils/fs'
19-
import { hasOwn, toSortedObject } from '@socketsecurity/registry/lib/objects'
2026
import { detect } from '../utils/package-manager-detector'
21-
import { pEach } from '@socketsecurity/registry/lib/promises'
22-
import { escapeRegExp } from '@socketsecurity/registry/lib/regexps'
23-
import { isNonEmptyString } from '@socketsecurity/registry/lib/strings'
2427

2528
import type { Content as NPMCliPackageJson } from '@npmcli/package-json'
2629
import type { ManifestEntry } from '@socketsecurity/registry'
@@ -618,7 +621,7 @@ async function addOverrides(
618621
})
619622
}
620623
if (state.added.size > 0 || state.updated.size > 0) {
621-
editablePkgJson.update(<NPMCliPackageJson>Object.fromEntries(depEntries))
624+
editablePkgJson.update(<NPMCliPackageJson>objectFromEntries(depEntries))
622625
for (const { overrides, type } of overridesDataObjects) {
623626
updateManifestByAgent[type](editablePkgJson, toSortedObject(overrides))
624627
}

0 commit comments

Comments
 (0)