backend-app-api: remove unique producer constraint from dependency tree

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-08-11 14:00:00 +02:00
parent 0474a4bb16
commit ed90ce7f2c
2 changed files with 1 additions and 22 deletions
@@ -24,17 +24,6 @@ describe('DependencyTree', () => {
expect(empty.detectCircularDependency()).toBeUndefined();
});
it('should reject multiple producers', () => {
expect(() =>
DependencyTree.fromMap({
1: { produces: ['a'] },
2: { produces: ['a'] },
}),
).toThrow(
"Dependency conflict detected, 'a' may not be produced by both '1' and '2'",
);
});
it('should detect circular dependencies', () => {
expect(
DependencyTree.fromMap({
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { ConflictError, ForwardedError, InputError } from '@backstage/errors';
import { ForwardedError, InputError } from '@backstage/errors';
interface NodeInput {
id: string;
@@ -62,26 +62,16 @@ export class DependencyTree {
#allProduced: Set<string>;
#allConsumed: Set<string>;
#producedBy: Map<string, string>;
#consumedBy: Map<string, Set<string>>;
private constructor(readonly nodes: Map<string, Node>) {
this.#allProduced = new Set();
this.#allConsumed = new Set();
this.#producedBy = new Map();
this.#consumedBy = new Map();
for (const node of this.nodes.values()) {
for (const produced of node.produces) {
this.#allProduced.add(produced);
if (this.#producedBy.has(produced)) {
throw new ConflictError(
`Dependency conflict detected, '${produced}' may not be produced by both '${this.#producedBy.get(
produced,
)}' and '${node.id}'`,
);
}
this.#producedBy.set(produced, node.id);
}
for (const consumed of node.consumes) {
this.#allConsumed.add(consumed);