-
Notifications
You must be signed in to change notification settings - Fork 33
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
Add civet unplugin #632
Add civet unplugin #632
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Some possible areas for future work:
- Update the Civet package build step so that people won't need to install a separate package and will be able to import any plugin directly.
- Add some basic tests for each plugin.
Overall this is very helpful as is, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so exciting! Mainly some docs comments, plus I wonder:
Should @danielx/civet
be a peerDependency (maybe with *
or >=
version) instead? Otherwise, wouldn't we need to publish this plugin after every Civet update? Hmm, or maybe package managers deal with this properly when versions don't mismatch. Indeed, I see vite-plugin-civet
uses a dependency not a peerDependency, and I haven't had issues with using newer versions. But we still might want *
or >=
version dependency here so it will default to the latest or whatever dependency is in the project root (I hope?).
Update the Civet package build step so that people won't need to install a separate package and will be able to import any plugin directly.
I think this is how it works already. Even peerDependencies seem to install by default though (despite not for a while).
Reading https://nodejs.org/en/blog/npm/peer-dependencies, it seems like peerDependency is the "right" thing here, but I'm not certain how it works with a regular dependency...
integration/unplugin/README.md
Outdated
|
||
- `dts`: `unplugin-civet` also supports generating `.d.ts` type definition files from the civet source, which is useful for building libraries. | ||
- `outputExtension`: Output filename extension to use. Default: `.civet.jsx`, or `.civet.tsx` if `js` is `false`. | ||
- `js`: Whether to transpile to JS or TS. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you state the default here? I believe it's false
, in which case should also rewrite the .civet.jsx
default for outputExtension
. (Should be .civet.tsx
, unless js
is true
.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that should be corrected. Though now that I think of it, maybe js
should be true by default. Most users would be using these for building applications and not libraries and in that case preserving types doesn't help much. I'm open to other opinions on this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A default of js: true
would break dts: true
. We could make dts
imply js: false
, but honestly js: false
is safer; some TypeScript features are not correctly implemented by Civet with js: true
, and it just costs a bit of time to use already existing TS integration. So I think js: false
is best.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could give imply js
based on the value of dts
first,
const transpileToJS = options.dts || options.js;
in which case both options should work. My main concern was that rollup and webpack can't process typescript without additional plugins, so would need to set js: true
to make the setup work, but if js: false
has better typescript features then let's go with that default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can include the {js: true}
in the README where we give recommended workflows for Webpack and Rollup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, we can do that
Thank you!
I assume you're talking about building this and outputting to
I thought that peer dependencies were not installed by default, didn't realise that changed in v7. If we update the Civet package and include it in |
Oh, sorry, now I understand Daniel's comment: make this part of the |
Yes, that's correct. Also updating the root Civet It will bulk up the published package a little bit compared to separate packages but should tree-shake out just fine thanks to the import mappings. Let me know if you have any questions about the build step, it's currently manually building a few different files that end up in Thanks again! |
integration/unplugin/README.md
Outdated
- `dts`: `unplugin-civet` also supports generating `.d.ts` type definition files from the civet source, which is useful for building libraries. Default: `false`. | ||
- `outputExtension`: Output filename extension to use. Default: `.civet.tsx`, or uses `.civet.jsx` if `js` is `true`. | ||
- `js`: Whether to transpile to JS or TS. Default: `false`. | ||
- `transformOutput`: Adds a custom transformer over jsx/tsx code produced by `civet.compile`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor point: It might be worth keeping the text that described the arguments to the function.
Should be now exported from |
I think
|
You have to run |
But build is failing; see CI. Does Yarn support submodules so that |
Yarn does support workspaces, but for that the root |
That's too bad. Would it be better if there was no |
Hm so we could either move the dependencies up to the top level (shouldn't require moving the script), or we can do |
Either way seems workable to me, though I'm not sure for the motivation of a separate |
I think that's a fair point. Adding it to top level 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now there seems to be an infinite build loop, both for me and for CI:
yarn build (unplugin-civet $)
yarn run v1.22.18
$ bash ./build/build.sh
$ bash ./build/build.sh
$ bash ./build/build.sh
$ bash ./build/build.sh
$ bash ./build/build.sh
Maybe you're using a different version of Yarn? v1 is standard, not v2. Or maybe you didn't test. 😉
Because there's no longer a integration/unplugin/package.json
, I believe yarn --cwd ./integration/unplugin build
just runs the same script as yarn build
. I think you want to run tsup
instead. Also, can you add type checking to the top-level yarn test
script?
Yeah I think I didn't test this change 😆 I have added a |
integration/unplugin/src/index.ts
Outdated
@@ -1,4 +1,5 @@ | |||
import { TransformResult, createUnplugin } from 'unplugin'; | |||
// @ts-ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to be necessary. Right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm yeah it looks like it works without this as well. That's weird because earlier it was throwing a type error that @danielx/civet
is not available to integration/unplugin
@@ -54,7 +54,7 @@ | |||
"docs:build": "yarn build && vitepress build civet.dev", | |||
"docs:preview": "yarn build && vitepress preview civet.dev", | |||
"prepublishOnly": "yarn build && yarn test", | |||
"test": "c8 mocha" | |||
"test": "c8 mocha && tsc" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#638 is now merged. Can you merge main
and test what happens now? We might need to exclude
it for now.
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ | ||
// "skipLibCheck": true /* Skip type checking all .d.ts files. */ | ||
"skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ | ||
"skipLibCheck": true /* Skip type checking all .d.ts files. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed, given that you're excluding dist
directories? It would be better to leave it false if possible. Ah, I see, it turns off checking of node_modules
, which currently fails (from missing @types
perhaps?). Still, seems like this turns off a lot of actual type checking... though we could leave it for later. Same for skipDefaultLibCheck
which seems risky.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed because unplugin
's dts imports webpack
, vite
, rollup
, rspack
, and esbuild
out of which we don't have webpack
and rspack
required in Civet, and @typescript/vfs
imports lz-string
. So when typescript does type checking it errors out on these imports. We could also install types for these packages, or add them to dev deps instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding dev dependencies for types sounds good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried adding them to dev dependencies, but @rspack/core
has a type error in it's declarations (imports a dts file that doesn't exist) and type checking fails because of it. Maybe we should turn on skipLibCheck
for now? skipDefaultLibCheck
won't be required
# unplugin | ||
yarn --cwd ./integration/unplugin build | ||
cp ./integration/unplugin/dist/* ./dist | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For Windows, I realize chmod a-x dist/*.*[jt]s
would be helpful.
Also, what is this new dist/chunk-UZRN3RFA.mjs
file? Presumably it's not desired?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the esm build, tsup splits the common chunks into a separate file by default. As all the bundler entrypoints /esbuild
, /rollup
etc. import the central civetUnplugin
it splits that into this chunk and imports it in them. Mostly helps keep the bundle size smaller as its not duplicated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that is nice. Can we choose a better name for that file? Given that there's only one, maybe a custom name rule would work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can choose a better name for it https://esbuild.github.io/api/#chunk-names, but i'm not sure if we should. There currently only exists one of these, but might be more than that in the future. I would suggest keeping it as is, or just turning off splitting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be nice to rename it for now; we can always change it if we need multiple chunks in the future (seems unlikely for the unplugin?). Maybe unplugin-shared
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize the examples from your repo aren't here. Probably they should be, for manual testing and for documentation?
Also, a reminder to finish the last couple tweaks here — would be great to get this out!
Should be good to land now! |
TS errors may be fixed by merging latest main now that our internals are in Civet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Looks good!
@edemaine any further comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Just tried out building including some examples.
types/node.d.ts
Outdated
@@ -1,6 +1,6 @@ | |||
// Add _compile to Module | |||
declare namespace NodeJS { | |||
interface Module { | |||
_compile(content: string, filename: string) | |||
_compile(content: string, filename: string): any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer : unknown
@@ -0,0 +1,21 @@ | |||
# build output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this directory should be called astro
not astro-example
.
@@ -182,51 +182,101 @@ | |||
resolved "https://registry.yarnpkg.com/@esbuild/android-arm64/-/android-arm64-0.17.19.tgz#bafb75234a5d3d1b690e7c2956a599345e84a2fd" | |||
integrity sha512-KBMWvEZooR7+kzY0BtbTQn0OAYY7CsiydT63pVEaPtVYF0hXbUaOyZog37DKxK7NF3XacBJOpYT4adIJh+avxA== | |||
|
|||
"@esbuild/[email protected]": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yarn.lock
might need updating; it changed when I ran yarn
Made the suggested changes! |
This PR adds an unplugin for simultaneously create vite, rollup, esbuild, rspack and esbuild transformer for civet.