-
-
Notifications
You must be signed in to change notification settings - Fork 936
/
getOptionsFromRootManifest.ts
67 lines (64 loc) · 2.37 KB
/
getOptionsFromRootManifest.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
import { PnpmError } from '@pnpm/error'
import {
AllowedDeprecatedVersions,
PackageExtension,
PeerDependencyRules,
ProjectManifest,
} from '@pnpm/types'
import mapValues from 'ramda/src/map'
export function getOptionsFromRootManifest (manifest: ProjectManifest): {
allowedDeprecatedVersions?: AllowedDeprecatedVersions
allowNonAppliedPatches?: boolean
overrides?: Record<string, string>
neverBuiltDependencies?: string[]
onlyBuiltDependencies?: string[]
packageExtensions?: Record<string, PackageExtension>
patchedDependencies?: Record<string, string>
peerDependencyRules?: PeerDependencyRules
} {
// We read Yarn's resolutions field for compatibility
// but we really replace the version specs to any other version spec, not only to exact versions,
// so we cannot call it resolutions
const overrides = mapValues(
createVersionReferencesReplacer(manifest),
manifest.pnpm?.overrides ?? manifest.resolutions ?? {}
)
const neverBuiltDependencies = manifest.pnpm?.neverBuiltDependencies
const onlyBuiltDependencies = manifest.pnpm?.onlyBuiltDependencies
const packageExtensions = manifest.pnpm?.packageExtensions
const peerDependencyRules = manifest.pnpm?.peerDependencyRules
const allowedDeprecatedVersions = manifest.pnpm?.allowedDeprecatedVersions
const allowNonAppliedPatches = manifest.pnpm?.allowNonAppliedPatches
const patchedDependencies = manifest.pnpm?.patchedDependencies
const settings = {
allowedDeprecatedVersions,
allowNonAppliedPatches,
overrides,
neverBuiltDependencies,
packageExtensions,
peerDependencyRules,
patchedDependencies,
}
if (onlyBuiltDependencies) {
settings['onlyBuiltDependencies'] = onlyBuiltDependencies
}
return settings
}
function createVersionReferencesReplacer (manifest: ProjectManifest) {
const allDeps = {
...manifest.devDependencies,
...manifest.dependencies,
...manifest.optionalDependencies,
}
return replaceVersionReferences.bind(null, allDeps)
}
function replaceVersionReferences (dep: Record<string, string>, spec: string) {
if (!spec.startsWith('$')) return spec
const dependencyName = spec.slice(1)
const newSpec = dep[dependencyName]
if (newSpec) return newSpec
throw new PnpmError(
'CANNOT_RESOLVE_OVERRIDE_VERSION',
`Cannot resolve version ${spec} in overrides. The direct dependencies don't have dependency "${dependencyName}".`
)
}