-
-
Notifications
You must be signed in to change notification settings - Fork 933
/
options.ts
73 lines (66 loc) · 2.08 KB
/
options.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
71
72
73
import path from 'path'
import { normalizeRegistries, DEFAULT_REGISTRIES } from '@pnpm/normalize-registries'
import { type StoreController } from '@pnpm/store-controller-types'
import {
type DependenciesField,
type ProjectManifest,
type Registries,
} from '@pnpm/types'
import { type ReporterFunction } from '../types'
interface StrictLinkOptions {
autoInstallPeers: boolean
binsDir: string
excludeLinksFromLockfile: boolean
force: boolean
forceSharedLockfile: boolean
useLockfile: boolean
lockfileDir: string
nodeLinker: 'isolated' | 'hoisted' | 'pnp'
pinnedVersion: 'major' | 'minor' | 'patch'
storeController: StoreController
manifest: ProjectManifest
registries: Registries
storeDir: string
reporter: ReporterFunction
targetDependenciesField?: DependenciesField
dir: string
preferSymlinkedExecutables: boolean
hoistPattern: string[] | undefined
forceHoistPattern: boolean
publicHoistPattern: string[] | undefined
forcePublicHoistPattern: boolean
useGitBranchLockfile: boolean
mergeGitBranchLockfiles: boolean
}
export type LinkOptions =
& Partial<StrictLinkOptions>
& Pick<StrictLinkOptions, 'storeController' | 'manifest'>
export async function extendOptions (opts: LinkOptions): Promise<StrictLinkOptions> {
if (opts) {
for (const key in opts) {
if (opts[key as keyof LinkOptions] === undefined) {
delete opts[key as keyof LinkOptions]
}
}
}
const defaultOpts = await defaults(opts)
const extendedOpts = { ...defaultOpts, ...opts, storeDir: defaultOpts.storeDir }
extendedOpts.registries = normalizeRegistries(extendedOpts.registries)
return extendedOpts
}
async function defaults (opts: LinkOptions) {
const dir = opts.dir ?? process.cwd()
return {
binsDir: path.join(dir, 'node_modules', '.bin'),
dir,
force: false,
forceSharedLockfile: false,
hoistPattern: undefined,
lockfileDir: opts.lockfileDir ?? dir,
nodeLinker: 'isolated',
registries: DEFAULT_REGISTRIES,
storeController: opts.storeController,
storeDir: opts.storeDir,
useLockfile: true,
} as StrictLinkOptions
}