Move unplugin and build using Civet instead of tsup #1306
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
My original goal was to enable
cli.civet
to beimport
ed fromsource
(in particular because we don't ship it indist
), to enable Mocha testing. The issue was that the CLI depends on the unplugin, which lived in a completely different universe (integration/unplugin
). This PR fixes this issue by moving the unplugin intosource/unplugin
, which makes sense given that the CLI depends directly on the unplugin (for typechecking). In particular,cli.civet
now imports locally instead of relying on how it will be indist
:Another benefit of this approach is that this import now gets the correct typing:
Before this PR we got this:
A secondary goal is that I wanted to start using Civet to write the unplugin, instead of being restricted to TypeScript. So the build system changed from raw tsup to an extension of our usual esbuild script, but now using the esbuild unplugin (from past versions) so that we can
emitDeclaration
s and get automatic.d.ts
files. This was a bit painful to get working, andbuild.sh
has some hacks to work around some issues, but it seems to work, and may be a good model for future automatic.d.ts
extraction. Notably, the only changes in thedist
directories are as follows:The second diff seems to have been a small bug:
esm.mjs
should import frommain.mjs
notmain.js
.The first diff is because of one other change: I moved all the built
unplugin
files fromdist
todist/unplugin
. I think this is a bit more organized, and it makes the directory structure ofdist
matchsource
, so relative imports still work (e.g.{rawPlugin} from ./unplugin/unplugin.civet
from above). Assuming users use theexports
defined inpackage.json
, such as"@danielx/civet/vite"
, they shouldn't notice any difference from this re-organization.I also relied less on bundling, so instead of a factored-out
unplugin-shared.mjs
which just worked for ESM, we have direct imports of./unplugin.{js,mjs}
in e.g.vite.js
. We also only generate one.d.ts
file (no more.d.mts
), so only run TypeScript once; the updatedexports
field inpackage.json
should correctly specify.d.ts
as the type declarations for both CJS and ESM. Here's a before and after for the built unplugin files:I've only minimally converted the unplugin from TypeScript to Civet. But this should reap benefits in the future. And enable CLI testing.