-
Notifications
You must be signed in to change notification settings - Fork 143
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
Build tools improvement: api-extractor for bundling dts #125
Conversation
@luin Could you help take a look? |
Hey @fnlctrl 👋 Thank you for the PR! I'm not sure if it's a good idea to provide both UMD/CJS and ESM, as I was under the impression that bundlers have issues dealing with them (ex webpack/webpack#5756). Additionally, this introduces the dual package hazard where we rely on We should maintain a consistent tech stack across all Quill repositories. Therefore, I'd suggest avoiding the introduction of Vite at this time solely for ESM support. In the future, we could consider transitioning the package to ESM only. |
@luin Thank you for taking the time to reivew! Here are my thoughts: For dual umd/esm builds:As for the webpack issue, I think it only affects default export: As for the dual package hazard, if I'm not mistaken, Parchment is currently only meant to be run in the browser. So it won't be running directly in node and thus subject to node's issue. For people using umd via <script> tag it's irrelevant. For people using modern bundlers (that should load esm by default), it's up to bundler's behavior to deal with simultaneous use of This is just my personal opinion, but using I think the tree-shaking benefit of dual umd/esm outweights the above (self-inflicted) For viteIf in the future we want ESM only build, webpack couldn't do the job since it doesn't support outputting ESM (webpack/webpack#2933). And considering webpack being retired in favor of turbopack (Tobias Koppers working on turbopack now), I don't think it's going to support it in the forseeable future, so a switch is inevitable (turbpack/vite/etc.). If you consider vite to be overkill, I can switch to plain If you still don't like the idea of dual UMD/ESM, I can remove the vite-related stuff and only keep api-extractor. Thank you again! |
quilljs/delta has a default export and I wanted to keep the tech stack identical between them. However, upon further consideration, quilljs/delta can remain as a CommonJS package to avoid the dual package hazard issue and likely the Webpack issue as well since it needs to run with Node.js and has default exports. quilljs/parchment can be built as both UMD and ESM, as outlined in this PR.
You are right about this.
Thanks for the reference. I can now see it makes sense to introduce Vite but I'll do more tests later this week or next week to make sure exporting ESM won't introduce breaking changes. Please let me know if you happen to have some insights about this. Thanks! |
Thank you! I didn't know much about dual package hazard before and was just taking the multi-format output ("formats" option) offered by rollup/vite for granted. This really is tricky, but I think we can make the problem simpler by not having default exports. Since quill-delta is exporting more than the import { Delta, Op, normalizeDelta } from "quill-delta";
const { Delta, Op, normalizeDelta } = require("quill-delta"); As for the dual package hazard (running in node), since everything can be considered JSON data (Delta, Op, AttributeMap) and they typically don't need |
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.
Thanks for the contribution! I left two comments. Let's focus this PR on exporting the missing types.
For quill-delta, I'd keep it as CJS as I don't see enough benefits to publish it as a dural package.
vite.config.ts
Outdated
@@ -0,0 +1,13 @@ | |||
import { defineConfig } from 'vite'; | |||
|
|||
export default defineConfig({ |
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 migrating to Vite is the right direction but I'd make a separate PR for it and also should remove webpack.
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.
Removed, will make a separate PR.
I tried removing webpack but found that karma config is still dependent on it. Maybe I should change the test script so that build is run before testing?
@luin The tests seems to have stuck for 5 hours... Probably should configure a timeout or something - otherwise it would probably burn through the github actions quota. |
Created a PR for the timeout issue: #126 |
Why
Typings
Current
dist
is inconsitent for typescript usage, e.g. this example from quill repo:could have simply been
Module format
Currently
dist/parchment.js
isumd
format. It would have been nice to haveesm
format too.Whats changed
Vite is used for bundling js that support both
umd
andesm
.api-extractor is used for bundling .d.ts.
dist/typings
is removed.api-extractor.json
is added for config.Missing type exports like
Blot
andBlotConstructor
found by api-extractor are added in the index file (src/parchment.ts)tsconfig.json
is modified."emitDeclarationOnly": true
is added sincetsc
is not used for runtime codegen (vite/esbuild are used instead)."moduleResolution": "node"
is added for vite config in ts.Added overrides
"semver-regex": "^3.1.4"
and"http-cache-semantics": "^4.1.1"
. This fixes somenpm audit
issues.Before
After