Skip to content

Commit

Permalink
[core] Simplify build scripts (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaldudak authored Mar 15, 2024
1 parent b549297 commit e70cc74
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 49 deletions.
23 changes: 2 additions & 21 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const productionPlugins = [
];

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

const defaultAlias = {
'@mui/base': resolveAliasPath('./packages/mui-base/src'),
Expand All @@ -32,7 +32,6 @@ module.exports = function getBabelConfig(api) {
browserslistEnv: process.env.BABEL_ENV || process.env.NODE_ENV,
debug: process.env.MUI_BUILD_VERBOSE === 'true',
modules: useESModules ? false : 'commonjs',
shippedProposals: api.env('modern'),
},
],
[
Expand Down Expand Up @@ -80,15 +79,6 @@ module.exports = function getBabelConfig(api) {
if (process.env.NODE_ENV === 'production') {
plugins.push(...productionPlugins);
}
if (process.env.NODE_ENV === 'test') {
plugins.push([
'babel-plugin-module-resolver',
{
alias: defaultAlias,
root: ['./'],
},
]);
}

return {
assumptions: {
Expand Down Expand Up @@ -121,11 +111,8 @@ module.exports = function getBabelConfig(api) {
[
'babel-plugin-module-resolver',
{
alias: {
...defaultAlias,
modules: './modules',
},
root: ['./'],
alias: defaultAlias,
},
],
],
Expand All @@ -140,12 +127,6 @@ module.exports = function getBabelConfig(api) {
],
],
},
legacy: {
plugins: [
// IE11 support
'@babel/plugin-transform-object-assign',
],
},
test: {
sourceMaps: 'both',
plugins: [
Expand Down
9 changes: 4 additions & 5 deletions packages/mui-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@
"url": "https://opencollective.com/mui-org"
},
"scripts": {
"build": "pnpm build:legacy && pnpm build:modern && pnpm build:node && pnpm build:stable && pnpm build:types && pnpm build:copy-files",
"build:legacy": "node ../../scripts/build.mjs legacy",
"build:modern": "node ../../scripts/build.mjs modern",
"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": "node ../../scripts/buildTypes.mjs",
"build:types": "tsc -b tsconfig.build.json",
"prebuild": "rimraf build tsconfig.build.tsbuildinfo",
"release": "pnpm build && pnpm publish",
"test": "cd ../../ && cross-env NODE_ENV=test mocha 'packages/mui-base/**/*.test.{js,ts,tsx}'",
Expand Down Expand Up @@ -65,7 +63,8 @@
"lodash": "^4.17.21",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"sinon": "^17.0.1"
"sinon": "^17.0.1",
"typescript": "^5.3.3"
},
"peerDependencies": {
"@types/react": "^17.0.0 || ^18.0.0",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import { getWorkspaceRoot } from './utils.mjs';
const exec = promisify(childProcess.exec);

const validBundles = [
// legacy build using ES6 modules
'legacy',
// modern build with a rolling target using ES6 modules
'modern',
// build for node using commonJS modules
'node',
// build with a hardcoded target using ES6 modules
Expand Down Expand Up @@ -63,9 +59,7 @@ async function run(argv) {
// TODO v6: Switch to `exports` field.
{
node: topLevelPathImportsCanBePackages ? './node' : './',
modern: './modern',
stable: topLevelPathImportsCanBePackages ? './' : './esm',
legacy: './legacy',
}[bundle],
);

Expand Down
29 changes: 12 additions & 17 deletions scripts/copyFiles.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,19 @@ async function addLicense(packageData) {
*/
`;
await Promise.all(
[
'./index.js',
'./legacy/index.js',
'./modern/index.js',
'./node/index.js',
'./umd/material-ui.development.js',
'./umd/material-ui.production.min.js',
].map(async (file) => {
try {
await prepend(path.resolve(buildPath, file), license);
} catch (err) {
if (err.code === 'ENOENT') {
console.log(`Skipped license for ${file}`);
} else {
throw err;
['./index.js', './legacy/index.js', './modern/index.js', './node/index.js'].map(
async (file) => {
try {
await prepend(path.resolve(buildPath, file), license);
} catch (err) {
if (err.code === 'ENOENT') {
console.log(`Skipped license for ${file}`);
} else {
throw err;
}
}
}
}),
},
),
);
}

Expand Down

0 comments on commit e70cc74

Please sign in to comment.