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

[core] Add exports field and build proper ES modules (no import extensions variant) #821

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
17 changes: 17 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,19 @@ jobs:
name: Run danger on PRs
command: pnpm danger ci --fail-on-errors
# TODO test bundle size https://github.com/mui/base-ui/issues/201
test_package:
<<: *default-job
steps:
- checkout
- install_js:
react-version: << parameters.react-version >>
- run:
name: Build packages
command: pnpm release:build
- run:
name: Are the types wrong?
command: pnpm -r test:package-types

workflows:
version: 2
pipeline:
Expand Down Expand Up @@ -419,6 +432,10 @@ workflows:
<<: *default-context
requires:
- checkout
- test_package:
<<: *default-context
requires:
- checkout
profile:
when:
equal: [profile, << pipeline.parameters.workflow >>]
Expand Down
53 changes: 17 additions & 36 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ function resolveAliasPath(relativeToBabelConf) {
return `./${resolvedPath.replace('\\', '/')}`;
}

const productionPlugins = [
['babel-plugin-react-remove-properties', { properties: ['data-mui-test'] }],
];

module.exports = function getBabelConfig(api) {
const useESModules = api.env(['regressions', 'stable', 'rollup']);
const useESModules = !api.env(['node']);

const defaultAlias = {
'@base_ui/react': resolveAliasPath('./packages/mui-base/src'),
Expand Down Expand Up @@ -70,9 +66,16 @@ module.exports = function getBabelConfig(api) {
],
];

if (process.env.NODE_ENV === 'production') {
plugins.push(...productionPlugins);
}
const devPlugins = [
[
'babel-plugin-module-resolver',
{
root: ['./'],
alias: defaultAlias,
},
],
'babel-plugin-add-import-extension',
];

return {
assumptions: {
Expand All @@ -98,39 +101,17 @@ module.exports = function getBabelConfig(api) {
],
env: {
coverage: {
plugins: [
'babel-plugin-istanbul',
[
'babel-plugin-module-resolver',
{
root: ['./'],
alias: defaultAlias,
},
],
],
plugins: ['babel-plugin-istanbul', ...devPlugins],
},
development: {
plugins: [
[
'babel-plugin-module-resolver',
{
root: ['./'],
alias: defaultAlias,
},
],
],
plugins: devPlugins,
},
test: {
sourceMaps: 'both',
plugins: [
[
'babel-plugin-module-resolver',
{
root: ['./'],
alias: defaultAlias,
},
],
],
plugins: devPlugins,
},
production: {
plugins: ['babel-plugin-add-import-extension'],
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion docs/vitest.config.ts → docs/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mergeConfig, defineProject } from 'vitest/config';
import sharedConfig from '../vitest.shared';
import sharedConfig from '../vitest.shared.mts';

export default mergeConfig(
sharedConfig,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"@vitest/coverage-v8": "^2.1.4",
"@vitest/ui": "2.1.4",
"babel-loader": "^9.2.1",
"babel-plugin-add-import-extension": "1.6.0",
"babel-plugin-istanbul": "^6.1.1",
"babel-plugin-macros": "^3.1.0",
"babel-plugin-module-resolver": "^5.0.2",
Expand Down
15 changes: 13 additions & 2 deletions packages/mui-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"private": false,
"author": "MUI Team",
"description": "Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.",
"main": "./src/index.ts",
"keywords": [
"react",
"react-component",
Expand All @@ -26,15 +25,25 @@
"type": "opencollective",
"url": "https://opencollective.com/mui-org"
},
"exports": {
".": {
"import": "./src/index.ts"
},
"./*": {
"import": "./src/*/index.ts"
}
},
"imports": {
"#test-utils": "./test/index.ts"
},
"type": "commonjs",
"scripts": {
"build": "pnpm build:node && pnpm build:stable && pnpm build:types && pnpm build:copy-files",
"build:node": "node ../../scripts/build.mjs node",
"build:stable": "node ../../scripts/build.mjs stable",
"build:copy-files": "node ../../scripts/copyFiles.mjs",
"build:types": "tsc -b tsconfig.build.json",
"build:types": "tsc -b tsconfig.build.json && tsc -b tsconfig.build.cjs.json && tsc-alias -p tsconfig.build.json",
"test:package-types": "attw --pack ./build --include-entrypoints ./Accordion ./Menu ./Tooltip",
"prebuild": "rimraf --glob build build-tests \"*.tsbuildinfo\"",
"release": "pnpm build && pnpm publish",
"test": "cd ../../ && cross-env NODE_ENV=test mocha 'packages/mui-base/**/*.test.{js,ts,tsx}'",
Expand All @@ -52,6 +61,7 @@
"use-sync-external-store": "^1.2.2"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.16.4",
"@mui/internal-test-utils": "https://pkg.csb.dev/mui/material-ui/commit/92c23999/@mui/internal-test-utils",
"@testing-library/react": "^16.0.1",
"@testing-library/user-event": "^14.5.2",
Expand All @@ -68,6 +78,7 @@
"react": "19.0.0-rc-fb9a90fa48-20240614",
"react-dom": "19.0.0-rc-fb9a90fa48-20240614",
"sinon": "^19.0.2",
"tsc-alias": "^1.8.10",
"typescript": "^5.6.3"
},
"peerDependencies": {
Expand Down
8 changes: 8 additions & 0 deletions packages/mui-base/tsconfig.build.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.build.json",
"compilerOptions": {
"module": "node16",
"moduleResolution": "node16",
"outDir": "build/cjs"
}
}
7 changes: 5 additions & 2 deletions packages/mui-base/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
"moduleResolution": "bundler",
"noEmit": false,
"rootDir": "./src",
"outDir": "build"
"outDir": "build/esm"
},
"include": ["src/**/*.ts*"],
"exclude": ["src/**/*.spec.ts*", "src/**/*.test.ts*"]
"exclude": ["src/**/*.spec.ts*", "src/**/*.test.ts*"],
"tsc-alias": {
"resolveFullPaths": true
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mergeConfig, defineProject } from 'vitest/config';
import sharedConfig from '../../vitest.shared';
import sharedConfig from '../../vitest.shared.mts';

export default mergeConfig(
sharedConfig,
Expand Down
Loading
Loading