Export ActionMenu/index for backward compatibility with #3713 #3740
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ActionMenu.tsx
#3713Short story:
To keep backward compatibility for ActionMenu import (used a bunch in dotcom), we are telling rollup to keep
lib-esm/ActionMenu/index.js
and not optimise it awayThere are no unintended changes, see package-diff (with release candidate canary) here: https://npmdiff.dev/%40primer%2Freact/35.30.0-rc.debc9d55/0.0.0-20230913142005/
Lots of research, one line change, classic 🙃
Long story:
Background
The ActionMenu component was published with the
index.js
root and inlib-esm/ActionMenu.js
, this means it can be imported from 2 paths:Following ADR 012: File structure, we copied to
src/ActionMenu
and publishing that fromindex.js
root and inlib-esm/ActionMenu/index.js
However, we didn't remove
src/ActionMenu.js
as part of this change, which means there are 2 ActionMenus which are out of sync! And depending on your import statement, you may be using the old one still!In #3713, we removed the
src/ActionMenu.js
for good! However, that means one of the imports is now breakingsrc/ActionMenu/index.ts
exists, so why doesn'tlib-esm/ActionMenu/index.js
exist?Because
src/ActionMenu/index.ts
simply exports everything fromsrc/ActionMenu/ActionMenu.ts
, rollup optimises the output and doesn't the index file to the build! This is true for most components.Check out the difference between
src/index.ts
andlib-esm/index.js
:Is not publishing index.js file a bad thing?!
In general, I don't think it's a bad thing because we recommend folks to import components from the root.
There is no real benefit for a index.js file. If really necessary, folks can still grab the component from it's deeply nested path.
Backward compatibility for ActionMenu import path
Because we used to export ActionMenu from
@primer/react/lib-esm/ActionMenu
, to keep backward compatibility, we can tell rollup to not optimise this specific path and add it to the build.Check out the package diff as a result of this change: https://npmdiff.dev/%40primer%2Freact/35.30.0-rc.debc9d55/0.0.0-20230913142005/