Skip to content

Commit 51aed02

Browse files
authored
Fix active config selection ignoring configs[] when root has no active field (#392)
Closes #390
1 parent ac1dcfc commit 51aed02

3 files changed

Lines changed: 27 additions & 10 deletions

File tree

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 `active: true` on `configs[]` instances being ignored unless the root object also has `active: false`

packages/b2c-tooling-sdk/src/config/dw-json.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,13 @@ function selectConfig(json: DwJsonMultiConfig, instanceName?: string): DwJsonCon
227227
}
228228

229229
// Find active config
230-
if (json.active === false) {
231-
// Root is inactive, look for active in configs
232-
const activeConfig = json.configs.find((c) => c.active === true);
233-
if (activeConfig) {
234-
logger.trace(
235-
{selection: 'active', instanceName: activeConfig.name},
236-
`[DwJsonSource] Selected config "${activeConfig.name}" by active flag`,
237-
);
238-
return activeConfig;
239-
}
230+
const activeConfig = json.configs.find((c) => c.active === true);
231+
if (activeConfig) {
232+
logger.trace(
233+
{selection: 'active', instanceName: activeConfig.name},
234+
`[DwJsonSource] Selected config "${activeConfig.name}" by active flag`,
235+
);
236+
return activeConfig;
240237
}
241238

242239
// Default to root config

packages/b2c-tooling-sdk/test/config/dw-json.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,21 @@ describe('config/dw-json', () => {
150150
expect(result?.config.name).to.equal('production');
151151
});
152152

153+
it('selects active config when root has no active field', async () => {
154+
const dwJsonPath = path.join(tempDir, 'dw.json');
155+
const multiConfig = {
156+
configs: [
157+
{name: 'sandbox1', hostname: 'sandbox1.demandware.net', active: true},
158+
{name: 'sandbox2', hostname: 'sandbox2.demandware.net'},
159+
],
160+
};
161+
fs.writeFileSync(dwJsonPath, JSON.stringify(multiConfig));
162+
163+
const result = await loadDwJson();
164+
expect(result?.config.hostname).to.equal('sandbox1.demandware.net');
165+
expect(result?.config.name).to.equal('sandbox1');
166+
});
167+
153168
it('returns root config when no active config found', async () => {
154169
const dwJsonPath = path.join(tempDir, 'dw.json');
155170
const multiConfig = {

0 commit comments

Comments
 (0)