Skip to content

Dry out config #2373

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

Merged
merged 5 commits into from
Sep 6, 2021
Merged

Dry out config #2373

merged 5 commits into from
Sep 6, 2021

Conversation

Rich-Harris
Copy link
Member

Simplifies the config validation without introducing new dependencies (follow-up to #2366 (comment))

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpx changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

@changeset-bot
Copy link

changeset-bot bot commented Sep 5, 2021

⚠️ No Changeset found

Latest commit: 90874c7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@bluwy
Copy link
Member

bluwy commented Sep 6, 2021

Some things I found while refactoring in #2366:

  1. target, adapter, host and hostHeader are nullable, but not reflected in Config and ValidatedConfig types.

    export interface Config {

  2. Maybe we want to validate/coerce this together as well:

    validated.kit.files.assets = path.resolve(cwd, validated.kit.files.assets);
    validated.kit.files.hooks = path.resolve(cwd, validated.kit.files.hooks);
    validated.kit.files.lib = path.resolve(cwd, validated.kit.files.lib);
    validated.kit.files.routes = path.resolve(cwd, validated.kit.files.routes);
    validated.kit.files.serviceWorker = path.resolve(cwd, validated.kit.files.serviceWorker);
    validated.kit.files.template = path.resolve(cwd, validated.kit.files.template);
    validate_template(cwd, validated);

@Rich-Harris
Copy link
Member Author

Ah yeah, that's mildly annoying about the types, though if I amend Config to have string | null etc it causes more problems, so I'm okay glossing over that for the time being.

I considered making the homegrown validation logic accept options so that we could do the resolution in the validator, but when I implemented it the extra complexity outweighed those six extra lines, so I made the pragmatic choice. Can always revisit that in future if we end up with more options that need to be amended post-validation to account for things like cwd.

@Rich-Harris Rich-Harris merged commit 855936a into master Sep 6, 2021
@Rich-Harris Rich-Harris deleted the dry-out-config branch September 6, 2021 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants