Skip to content

Commit 2dbc69c

Browse files
committed
[infra] Migrate error code extraction to code-infra
1 parent 78bd6af commit 2dbc69c

File tree

12 files changed

+149
-42
lines changed

12 files changed

+149
-42
lines changed

.markdownlint-cli2.cjs

Lines changed: 0 additions & 10 deletions
This file was deleted.

.markdownlint-cli2.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { createBaseConfig } from '@mui/internal-code-infra/markdownlint';
2+
3+
const baseConfig = createBaseConfig();
4+
5+
export default {
6+
...baseConfig,
7+
config: {
8+
...baseConfig.config,
9+
MD038: false, // false poisitives in MDX
10+
},
11+
};

babel.config.mjs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
import getBaseConfig from '@mui/internal-code-infra/babel-config';
2+
import * as path from 'node:path';
3+
import { fileURLToPath } from 'node:url';
24

3-
const errorCodesPath = new URL(import.meta.resolve('./docs/public/static/error-codes.json'))
4-
.pathname;
5-
const missingError = process.env.MUI_EXTRACT_ERROR_CODES === 'true' ? 'write' : 'annotate';
5+
const dirname = path.dirname(fileURLToPath(import.meta.url));
6+
7+
const errorCodesPath = path.join(dirname, 'docs/src/error-codes.json');
68

79
export default function getBabelConfig(api) {
810
const baseConfig = getBaseConfig(api);
911

1012
const plugins = [
1113
[
12-
'babel-plugin-macros',
14+
'@mui/internal-babel-plugin-minify-errors',
1315
{
14-
muiError: {
15-
errorCodesPath,
16-
missingError,
17-
},
16+
missingError: 'annotate',
17+
runtimeModule: '#formatErrorMessage',
18+
detection: 'opt-out',
19+
errorCodesPath,
1820
},
1921
],
2022
];

docs/public/static/error-codes.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/src/error-codes.json

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"1": "Unsupported number of selectors",
3+
"2": "Unsupported number of arguments",
4+
"3": "Base UI: CheckboxGroupContext is missing. CheckboxGroup parts must be placed within <CheckboxGroup>.",
5+
"4": "Base UI: DirectionContext is missing.",
6+
"5": "Base UI: MenubarContext is missing. Menubar parts must be placed within <Menubar>.",
7+
"6": "Base UI: useToast must be used within <Toast.Provider>.",
8+
"7": "Base UI: ToggleGroupContext is missing. ToggleGroup parts must be placed within <ToggleGroup>.",
9+
"8": "Base UI: Render element or function are not defined.",
10+
"9": "Base UI: AccordionItemContext is missing. Accordion parts must be placed within <Accordion.Item>.",
11+
"10": "Base UI: AccordionRootContext is missing. Accordion parts must be placed within <Accordion.Root>.",
12+
"11": "Base UI: <AlertDialog.Portal> is missing.",
13+
"12": "Base UI: AlertDialogRootContext is missing. AlertDialog parts must be placed within <AlertDialog.Root>.",
14+
"13": "Base UI: AvatarRootContext is missing. Avatar parts must be placed within <Avatar.Root>.",
15+
"14": "Base UI: CheckboxRootContext is missing. Checkbox parts must be placed within <Checkbox.Root>.",
16+
"15": "Base UI: CollapsibleRootContext is missing. Collapsible parts must be placed within <Collapsible.Root>.",
17+
"16": "Base UI: CompositeRootContext is missing. Composite parts must be placed within <Composite.Root>.",
18+
"17": "useComboboxChipContext must be used within a ComboboxChip",
19+
"18": "Base UI: ComboboxGroupContext is missing. ComboboxGroup parts must be placed within <Combobox.Group>.",
20+
"19": "Base UI: ComboboxItemContext is missing. ComboboxItem parts must be placed within <Combobox.Item>.",
21+
"20": "Base UI: <Combobox.Portal> is missing.",
22+
"21": "Base UI: <Combobox.Popup> and <Combobox.Arrow> must be used within the <Combobox.Positioner> component",
23+
"22": "Base UI: ComboboxRootContext is missing. Combobox parts must be placed within <Combobox.Root>.",
24+
"23": "Base UI: ComboboxFloatingContext is missing. Combobox parts must be placed within <Combobox.Root>.",
25+
"24": "Base UI: ComboboxItemsContext is missing. Combobox parts must be placed within <Combobox.Root>.",
26+
"25": "Base UI: ContextMenuRootContext is missing. ContextMenu parts must be placed within <ContextMenu.Root>.",
27+
"26": "Base UI: <Dialog.Portal> is missing.",
28+
"27": "Base UI: DialogRootContext is missing. Dialog parts must be placed within <Dialog.Root>.",
29+
"28": "Base UI: FieldRootContext is missing. Field parts must be placed within <Field.Root>.",
30+
"29": "[Floating UI]: Invalid grid - item width at index %s is greater than grid columns",
31+
"30": "Base UI: MenuCheckboxItemContext is missing. MenuCheckboxItem parts must be placed within <Menu.CheckboxItem>.",
32+
"31": "Base UI: MenuGroupRootContext is missing. Menu group parts must be used within <Menu.Group>.",
33+
"32": "Base UI: <Menu.Portal> is missing.",
34+
"33": "Base UI: MenuPositionerContext is missing. MenuPositioner parts must be placed within <Menu.Positioner>.",
35+
"34": "Base UI: MenuRadioGroupContext is missing. MenuRadioGroup parts must be placed within <Menu.RadioGroup>.",
36+
"35": "Base UI: MenuRadioItemContext is missing. MenuRadioItem parts must be placed within <Menu.RadioItem>.",
37+
"36": "Base UI: MenuRootContext is missing. Menu parts must be placed within <Menu.Root>.",
38+
"37": "Base UI: <Menu.SubmenuTrigger> must be placed in <Menu.SubmenuRoot>.",
39+
"38": "Base UI: MeterRootContext is missing. Meter parts must be placed within <Meter.Root>.",
40+
"39": "Base UI: NavigationMenuItem parts must be used within a <NavigationMenu.Item>.",
41+
"40": "Base UI: <NavigationMenu.Portal> is missing.",
42+
"41": "Base UI: NavigationMenuRootContext is missing. Navigation Menu parts must be placed within <NavigationMenu.Root>.",
43+
"42": "Base UI: NavigationMenuPositionerContext is missing. NavigationMenuPositioner parts must be placed within <NavigationMenu.Positioner>.",
44+
"43": "Base UI: NumberFieldRootContext is missing. NumberField parts must be placed within <NumberField.Root>.",
45+
"44": "Base UI: NumberFieldScrubAreaContext is missing. NumberFieldScrubArea parts must be placed within <NumberField.ScrubArea>.",
46+
"45": "Base UI: <Popover.Portal> is missing.",
47+
"46": "Base UI: PopoverPositionerContext is missing. PopoverPositioner parts must be placed within <Popover.Positioner>.",
48+
"47": "Base UI: PopoverRootContext is missing. Popover parts must be placed within <Popover.Root>.",
49+
"48": "Base UI: <PreviewCard.Portal> is missing.",
50+
"49": "Base UI: <PreviewCard.Popup> and <PreviewCard.Arrow> must be used within the <PreviewCard.Positioner> component",
51+
"50": "Base UI: PreviewCardRootContext is missing. PreviewCard parts must be placed within <PreviewCard.Root>.",
52+
"51": "Base UI: ProgressRootContext is missing. Progress parts must be placed within <Progress.Root>.",
53+
"52": "Base UI: RadioRootContext is missing. Radio parts must be placed within <Radio.Root>.",
54+
"53": "Base UI: ScrollAreaRootContext is missing. ScrollArea parts must be placed within <ScrollArea.Root>.",
55+
"54": "Base UI: ScrollAreaScrollbarContext is missing. ScrollAreaScrollbar parts must be placed within <ScrollArea.Scrollbar>.",
56+
"55": "Base UI: ScrollAreaViewportContext missing. ScrollAreaViewport parts must be placed within <ScrollArea.Viewport>.",
57+
"56": "Base UI: SelectGroupContext is missing. SelectGroup parts must be placed within <Select.Group>.",
58+
"57": "Base UI: SelectItemContext is missing. SelectItem parts must be placed within <Select.Item>.",
59+
"58": "Base UI: <Select.Portal> is missing.",
60+
"59": "Base UI: SelectPositionerContext is missing. SelectPositioner parts must be placed within <Select.Positioner>.",
61+
"60": "Base UI: SelectRootContext is missing. Select parts must be placed within <Select.Root>.",
62+
"61": "Base UI: SelectFloatingContext is missing. Select parts must be placed within <Select.Root>.",
63+
"62": "Base UI: SliderRootContext is missing. Slider parts must be placed within <Slider.Root>.",
64+
"63": "Base UI: SwitchRootContext is missing. Switch parts must be placed within <Switch.Root>.",
65+
"64": "Base UI: TabsRootContext is missing. Tabs parts must be placed within <Tabs.Root>.",
66+
"65": "Base UI: TabsListContext is missing. TabsList parts must be placed within <Tabs.List>.",
67+
"66": "Base UI: ToastRootContext is missing. Toast parts must be used within <Toast.Root>.",
68+
"67": "Base UI: ToastViewportContext is missing. Toast parts must be placed within <Toast.Viewport>.",
69+
"68": "Base UI: ToolbarGroupContext is missing. ToolbarGroup parts must be placed within <Toolbar.Group>.",
70+
"69": "Base UI: ToolbarRootContext is missing. Toolbar parts must be placed within <Toolbar.Root>.",
71+
"70": "Base UI: <Tooltip.Portal> is missing.",
72+
"71": "Base UI: TooltipPositionerContext is missing. TooltipPositioner parts must be placed within <Tooltip.Positioner>.",
73+
"72": "Base UI: TooltipRootContext is missing. Tooltip parts must be placed within <Tooltip.Root>."
74+
}

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"docs:start": "pnpm --filter docs serve",
2121
"docs:link-check": "pnpm --filter docs link-check",
2222
"docs:generate-llms": "pnpm --filter docs run generate-llms",
23-
"extract-error-codes": "cross-env MUI_EXTRACT_ERROR_CODES=true lerna run --concurrency 1 build:stable",
23+
"extract-error-codes": "code-infra extract-error-codes --errorCodesPath docs/src/error-codes.json --detection opt-out",
2424
"jsonlint": "code-infra jsonlint",
2525
"eslint": "eslint . --cache --report-unused-disable-directives --ext .js,.ts,.tsx,.mts --max-warnings 0 && pnpm -r lint",
2626
"eslint:ci": "eslint . --report-unused-disable-directives --ext .js,.ts,.tsx,.mts --max-warnings 0 && pnpm -r lint",
@@ -65,7 +65,8 @@
6565
"@babel/node": "^7.28.0",
6666
"@babel/plugin-transform-react-constant-elements": "^7.27.1",
6767
"@base-ui-components/monorepo-tests": "workspace:*",
68-
"@mui/internal-code-infra": "^0.0.3-canary.3",
68+
"@mui/internal-babel-plugin-minify-errors": "https://pkg.pr.new/mui/mui-public/@mui/internal-babel-plugin-minify-errors@405bc3a",
69+
"@mui/internal-code-infra": "https://pkg.pr.new/mui/mui-public/@mui/internal-code-infra@405bc3a",
6970
"@mui/internal-docs-utils": "^2.0.1",
7071
"@mui/internal-markdown": "^2.0.7",
7172
"@mui/internal-scripts": "^2.0.10",
@@ -148,6 +149,7 @@
148149
"@babel/preset-react": "^7.27.1",
149150
"@babel/preset-typescript": "^7.27.1",
150151
"@babel/types": "^7.28.2",
152+
"@mui/internal-babel-plugin-minify-errors": "https://pkg.pr.new/mui/mui-public/@mui/internal-babel-plugin-minify-errors@405bc3a",
151153
"@types/node": "^22.18.1",
152154
"@types/react": "^19.1.12",
153155
"@types/react-dom": "^19.1.9"

packages/react/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
"./use-render": "./src/use-render/index.ts"
7070
},
7171
"imports": {
72-
"#test-utils": "./test/index.ts"
72+
"#test-utils": "./test/index.ts",
73+
"#formatErrorMessage": "@base-ui-components/utils/formatErrorMessage"
7374
},
7475
"type": "commonjs",
7576
"scripts": {

packages/utils/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
"./store": "./src/store/index.ts",
1313
"./*": "./src/*.ts"
1414
},
15+
"imports": {
16+
"#formatErrorMessage": "./src/formatErrorMessage.ts"
17+
},
1518
"type": "commonjs",
1619
"scripts": {
1720
"prebuild": "rimraf --glob build build-tests \"*.tsbuildinfo\"",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* WARNING: Don't import this directly. It's imported by the code generated by
3+
* `@mui/interal-babel-plugin-minify-errors`. Make sure to always use string literals in `Error`
4+
* constructors to ensure the plugin works as expected. Supported patterns include:
5+
* throw new Error('My message');
6+
* throw new Error(`My message: ${foo}`);
7+
* throw new Error(`My message: ${foo}` + 'another string');
8+
* ...
9+
*/
10+
export default function formatErrorMessage(code: number, ...args: string[]): string {
11+
const url = new URL(`https://base-ui.com/production-error/${code}`);
12+
args.forEach((arg) => url.searchParams.append('args[]', arg));
13+
return `Base UI error #${code}; visit ${url} for the full message.`;
14+
}

packages/utils/src/store/createSelector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export const createSelector = ((
125125
} else if (a) {
126126
selector = a;
127127
} else {
128-
throw new Error('Missing arguments');
128+
throw /* minify-error-disabled */ new Error('Missing arguments');
129129
}
130130

131131
return selector;
@@ -206,7 +206,7 @@ export const createSelectorMemoized: CreateSelectorFunction = (...selectors: any
206206
case 2: return fn(state, a1, a2);
207207
case 3: return fn(state, a1, a2, a3);
208208
default:
209-
throw new Error('unreachable');
209+
throw /* minify-error-disabled */ new Error('unreachable');
210210
}
211211
};
212212

0 commit comments

Comments
 (0)