From c1e460d071c831641f2bc2d5ee57c74d629c45c9 Mon Sep 17 00:00:00 2001 From: DiegoAndai Date: Tue, 6 Aug 2024 11:27:52 -0400 Subject: [PATCH] Add parsed exports --- packages/mui-material/src/index.d.ts | 5 +++-- packages/mui-material/src/index.js | 5 +++-- packages/mui-material/src/index.test.js | 15 ++++++++++--- packages/mui-material/src/version/index.ts | 25 ++++++++++++++++++++++ packages/mui-system/src/index.d.ts | 5 +++-- packages/mui-system/src/index.js | 4 ++-- packages/mui-system/src/version/index.ts | 25 ++++++++++++++++++++++ 7 files changed, 73 insertions(+), 11 deletions(-) create mode 100644 packages/mui-material/src/version/index.ts create mode 100644 packages/mui-system/src/version/index.ts diff --git a/packages/mui-material/src/index.d.ts b/packages/mui-material/src/index.d.ts index c20f8a57dc583a..dab4161e3304c4 100644 --- a/packages/mui-material/src/index.d.ts +++ b/packages/mui-material/src/index.d.ts @@ -2,8 +2,6 @@ import * as React from 'react'; import { DistributiveOmit } from '@mui/types'; import { StyledComponentProps } from './styles'; -export const version: string; - export { StyledComponentProps }; /** @@ -477,6 +475,9 @@ export * from './useAutocomplete'; export { default as GlobalStyles } from './GlobalStyles'; export * from './GlobalStyles'; +export { default as version } from './version'; +export * from './version'; + /** * @deprecated will be removed in v5.beta, please use StyledEngineProvider from @mui/material/styles instead */ diff --git a/packages/mui-material/src/index.js b/packages/mui-material/src/index.js index 53f7e54af0bbf2..3586991f521f5b 100644 --- a/packages/mui-material/src/index.js +++ b/packages/mui-material/src/index.js @@ -1,8 +1,6 @@ /* eslint-disable import/export */ import * as colors from './colors'; -export const version = process.env.MUI_PACKAGE_VERSION; - export { colors }; export * from './styles'; @@ -418,3 +416,6 @@ export * from './generateUtilityClass'; export { default as generateUtilityClasses } from './generateUtilityClasses'; export { default as Unstable_TrapFocus } from './Unstable_TrapFocus'; + +export { default as version } from './version'; +export * from './version'; diff --git a/packages/mui-material/src/index.test.js b/packages/mui-material/src/index.test.js index df67ee7a06abdf..f015581099d04e 100644 --- a/packages/mui-material/src/index.test.js +++ b/packages/mui-material/src/index.test.js @@ -6,15 +6,24 @@ import { expect } from 'chai'; import * as MaterialUI from './index'; +const versionExports = [ + 'version', + 'major', + 'minor', + 'patch', + 'preReleaseLabel', + 'preReleaseNumber', +]; + describe('material-ui', () => { it('should have exports', () => { expect(typeof MaterialUI).to.equal('object'); }); it('should not have undefined exports', () => { - Object.keys(MaterialUI).forEach((exportKey) => - expect(Boolean(MaterialUI[exportKey])).to.equal(true), - ); + Object.keys(MaterialUI) + .filter((exportKey) => !versionExports.includes(exportKey)) + .forEach((exportKey) => expect(Boolean(MaterialUI[exportKey])).to.equal(true)); }); it('should reexport certain members from @mui/base', () => { diff --git a/packages/mui-material/src/version/index.ts b/packages/mui-material/src/version/index.ts new file mode 100644 index 00000000000000..5dfb1765e2b19e --- /dev/null +++ b/packages/mui-material/src/version/index.ts @@ -0,0 +1,25 @@ +const version = process.env.MUI_PACKAGE_VERSION || null; + +let versionNumber: string | null = null; +let preReleaseInfo: string | null = null; + +if (version) { + [versionNumber, preReleaseInfo] = version.split('-'); +} + +let destructuredVersion: number[] | null[] = [null, null, null]; +let destructuredPreReleaseInfo: [string, number] | null[] = [null, null]; + +if (versionNumber) { + destructuredVersion = versionNumber.split('.').map(Number); +} + +if (preReleaseInfo) { + destructuredPreReleaseInfo = [preReleaseInfo.split('.')[0], Number(preReleaseInfo.split('.')[1])]; +} + +const [major, minor, patch] = destructuredVersion; +const [preReleaseLabel, preReleaseNumber] = destructuredPreReleaseInfo; + +export { version, major, minor, patch, preReleaseLabel, preReleaseNumber }; +export default version; diff --git a/packages/mui-system/src/index.d.ts b/packages/mui-system/src/index.d.ts index 01d294e68a4d6d..5f12b5b99a8f34 100644 --- a/packages/mui-system/src/index.d.ts +++ b/packages/mui-system/src/index.d.ts @@ -1,8 +1,6 @@ // disable automatic export export {}; -export const version: string; - export * from './borders'; export { default as breakpoints, handleBreakpoints, mergeBreakpointsInOrder } from './breakpoints'; @@ -124,3 +122,6 @@ export * from './Grid'; export { default as Stack } from './Stack'; export * from './Stack'; + +export { default as version } from './version'; +export * from './version'; diff --git a/packages/mui-system/src/index.js b/packages/mui-system/src/index.js index 9a266017c546a6..50d0639d765e14 100644 --- a/packages/mui-system/src/index.js +++ b/packages/mui-system/src/index.js @@ -1,7 +1,5 @@ import MuiError from '@mui/internal-babel-macros/MuiError.macro'; -export const version = process.env.MUI_PACKAGE_VERSION; - export { css, keyframes, StyledEngineProvider } from '@mui/styled-engine'; export { default as GlobalStyles } from './GlobalStyles'; export { default as borders } from './borders'; @@ -69,6 +67,8 @@ export { default as unstable_createCssVarsTheme } from './cssVars/createCssVarsT export { default as responsivePropType } from './responsivePropType'; export { default as RtlProvider } from './RtlProvider'; export * from './RtlProvider'; +export { default as version } from './version'; +export * from './version'; /** ----------------- */ /** Layout components */ diff --git a/packages/mui-system/src/version/index.ts b/packages/mui-system/src/version/index.ts new file mode 100644 index 00000000000000..5dfb1765e2b19e --- /dev/null +++ b/packages/mui-system/src/version/index.ts @@ -0,0 +1,25 @@ +const version = process.env.MUI_PACKAGE_VERSION || null; + +let versionNumber: string | null = null; +let preReleaseInfo: string | null = null; + +if (version) { + [versionNumber, preReleaseInfo] = version.split('-'); +} + +let destructuredVersion: number[] | null[] = [null, null, null]; +let destructuredPreReleaseInfo: [string, number] | null[] = [null, null]; + +if (versionNumber) { + destructuredVersion = versionNumber.split('.').map(Number); +} + +if (preReleaseInfo) { + destructuredPreReleaseInfo = [preReleaseInfo.split('.')[0], Number(preReleaseInfo.split('.')[1])]; +} + +const [major, minor, patch] = destructuredVersion; +const [preReleaseLabel, preReleaseNumber] = destructuredPreReleaseInfo; + +export { version, major, minor, patch, preReleaseLabel, preReleaseNumber }; +export default version;