-
-
Notifications
You must be signed in to change notification settings - Fork 934
/
licensesList.ts
70 lines (62 loc) · 1.82 KB
/
licensesList.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { readProjectManifestOnly } from '@pnpm/cli-utils'
import { Config } from '@pnpm/config'
import { PnpmError } from '@pnpm/error'
import { getStorePath } from '@pnpm/store-path'
import { WANTED_LOCKFILE } from '@pnpm/constants'
import { readWantedLockfile } from '@pnpm/lockfile-file'
import { findDependencyLicenses } from '@pnpm/license-scanner'
import { renderLicences } from './outputRenderer'
export type LicensesCommandOptions = {
compatible?: boolean
long?: boolean
recursive?: boolean
json?: boolean
} & Pick<
Config,
| 'dev'
| 'dir'
| 'lockfileDir'
| 'registries'
| 'optional'
| 'production'
| 'storeDir'
| 'virtualStoreDir'
| 'modulesDir'
| 'pnpmHomeDir'
> &
Partial<Pick<Config, 'userConfig'>>
export async function licensesList (opts: LicensesCommandOptions) {
const lockfile = await readWantedLockfile(opts.lockfileDir ?? opts.dir, {
ignoreIncompatible: true,
})
if (lockfile == null) {
throw new PnpmError(
'LICENSES_NO_LOCKFILE',
`No ${WANTED_LOCKFILE} found: Cannot check a project without a lockfile`
)
}
const include = {
dependencies: opts.production !== false,
devDependencies: opts.dev !== false,
optionalDependencies: opts.optional !== false,
}
const manifest = await readProjectManifestOnly(opts.dir, {})
const storeDir = await getStorePath({
pkgRoot: opts.dir,
storePath: opts.storeDir,
pnpmHomeDir: opts.pnpmHomeDir,
})
const licensePackages = await findDependencyLicenses({
include,
lockfileDir: opts.dir,
storeDir,
virtualStoreDir: opts.virtualStoreDir ?? '.',
modulesDir: opts.modulesDir,
registries: opts.registries,
wantedLockfile: lockfile,
manifest,
})
if (licensePackages.length === 0)
return { output: 'No licenses in packages found', exitCode: 0 }
return renderLicences(licensePackages, opts)
}