Skip to content

Commit 300968f

Browse files
committed
refactor(config): skip cycle tracking for leaf configs
1 parent 8cbee81 commit 300968f

2 files changed

Lines changed: 21 additions & 15 deletions

File tree

‎packages/rstack/src/configLayers.ts‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,21 @@ export const flattenConfigLayers = (
3838
const ancestors = new Map<RstackConfig, string>();
3939

4040
const visit = (config: RstackConfig, path: string): void => {
41-
const ancestorPath = ancestors.get(config);
42-
if (ancestorPath !== undefined) {
43-
throw new Error(
44-
`Circular config inheritance at ${path}: references ${ancestorPath}.`,
45-
);
46-
}
41+
if (config.extends?.length) {
42+
const ancestorPath = ancestors.get(config);
43+
if (ancestorPath !== undefined) {
44+
throw new Error(
45+
`Circular config inheritance at ${path}: references ${ancestorPath}.`,
46+
);
47+
}
4748

48-
ancestors.set(config, path);
49-
config.extends?.forEach((inherited, index) => {
50-
visit(inherited, `${path}.extends[${index}]`);
51-
});
49+
ancestors.set(config, path);
50+
config.extends.forEach((inherited, index) => {
51+
visit(inherited, `${path}.extends[${index}]`);
52+
});
53+
ancestors.delete(config);
54+
}
5255
layers.push(normalizeRstackConfig(config));
53-
ancestors.delete(config);
5456
};
5557

5658
configs.forEach((config, index) => visit(config, `extends[${index}]`));

‎packages/rstack/tests/config/flatten.test.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ test('flattens nested configs in order and preserves repeated references without
1919
base,
2020
]);
2121
expect(app).not.toHaveBeenCalled();
22-
expect(left.extends).toEqual([base]);
23-
expect(nested.extends).toEqual([left]);
24-
expect(right.extends).toEqual([base]);
25-
expect(configs).toEqual([nested, right, base]);
22+
expect(configs).toEqual([
23+
{
24+
extends: [{ extends: [base], fmt: { singleQuote: true } }],
25+
fmt: { semi: false },
26+
},
27+
{ extends: [base], fmt: { tabWidth: 4 } },
28+
base,
29+
]);
2630
});
2731

2832
test('reports the inheritance positions of a direct cycle', () => {

0 commit comments

Comments
 (0)