-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
ESM build, with helpers separated #7400
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.
won't this results that the helpers are both in the esm bundle and separated? so they are still in the bundle but not accessible anymore.
Moreover, the helpers are just part of the issue. The bigger ones are the controllers and elements.
No, rollup is smart enough. Its referencing the helpers from the directory (and also creating a chunk for helpers.options to prevent circular dependency) Here's the output: |
good to know. Another general question: what is the purpose of a minified esm build? who should reference it? I assume most users will use a bundler in an esm case so what are the benefits? |
no idea really. could be referenced directly from browser, i think? |
Is |
Its the files that would be in npm package, excluding the UMD bundle. (and excluding the dist folder, that I later restored) |
That's nice 👍 Since this gives us something similar to what @sgratzl called the seperated case in #7371 (comment), is this a look at the future/3.x structure of ChartJS repo? |
rollup.config.js
Outdated
@@ -10,6 +10,22 @@ const terser = require('rollup-plugin-terser').terser; | |||
const pkg = require('./package.json'); | |||
|
|||
const input = 'src/index.js'; | |||
const inputESM = { | |||
'dist/chart.esm': 'src/index.esm.js', | |||
'helpers/canvas': 'src/helpers/helpers.canvas.js', |
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 could programatically build the rollup input instead of having to list every file?
Though this is pretty explicit, so it would still be helpful to have a comment showing exactly what it's doing if done programatically
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 necessary to do programatically on the long term?
If esm_buid.zip
is not anticipating the future repo structure (which would cause this to become obsolete), I do not see the benefit to generate an additional multi-file ESM package, which basically restructures src/
, instead of delivering src/
directly, as it already is a fully working ESM package.
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.
The problem is, it is not a fully working esm module. Because there are proposal features used.
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.
Oh I see, wasn't aware of this.
If it is in order to pull the source through babel, we could also preserve the current structure and wouldn't need to define a restructured package.
However, I am unsure if all this effort is worth it to build ChartJS on top of non-JS syntax/features. I assume that you already need to babel the source to apply ESLint (which only supports Stage 4) and your testing environment?
Is the only used proposal feature the out of constructor-class property initialisation from @babel/plugin-proposal-class-properties
? Object.assign
and static
methods should be Stage 4 since 2015? If we only need to move the property initialisation into the class constructors (and static ones in the module scope), in order to avoid all this additional tooling, building (and the whole maintenance behind it), I believe it would be worth it 😃
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, it's just the static
initializations. It wouldn't be hard to change. I wasn't fully aware of the implications when I originally introduced it and would definitely be in favor of removing it and babel from the ES builds
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 still need the tooling for IE support, so it does not really reduce any maintenance. But I created a request for moving the statics to module scope: #7425
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.
Wouldn't it remove the need to babel everything during testing and linting (as well as the dependencies necessary for this)?
Since IE does not support the ESM syntax, I assume that at most IE-compatible packages need Babel after their generation?
I would also suggest to never apply Babel to the ESM package. This would allow users to downgrade the JS standard of ChartJS (which can have quite the performance impact if you simulate some native functions) based on their own needs.
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 could programatically build the rollup input instead of having to list every file?
Added glob for that.
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.
@sebiniemann Chart.js v3 umd
bundle is IE compatible and we need babel for that. Its produced from the same source. Some tests use ESM syntax, so we need to rollup those so karma can cope with them. We also need babel for the tests to get coverage right (I've tried to get it done with rollup-plugin-istanbul and several other packages, but it just does not work 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.
I am 100% with you on this :)
Not sure why babel is needed for test coverage, might be some special configuration. We could also remove babel-eslint
(hard to see, as it comes as a sub-dep of eslint-config-esnext
).
Babel will surly remain in most projects to deliver at least one fast-to-use version with guaranteed browser compatibility (which is nice), but as testing and linting is not bound to use land, it shouldn't be necessary for these.
It might be confusing that we have I also wonder about the names of the plugins |
These are related to the registration and should be handled in #7435 |
This makes the helpers fully shakeable. Core stuff is not yet, because of the registrations etc. But the exports are fine, just need to remove the internal access. |
Looks good to me. I'll play around with this locally tonight and test it out. |
I was trying to remember the high-level idea here since it's been a few weeks since we were really active on this stuff. Here's a link to the original discussion: #7371 (comment) |
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 played around with this a bit locally and it seemed ok. npm pack --dry-run
reports the helpers being included.
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 looks good to me. just one super minor issue I noticed
a couple things about the documentation I was thinking, which could be handled in a follow-up if we wanted:
- we should probably have the TypeDoc be generated off the es 6 output bundle or else the namespaces won't match what users see
- we should probably update https://www.chartjs.org/docs/master/developers/charts to show it using es6 + npm way of doing things
If not already done by this, is it possible to also deliver Its actually how we consume most of our dependencies and how its specified in their |
Aws-sdk is a type script project, you are consuming the *.ts? |
|
What is the down side of processing the distributed files? Its more likely compatible with webpack etc, because rollup fills the missing '.js' to imports etc, that we really don't care to manually keep track with. Only thing that I can think of you gaining from direct source npm package, is the line numbers for debugging. But that is going to be in the tag anyway, not the master branch. Previously our source was not usable directly. That day might come again, and if it was directly published. it would be a breaking change. We don't want to tie our source tree down. Another thing to consider is that its only your use case we are talking about here. There are quite a few other use cases out there, that would need to be considered. At the minimum those This works, it should not really harm your use case, and I really don't see a valid reason (in Chart.js perspective!) to change from |
That's totally fine for me if you are not considering this at the moment 😃 Since we have our own rollup process, it will work for us either way -- regardless which file structure is shipped. It was more meant to say that a pre-chunked version might not be necessary for Regarding your questions, there are only two main reasons I see for this:
There is also a special case about caching, when ChartJS is consumed by In summary I would say that the ChartJS source is already written in JS and shouldn't need a build step to be usable. And only consider build steps to provide additional packages (umd package, single-file-packages, pre-babel builds, ...). Regarding the missing file extension, I personally consider the omission to be a mistake/bug, since something like something like the resolution of module file extensions does not seem to be a necessary part of the ECMAScript standard. It is not very likely to change, as browsers would require multiple server round-trips/HTTP request to support this. If you like to address this, you can ensure that it is always set via the import/extensions rule from
I am not sure what you meant by this? |
Just that we want to produced and publish ECMA script compatible package, but might want to use typescript in parts of the source (for example). Or anything other that transpile to valid package. |
I agree it'd be nice not to have a build step since we already have the source code in ES6. But that would mean that end users need to import one component per line instead of being able to do |
* ESM build, with helpers separated * Remove umd environment * Include the chunks in package
Ref: #7371
Closes: #7395
This could be one approach