From 9f10bb771d8d5631e5d7cfa5c50d381c9c1f435a Mon Sep 17 00:00:00 2001 From: Lukas Date: Wed, 20 Dec 2023 16:55:37 +0200 Subject: [PATCH 1/3] [core] Remove explicit `mui-x` dependency resolving --- docs/src/modules/sandbox/Dependencies.ts | 54 ++++++------------------ 1 file changed, 13 insertions(+), 41 deletions(-) diff --git a/docs/src/modules/sandbox/Dependencies.ts b/docs/src/modules/sandbox/Dependencies.ts index c4c618a7f3f081..c3fb6309885e02 100644 --- a/docs/src/modules/sandbox/Dependencies.ts +++ b/docs/src/modules/sandbox/Dependencies.ts @@ -1,13 +1,6 @@ import { CODE_VARIANTS } from 'docs/src/modules/constants'; import type { MuiProductId } from 'docs/src/modules/utils/getProductInfoFromUrl'; -type RegExpMatchArrayWithGroupsOnly = { - groups?: { - [key in keyof T]: string; - }; -}; -type RegExpMatchArrayWithGroups = (RegExpMatchArray & RegExpMatchArrayWithGroupsOnly) | null; - export default function SandboxDependencies( demo: { raw: string; @@ -62,6 +55,8 @@ export default function SandboxDependencies( } function extractDependencies(raw: string) { + const muiDocConfig = (window as any).muiDocConfig; + function includePeerDependencies( deps: Record, versions: Record, @@ -78,13 +73,11 @@ export default function SandboxDependencies( newDeps['@mui/material'] = versions['@mui/material']; } - if (newDeps['@mui/x-data-grid']) { - newDeps['@mui/material'] = versions['@mui/material']; - } - // TODO: consider if this configuration could be injected in a "cleaner" way. - if ((window as any).muiDocConfig) { - newDeps = (window as any).muiDocConfig.csbIncludePeerDependencies(newDeps, { versions }); + if (muiDocConfig) { + newDeps = muiDocConfig.csbIncludePeerDependencies(newDeps, { + versions, + }); } return newDeps; @@ -110,9 +103,9 @@ export default function SandboxDependencies( }; // TODO: consider if this configuration could be injected in a "cleaner" way. - if ((window as any).muiDocConfig) { + if (muiDocConfig) { const muiCommitRef = process.env.PULL_REQUEST_ID ? process.env.COMMIT_REF : undefined; - versions = (window as any).muiDocConfig.csbGetVersions(versions, { muiCommitRef }); + versions = muiDocConfig.csbGetVersions(versions, { muiCommitRef }); } const re = /^import\s'([^']+)'|import\s[\s\S]*?\sfrom\s+'([^']+)/gm; @@ -125,35 +118,14 @@ export default function SandboxDependencies( fullName.charAt(0) === '@' ? fullName.split('/', 2).join('/') : fullName.split('/', 1)[0]; if (!deps[name] && !name.startsWith('.')) { - deps[name] = versions[name] ? versions[name] : 'latest'; + deps[name] = versions[name] ?? 'latest'; } - // e.g. date-fns - const dateAdapterMatch = fullName.match( - /^@mui\/(lab|x-date-pickers)\/(?Adapter.*)/, - ) as RegExpMatchArrayWithGroups<{ adapterName: string }>; - if (dateAdapterMatch !== null) { - /** - * Mapping from the date adapter sub-packages to the npm packages they require. - * @example `@mui/x-date-pickers/AdapterDayjs` has a peer dependency on `dayjs`. - */ - const packageName = ( - { - AdapterDateFns: 'date-fns', - AdapterDateFnsJalali: 'date-fns-jalali', - AdapterDayjs: 'dayjs', - AdapterLuxon: 'luxon', - AdapterMoment: 'moment', - AdapterMomentHijri: 'moment-hijri', - AdapterMomentJalaali: 'moment-jalaali', - } as Record - )[dateAdapterMatch.groups?.adapterName || '']; - if (packageName === undefined) { - throw new TypeError( - `Can't determine required npm package for adapter '${dateAdapterMatch[1]}'`, - ); + if (muiDocConfig) { + const resolvedDep = muiDocConfig?.postProcessImport(fullName); + if (resolvedDep) { + deps = { ...deps, ...resolvedDep }; } - deps[packageName] = 'latest'; } } From 5dbb0ac2bea2373abb192c60b7ea21e019a9bd15 Mon Sep 17 00:00:00 2001 From: Lukas Date: Wed, 20 Dec 2023 18:41:42 +0200 Subject: [PATCH 2/3] Remove `mui-x` related tests --- docs/src/modules/sandbox/Dependencies.test.js | 67 ------------------- 1 file changed, 67 deletions(-) diff --git a/docs/src/modules/sandbox/Dependencies.test.js b/docs/src/modules/sandbox/Dependencies.test.js index 98ea35a1c8e950..71b4f6b1cba69b 100644 --- a/docs/src/modules/sandbox/Dependencies.test.js +++ b/docs/src/modules/sandbox/Dependencies.test.js @@ -102,7 +102,6 @@ import { LocalizationProvider as MuiPickersLocalizationProvider, KeyboardTimePic '@emotion/styled': 'latest', '@mui/material': 'latest', '@mui/lab': 'latest', - 'date-fns': 'latest', }); }); @@ -130,7 +129,6 @@ import 'exceljs'; '@emotion/styled': 'latest', '@mui/material': 'latest', '@mui/lab': 'latest', - 'date-fns': 'latest', exceljs: 'latest', }); }); @@ -199,7 +197,6 @@ import { '@emotion/styled': 'latest', '@mui/material': 'latest', '@mui/lab': 'latest', - 'date-fns': 'latest', }); }); @@ -258,70 +255,6 @@ import * as Utils from '@mui/utils'; }); }); - it('should handle date adapters', () => { - const source = ` -import * as React from 'react'; -import AdapterDateFns from '@mui/lab/AdapterDateFns'; -import AdapterDayjs from '@mui/lab/AdapterDayjs'; -import AdapterLuxon from '@mui/lab/AdapterLuxon'; -import AdapterMoment from '@mui/lab/AdapterMoment'; - `; - - const { dependencies } = SandboxDependencies({ - raw: source, - codeVariant: 'JS', - }); - - expect(dependencies).to.deep.equal({ - react: 'latest', - 'react-dom': 'latest', - '@emotion/react': 'latest', - '@emotion/styled': 'latest', - '@mui/material': 'latest', - '@mui/lab': 'latest', - 'date-fns': 'latest', - dayjs: 'latest', - luxon: 'latest', - moment: 'latest', - }); - }); - - it('should handle dependencies for @mui/x-date-pickers', () => { - const source = ` -import * as React from 'react'; -import TextField from '@mui/material/TextField'; -import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns'; -import { AdapterDateFnsJalali } from '@mui/x-date-pickers/AdapterDateFnsJalali'; -import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; -import { AdapterLuxon } from '@mui/x-date-pickers/AdapterLuxon'; -import { AdapterMoment } from '@mui/x-date-pickers/AdapterMoment'; -import { AdapterMomentHijri } from '@mui/x-date-pickers/AdapterMomentHijri'; -import { AdapterMomentJalaali } from '@mui/x-date-pickers/AdapterMomentJalaali'; -import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; -import { DatePicker } from '@mui/x-date-pickers/DatePicker';`; - - const { dependencies } = SandboxDependencies({ - raw: source, - codeVariant: 'JS', - }); - - expect(dependencies).to.deep.equal({ - react: 'latest', - 'react-dom': 'latest', - '@emotion/react': 'latest', - '@emotion/styled': 'latest', - '@mui/material': 'latest', - '@mui/x-date-pickers': 'latest', - 'date-fns': 'latest', - 'date-fns-jalali': 'latest', - dayjs: 'latest', - luxon: 'latest', - moment: 'latest', - 'moment-hijri': 'latest', - 'moment-jalaali': 'latest', - }); - }); - it('should not have . as a dependency', () => { const source = `import * as React from 'react'; import Box, { BoxProps } from '@mui/joy/Box'; From bed98a3b2123b992bd0541f1bcb0133741418b95 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 21 Dec 2023 10:26:10 +0200 Subject: [PATCH 3/3] Revert explicit `mui/material` inclusion in case of Data Grid demo --- docs/src/modules/sandbox/Dependencies.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/src/modules/sandbox/Dependencies.ts b/docs/src/modules/sandbox/Dependencies.ts index c3fb6309885e02..f42f75164be5d1 100644 --- a/docs/src/modules/sandbox/Dependencies.ts +++ b/docs/src/modules/sandbox/Dependencies.ts @@ -73,6 +73,10 @@ export default function SandboxDependencies( newDeps['@mui/material'] = versions['@mui/material']; } + if (newDeps['@mui/x-data-grid']) { + newDeps['@mui/material'] = versions['@mui/material']; + } + // TODO: consider if this configuration could be injected in a "cleaner" way. if (muiDocConfig) { newDeps = muiDocConfig.csbIncludePeerDependencies(newDeps, {