-
-
Notifications
You must be signed in to change notification settings - Fork 934
/
extendStoreStatusOptions.ts
60 lines (55 loc) · 1.7 KB
/
extendStoreStatusOptions.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
import path from 'path'
import { normalizeRegistries, DEFAULT_REGISTRIES } from '@pnpm/normalize-registries'
import { type Registries } from '@pnpm/types'
import { type ReporterFunction } from '../types'
export interface StrictStoreStatusOptions {
autoInstallPeers: boolean
excludeLinksFromLockfile: boolean
lockfileDir: string
dir: string
storeDir: string
force: boolean
forceSharedLockfile: boolean
nodeLinker: 'isolated' | 'hoisted' | 'pnp'
useLockfile: boolean
registries: Registries
shamefullyHoist: boolean
reporter: ReporterFunction
production: boolean
development: boolean
optional: boolean
binsDir: string
}
export type StoreStatusOptions = Partial<StrictStoreStatusOptions> &
Pick<StrictStoreStatusOptions, 'storeDir'>
const defaults = async (opts: StoreStatusOptions) => {
const dir = opts.dir ?? process.cwd()
const lockfileDir = opts.lockfileDir ?? dir
return {
binsDir: path.join(dir, 'node_modules', '.bin'),
dir,
force: false,
forceSharedLockfile: false,
lockfileDir,
nodeLinker: 'isolated',
registries: DEFAULT_REGISTRIES,
shamefullyHoist: false,
storeDir: opts.storeDir,
useLockfile: true,
} as StrictStoreStatusOptions
}
export async function extendStoreStatusOptions (
opts: StoreStatusOptions
): Promise<StrictStoreStatusOptions> {
if (opts) {
for (const key in opts) {
if (opts[key as keyof StoreStatusOptions] === undefined) {
delete opts[key as keyof StoreStatusOptions]
}
}
}
const defaultOpts = await defaults(opts)
const extendedOpts = { ...defaultOpts, ...opts, storeDir: defaultOpts.storeDir }
extendedOpts.registries = normalizeRegistries(extendedOpts.registries)
return extendedOpts
}