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

[icons] Add exports field to package.json #43624

Merged
merged 8 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions apps/pigment-css-vite-app/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,4 @@ export default defineConfig({
Pages(),
splitVendorChunkPlugin(),
],
resolve: {
alias: [
{
find: /^@mui\/icons-material\/(.*)/,
replacement: '@mui/icons-material/esm/$1',
},
],
},
});
16 changes: 16 additions & 0 deletions packages/mui-icons-material/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,21 @@
},
"engines": {
"node": ">=14.0.0"
},
"exports": {
".": {
"types": "./index.d.ts",
"node": "./index.js",
"import": "./esm/index.js",
"require": "./index.js"
},
"./*": {
"types": "./*.d.ts",
"node": "./*.js",
"import": "./esm/*.js",
"require": "./*.js"
},
"./esm/*": "./esm/*.js",
Copy link
Contributor

Choose a reason for hiding this comment

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

Why has this been added? For backward compatibility ?

Copy link
Member Author

@Janpot Janpot Sep 9, 2024

Choose a reason for hiding this comment

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

Exactly, someone might have added

  resolve: {
    alias: [
      {
        find: /^@mui\/icons-material\/(.*)/,
        replacement: '@mui/icons-material/esm/$1',
      },
    ],
  },

to their vite config. It means under the hood their bundler is changing @mui/icons-material/Add to @mui/icons-material/esm/Add before the package.json resolution algorithm has even kicked in. If we don't add an export for this, that module request will follow the ./* => ./esm/*.js export and try to access ./esm/esm/Add.js (* == esm/Add). When we add this export, we special case the ./esm path to not add an extra esm segment (* == Add). We can remove this in a major version.

Same problem for users of https://github.com/avocadowastaken/babel-plugin-direct-import?tab=readme-ov-file#example

edit: you can test this with the pigment vite app. removing the export and putting back the vite config should break its build

"./esm/*.js": "./esm/*.js"
}
}
Loading