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

[charts] Use vendor to have CJS working out of the box #13608

Open
wants to merge 35 commits into
base: master
Choose a base branch
from

Conversation

alexfauquette
Copy link
Member

@alexfauquette alexfauquette commented Jun 24, 2024

Related issues

- import { BarChart } from '@mui/x-charts/BarChart';
+ import { BarChart } from '@mui/x-charts/BarChart/index.js';

What has been done

I copy pasted the victory-vendor script and adapted it such that it includes all the d3 lib we need (colors, interpolation, scale)

I did not used directly the victory-vendor package because they use the legacy d3-voronoid and we are using the new d3-delaunay.

The d3-delaunay is a wrapper on top of delaunator which relies on robust-predicates. This last one seems to also be only ESM so I added both of them to the script such that they are correctly imported for CJS

Open question

Is it a breaking change? I don't hink so, because if user are woking with ESM this vendor should be transparent. ANd if they were transpiling d3 modules now they don't need because we do it for theme

TODO if we agree on the strategy

  • Clean the Readme and Licence
  • Make sure the built package only contains the needed stuff
  • Make sure release is working fine
  • Update instalation documentation

@alexfauquette alexfauquette added the component: charts This is the name of the generic UI component, not the React module! label Jun 24, 2024
@mui-bot
Copy link

mui-bot commented Jun 24, 2024

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jun 25, 2024
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jun 25, 2024
@alexfauquette alexfauquette changed the title [charts] Test victory-vendor [charts] Use vendor to have CJS working out of the box Jun 26, 2024
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jun 26, 2024
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jul 1, 2024
Comment on lines +94 to +96
- run:
name: Build charts vendor
command: node ./packages/x-charts-vendor/scripts/build.js
Copy link
Member Author

Choose a reason for hiding this comment

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

We need to build the package each time. Otherwise the folder is empty and so every script complains that the package does not exist

Copy link
Member

Choose a reason for hiding this comment

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

Should we provide the package built already instead of having to build it in the pipelines and docs?

Copy link
Member Author

Choose a reason for hiding this comment

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

This would create an inconsistency in the release:

  • For not the @mui/x-charts-vendor is not published so no preview could work
  • The preview would used the last released version of the @mui/x-charts-vendor which is not practical if you need to bump one of the d3-lib

Comment on lines 133 to 134
- install_js
- run:
name: Tests charts
command: pnpm test:charts:unit # Run special test for charts due to ESM compatibility issue
- run:
Copy link
Member Author

Choose a reason for hiding this comment

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

Thos test are now in unit test since it does not require any specific babel config

@@ -23,6 +24,7 @@
"@mui/x-date-pickers": "packages/x-date-pickers/build",
"@mui/x-date-pickers-pro": "packages/x-date-pickers-pro/build",
"@mui/x-charts": "packages/x-charts/build",
"@mui/x-charts-vendor": "packages/x-charts-vendor",
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure it's usefull to ask circle ci to build it 🤔

@@ -6,6 +6,7 @@ netlify/functions
/docs/pages/playground/
/lerna.json
/packages/x-codemod/src/**/*.spec.js
/packages/x-charts-vendor
Copy link
Member Author

Choose a reason for hiding this comment

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

Except the script all the files are automatically generated, so I just skipped the entire folder

Copy link
Member

Choose a reason for hiding this comment

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

I would argue it is useful for the script itself to be linted 😅

Copy link
Member Author

@alexfauquette alexfauquette Jul 3, 2024

Choose a reason for hiding this comment

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

It's a copy past of victory-vendor so it nearly respect non of our linting rules. But could do it in a cleanup phase

@@ -5,7 +5,7 @@
"author": "MUI Team",
"license": "MIT",
"scripts": {
"build": "rimraf ./export && cross-env NODE_ENV=production next build --profile && pnpm build-sw",
"build": "rimraf ./export && node ../packages/x-charts-vendor/scripts/build.js && cross-env NODE_ENV=production next build --profile && pnpm build-sw",
Copy link
Member Author

Choose a reason for hiding this comment

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

Build the vendor package otherwise netlify has no access to it

Copy link
Member

@JCQuintas JCQuintas Jul 19, 2024

Choose a reason for hiding this comment

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

This currently means all our devs need to build the lib before we can run pnpm docs:dev, else docs can't find the files. We probably need to run it on the dev command as well 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

I assumed that once merged, everybody would run the build, and then it's done since all the generated files are in .gitignore

But effectively it's not friendly for external contributors. Maybe adding a parameter such that build.js chached check if some files already exist. if yes it just skip the build. Such that when running dev, we don't lose time generating this package

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, maybe check if the entrypoints are present and run the script otherwise?

Copy link
Member

Choose a reason for hiding this comment

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

It also breaks when running tests btw

? path.resolve(__dirname, `./lib-vendor/${match.groups.pkg}/index.js`)
: path.resolve(__dirname, `./lib-vendor/${match.groups.pkg}/src/index.js`);

console.log({ vendorPkg });
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
console.log({ vendorPkg });

Comment on lines +38 to +40
const vendorPkg = ['delaunator', 'robust-predicates'].includes(match.groups.pkg)
? path.resolve(__dirname, `./lib-vendor/${match.groups.pkg}/index.js`)
: path.resolve(__dirname, `./lib-vendor/${match.groups.pkg}/src/index.js`);
Copy link
Member Author

Choose a reason for hiding this comment

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

Here is the main difference with the original script.

d3-delaunay requires delaunator which requires robust-predicates which seems to be ESM only too.

So I added the to the vendor too.

Those lines are here because they do not have the exact same structure as the d3 packages

@alexfauquette alexfauquette marked this pull request as ready for review July 2, 2024 15:09
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jul 2, 2024
Copy link

github-actions bot commented Jul 2, 2024

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Comment on lines +94 to +96
- run:
name: Build charts vendor
command: node ./packages/x-charts-vendor/scripts/build.js
Copy link
Member

Choose a reason for hiding this comment

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

Should we provide the package built already instead of having to build it in the pipelines and docs?

package.json Show resolved Hide resolved
packages/x-charts/package.json Show resolved Hide resolved
@@ -6,6 +6,7 @@ netlify/functions
/docs/pages/playground/
/lerna.json
/packages/x-codemod/src/**/*.spec.js
/packages/x-charts-vendor
Copy link
Member

Choose a reason for hiding this comment

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

I would argue it is useful for the script itself to be linted 😅

packages/x-charts-vendor/scripts/build.js Outdated Show resolved Hide resolved
packages/x-charts-vendor/package.json Outdated Show resolved Hide resolved
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jul 3, 2024
Copy link

github-actions bot commented Jul 5, 2024

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jul 5, 2024
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jul 12, 2024
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jul 16, 2024
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jul 16, 2024
@@ -5,7 +5,7 @@
"author": "MUI Team",
"license": "MIT",
"scripts": {
"build": "rimraf ./export && cross-env NODE_ENV=production next build --profile && pnpm build-sw",
"build": "rimraf ./export && node ../packages/x-charts-vendor/scripts/build.js && cross-env NODE_ENV=production next build --profile && pnpm build-sw",
Copy link
Member

@JCQuintas JCQuintas Jul 19, 2024

Choose a reason for hiding this comment

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

This currently means all our devs need to build the lib before we can run pnpm docs:dev, else docs can't find the files. We probably need to run it on the dev command as well 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: charts This is the name of the generic UI component, not the React module!
Projects
None yet
3 participants