Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[code-infra] Fix bundler tests and cover @mui/material-nextjs #44966

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,13 @@ module.exports = /** @type {Config} */ ({
'import/extensions': ['error', 'ignorePackages'],
},
},
{
files: ['test/bundling/fixtures/**/*.?(c|m)[jt]s?(x)'],
rules: {
'react/prop-types': 'off',
'import/no-unresolved': 'off',
},
},
{
files: ['**/*.mjs'],
rules: {
Expand Down
9 changes: 5 additions & 4 deletions scripts/releasePack.mts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ interface RunOptions {

async function packWorkspace(workspace: WorkspaceDefinition, outDir: string): Promise<string> {
const packages: Record<string, string> = {};
const { stdout: zipFilePath } = await $({
const { stdout } = await $({
cwd: workspace.path,
})`pnpm pack --pack-destination ${outDir}`;
packages[workspace.name] = zipFilePath;
return zipFilePath;
})`pnpm pack --json --pack-destination ${outDir}`;
const result = JSON.parse(stdout);
packages[workspace.name] = result.filename;
return result.filename;
}

async function run({ packages, outDir, concurrency }: RunOptions) {
Expand Down
6 changes: 3 additions & 3 deletions test/bundling/fixtures/next-webpack4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"@mui/system": "workspace:*",
"@mui/utils": "workspace:*",
"next": "14.2.21",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-is": "^17.0.2"
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-is": "^18.2.0"
},
"devDependencies": {
"concurrently": "7.4.0",
Expand Down
9 changes: 6 additions & 3 deletions test/bundling/fixtures/next-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
},
"dependencies": {
"@emotion/core": "11.0.0",
"@emotion/react": "11.10.4",
"@emotion/styled": "11.10.4",
"@emotion/react": "11.14.0",
"@emotion/server": "11.11.0",
"@emotion/styled": "11.14.0",
"@mui/material": "workspace:*",
"@mui/material-nextjs": "workspace:*",
"@mui/icons-material": "workspace:*",
"@mui/lab": "workspace:*",
"@mui/styled-engine": "workspace:*",
"@mui/styles": "workspace:*",
"@mui/system": "workspace:*",
"@mui/utils": "workspace:*",
"next": "14.2.21",
"next": "15.1.3",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-is": "18.2.0"
Expand All @@ -29,6 +31,7 @@
"overrides": {
"@mui/base": "file:../../../../packed/@mui/base.tgz",
"@mui/material": "file:../../../../packed/@mui/material.tgz",
"@mui/material-nextjs": "file:../../../../packed/@mui/material-nextjs.tgz",
"@mui/icons-material": "file:../../../../packed/@mui/icons-material.tgz",
"@mui/lab": "file:../../../../packed/@mui/lab.tgz",
"@mui/styled-engine": "file:../../../../packed/@mui/styled-engine.tgz",
Expand Down
23 changes: 23 additions & 0 deletions test/bundling/fixtures/next-webpack5/pages/_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as React from 'react';
import Head from 'next/head';
import { AppCacheProvider } from '@mui/material-nextjs/v15-pagesRouter';
import { ThemeProvider } from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline';
import theme from '../src/theme';

export default function MyApp(props) {
const { Component, pageProps } = props;

return (
<AppCacheProvider {...props}>
<Head>
<meta name="viewport" content="initial-scale=1, width=device-width" />
</Head>
<ThemeProvider theme={theme}>
{/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
<CssBaseline />
<Component {...pageProps} />
</ThemeProvider>
</AppCacheProvider>
);
}
27 changes: 27 additions & 0 deletions test/bundling/fixtures/next-webpack5/pages/_document.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as React from 'react';
import { Html, Head, Main, NextScript } from 'next/document';
import { DocumentHeadTags, documentGetInitialProps } from '@mui/material-nextjs/v15-pagesRouter';
import theme from '../src/theme';

export default function MyDocument(props) {
return (
<Html lang="en">
<Head>
{/* PWA primary color */}
<meta name="theme-color" content={theme.palette.primary.main} />
<link rel="shortcut icon" href="/favicon.ico" />
<meta name="emotion-insertion-point" content="" />
<DocumentHeadTags {...props} />
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}

MyDocument.getInitialProps = async (ctx) => {
const finalProps = await documentGetInitialProps(ctx);
return finalProps;
};
30 changes: 30 additions & 0 deletions test/bundling/fixtures/next-webpack5/src/theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Roboto } from 'next/font/google';
import { createTheme } from '@mui/material/styles';
import { red } from '@mui/material/colors';

const roboto = Roboto({
weight: ['300', '400', '500', '700'],
subsets: ['latin'],
display: 'swap',
});

// Create a theme instance.
const theme = createTheme({
cssVariables: true,
palette: {
primary: {
main: '#556cd6',
},
secondary: {
main: '#19857b',
},
error: {
main: red.A400,
},
},
typography: {
fontFamily: roboto.style.fontFamily,
},
});

export default theme;
Loading