-
-
Notifications
You must be signed in to change notification settings - Fork 933
/
extendRebuildOptions.ts
97 lines (92 loc) · 2.89 KB
/
extendRebuildOptions.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import path from 'path'
import { type LogBase } from '@pnpm/logger'
import { normalizeRegistries, DEFAULT_REGISTRIES } from '@pnpm/normalize-registries'
import { type StoreController } from '@pnpm/store-controller-types'
import { type Registries } from '@pnpm/types'
import loadJsonFile from 'load-json-file'
export interface StrictRebuildOptions {
autoInstallPeers: boolean
cacheDir: string
childConcurrency: number
excludeLinksFromLockfile: boolean
extraBinPaths: string[]
extraEnv: Record<string, string>
lockfileDir: string
nodeLinker: 'isolated' | 'hoisted' | 'pnp'
scriptShell?: string
sideEffectsCacheRead: boolean
scriptsPrependNodePath: boolean | 'warn-only'
shellEmulator: boolean
storeDir: string // TODO: remove this property
storeController: StoreController
force: boolean
forceSharedLockfile: boolean
useLockfile: boolean
registries: Registries
dir: string
pnpmHomeDir: string
reporter: (logObj: LogBase) => void
production: boolean
development: boolean
optional: boolean
rawConfig: object
userConfig: Record<string, string>
userAgent: string
packageManager: {
name: string
version: string
}
unsafePerm: boolean
pending: boolean
shamefullyHoist: boolean
deployAllFiles: boolean
}
export type RebuildOptions = Partial<StrictRebuildOptions> &
Pick<StrictRebuildOptions, 'storeDir' | 'storeController'>
const defaults = async (opts: RebuildOptions) => {
const packageManager = opts.packageManager ??
await loadJsonFile<{ name: string, version: string }>(path.join(__dirname, '../../package.json'))!
const dir = opts.dir ?? process.cwd()
const lockfileDir = opts.lockfileDir ?? dir
return {
childConcurrency: 5,
development: true,
dir,
force: false,
forceSharedLockfile: false,
lockfileDir,
nodeLinker: 'isolated',
optional: true,
packageManager,
pending: false,
production: true,
rawConfig: {},
registries: DEFAULT_REGISTRIES,
scriptsPrependNodePath: false,
shamefullyHoist: false,
shellEmulator: false,
sideEffectsCacheRead: false,
storeDir: opts.storeDir,
unsafePerm: process.platform === 'win32' ||
process.platform === 'cygwin' ||
!process.setgid ||
process.getuid() !== 0,
useLockfile: true,
userAgent: `${packageManager.name}/${packageManager.version} npm/? node/${process.version} ${process.platform} ${process.arch}`,
} as StrictRebuildOptions
}
export async function extendRebuildOptions (
opts: RebuildOptions
): Promise<StrictRebuildOptions> {
if (opts) {
for (const key in opts) {
if (opts[key as keyof RebuildOptions] === undefined) {
delete opts[key as keyof RebuildOptions]
}
}
}
const defaultOpts = await defaults(opts)
const extendedOpts = { ...defaultOpts, ...opts, storeDir: defaultOpts.storeDir }
extendedOpts.registries = normalizeRegistries(extendedOpts.registries)
return extendedOpts
}