Skip to content

Commit f9ebb56

Browse files
committed
Fix duplicate config source registration in ConfigSourceRegistry
Deduplicate by name in register() to prevent accumulation when both B2CPluginManager and oclif hook paths discover the same plugins.
1 parent 3a987c5 commit f9ebb56

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@salesforce/b2c-tooling-sdk': patch
3+
---
4+
5+
Fix duplicate config source registration in `ConfigSourceRegistry` when multiple discovery paths find the same plugins

packages/b2c-tooling-sdk/src/config/config-source-registry.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export class ConfigSourceRegistry {
6767
* @param source - The config source to register
6868
*/
6969
register(source: ConfigSource): void {
70+
if (this.sources.some((s) => s.name === source.name)) return;
7071
this.sources.push(source);
7172
}
7273

packages/b2c-tooling-sdk/test/config/config-source-registry.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ describe('config/config-source-registry', () => {
2929
expect(registry.getSourceNames()).to.deep.equal(['s1', 's2']);
3030
});
3131

32+
it('register() silently ignores duplicate source names', () => {
33+
const registry = new ConfigSourceRegistry();
34+
registry.register(createStubSource('s1'));
35+
registry.register(createStubSource('s1'));
36+
37+
expect(registry.size).to.equal(1);
38+
expect(registry.getSourceNames()).to.deep.equal(['s1']);
39+
});
40+
3241
it('unregister() removes an existing source by name', () => {
3342
const registry = new ConfigSourceRegistry();
3443

0 commit comments

Comments
 (0)