-
Notifications
You must be signed in to change notification settings - Fork 535
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
Mark build output "sideEffects": false #23501
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.
Copilot reviewed 1 out of 6 changed files in this pull request and generated no comments.
Files not reviewed (5)
- common/build/build-common/src/esm/package.json: Language not supported
- experimental/framework/tree-react-api/package.json: Language not supported
- packages/dds/tree/package.json: Language not supported
- packages/tools/devtools/devtools-test-app/package.json: Language not supported
- packages/tools/devtools/devtools-view/package.json: Language not supported
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.
Should/could we instead add sideEffects:false to common/build/build-common/src/esm/package.json?
I considered that, however with only one production package using this package.json file, I think having the tree build be special and use this file when nothing else does is confusing and needlessly complicates its build. That would keep its sideEffects block (which might someday be something other than false as it can list files and might need to at some point) duplicated in a way thats hard to notice, and harder to update (I'm not sure how we would go about adding files with side effects if using this copy approach: we would need something that copied the relevant subset of the actual main package.json or something. Just deleting the extra build step that adds redundant and wrong configuration so that all our packages build in a way thats more similar seems like a nice simplification and fix, and future risk reduction for people getting sideEffects wrong. Perhaps I'm missing something, but I don't see the value in keeping that file and its copy into a small subset of our packages during their build. |
The value is that we don't have good coverage one CommonJS. We would like CommonJS and ESM outputs to be similar to mitigate trouble with CommonJS uses. I won't block removal of |
…to sideEffects
…ng of these files except for tree.
@@ -1,3 +1,4 @@ | |||
{ | |||
"type": "commonjs" | |||
"type": "commonjs", | |||
"sideEffects": false |
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 believe this is meaningless. As far as I know this is only relevant to ESM where import and export are used. 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.
Some tools might use this. I think webpack might if you bundle the common JS code for some reason (maybe for a deployable service bundle). Webpack's documentation about it notes that this annotation is a workaround for non 100% esm stuff, which sounds like it likely has more significant in non-esm stuff. https://webpack.js.org/guides/tree-shaking/
Generally if we want CommonJS and esm to work as similarly as possible it seems like including this is a good idea so we don't get different bundling policies between the tool for any tools that use this setting.
While we don't use webpack or other bundling tools that use this setting on our CommonJS code, that seems like more of an argument for including it (so the thing we test, using this on ESM is more similar to the thing we don't test: bundling CJS which a customer might do)
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 webpack docs say that only ESM with import/export is supported. Then they warn about translators changing your code.
Since CommonJS can't use ESM, I don't think we are in any danger of this setting being obscurely relevant. Would be nice to at least comment in the description that we don't think it is relevant (since we can't comment in package.json). Ah, I just missed the merge.
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.
Please update the PR title and description.
Ideally skip the CJS change unless we think there is a case where it actually comes into play.
I have updated the description and title. I've leaving the change to the CommonJS modules for now (justification in other thread). This is yet another case of lack of ability to put nice comments in package.json files being annoying... |
Description
During the build we copy package.json files into the output for CJS builds and some ESM builds. Thes files lacked
"sideEffects": false
resulting in poor tree shaking for any bundle using build output with a copied package.json. This included the tree package ESM build which caused its bundle to bloat.This package.json copy has been removed from the tree package's esm build, but also update to include
"sideEffects": false
for builds that use it.Reviewer Guidance
The review process is outlined on this wiki page.