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] Move MuiError babel macro to babel plugin #43904

Merged
merged 30 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
898d46f
[code-infra] Move MuiError babel macros to babel plugin
Janpot Sep 27, 2024
0e4f0ce
Update babel.config.js
Janpot Sep 27, 2024
815a585
Update config.yml
Janpot Sep 27, 2024
7073b26
dwef
Janpot Sep 27, 2024
9fb40f5
wip
Janpot Sep 28, 2024
1a04819
clean p
Janpot Sep 28, 2024
7fcc5ce
Update dangerFileContent.ts
Janpot Sep 28, 2024
b705695
Update dangerFileContent.ts
Janpot Sep 28, 2024
53f24ad
All errors
Janpot Sep 30, 2024
36565ac
copy over tests
Janpot Sep 30, 2024
43edd08
Update pnpm-lock.yaml
Janpot Sep 30, 2024
56fd040
more tests
Janpot Sep 30, 2024
eb960df
remove babel-plugin-macros
Janpot Sep 30, 2024
1e851f1
new errors
Janpot Oct 1, 2024
94e0df1
newline
Janpot Oct 1, 2024
890be7d
dwef
Janpot Oct 1, 2024
151d2dd
Update formatMuiErrorMessage.ts
Janpot Oct 1, 2024
544874d
Update babel.config.js
Janpot Oct 1, 2024
607e9cf
Update babel.config.js
Janpot Oct 1, 2024
a90e7c2
comment marker
Janpot Oct 1, 2024
1814bc3
Update .eslintrc.js
Janpot Oct 1, 2024
dde2095
Update .eslintrc.js
Janpot Oct 1, 2024
4cd4eb7
Merge remote-tracking branch 'upstream/master' into replace-error-infra
Janpot Oct 1, 2024
b01c8c5
Merge remote-tracking branch 'upstream/master' into replace-error-infra
Janpot Oct 1, 2024
eda022b
tests
Janpot Oct 1, 2024
9e81663
Update createRenderer.tsx
Janpot Oct 1, 2024
3d54539
Merge remote-tracking branch 'upstream/master' into replace-error-infra
Janpot Oct 3, 2024
f3269ac
Merge remote-tracking branch 'upstream/master' into replace-error-infra
Janpot Oct 5, 2024
65cf4dd
rename
Janpot Oct 5, 2024
f49eba0
Update error-codes.json
Janpot Oct 7, 2024
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
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ default-job: &default-job
TEST_GATE: << parameters.test-gate >>
AWS_REGION_ARTIFACTS: eu-central-1
COREPACK_ENABLE_DOWNLOAD_PROMPT: '0'
DANGER_DISABLE_TRANSPILATION: 'true'
working_directory: /tmp/material-ui
docker:
- image: cimg/node:20.17
Expand Down
2 changes: 0 additions & 2 deletions .codesandbox/ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"node": "20",
"packages": [
"packages/markdown",
"packages/mui-babel-macros",
"packages/mui-base",
"packages/mui-codemod",
"packages/mui-core-downloads-tracker",
Expand Down Expand Up @@ -33,7 +32,6 @@
"@mui/docs": "packages/mui-docs/build",
"@mui/icons-material": "packages/mui-icons-material/build",
"@mui/internal-test-utils": "packages-internal/test-utils",
"@mui/internal-babel-macros": "packages/mui-babel-macros",
"@mui/internal-docs-utils": "packages-internal/docs-utils",
"@mui/internal-markdown": "packages/markdown",
"@mui/internal-scripts": "packages-internal/scripts",
Expand Down
16 changes: 7 additions & 9 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,6 @@ module.exports = function getBabelConfig(api) {

/** @type {babel.PluginItem[]} */
const plugins = [
[
'babel-plugin-macros',
{
muiError: {
errorCodesPath,
missingError,
},
},
],
'babel-plugin-optimize-clsx',
[
'@babel/plugin-transform-runtime',
Expand Down Expand Up @@ -114,6 +105,13 @@ module.exports = function getBabelConfig(api) {
],
},
],
[
'@mui/internal-babel-plugin-minify-errors',
{
missingError,
errorCodesPath,
},
],
...(useESModules
? [
[
Expand Down
6 changes: 4 additions & 2 deletions dangerfile.ts → dangerFileContent.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// danger has to be the first thing required!
import { danger, markdown } from 'danger';
import { exec } from 'child_process';
import type * as dangerModule from 'danger';
import { loadComparison } from './scripts/sizeSnapshot';
import replaceUrl from './packages/api-docs-builder/utils/replaceUrl';

declare const danger: (typeof dangerModule)['danger'];
declare const markdown: (typeof dangerModule)['markdown'];

const circleCIBuildNumber = process.env.CIRCLE_BUILD_NUM;
const circleCIBuildUrl = `https://app.circleci.com/pipelines/github/mui/material-ui/jobs/${circleCIBuildNumber}`;
const dangerCommand = process.env.DANGER_COMMAND;
Expand Down
7 changes: 7 additions & 0 deletions dangerfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// danger uses babelify under the hood. The implementation is buggy and fails on our
// custom plugins in our codebase. We'll just disable it and do our own compilation.
// Danger must always be run with envirnonent variable `DANGER_DISABLE_TRANSPILATION="true"`.
require('@babel/register')({
extensions: ['.js', '.ts', '.tsx'],
});
require('./dangerFileContent');
3 changes: 2 additions & 1 deletion docs/public/static/error-codes.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
"18": "MUI: The provided shorthand %s is invalid. The format should be `@<breakpoint | number>` or `@<breakpoint | number>/<container>`.\nFor example, `@sm` or `@600` or `@40rem/sidebar`.",
"19": "MUI: The `experimental_sx` has been moved to `theme.unstable_sx`.For more details, see https://github.com/mui/material-ui/pull/35150.",
"20": "MUI: `vars` is a private field used for CSS variables support.\nPlease use another name.",
"21": "MUI: The `colorSchemes.%s` option is either missing or invalid."
"21": "Invalid %s `%s` supplied to `%s`. Expected an HTMLElement.",
"22": "MUI: The `colorSchemes.%s` option is either missing or invalid."
JCQuintas marked this conversation as resolved.
Show resolved Hide resolved
}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"docs:typescript:formatted": "tsx ./docs/scripts/formattedTSDemos",
"docs:mdicons:synonyms": "cross-env BABEL_ENV=development babel-node --extensions \".tsx,.ts,.js,.mjs\" ./docs/scripts/updateIconSynonyms && pnpm prettier",
"docs:zipRules": "cd docs && rm mui-vale.zip && zip -r mui-vale.zip mui-vale && cd ../ && vale sync",
"extract-error-codes": "cross-env MUI_EXTRACT_ERROR_CODES=true lerna run --concurrency 8 build:modern",
"extract-error-codes": "cross-env MUI_EXTRACT_ERROR_CODES=true lerna run --concurrency 1 build:modern",
"rsc:build": "tsx ./packages/rsc-builder/buildRsc.ts",
"template:screenshot": "cross-env BABEL_ENV=development babel-node --extensions \".tsx,.ts,.js\" ./docs/scripts/generateTemplateScreenshots",
"template:update-theme": "cross-env BABEL_ENV=development babel-node --extensions \".tsx,.ts,.js\" ./docs/scripts/updateTemplatesTheme",
Expand Down Expand Up @@ -139,7 +139,6 @@
"@typescript-eslint/parser": "^7.18.0",
"babel-loader": "^9.2.1",
"babel-plugin-istanbul": "^7.0.0",
"babel-plugin-macros": "^3.1.0",
"babel-plugin-module-resolver": "^5.0.2",
"babel-plugin-optimize-clsx": "^2.6.2",
"babel-plugin-react-remove-properties": "^0.3.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
throw /* minify-error */ new Error('exists');
throw /* minify-error */ new Error('will be created');
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _formatMuiErrorMessage from '@mui/utils/formatMuiErrorMessage';
throw new Error(process.env.NODE_ENV !== 'production' ? `exists` : _formatMuiErrorMessage(1));
throw new Error(process.env.NODE_ENV !== 'production' ? 'exists' : _formatMuiErrorMessage(1));
throw new Error(
process.env.NODE_ENV !== 'production' ? `will be created` : _formatMuiErrorMessage(2),
process.env.NODE_ENV !== 'production' ? 'will be created' : _formatMuiErrorMessage(2),
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"1": "MUI: %s, %s"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const foo = 'foo';
const bar = 'bar';
throw /* minify-error */ new Error(`MUI: ${foo}, ${bar}`);
throw /* minify-error */ new Error(`MUI: ${foo}` + `, ${bar}`);
throw /* minify-error */ new Error('MUI: ' + `${foo}, ${bar}`);
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import _formatMuiErrorMessage from '@mui/utils/formatMuiErrorMessage';
const foo = 'foo';
const bar = 'bar';
throw new Error(
process.env.NODE_ENV !== 'production'
? `MUI: ${foo}, ${bar}`
: _formatMuiErrorMessage(1, foo, bar),
);
throw new Error(
process.env.NODE_ENV !== 'production'
? `MUI: ${foo}` + `, ${bar}`
: _formatMuiErrorMessage(1, foo, bar),
);
throw new Error(
process.env.NODE_ENV !== 'production'
? 'MUI: ' + `${foo}, ${bar}`
: _formatMuiErrorMessage(1, foo, bar),
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
throw /* minify-error */ new Error(
'MUI: Expected valid input target.\n' + 'Did you use `inputComponent`',
);
throw /* minify-error */ new Error(
`MUI: Expected valid input target.\n` + `Did you use \`inputComponent\``,
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import _formatMuiErrorMessage from '@mui/utils/formatMuiErrorMessage';
throw new Error(
process.env.NODE_ENV !== 'production'
? 'MUI: Expected valid input target.\n' + 'Did you use `inputComponent`'
: _formatMuiErrorMessage(1),
);
throw new Error(
process.env.NODE_ENV !== 'production'
? `MUI: Expected valid input target.\n` + `Did you use \`inputComponent\``
: _formatMuiErrorMessage(1),
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
throw /* minify-error */ new Error(
'MUI: Expected valid input target.\n' + 'Did you use inputComponent',
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
throw /* FIXME (minify-errors-in-prod): Unminified error message in production build! */ new Error(
'MUI: Expected valid input target.\n' + 'Did you use inputComponent',
);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
throw /* minify-error */ new Error('missing');
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const foo = 'foo';
const bar = ['bar'];
throw /* minify-error */ new Error(foo);
throw /* minify-error */ new Error(...bar);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const foo = 'foo';
const bar = ['bar'];
throw /* FIXME (minify-errors-in-prod): Unminifyable error in production! */ new Error(foo);
throw /* FIXME (minify-errors-in-prod): Unminifyable error in production! */ new Error(...bar);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const foo = 'foo';
const bar = ['bar'];
throw /* minify-error */ new Error(foo);
throw /* minify-error */ new Error(...bar);
Loading