Skip to content

Commit 367cbf8

Browse files
committed
fix: avoid double merging of layers
resolves nuxt/framework#3800
1 parent 389e6d2 commit 367cbf8

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

src/loader.ts

+12-11
Original file line numberDiff line numberDiff line change
@@ -95,27 +95,28 @@ export async function loadConfig<T extends InputConfig=InputConfig> (opts: LoadC
9595
configRC
9696
) as T
9797

98-
// Preserve unmerged sources
99-
const baseLayers = [
100-
opts.overrides && { config: opts.overrides, configFile: undefined, cwd: undefined },
101-
{ config, configFile: opts.configFile, cwd: opts.cwd },
102-
opts.rcFile && { config: configRC, configFile: opts.rcFile }
103-
].filter(l => l && l.config)
104-
10598
// Allow extending
10699
if (opts.extend) {
107100
await extendConfig(r.config, opts)
108-
r.layers = [
109-
...baseLayers,
110-
...r.config._layers
111-
]
101+
r.layers = r.config._layers
112102
delete r.config._layers
113103
r.config = defu(
114104
r.config,
115105
...r.layers.map(e => e.config)
116106
) as T
117107
}
118108

109+
// Preserve unmerged sources as layers
110+
const baseLayers = [
111+
opts.overrides && { config: opts.overrides, configFile: undefined, cwd: undefined },
112+
{ config, configFile: opts.configFile, cwd: opts.cwd },
113+
opts.rcFile && { config: configRC, configFile: opts.rcFile }
114+
].filter(l => l && l.config) as ConfigLayer<T>[]
115+
r.layers = [
116+
...baseLayers,
117+
...r.layers
118+
]
119+
119120
// Apply defaults
120121
if (opts.defaults) {
121122
r.config = defu(r.config, opts.defaults) as T

test/fixture/base/config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ export default {
33
colors: {
44
primary: 'base_primary',
55
text: 'base_text'
6-
}
6+
},
7+
array: ['b']
78
}

test/fixture/config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ export default {
77
primary: 'user_primary'
88
},
99
configFile: true,
10-
overriden: false
10+
overriden: false,
11+
array: ['a']
1112
}

test/index.test.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ describe('c12', () => {
2727

2828
expect(transformPaths(config)).toMatchInlineSnapshot(`
2929
{
30+
"array": [
31+
"b",
32+
"a",
33+
],
3034
"baseConfig": true,
3135
"colors": {
3236
"primary": "user_primary",
@@ -36,11 +40,6 @@ describe('c12', () => {
3640
"configFile": true,
3741
"defaultConfig": true,
3842
"devConfig": true,
39-
"extends": [
40-
"./theme",
41-
"./config.dev",
42-
"virtual",
43-
],
4443
"overriden": true,
4544
"rcFile": true,
4645
"virtual": true,
@@ -59,6 +58,9 @@ describe('c12', () => {
5958
},
6059
{
6160
"config": {
61+
"array": [
62+
"a",
63+
],
6264
"colors": {
6365
"primary": "user_primary",
6466
},
@@ -90,6 +92,9 @@ describe('c12', () => {
9092
},
9193
{
9294
"config": {
95+
"array": [
96+
"b",
97+
],
9398
"baseConfig": true,
9499
"colors": {
95100
"primary": "base_primary",

0 commit comments

Comments
 (0)