Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] allow any top-level keys in svelte config #2267

Merged
merged 4 commits into from Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eight-keys-give.md
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

allow any top-level keys in svelte config
22 changes: 12 additions & 10 deletions packages/kit/src/core/config/index.js
Expand Up @@ -24,17 +24,19 @@ function validate(definition, option, keypath) {
);
}
}
for (const key in option) {
if (!(key in definition)) {
let message = `Unexpected option ${keypath}.${key}`;

if (keypath === 'config' && key in options.kit) {
message += ` (did you mean config.kit.${key}?)`;
} else if (keypath === 'config.kit' && key in options) {
message += ` (did you mean config.${key}?)`;
}

throw new Error(message);
// only validate nested key paths
if (keypath !== 'config') {
for (const key in option) {
if (!(key in definition)) {
let message = `Unexpected option ${keypath}.${key}`;

if (keypath === 'config.kit' && key in options) {
message += ` (did you mean config.${key}?)`;
}

throw new Error(message);
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions packages/kit/src/core/config/index.spec.js
Expand Up @@ -87,6 +87,15 @@ test('errors on invalid nested values', () => {
}, /^Unexpected option config\.kit\.files\.potato$/);
});

test('does not error on invalid top-level values', () => {
assert.not.throws(() => {
validate_config({
// @ts-expect-error
bluwy marked this conversation as resolved.
Show resolved Hide resolved
onwarn: () => {}
});
});
});

test('errors on extension without leading .', () => {
assert.throws(() => {
validate_config({
Expand Down