Skip to content
This repository was archived by the owner on Jan 6, 2024. It is now read-only.

Commit 79213b0

Browse files
authored
refactor(rpc): getPackages (#102)
1 parent 8833aff commit 79213b0

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/node/rpc/packages.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,20 @@ export async function getPackages(root: string) {
66
// TODO: support monorepo workspace ?
77
const pkgPath = resolve(root, 'package.json')
88
const data = JSON.parse(await fsp.readFile(pkgPath, 'utf-8').catch(() => '{}'))
9-
const categorizedPackages = {}
109
const packages: Record<string, Omit<PackageMeta, 'name'>> = {}
10+
1111
for (const type of ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies']) {
12-
if (!data[type])
12+
const dep = data[type]
13+
if (!dep)
1314
continue
14-
categorizedPackages[type] = data[type]
15-
}
16-
for (const type in categorizedPackages) {
17-
for (const name in categorizedPackages[type]) {
18-
const version = categorizedPackages[type][name]
19-
packages[name] = {
20-
version,
15+
for (const depName in dep) {
16+
packages[depName] = {
17+
version: dep[depName],
2118
type,
2219
}
2320
}
2421
}
22+
2523
return {
2624
packages,
2725
}

0 commit comments

Comments
 (0)