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

Generate .d.ts bundle from source #9992

Merged
merged 43 commits into from
May 25, 2023
Merged

Generate .d.ts bundle from source #9992

merged 43 commits into from
May 25, 2023

Conversation

Rich-Harris
Copy link
Member

@Rich-Harris Rich-Harris commented May 19, 2023

I nerd-sniped myself in #9895 (comment) — I've created a small library, dts-buddy (couldn't think of a better name), for generating .d.ts bundles.

It's currently missing two important features:

  • only exporting the things you actually want to export, instead of everything
  • sourcemaps

Also, virtual modules like __sveltekit/environment are currently a TODO. We also need to

  • update the doc generation logic

Once those things are fixed, I think this gives us the best of all possible worlds — everything is derived from source (no more duplicating function definitions inside the hand-authored .d.ts files), and 'go to definition' will finally work properly. We also get to delete a bunch of stuff.

Please don't delete this checklist! 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 pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

@changeset-bot
Copy link

changeset-bot bot commented May 19, 2023

⚠️ No Changeset found

Latest commit: 536f474

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

Rich Harris added 3 commits May 22, 2023 15:39
@Rich-Harris
Copy link
Member Author

One compromise — had to expose __sveltekit/paths and __sveltekit/environment. Couldn't come up with a better solution that wouldn't have involved a lot more work.

That said, I realised just now that we're currently messing up by referencing these modules anyway, and need to come up with a different solution. Both of them indirectly reference the app version, which defeats the goal of maintaining hash stability between deployments. I therefore think we need to rethink how that's implemented, but that's out of scope of this PR so I'm going to punt on it for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l.g.t.m.
a o e o 
u d n m 
d l d e 
e y i n 
d   n t 
    g a 
      r 
      i 
      l 
      y 

/**
* @type {import('@sveltejs/kit').error}
* @overload

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL -- I was searching for this a while ago and couldn't find it!

Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
Copy link
Member

@benmccann benmccann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. for those who haven't been following along, the motivation for this PR is explained in #9883 (comment)

packages/kit/src/exports/index.js Outdated Show resolved Hide resolved
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.

4 participants