Skip to content

Commit 7b89d01

Browse files
authored
fix: remove overly strict checks on peer versions (#306)
1) ProjectInfo was verifying that the specified version range in peerDependencies is exactly the same as the version range in regular dependencies. This is not necessary, the only requirement is that the actual concrete dependency version satisfies the peer dependency version (which is already checked in _loadDependencies). 2) Assembler was verifying that the concrete version of a library found in dependencies was the same as that same concrete library found in peerDependencies. But since there's ever only one concrete copy of any dependency, this check can never fail.
1 parent 094a215 commit 7b89d01

File tree

2 files changed

+6
-23
lines changed

2 files changed

+6
-23
lines changed

packages/jsii/lib/assembler.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,7 @@ function _sortMembers(type: spec.ClassType | spec.InterfaceType): spec.ClassTyp
10851085

10861086
function _toDependencies(assemblies: ReadonlyArray<spec.Assembly>, peers: ReadonlyArray<spec.Assembly>): { [name: string]: spec.PackageVersion } {
10871087
const result: { [name: string]: spec.PackageVersion } = {};
1088+
10881089
for (const assembly of assemblies) {
10891090
result[assembly.name] = {
10901091
version: assembly.version,
@@ -1094,16 +1095,6 @@ function _toDependencies(assemblies: ReadonlyArray<spec.Assembly>, peers: Readon
10941095
}
10951096

10961097
for (const peer of peers) {
1097-
if (peer.name in result) {
1098-
// module already appears as a normal dependency. just make sure it's the same version
1099-
const depVersion = result[peer.name].version;
1100-
if (depVersion !== peer.version) {
1101-
throw new Error(
1102-
`Module '${peer.name}' appears both as a dependency (${depVersion}) ` +
1103-
`and a peer dependency (${peer.version}), with mismatching versions`);
1104-
}
1105-
}
1106-
11071098
result[peer.name] = {
11081099
version: peer.version,
11091100
targets: peer.targets,

packages/jsii/lib/project-info.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,13 @@ export async function loadProjectInfo(projectRoot: string): Promise<ProjectInfo>
4444
if (!version) {
4545
throw new Error(`The "package.json" has "${name}" in "bundleDependencies", but it is not declared in "dependencies"`);
4646
}
47-
bundleDependencies[name] = version;
48-
});
4947

50-
// verify peer dependencies and dependencies have the same version specs
51-
const deps = pkg.dependencies || { };
52-
const peerDeps = pkg.peerDependencies || { };
53-
for (const module of Object.keys(peerDeps)) {
54-
const peerVersion = peerDeps[module];
55-
const depVersion = deps[module];
56-
if (depVersion && peerVersion !== depVersion) {
57-
throw new Error(
58-
`The module '${module}' is specified as ${peerVersion} under ` +
59-
`"peerDependencieds" and as ${depVersion} under "dependencies"`);
48+
if (pkg.peerDependencies && name in pkg.peerDependencies) {
49+
throw new Error(`The "package.json" has "${name}" in "bundleDependencies", and also in "peerDependencies"`);
6050
}
61-
}
51+
52+
bundleDependencies[name] = version;
53+
});
6254

6355
const transitiveAssemblies: { [name: string]: spec.Assembly } = {};
6456
const dependencies =

0 commit comments

Comments
 (0)