Skip to content

Commit

Permalink
fix: remove overly strict checks on peer versions (#306)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rix0rrr authored Nov 9, 2018
1 parent 094a215 commit 7b89d01
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 23 deletions.
11 changes: 1 addition & 10 deletions packages/jsii/lib/assembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,7 @@ function _sortMembers(type: spec.ClassType | spec.InterfaceType): spec.ClassTyp

function _toDependencies(assemblies: ReadonlyArray<spec.Assembly>, peers: ReadonlyArray<spec.Assembly>): { [name: string]: spec.PackageVersion } {
const result: { [name: string]: spec.PackageVersion } = {};

for (const assembly of assemblies) {
result[assembly.name] = {
version: assembly.version,
Expand All @@ -1094,16 +1095,6 @@ function _toDependencies(assemblies: ReadonlyArray<spec.Assembly>, peers: Readon
}

for (const peer of peers) {
if (peer.name in result) {
// module already appears as a normal dependency. just make sure it's the same version
const depVersion = result[peer.name].version;
if (depVersion !== peer.version) {
throw new Error(
`Module '${peer.name}' appears both as a dependency (${depVersion}) ` +
`and a peer dependency (${peer.version}), with mismatching versions`);
}
}

result[peer.name] = {
version: peer.version,
targets: peer.targets,
Expand Down
18 changes: 5 additions & 13 deletions packages/jsii/lib/project-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,13 @@ export async function loadProjectInfo(projectRoot: string): Promise<ProjectInfo>
if (!version) {
throw new Error(`The "package.json" has "${name}" in "bundleDependencies", but it is not declared in "dependencies"`);
}
bundleDependencies[name] = version;
});

// verify peer dependencies and dependencies have the same version specs
const deps = pkg.dependencies || { };
const peerDeps = pkg.peerDependencies || { };
for (const module of Object.keys(peerDeps)) {
const peerVersion = peerDeps[module];
const depVersion = deps[module];
if (depVersion && peerVersion !== depVersion) {
throw new Error(
`The module '${module}' is specified as ${peerVersion} under ` +
`"peerDependencieds" and as ${depVersion} under "dependencies"`);
if (pkg.peerDependencies && name in pkg.peerDependencies) {
throw new Error(`The "package.json" has "${name}" in "bundleDependencies", and also in "peerDependencies"`);
}
}

bundleDependencies[name] = version;
});

const transitiveAssemblies: { [name: string]: spec.Assembly } = {};
const dependencies =
Expand Down

0 comments on commit 7b89d01

Please sign in to comment.