Skip to content

Commit 8fc5e52

Browse files
authored
[fix] allow any top-level keys in svelte config (#2267)
1 parent aaea5cf commit 8fc5e52

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

.changeset/eight-keys-give.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
allow any top-level keys in svelte config

packages/kit/src/core/config/index.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,19 @@ function validate(definition, option, keypath) {
2424
);
2525
}
2626
}
27-
for (const key in option) {
28-
if (!(key in definition)) {
29-
let message = `Unexpected option ${keypath}.${key}`;
30-
31-
if (keypath === 'config' && key in options.kit) {
32-
message += ` (did you mean config.kit.${key}?)`;
33-
} else if (keypath === 'config.kit' && key in options) {
34-
message += ` (did you mean config.${key}?)`;
35-
}
3627

37-
throw new Error(message);
28+
// only validate nested key paths
29+
if (keypath !== 'config') {
30+
for (const key in option) {
31+
if (!(key in definition)) {
32+
let message = `Unexpected option ${keypath}.${key}`;
33+
34+
if (keypath === 'config.kit' && key in options) {
35+
message += ` (did you mean config.${key}?)`;
36+
}
37+
38+
throw new Error(message);
39+
}
3840
}
3941
}
4042

packages/kit/src/core/config/index.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ test('errors on invalid nested values', () => {
8787
}, /^Unexpected option config\.kit\.files\.potato$/);
8888
});
8989

90+
test('does not error on invalid top-level values', () => {
91+
assert.not.throws(() => {
92+
validate_config({
93+
// @ts-expect-error - valid option for others but not in our definition
94+
onwarn: () => {}
95+
});
96+
});
97+
});
98+
9099
test('errors on extension without leading .', () => {
91100
assert.throws(() => {
92101
validate_config({

0 commit comments

Comments
 (0)