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

Change our js/ts/npm build config to get types working in downstream projects #78

Merged
merged 4 commits into from
Jan 29, 2024

Conversation

gregsexton
Copy link
Contributor

This was a journey. And I've had some journeys with JS. I hope it's
over. But I'm definitely playing with fire here.

The goal: when you use skdb as a dependency in a downstream project,
you don't get any typing info other than for the one exported function
defined in skdb.ts. I wanted to fix this.

I tried a lot of things, but eventually found compiler and npm config
that works and is recommended by the typescript documentation.

https://www.typescriptlang.org/docs/handbook/modules/guides/choosing-compiler-options.html#im-writing-a-library

I had to make a lot of adjustments to how we define imports/exports to
make typescript happy under this new config. Which then broke what
sknpm produces, so I fixed that.

Something to note -- which sknpm was already taking care of, so I left
well alone -- is that using paths in libraries is bad and we should
make sure they never leak out in to the deliverable. They are not
re-written by the compiler and require all downstream libraries to
define them. Complete insanity.

https://stackoverflow.com/a/52501384
microsoft/TypeScript#15479

I'm somewhat confident this works and is correct, but it's JS and
there are many many permutations of env, so who knows?

  • The tests all pass
  • My node service that I'm working on gets type info, compiles, and runs
  • I checked out the todo app as a vite example and this appears to load up, run, and work

@gregsexton
Copy link
Contributor Author

@bennostein, when you're back, I'd really appreciate you testing the todo app with a package built from these changes. I think I tested it and it worked but I think there's multiple branches etc right so I'm not confident. Note you'll need to rebuild sknpm first.

Copy link
Contributor

@skiplabsdaniel skiplabsdaniel left a comment

Choose a reason for hiding this comment

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

LGTM

The goal: get declaration files working so that we get typing
information for downstream projects.

Why these settings? Because typescript docs tell me to:
https://www.typescriptlang.org/docs/handbook/modules/guides/choosing-compiler-options.html

And they work! And I tried a _lot_ of things that didn't until I found
these docs.
These are now correctly produced and work. But the path stuff does
still need to be stripped. It is not supported and requires downstream
projects to also define the paths. Refer:

https://stackoverflow.com/a/52501384
microsoft/TypeScript#15479
We rename the extension when copying runtime js files over, so we need
to massage the imports/exports to comply.
@gregsexton gregsexton merged commit 72d4022 into SkipLabs:main Jan 29, 2024
2 of 5 checks passed
@gregsexton gregsexton deleted the wasm-types branch January 30, 2024 10:36
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