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

[code-infra] Update package layout for better ESM support #43264

Draft
wants to merge 49 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
0c2d530
WIP
Janpot Aug 11, 2024
f0cc38e
exclude icons
Janpot Aug 11, 2024
3955055
MUI_PACKAGE_EXPORTS
Janpot Aug 11, 2024
33c43c1
more
Janpot Aug 11, 2024
5888018
Update copyFilesUtils.mjs
Janpot Aug 11, 2024
642fdcd
remove deep export
Janpot Aug 12, 2024
868a81d
bring back flag
Janpot Aug 12, 2024
e03039f
Update ci.yml
Janpot Aug 12, 2024
f5bb040
WIP
Janpot Aug 12, 2024
da26652
Merge branch 'next' into esm-exports
Janpot Aug 23, 2024
4229626
Update build.mjs
Janpot Aug 23, 2024
c11b8e5
remove this
Janpot Aug 25, 2024
a98520b
fix snapshot
Janpot Aug 25, 2024
60e04ca
vite icons alias
Janpot Aug 25, 2024
6e2bbcc
remove 'use client' from index.* fles
Janpot Aug 25, 2024
9348956
Update package.json
Janpot Aug 25, 2024
860a36e
Update package.json
Janpot Aug 25, 2024
904f65b
Update package.json
Janpot Aug 25, 2024
0de01ee
Revert "remove 'use client' from index.* fles"
Janpot Aug 26, 2024
5172a89
bring changes to snashots
Janpot Aug 27, 2024
9eaa517
Update webpack.config.js
Janpot Aug 27, 2024
2011763
Merge remote-tracking branch 'upstream/master' into esm-exports
Janpot Aug 27, 2024
4c44355
Update scripts/build.mjs
Janpot Aug 28, 2024
626135d
Reapply "remove 'use client' from index.* fles"
Janpot Aug 28, 2024
b4e9968
remove 'use client'
Janpot Aug 28, 2024
6bf0206
Update pnpm-lock.yaml
Janpot Aug 28, 2024
ba50924
Merge remote-tracking branch 'upstream/master' into esm-exports
Janpot Aug 28, 2024
97f711a
fix tsc
Janpot Aug 28, 2024
f7b83b9
Update tsconfig.json
Janpot Aug 28, 2024
32afa8d
Merge branch 'master' into esm-exports
Janpot Aug 28, 2024
72beb0e
zis
Janpot Aug 28, 2024
bb746d1
update exports of icons
Janpot Aug 28, 2024
db13926
fix overrides of export field
Janpot Aug 28, 2024
ee3f56b
Merge branch 'master' into esm-exports
Janpot Aug 28, 2024
85e1af7
Update build.mjs
Janpot Aug 29, 2024
d881880
next document fix
Janpot Aug 30, 2024
66e9d33
ci
Janpot Aug 30, 2024
d4953d4
ci
Janpot Aug 30, 2024
c6212c5
Update pagesRouterV13Document.tsx
Janpot Aug 30, 2024
debe230
Update package.json
Janpot Aug 30, 2024
02749c1
Update package.json
Janpot Aug 30, 2024
c1061e7
Update package.json
Janpot Aug 30, 2024
ff6c473
remove mjs
Janpot Aug 31, 2024
096d907
remove unnecessary
Janpot Sep 2, 2024
6074ce9
extension
Janpot Sep 2, 2024
9aabf3b
Update copyFiles.mjs
Janpot Sep 2, 2024
3cccf14
Merge remote-tracking branch 'upstream/master' into esm-exports
Janpot Sep 4, 2024
eedc2b9
Revert
Janpot Sep 4, 2024
029389f
jdsh
Janpot Sep 4, 2024
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
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ default-job: &default-job
REACT_VERSION: << parameters.react-version >>
TEST_GATE: << parameters.test-gate >>
AWS_REGION_ARTIFACTS: eu-central-1
MUI_USE_PACKAGE_EXPORTS: 'true'
working_directory: /tmp/material-ui
docker:
- image: cimg/node:18.20
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ on:

permissions: {}

env:
MUI_USE_PACKAGE_EXPORTS: 'true'

jobs:
# Tests dev-only scripts across all supported dev environments
test-dev:
Expand Down
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',
},
],
},
});
4 changes: 2 additions & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module.exports = function getBabelConfig(api) {
'@babel/preset-env',
{
bugfixes: true,
browserslistEnv: process.env.BABEL_ENV || process.env.NODE_ENV,
browserslistEnv: api.env() || process.env.NODE_ENV,
debug: process.env.MUI_BUILD_VERBOSE === 'true',
modules: useESModules ? false : 'commonjs',
shippedProposals: api.env('modern'),
Expand All @@ -74,7 +74,7 @@ module.exports = function getBabelConfig(api) {
// in webpack config:
api.env(['regressions']);

const outFileExtension = '.js';
const outFileExtension = useESModules ? '.mjs' : '.js';

/** @type {babel.PluginItem[]} */
const plugins = [
Expand Down
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"build:ci": "lerna run build --ignore docs --concurrency 8 --skip-nx-cache",
"build:public": "lerna run --no-private build",
"build:public:ci": "lerna run --no-private build --concurrency 8 --skip-nx-cache",
"build:codesandbox": "NODE_OPTIONS=\"--max_old_space_size=4096\" lerna run --concurrency 8 --scope \"@mui/*\" --scope \"@mui-internal/*\" --no-private build",
"build:codesandbox": "MUI_USE_PACKAGE_EXPORTS=true NODE_OPTIONS=\"--max_old_space_size=4096\" lerna run --concurrency 8 --scope \"@mui/*\" --scope \"@mui-internal/*\" --no-private build",
"release:version": "lerna version --no-changelog --no-push --no-git-tag-version --no-private --force-publish=@mui/core-downloads-tracker",
"release:build": "lerna run --concurrency 8 --no-private build --skip-nx-cache",
"release:changelog": "node scripts/releaseChangelog.mjs",
Expand Down Expand Up @@ -89,7 +89,8 @@
"nx_test_karma_profile": "cross-env NODE_ENV=test karma start test/karma.conf.profile.js",
"nx_test_karma": "cross-env NODE_ENV=test karma start test/karma.conf.js",
"nx_test_regressions_run": "mocha --config test/regressions/.mocharc.js --delay 'test/regressions/**/*.test.js'",
"nx_test_unit": "cross-env NODE_ENV=test mocha 'packages/**/*.test.{js,ts,tsx}' 'packages-internal/**/*.test.{js,ts,tsx}' 'docs/**/*.test.{js,ts,tsx}'"
"nx_test_unit": "cross-env NODE_ENV=test mocha 'packages/**/*.test.{js,ts,tsx}' 'packages-internal/**/*.test.{js,ts,tsx}' 'docs/**/*.test.{js,ts,tsx}'",
"clean": "pnpm -r exec rm -rf build"
},
"dependencies": {
"@googleapis/sheets": "^9.3.0",
Expand Down Expand Up @@ -121,6 +122,9 @@
"@octokit/rest": "^21.0.2",
"@pigment-css/react": "0.0.20",
"@playwright/test": "1.46.1",
"@rollup/plugin-alias": "^5.1.0",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-node-resolve": "^15.2.3",
"@types/babel__core": "^7.20.5",
"@types/fs-extra": "^11.0.4",
"@types/lodash": "^4.17.7",
Expand Down Expand Up @@ -181,6 +185,8 @@
"pretty-quick": "^4.0.0",
"process": "^0.11.10",
"rimraf": "^5.0.10",
"rollup": "^4.20.0",
"rollup-plugin-preserve-directives": "^0.4.0",
"serve": "^14.2.3",
"stylelint": "^15.11.0",
"stylelint-config-standard": "^34.0.0",
Expand Down
21 changes: 19 additions & 2 deletions packages/mui-icons-material/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
},
"scripts": {
"build": "shx cp -r lib/ build/ && pnpm build:typings && pnpm build:copy-files",
"build:lib": "pnpm build:node && pnpm build:stable",
"build:lib": "cross-env MUI_USE_PACKAGE_EXPORTS=false pnpm build:node && cross-env MUI_USE_PACKAGE_EXPORTS=false pnpm build:stable",
"build:lib:clean": "rimraf lib/ && pnpm build:lib",
"build:modern": "echo 'Skip modern build'",
"build:node": "node ../../scripts/build.mjs node --largeFiles --outDir lib",
"build:stable": "node ../../scripts/build.mjs stable --largeFiles --outDir lib",
"build:copy-files": "node ../../scripts/copyFiles.mjs",
"build:copy-files": "cross-env MUI_USE_PACKAGE_EXPORTS=false node ../../scripts/copyFiles.mjs",
"build:typings": "node ./scripts/create-typings.mjs",
"prebuild": "rimraf build",
"release": "pnpm build && pnpm publish",
Expand Down Expand Up @@ -83,5 +83,22 @@
},
"engines": {
"node": ">=14.0.0"
},
"exports": {
".": {
"types": "./index.d.ts",
"import": "./esm/index.js",
"require": "./index.js"
},
"./*": {
"types": "./*.d.ts",
"import": "./esm/*.js",
"require": "./*.js"
},
"./esm/*": {
Copy link
Member Author

Choose a reason for hiding this comment

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

Maintain backwards compatibility for users that have done

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

"types": "./*.d.ts",
"import": "./esm/*.js",
"require": null
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('next/document');
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import * as React from 'react';
import { AppType } from 'next/app';
import { EmotionCache } from '@emotion/react';
import createEmotionServer from '@emotion/server/create-instance';
import Document, { DocumentContext, DocumentInitialProps } from 'next/document';
import type { DocumentContext, DocumentInitialProps } from 'next/document';
import nextDocument from './nextDocument.cjs';
import { EmotionCacheProviderProps } from './pagesRouterV13App';
import createEmotionCache from './createCache';

const Document = nextDocument.default ?? nextDocument;

interface Plugin {
enhanceApp: (
App: React.ComponentType<React.ComponentProps<AppType>>,
Expand Down
4 changes: 2 additions & 2 deletions packages/mui-material-nextjs/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"outDir": "build",
"rootDir": "./src"
},
"include": ["./src/**/*.ts*"],
"exclude": ["src/**/*.spec.ts*", "src/**/*.test.ts*"]
"include": ["./src/**/*"],
"exclude": ["src/**/*.spec.*", "src/**/*.test.*"]
}
5 changes: 5 additions & 0 deletions packages/mui-material-pigment-css/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"typescript:module-augmentation": "node scripts/testModuleAugmentation.js"
},
"dependencies": {
"@babel/runtime": "^7.25.0",
"@mui/system": "workspace:*",
"@pigment-css/react": "0.0.20"
},
Expand All @@ -60,6 +61,10 @@
"useTheme": "@pigment-css/react/exports/useTheme"
}
},
"exports": {
"./styles.css": "./styles.css",
"./modern/styles.css": "./styles.css"
},
"engines": {
"node": ">=14.0.0"
}
Expand Down
8 changes: 8 additions & 0 deletions packages/mui-material/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@
"engines": {
"node": ">=14.0.0"
},
"exports": {
"/ButtonBase/TouchRipple": {
Copy link
Member Author

Choose a reason for hiding this comment

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

"types": "./ButtonBase/TouchRipple.d.ts",
"import": "./ButtonBase/TouchRipple.mjs",
"mui-modern": "./ButtonBase/TouchRipple.moder.mjs",
"require": "./ButtonBase/TouchRipple.js"
}
},
"pigment-css": {
"vite": {
"include": [
Expand Down
8 changes: 4 additions & 4 deletions packages/mui-material/src/PigmentGrid/PigmentGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import Grid from '@mui/material-pigment-css/Grid';
import composeClasses from '@mui/utils/composeClasses';
import generateUtilityClass from '@mui/utils/generateUtilityClass';
import {
generateDirectionClasses,
generateSizeClassNames,
generateSpacingClassNames,
} from '@mui/system/Grid/gridGenerator';
unstable_generateDirectionClasses as generateDirectionClasses,
unstable_generateSizeClassNames as generateSizeClassNames,
unstable_generateSpacingClassNames as generateSpacingClassNames,
} from '@mui/system/Grid';
import { Breakpoint, Theme } from '../styles';

type ResponsiveStyleValue<T> = T | Array<T | null> | { [key in Breakpoint]?: T | null };
Expand Down
1 change: 0 additions & 1 deletion packages/mui-material/src/useLazyRipple/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
'use client';
export { default } from './useLazyRipple';
1 change: 0 additions & 1 deletion packages/mui-material/src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use client';
import { unstable_ClassNameGenerator as ClassNameGenerator } from '@mui/utils';

export { default as capitalize } from './capitalize';
Expand Down
5 changes: 5 additions & 0 deletions packages/mui-system/src/Grid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ export * from './GridProps';
export { default as gridClasses } from './gridClasses';
export * from './gridClasses';
export { traverseBreakpoints as unstable_traverseBreakpoints } from './traverseBreakpoints';
export {
generateDirectionClasses as unstable_generateDirectionClasses,
generateSizeClassNames as unstable_generateSizeClassNames,
generateSpacingClassNames as unstable_generateSpacingClassNames,
} from './gridGenerator';
Loading
Loading