Skip to content

feat: add ESM support#10525

Merged
etimberg merged 9 commits into
chartjs:masterfrom
TrigenSoftware:feat-esm
Aug 4, 2022
Merged

feat: add ESM support#10525
etimberg merged 9 commits into
chartjs:masterfrom
TrigenSoftware:feat-esm

Conversation

@dangreen

Copy link
Copy Markdown
Collaborator

Alternative of #10479

More changes than expected, but still.

To import CommonJS modules in/from ESM project .cjs extension is required.

Comment thread rollup.config.cjs
Comment thread types/tests/autogen.js Outdated
Comment thread package.json Outdated
Comment thread package.json Outdated
@kurkle kurkle added this to the Version 4.0 milestone Jul 28, 2022
@dangreen

dangreen commented Jul 29, 2022

Copy link
Copy Markdown
Collaborator Author

I think this PR also resolves this issue #9436

If we still want to support commonjs, cjs bundle from this PR has compatible with ESM exports:

Chart.helpers = {...helpers};
Chart._adapters = _adapters;
Chart.Animation = Animation;
Chart.Animations = Animations;
Chart.animator = animator;
Chart.controllers = registry.controllers.items;
Chart.DatasetController = DatasetController;
Chart.Element = Element;
Chart.elements = elements;
Chart.Interaction = Interaction;
Chart.layouts = layouts;
Chart.platforms = platforms;
Chart.Scale = Scale;
Chart.Ticks = Ticks;
Object.assign(Chart, controllers, scales, elements, plugins, platforms);
Chart.Chart = Chart;
module.exports = Chart;

@benmccann What do you think?

@benmccann

Copy link
Copy Markdown
Contributor

I'd love to drop CJS and do ESM-only if possible

@kurkle kurkle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure how the files should be named, because I guess chart.js can't be UMD when type='module'.

Comment thread package.json Outdated
Comment thread package.json
Comment thread rollup.config.cjs
Comment thread auto/package.json Outdated
@dangreen
dangreen requested review from benmccann and kurkle and removed request for benmccann August 3, 2022 07:17

@kurkle kurkle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just one more comment (considering all of the package.json's)

Comment thread helpers/package.json
Comment thread package.json
kurkle
kurkle previously approved these changes Aug 3, 2022

@kurkle kurkle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Needs a rebase though

@dangreen
dangreen requested review from benmccann and kurkle and removed request for benmccann August 3, 2022 16:06
Comment thread test/integration/node/package.json Outdated
kurkle
kurkle previously approved these changes Aug 3, 2022

@kurkle kurkle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Something about this should be mentioned in https://www.chartjs.org/docs/master/migration/v4-migration.html but I don't want to hold because of that.

@dangreen
dangreen dismissed stale reviews from kurkle, etimberg, and benmccann via 606b9be August 4, 2022 09:30
@dangreen dangreen mentioned this pull request Aug 4, 2022
etimberg
etimberg previously approved these changes Aug 4, 2022
kurkle
kurkle previously approved these changes Aug 4, 2022
@dangreen

dangreen commented Aug 4, 2022

Copy link
Copy Markdown
Collaborator Author

I will resolve conflicts later today

@dangreen
dangreen dismissed stale reviews from kurkle and etimberg via cfd8613 August 4, 2022 13:45
@benmccann

Copy link
Copy Markdown
Contributor

Should we keep the unminified UMD build? It might help people if they encounter an error in the minified build or otherwise want to debug. Perhaps we should have a chart.umd.js and chart.umd.min.js?

@dangreen

dangreen commented Aug 4, 2022

Copy link
Copy Markdown
Collaborator Author

@benmccann maybe just emit sourcemaps for UMD bundle ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants