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

Merged
merged 54 commits into from
Jul 29, 2024

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 use 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 think so, because if users are working with ESM this vendor should be transparent. And if they were transpiling d3 modules now they don't need it because we do it for them.

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

Changelog

  • 📦 [charts] Use vendor to have CJS working out of the box
    This modifies how the package imports D3.js. It should not impact you.

    For more context, the initial issue is caused by D3 only exporting ESM. The solution up until now was to export charts with only ESM. But some frameworks are confused by this configuration. So the time we can fix our build, we use a vendor package providing a CJS version of D3.
    image

@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
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jul 24, 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 26, 2024
@alexfauquette
Copy link
Member Author

vale github action failing is expected.

It fails when to many lines are modified, because that crash the review dog (which usually put comment in docs update)

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

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

Copy link
Member

@LukasTy LukasTy left a comment

Choose a reason for hiding this comment

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

LGTM. 👍
Leaving some final comments and noting that I didn't take the time to test if the latest changes still fix the mentioned issues. 🙈

}
},
"dependencies": {
"@babel/runtime": "^7.24.8",
Copy link
Member

Choose a reason for hiding this comment

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

Would putting it into peerDependencies instead make any difference? 🤔
Given that it is always going to be used in tandem with mui/x-charts, which has a direct @babel/runtime dependency, it should be "fine".
However, if it doesn't change anything in the build process—there is probably no reason to do it. 🤔

@@ -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

Choose a reason for hiding this comment

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

Will deploy examples work without it by using the latest version?

package.json Outdated
@@ -65,7 +64,8 @@
"release:publish:dry-run": "pnpm publish --recursive --tag latest --registry=\"http://localhost:4873/\"",
"release:tag": "node scripts/releaseTag.mjs",
"validate": "concurrently \"pnpm prettier && pnpm eslint\" \"pnpm proptypes\" \"pnpm docs:typescript:formatted\" \"pnpm docs:api\"",
"clean:node_modules": "rimraf --glob \"**/node_modules\""
"clean:node_modules": "rimraf --glob \"**/node_modules\"",
"build:charts:vendor": "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.

Is there a point in having this script if we can run pnpm --filter @mui/x-charts-vendor build or at least use it here? 🤔

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 was not aware of this --filter option

- run:
name: '`pnpm build:charts:vendor` changes committed?'
command: |
pnpm build: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.

Nitpick: I see that it takes ~9 seconds on CI, but still, have you considered running it less frequently?
Maybe use the same logic as for the dedupe?

mui-x/.circleci/config.yml

Lines 126 to 134 in ad605ff

name: '`pnpm dedupe` was run?'
command: |
# #default-branch-switch
if [[ $(git diff --name-status master | grep pnpm-lock) == "" ]];
then
echo "No changes to dependencies detected. Skipping..."
else
pnpm dedupe --check
fi

@alexfauquette
Copy link
Member Author

I didn't take the time to test if the latest changes still fix the mentioned issues. 🙈

No wories, I plan to do it before merging, but after having CI green :)

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jul 26, 2024
.circleci/config.yml Outdated Show resolved Hide resolved
.circleci/config.yml Outdated Show resolved Hide resolved
alexfauquette and others added 2 commits July 29, 2024 09:54
Co-authored-by: Lukas Tyla <llukas.tyla@gmail.com>
Signed-off-by: Alexandre Fauquette <45398769+alexfauquette@users.noreply.github.com>
@alexfauquette alexfauquette merged commit 743779f into mui:master Jul 29, 2024
16 of 17 checks passed
@JCQuintas
Copy link
Member

It only occurred to me now, but couldn't we have bundled the lib files into a single file for cjs? 🤔 Probably for a future iteration though 😆

@LukasTy
Copy link
Member

LukasTy commented Jul 30, 2024

couldn't we have bundled the lib files into a single file for cjs? 🤔 Probably for a future iteration though 😆

We could have done that, yes. 👍
But we tried keeping the solution close to victory-vendor AFAIK. 🤔

@alexfauquette
Copy link
Member Author

Good idea. I keep it in case the number of file generated reveals to be an issue 👍

@Janpot
Copy link
Member

Janpot commented Aug 29, 2024

Finally managed to take a look at this. Some remarks:

  • Looks good! I see nothing in the package layout that wouldn't work. It's just re-exporting for ESM so no resolution problems there.
  • Rollup would likely have been more appropriate here as a tool to bundle those d3 sources. It would completely eliminate the custom resolver required in babel. (If you find that resolving is required in babel, it's an indication that a bundler should be used instead). But it's working well, we can roll with it 👍.
  • Ideally the output extensions of the esm target are .mjs

"version": "7.8.0",
"description": "Vendored dependencies for MUI X Charts",
"author": "MUI Team",
"main": "./index.js",
Copy link
Member

@oliviertassinari oliviertassinari Sep 2, 2024

Choose a reason for hiding this comment

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

This file doesn't exist:

SCR-20240903-bwyo

https://publint.dev/@mui/x-charts-vendor@7.15.0

I think that we can remove it, it will be clearer:

Suggested change
"main": "./index.js",

Edit: fixed in #14465

thomasmoon pushed a commit to thomasmoon/mui-x that referenced this pull request Sep 9, 2024
Signed-off-by: Alexandre Fauquette <45398769+alexfauquette@users.noreply.github.com>
Co-authored-by: Lukas Tyla <llukas.tyla@gmail.com>
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
6 participants