Skip to content

Commit 74ac40c

Browse files
authored
[material-ui][mui-system] Cherry-pick: Add support for version runtime checks (#43190) (#43233)
1 parent a565be0 commit 74ac40c

File tree

12 files changed

+90
-4
lines changed

12 files changed

+90
-4
lines changed

babel.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,19 @@ module.exports = function getBabelConfig(api) {
8888
mode: 'unsafe-wrap',
8989
},
9090
],
91+
[
92+
'transform-inline-environment-variables',
93+
{
94+
include: [
95+
'MUI_VERSION',
96+
'MUI_MAJOR_VERSION',
97+
'MUI_MINOR_VERSION',
98+
'MUI_PATCH_VERSION',
99+
'MUI_PRERELEASE_LABEL',
100+
'MUI_PRERELEASE_NUMBER',
101+
],
102+
},
103+
],
91104
];
92105

93106
if (process.env.NODE_ENV === 'production') {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
"babel-plugin-module-resolver": "^5.0.0",
133133
"babel-plugin-optimize-clsx": "^2.6.2",
134134
"babel-plugin-react-remove-properties": "^0.3.0",
135+
"babel-plugin-transform-inline-environment-variables": "^0.4.4",
135136
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
136137
"chalk": "^5.3.0",
137138
"compression-webpack-plugin": "^11.1.0",

packages/mui-material/src/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,8 @@ export * from './useAutocomplete';
476476
export { default as GlobalStyles } from './GlobalStyles';
477477
export * from './GlobalStyles';
478478

479+
export * from './version';
480+
479481
/**
480482
* @deprecated will be removed in v5.beta, please use StyledEngineProvider from @mui/material/styles instead
481483
*/

packages/mui-material/src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,3 +417,5 @@ export * from './generateUtilityClass';
417417
export { default as generateUtilityClasses } from './generateUtilityClasses';
418418

419419
export { default as Unstable_TrapFocus } from './Unstable_TrapFocus';
420+
421+
export * from './version';

packages/mui-material/src/index.test.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,24 @@
66
import { expect } from 'chai';
77
import * as MaterialUI from './index';
88

9+
const versionExports = [
10+
'version',
11+
'major',
12+
'minor',
13+
'patch',
14+
'preReleaseLabel',
15+
'preReleaseNumber',
16+
];
17+
918
describe('material-ui', () => {
1019
it('should have exports', () => {
1120
expect(typeof MaterialUI).to.equal('object');
1221
});
1322

1423
it('should not have undefined exports', () => {
15-
Object.keys(MaterialUI).forEach((exportKey) =>
16-
expect(Boolean(MaterialUI[exportKey])).to.equal(true),
17-
);
24+
Object.keys(MaterialUI)
25+
.filter((exportKey) => !versionExports.includes(exportKey))
26+
.forEach((exportKey) => expect(Boolean(MaterialUI[exportKey])).to.equal(true));
1827
});
1928

2029
it('should reexport certain members from @mui/base', () => {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const version = process.env.MUI_VERSION;
2+
export const major = Number(process.env.MUI_MAJOR_VERSION);
3+
export const minor = Number(process.env.MUI_MINOR_VERSION);
4+
export const patch = Number(process.env.MUI_PATCH_VERSION);
5+
export const preReleaseLabel = process.env.MUI_PRERELEASE_LABEL || null;
6+
export const preReleaseNumber = Number(process.env.MUI_PRERELEASE_NUMBER) || null;
7+
8+
export default version;

packages/mui-system/src/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,5 @@ export * from './Unstable_Grid';
181181

182182
export { default as Stack } from './Stack';
183183
export * from './Stack';
184+
185+
export * from './version';

packages/mui-system/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export { default as unstable_createCssVarsTheme } from './cssVars/createCssVarsT
6666
export { default as responsivePropType } from './responsivePropType';
6767
export { default as RtlProvider } from './RtlProvider';
6868
export * from './RtlProvider';
69+
export * from './version';
6970

7071
/** ----------------- */
7172
/** Layout components */
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const version = process.env.MUI_VERSION;
2+
export const major = Number(process.env.MUI_MAJOR_VERSION);
3+
export const minor = Number(process.env.MUI_MINOR_VERSION);
4+
export const patch = Number(process.env.MUI_PATCH_VERSION);
5+
export const preReleaseLabel = process.env.MUI_PRERELEASE_LABEL || null;
6+
export const preReleaseNumber = Number(process.env.MUI_PRERELEASE_NUMBER) || null;
7+
8+
export default version;

pnpm-lock.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)