/
getPkgInfo.ts
39 lines (34 loc) · 921 Bytes
/
getPkgInfo.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import path from 'path'
import readPkg from './readPkg'
export default async function getPkgInfo (
pkg: {
alias: string
name: string
version: string
path: string
resolved?: string
}
) {
let manifest
try {
manifest = await readPkg(path.join(pkg.path, 'node_modules', pkg.name, 'package.json'))
} catch (err: any) { // eslint-disable-line
// This will probably never happen
manifest = {
description: '[Could not find additional info about this dependency]',
}
}
return {
alias: pkg.alias,
from: pkg.name,
version: pkg.version,
resolved: pkg.resolved,
description: manifest.description,
license: manifest.license,
author: manifest.author,
homepage: manifest.homepage,
repository: (manifest.repository && (
typeof manifest.repository === 'string' ? manifest.repository : manifest.repository.url
)) ?? undefined,
}
}