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

chore: use rollup instead of webpack and esbuild #1701

Closed
wants to merge 5 commits into from
Closed

Conversation

NaridaL
Copy link
Collaborator

@NaridaL NaridaL commented Nov 3, 2021

No description provided.

@NaridaL
Copy link
Collaborator Author

NaridaL commented Nov 3, 2021

  1. w/o deps, commonjs
  2. w/o deps, es
  3. w/ deps, umd
  4. w/ deps, umd + minified
  5. w/ deps, es
  6. w/ deps, es + minified

We want all these combinations?

@NaridaL NaridaL mentioned this pull request Nov 3, 2021
reporter: "spec",
spec: "./lib/test/**/*spec.js"
spec: "./test/**/*spec.ts"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The "build tests and source first, then run built tests" seemed a bit awkward. Also it had problems with wrong source lines in stack traces.

This runs the .ts spec files directly on the .ts source. This should have the advantage that the coverage report is more useful as it applies to the the .ts source. Also fix-coverage-report shouldn't be necessary anymore (?)

@bd82
Copy link
Member

bd82 commented Nov 3, 2021

Separating the bundling and compilations steps was done intentionally.
I personally believe it allows greater flexibility dev flows.

I see the following issues:

Issues / Cons

Major: (not working correctly)

  • The bundle:watch does not trigger when changes are made in other packages in this mono-repo.
  • The bundle does not include the other packages in this mono-repo or external packages, so I don't expect it to work in a browser env.
    -Edit: only now I noticed you commented on the deps/no-deps earlier.

Minor (possible concerns)

Pros

  • The (un-minified bundle) now gets automated testing as it is loaded by tests via exports / main field.
  • Avoid issues with source maps due to multiple transformation steps.
    • This may not be a major issue, perhaps we should disable source maps completely for the bundles as
      I personally am unlikely to debug an issues that is not reproducible in a nodejs env, so maybe it does not matter if there are no source maps.

"sinon": "11.1.2",
"sinon-chai": "3.7.0",
"webpack": "5.59.1",
"webpack-cli": "4.9.1",
"ts-node": "^10.4.0",
Copy link
Member

Choose a reason for hiding this comment

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

I think these deps are no longer needed (from previous version with mocha + tsnode)

name: "chevrotain",
exports: "named"
})),
external: Object.keys(pkg.dependencies),
Copy link
Member

Choose a reason for hiding this comment

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

Should not we include everything in the bundle?

{
input: "src/api.ts",
output: [
["es", false, true],
Copy link
Member

Choose a reason for hiding this comment

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

what do these combination mean?

terser({
compress: {
passes: 3,
unsafe: true,
Copy link
Member

Choose a reason for hiding this comment

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

How do we know everything works after bundling particularly when using unsafe minification modes? what benefit does unsafe produce in the bundle size?

compress: {
passes: 3,
unsafe: true,
ecma: 7
Copy link
Member

Choose a reason for hiding this comment

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

ecma 7 means ECMAScript 2017? or 2016?
anyhow we are officially targeting ECMAScript 2015, so this does not seem to make sense.

@bd82
Copy link
Member

bd82 commented Nov 3, 2021

My initial impression is is that there are more cons to replacing the main / exports fields than advantages.
And I think it may be best to just implement a drop in replacement to the current development flows and types of bundles.
But this is open for discussion.

A possible hybrid approach would be to, combine bundle + tsc compile, but only for the web bundles.
and keep the separate mono-repo aware tsc compile step for the entry points of exports and main.
But maybe we would want additional tests for the bundles in that case.

Long Term

Comparing the configuration complexity of rollup versus esbuild does make suspect I would prefer in the long term to use esbuild (once it supports UMD output natively). Basically if we can get x10 faster bundling with only two extra scripts in the package.json, It seems better than having a whole extra config file to me 😄

@NaridaL
Copy link
Collaborator Author

NaridaL commented Nov 3, 2021

The big pro here is that the ES bundle works correctly now: It does export { CstParser, EmbeddedActionsParser, ... } instead of const module = { CstParser, EmbeddedActionsParser }; export default module. I'm unclear what the advantage of the ES bundle over UMD in the current form is.

Additionally the amount of custom scripts is reduced, which is good for maintability.

@bd82
Copy link
Member

bd82 commented Nov 3, 2021

The big pro here is that the ES bundle works correctly now: It does export { CstParser, EmbeddedActionsParser, ... } instead of const module = { CstParser, EmbeddedActionsParser }; export default module. I'm unclear what the advantage of the ES bundle over UMD in the current form is.

I completely agree.

I just wonder if we should (in mid term):

  • move to only support ESM
  • wont need the esm-wrapper then
  • wont need UMD bundle.
  • can keep using esbuild and only produce a 1-2 bundles (instead of 4).
  • Maybe won't need any bundle if we use ESM and expect consumers to bundle themselves with tree-shaking?

See more on this topic here:

@bd82
Copy link
Member

bd82 commented Nov 4, 2021

Technical discussion on supporting dual style libraries (CJS/ESM).

@bd82
Copy link
Member

bd82 commented Nov 4, 2021

@NaridaL I appreciate the effort you've put into this PR. 👍
However, it is possible we would be better off by shelving it and re-evaluating the status in ~6 months.

This in no way means this PR is "waste effort", rather it is quite possible the main benefit of this PR
and other issue your raised regarding ESM bundling is in the discussion itself, deep dive into ESM vs CJS and possible future decisions in regards to ESM / dual CJS/ESM support.

My thoughts at the moment is that we may even be able to drop all bundled artifacts if we can switch to an ESM
only output in the mid term. Which means both goals of:

  1. Reducing maintenance TCO.
  2. Better support for ESM.

Could be achieved at the cost of breaking CJS support.

The main question is how stable would the eco-system support for ESM be in the mid term?
But as long as it does not take more than ~1 year to reach the state where CJS support can be dropped
It might not be worth additional effort investment in the introduction of rollup.

WDYT?

@bd82
Copy link
Member

bd82 commented Aug 13, 2022

I am closing the PR for now with the hope that in ~7 months when nodejs 14 reaches EOL
we can provide an ESM only package, perhaps even without a bundling step so no bundling tool would be needed.

@bd82 bd82 closed this Aug 13, 2022
@bd82 bd82 deleted the rollup branch June 29, 2023 22:18
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.

None yet

2 participants