in src/snippet-dependencies.ts [98:142]
function resolveConflict(
name: string,
a: CompilationDependency,
b: CompilationDependency | undefined,
): CompilationDependency {
if (!b) {
return a;
}
if (a.type === 'concrete' && b.type === 'concrete') {
if (b.resolvedDirectory !== a.resolvedDirectory) {
throw new Error(`Dependency conflict: ${name} can be either ${a.resolvedDirectory} or ${b.resolvedDirectory}`);
}
return a;
}
if (a.type === 'symbolic' && b.type === 'symbolic') {
// Intersect the ranges
return {
type: 'symbolic',
versionRange: myVersionIntersect(a.versionRange, b.versionRange),
};
}
if (a.type === 'concrete' && b.type === 'symbolic') {
const concreteVersion: string = JSON.parse(
fs.readFileSync(path.join(a.resolvedDirectory, 'package.json'), 'utf-8'),
).version;
if (!semver.satisfies(concreteVersion, b.versionRange, { includePrerelease: true })) {
throw new Error(
`Dependency conflict: ${name} expected to match ${b.versionRange} but found ${concreteVersion} at ${a.resolvedDirectory}`,
);
}
return a;
}
if (a.type === 'symbolic' && b.type === 'concrete') {
// Reverse roles so we fall into the previous case
return resolveConflict(name, b, a);
}
throw new Error('Cases should have been exhaustive');
}