From c18af7415686d957fc4a2b512d4937ff21ad74aa Mon Sep 17 00:00:00 2001 From: Rom Grk Date: Mon, 17 Jul 2023 23:46:38 -0400 Subject: [PATCH 1/6] chore: share babel config --- babel.config.js | 63 +++++++++++++++++------------------ docs/babel.config.js | 79 +++++++++++++++++++++++--------------------- 2 files changed, 71 insertions(+), 71 deletions(-) diff --git a/babel.config.js b/babel.config.js index 5696f47bba614..640c60092577f 100644 --- a/babel.config.js +++ b/babel.config.js @@ -22,6 +22,31 @@ const defaultAlias = { packages: resolveAliasPath('./packages'), }; +const basePlugins = [ + 'babel-plugin-optimize-clsx', + // Need the following 3 proposals for all targets in .browserslistrc. + // With our usage the transpiled loose mode is equivalent to spec mode. + ['@babel/plugin-proposal-class-properties', { loose: true }], + ['@babel/plugin-proposal-private-methods', { loose: true }], + ['@babel/plugin-proposal-private-property-in-object', { loose: true }], + ['@babel/plugin-proposal-object-rest-spread', { loose: true }], + [ + '@babel/plugin-transform-runtime', + { + useESModules, + // any package needs to declare 7.4.4 as a runtime dependency. default is ^7.0.0 + version: '^7.4.4', + }, + ], + [ + 'babel-plugin-transform-react-remove-prop-types', + { + mode: 'unsafe-wrap', + ignoreFilenames: ['DataGrid.tsx', 'DataGridPro.tsx'], + }, + ], +]; + const productionPlugins = [ ['babel-plugin-react-remove-properties', { properties: ['data-mui-test'] }], ]; @@ -49,30 +74,7 @@ module.exports = function getBabelConfig(api) { '@babel/preset-typescript', ]; - const plugins = [ - 'babel-plugin-optimize-clsx', - // Need the following 3 proposals for all targets in .browserslistrc. - // With our usage the transpiled loose mode is equivalent to spec mode. - ['@babel/plugin-proposal-class-properties', { loose: true }], - ['@babel/plugin-proposal-private-methods', { loose: true }], - ['@babel/plugin-proposal-private-property-in-object', { loose: true }], - ['@babel/plugin-proposal-object-rest-spread', { loose: true }], - [ - '@babel/plugin-transform-runtime', - { - useESModules, - // any package needs to declare 7.4.4 as a runtime dependency. default is ^7.0.0 - version: '^7.4.4', - }, - ], - [ - 'babel-plugin-transform-react-remove-prop-types', - { - mode: 'unsafe-wrap', - ignoreFilenames: ['DataGrid.tsx', 'DataGridPro.tsx'], - }, - ], - ]; + const plugins = basePlugins.slice(); if (process.env.NODE_ENV === 'production') { plugins.push(...productionPlugins); @@ -91,19 +93,14 @@ module.exports = function getBabelConfig(api) { ]); } } - if (process.env.NODE_ENV === 'test') { - plugins.push([ - 'babel-plugin-module-resolver', - { - alias: defaultAlias, - root: ['./'], - }, - ]); - } return { assumptions: { noDocumentAll: true, + setPublicClassFields: true, + privateFieldsAsProperties: true, + objectRestNoSymbols: true, + setSpreadProperties: true, }, presets, plugins, diff --git a/docs/babel.config.js b/docs/babel.config.js index 3a7f35d51e4ed..6cbec4964df64 100644 --- a/docs/babel.config.js +++ b/docs/babel.config.js @@ -1,3 +1,4 @@ +const getBaseConfig = require('../babel.config'); const fse = require('fs-extra'); const alias = { @@ -21,45 +22,47 @@ const { version: transformRuntimeVersion } = fse.readJSONSync( require.resolve('@babel/runtime-corejs2/package.json'), ); -module.exports = { - presets: [ - // backport of https://github.com/zeit/next.js/pull/9511 - ['next/babel', { 'transform-runtime': { corejs: 2, version: transformRuntimeVersion } }], - ], - plugins: [ - [ - 'babel-plugin-transform-rename-import', - { - replacements: [{ original: '@mui/utils/macros/MuiError.macro', replacement: 'react' }], - }, - ], - 'babel-plugin-optimize-clsx', - // for IE 11 support - '@babel/plugin-transform-object-assign', - 'babel-plugin-preval', - [ - 'babel-plugin-module-resolver', - { - alias, - transformFunctions: ['require', 'require.context'], - }, +module.exports = function getBabelConfig() { + const baseConfig = getBaseConfig(); + + return { + assumptions: baseConfig.assumptions, + presets: [ + // backport of https://github.com/zeit/next.js/pull/9511 + ['next/babel', { 'transform-runtime': { corejs: 2, version: transformRuntimeVersion } }], ], - ], - ignore: [ - // Fix a Windows issue. - /@babel[\\|/]runtime/, - // Fix const foo = /{{(.+?)}}/gs; crashing. - /prettier/, - /@mui[\\|/]docs[\\|/]markdown/, - ], - env: { - production: { - plugins: [ - // TODO fix useGridSelector side effect and enable back. - // '@babel/plugin-transform-react-constant-elements', - ['babel-plugin-react-remove-properties', { properties: ['data-mui-test'] }], - ['babel-plugin-transform-react-remove-prop-types', { mode: 'remove' }], + plugins: [ + ...baseConfig.plugins, + [ + 'babel-plugin-transform-rename-import', + { + replacements: [{ original: '@mui/utils/macros/MuiError.macro', replacement: 'react' }], + }, ], + // for IE 11 support + '@babel/plugin-transform-object-assign', + 'babel-plugin-preval', + [ + 'babel-plugin-module-resolver', + { + alias, + transformFunctions: ['require', 'require.context'], + }, + ], + ], + ignore: [ + ...baseConfig.ignore, + /@mui[\\|/]docs[\\|/]markdown/, + ], + env: { + production: { + plugins: [ + // TODO fix useGridSelector side effect and enable back. + // '@babel/plugin-transform-react-constant-elements', + ['babel-plugin-react-remove-properties', { properties: ['data-mui-test'] }], + ['babel-plugin-transform-react-remove-prop-types', { mode: 'remove' }], + ], + }, }, - }, + } }; From 84178f11395e673ec9581894e022716e65b37d95 Mon Sep 17 00:00:00 2001 From: Rom Grk Date: Mon, 17 Jul 2023 23:56:38 -0400 Subject: [PATCH 2/6] lint --- babel.config.js | 58 ++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/babel.config.js b/babel.config.js index 640c60092577f..5bacac20917e5 100644 --- a/babel.config.js +++ b/babel.config.js @@ -22,35 +22,6 @@ const defaultAlias = { packages: resolveAliasPath('./packages'), }; -const basePlugins = [ - 'babel-plugin-optimize-clsx', - // Need the following 3 proposals for all targets in .browserslistrc. - // With our usage the transpiled loose mode is equivalent to spec mode. - ['@babel/plugin-proposal-class-properties', { loose: true }], - ['@babel/plugin-proposal-private-methods', { loose: true }], - ['@babel/plugin-proposal-private-property-in-object', { loose: true }], - ['@babel/plugin-proposal-object-rest-spread', { loose: true }], - [ - '@babel/plugin-transform-runtime', - { - useESModules, - // any package needs to declare 7.4.4 as a runtime dependency. default is ^7.0.0 - version: '^7.4.4', - }, - ], - [ - 'babel-plugin-transform-react-remove-prop-types', - { - mode: 'unsafe-wrap', - ignoreFilenames: ['DataGrid.tsx', 'DataGridPro.tsx'], - }, - ], -]; - -const productionPlugins = [ - ['babel-plugin-react-remove-properties', { properties: ['data-mui-test'] }], -]; - module.exports = function getBabelConfig(api) { const useESModules = api.env(['legacy', 'modern', 'stable', 'rollup']); @@ -74,7 +45,34 @@ module.exports = function getBabelConfig(api) { '@babel/preset-typescript', ]; - const plugins = basePlugins.slice(); + const plugins = [ + 'babel-plugin-optimize-clsx', + // Need the following 3 proposals for all targets in .browserslistrc. + // With our usage the transpiled loose mode is equivalent to spec mode. + ['@babel/plugin-proposal-class-properties', { loose: true }], + ['@babel/plugin-proposal-private-methods', { loose: true }], + ['@babel/plugin-proposal-private-property-in-object', { loose: true }], + ['@babel/plugin-proposal-object-rest-spread', { loose: true }], + [ + '@babel/plugin-transform-runtime', + { + useESModules, + // any package needs to declare 7.4.4 as a runtime dependency. default is ^7.0.0 + version: '^7.4.4', + }, + ], + [ + 'babel-plugin-transform-react-remove-prop-types', + { + mode: 'unsafe-wrap', + ignoreFilenames: ['DataGrid.tsx', 'DataGridPro.tsx'], + }, + ], + ]; + + const productionPlugins = [ + ['babel-plugin-react-remove-properties', { properties: ['data-mui-test'] }], + ]; if (process.env.NODE_ENV === 'production') { plugins.push(...productionPlugins); From 93a8adbbfaa4c33ba03e2cea60a07f024d35995d Mon Sep 17 00:00:00 2001 From: Rom Grk Date: Mon, 17 Jul 2023 23:57:16 -0400 Subject: [PATCH 3/6] lint --- docs/babel.config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/babel.config.js b/docs/babel.config.js index 6cbec4964df64..3469e6c49f2b0 100644 --- a/docs/babel.config.js +++ b/docs/babel.config.js @@ -22,8 +22,8 @@ const { version: transformRuntimeVersion } = fse.readJSONSync( require.resolve('@babel/runtime-corejs2/package.json'), ); -module.exports = function getBabelConfig() { - const baseConfig = getBaseConfig(); +module.exports = function getBabelConfig(api) { + const baseConfig = getBaseConfig(api); return { assumptions: baseConfig.assumptions, From 7d0bee560957434130c8bb1662e4141443a7b248 Mon Sep 17 00:00:00 2001 From: Rom Grk Date: Tue, 18 Jul 2023 00:02:49 -0400 Subject: [PATCH 4/6] lint --- babel.config.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/babel.config.js b/babel.config.js index 5bacac20917e5..5cec110bfc1c0 100644 --- a/babel.config.js +++ b/babel.config.js @@ -49,10 +49,10 @@ module.exports = function getBabelConfig(api) { 'babel-plugin-optimize-clsx', // Need the following 3 proposals for all targets in .browserslistrc. // With our usage the transpiled loose mode is equivalent to spec mode. - ['@babel/plugin-proposal-class-properties', { loose: true }], - ['@babel/plugin-proposal-private-methods', { loose: true }], - ['@babel/plugin-proposal-private-property-in-object', { loose: true }], - ['@babel/plugin-proposal-object-rest-spread', { loose: true }], + '@babel/plugin-proposal-class-properties', + '@babel/plugin-proposal-private-methods', + '@babel/plugin-proposal-private-property-in-object', + '@babel/plugin-proposal-object-rest-spread', [ '@babel/plugin-transform-runtime', { From d99c46ce1f16bba983c2c67ff54139b953beadfd Mon Sep 17 00:00:00 2001 From: Rom Grk Date: Tue, 18 Jul 2023 00:08:24 -0400 Subject: [PATCH 5/6] lint --- docs/babel.config.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/docs/babel.config.js b/docs/babel.config.js index 3469e6c49f2b0..b4d12d1529200 100644 --- a/docs/babel.config.js +++ b/docs/babel.config.js @@ -1,5 +1,5 @@ -const getBaseConfig = require('../babel.config'); const fse = require('fs-extra'); +const getBaseConfig = require('../babel.config'); const alias = { '@mui/x-data-grid': '../packages/grid/x-data-grid/src', @@ -50,10 +50,7 @@ module.exports = function getBabelConfig(api) { }, ], ], - ignore: [ - ...baseConfig.ignore, - /@mui[\\|/]docs[\\|/]markdown/, - ], + ignore: [...baseConfig.ignore, /@mui[\\|/]docs[\\|/]markdown/], env: { production: { plugins: [ @@ -64,5 +61,5 @@ module.exports = function getBabelConfig(api) { ], }, }, - } + }; }; From d0d0002328c4c0b7884c08e9eaa491ec095ffd9d Mon Sep 17 00:00:00 2001 From: Rom Grk Date: Wed, 19 Jul 2023 17:41:40 -0400 Subject: [PATCH 6/6] build --- babel.config.js | 25 +++++++++++++------------ docs/babel.config.js | 10 ---------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/babel.config.js b/babel.config.js index 5cec110bfc1c0..fe41073ca1afa 100644 --- a/babel.config.js +++ b/babel.config.js @@ -22,6 +22,10 @@ const defaultAlias = { packages: resolveAliasPath('./packages'), }; +const productionPlugins = [ + ['babel-plugin-react-remove-properties', { properties: ['data-mui-test'] }], +]; + module.exports = function getBabelConfig(api) { const useESModules = api.env(['legacy', 'modern', 'stable', 'rollup']); @@ -49,10 +53,10 @@ module.exports = function getBabelConfig(api) { 'babel-plugin-optimize-clsx', // Need the following 3 proposals for all targets in .browserslistrc. // With our usage the transpiled loose mode is equivalent to spec mode. - '@babel/plugin-proposal-class-properties', - '@babel/plugin-proposal-private-methods', - '@babel/plugin-proposal-private-property-in-object', - '@babel/plugin-proposal-object-rest-spread', + ['@babel/plugin-proposal-class-properties', { loose: true }], + ['@babel/plugin-proposal-private-methods', { loose: true }], + ['@babel/plugin-proposal-private-property-in-object', { loose: true }], + ['@babel/plugin-proposal-object-rest-spread', { loose: true }], [ '@babel/plugin-transform-runtime', { @@ -70,10 +74,6 @@ module.exports = function getBabelConfig(api) { ], ]; - const productionPlugins = [ - ['babel-plugin-react-remove-properties', { properties: ['data-mui-test'] }], - ]; - if (process.env.NODE_ENV === 'production') { plugins.push(...productionPlugins); @@ -95,10 +95,11 @@ module.exports = function getBabelConfig(api) { return { assumptions: { noDocumentAll: true, - setPublicClassFields: true, - privateFieldsAsProperties: true, - objectRestNoSymbols: true, - setSpreadProperties: true, + // TODO: Replace "loose" mode with these: + // setPublicClassFields: true, + // privateFieldsAsProperties: true, + // objectRestNoSymbols: true, + // setSpreadProperties: true, }, presets, plugins, diff --git a/docs/babel.config.js b/docs/babel.config.js index b4d12d1529200..acc525f6be13b 100644 --- a/docs/babel.config.js +++ b/docs/babel.config.js @@ -51,15 +51,5 @@ module.exports = function getBabelConfig(api) { ], ], ignore: [...baseConfig.ignore, /@mui[\\|/]docs[\\|/]markdown/], - env: { - production: { - plugins: [ - // TODO fix useGridSelector side effect and enable back. - // '@babel/plugin-transform-react-constant-elements', - ['babel-plugin-react-remove-properties', { properties: ['data-mui-test'] }], - ['babel-plugin-transform-react-remove-prop-types', { mode: 'remove' }], - ], - }, - }, }; };