Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
232 commits
Select commit Hold shift + click to select a range
394e18f
Add CodeHighlighter component for loading demos and codeblocks
dav-is Jun 30, 2025
464f786
Add first docs
dav-is Jul 1, 2025
940b0ec
Merge branch 'master' into davis/add-code-highlighter-loader
dav-is Jul 2, 2025
4f46987
Refactor CodeHighlighter
dav-is Jul 2, 2025
b76621b
Stabilize API
dav-is Jul 11, 2025
fc65c6c
Fix context types
dav-is Jul 11, 2025
6c935b6
Transformers, Linking, Improve docs display
dav-is Jul 13, 2025
64d432b
Improve highlighting transforms
dav-is Jul 13, 2025
1fef68b
Replace TsToJs lib
dav-is Jul 13, 2025
7ad5d7e
removeTypes from tsx file
dav-is Jul 13, 2025
1a2b3a3
Fix docs build
dav-is Jul 13, 2025
67d2b8d
TS/JS Switcher working
dav-is Jul 14, 2025
48f825e
Fix filename switcher
dav-is Jul 14, 2025
186261f
loadVariant support extraFiles transforms
dav-is Jul 14, 2025
4f796f2
Get webpack loader working
dav-is Jul 14, 2025
a2132b8
Refactor loader with tests
dav-is Jul 16, 2025
fc1a814
Improve module resolution logic
dav-is Jul 16, 2025
b013c08
Add loadCode()
dav-is Jul 16, 2025
d419bbb
Rewrite loadVariant with tests
dav-is Jul 17, 2025
8863f10
loadVariant returns dependencies
dav-is Jul 17, 2025
8925b29
More loadVariant edge cases
dav-is Jul 17, 2025
0b1b59a
Improve transform and parse tests
dav-is Jul 17, 2025
710569e
Improve loadFallbackCode and add tests
dav-is Jul 17, 2025
0d50e7d
Refactor loader and fallback loading
dav-is Jul 18, 2025
0bed161
Add more info to readme + extensions recommendation for MDX
dav-is Jul 18, 2025
79573f8
loadCode() cache
dav-is Jul 18, 2025
bc0314f
Rename loadCode and loadVariantCode to loadCodeMeta and loadVariantMeta
dav-is Jul 18, 2025
f153846
loadVariantMeta is now optional
dav-is Jul 18, 2025
28f5450
Refactor getFileNameFromUrl() and remove use of node:path
dav-is Jul 18, 2025
ff85803
refactor to `serverLoadSource` and `serverLoadCodeMeta`
dav-is Jul 18, 2025
e423baa
Rename `loadPrecomputedCodeHighlighter`
dav-is Jul 18, 2025
76752b8
improve transforms exports, rename loaderUtils
dav-is Jul 18, 2025
d8cbd2c
More renaming
dav-is Jul 18, 2025
b1a18d5
Rename fix
dav-is Jul 18, 2025
a11f4eb
Improve transform testing
dav-is Jul 18, 2025
5fa3649
Refactor, remove delete calls
dav-is Jul 18, 2025
9d06df8
Refactor useHighlighted hook
dav-is Jul 18, 2025
5a8926b
Change parseSource type to by synchronous
dav-is Jul 19, 2025
7e1af5f
Refactor Client Component with tests
dav-is Jul 19, 2025
bbafcb3
Fix tests
dav-is Jul 19, 2025
1efaed8
Fix infinite loop
dav-is Jul 19, 2025
6b0c2ce
useCode + useDemo improvements
dav-is Jul 19, 2025
016137d
loadFallbackCode produces valid initialData tests
dav-is Jul 19, 2025
c55f17c
Add tests and validation ensuring the `allFilesListed=true` doesn't l…
dav-is Jul 19, 2025
35c5c43
Fix transforms
dav-is Jul 20, 2025
23cdc59
Cleanup Demo CSS, Add file tabs
dav-is Jul 20, 2025
5b833ce
resolveModulePath should be isomorphic
dav-is Jul 21, 2025
b861f57
Fix webpack cache paths
dav-is Jul 21, 2025
baa3941
Fix loadVariant test
dav-is Jul 21, 2025
07c01fd
Update package scripts
dav-is Jul 21, 2025
2cc1fe9
Fix loadVariant relative paths
dav-is Jul 21, 2025
bac7c40
Normalize extraFiles
dav-is Jul 21, 2025
b302794
Transformation bugfixes
dav-is Jul 21, 2025
5108f3e
Progress on docs
dav-is Jul 21, 2025
ff05e79
Add copy button to docs
dav-is Jul 21, 2025
5053c4c
Workaround until publishing is fixed
dav-is Jul 21, 2025
155277e
Merge branch 'master' into davis/add-code-highlighter-loader
dav-is Jul 21, 2025
75c9448
Fix bad merge
dav-is Jul 21, 2025
5db5c70
Another package.json fix
dav-is Jul 21, 2025
d91dcd7
Fix named imports
dav-is Jul 23, 2025
1452ff0
Improve createDemo() API
dav-is Jul 24, 2025
84b2377
Add fileConventions to Contributing page
dav-is Jul 24, 2025
c00afa2
Update createDemo() docs
dav-is Jul 24, 2025
823b06a
Fix more createDemo() calls
dav-is Jul 24, 2025
22c94da
Remove mentions of precompute: true
dav-is Jul 24, 2025
30c1060
Improve docs output
dav-is Jul 25, 2025
7a2a637
Merge branch 'master' into davis/add-code-highlighter-loader
dav-is Jul 25, 2025
db25238
Variant Selector
dav-is Jul 25, 2025
a1e05ac
Got Code Controller Demos Working
dav-is Jul 26, 2025
8cf4b43
Setup esm only build
dav-is Jul 26, 2025
0deda80
Node 22 Requirement
dav-is Jul 26, 2025
dfe214e
Handle markdown code blocks at build time
dav-is Jul 26, 2025
9fb408a
Cleanup
dav-is Jul 26, 2025
8761252
transformMarkdownCodeVariants
dav-is Jul 26, 2025
63c7d45
Improve loader testing, docs
dav-is Jul 28, 2025
e7a8dc0
Improve CodeContent
dav-is Jul 28, 2025
d990e85
Fix markdown -> html <code> AST parsing
dav-is Jul 28, 2025
a700be8
<CodeHighlighter> without filename or URL
dav-is Jul 28, 2025
d560759
Skip transforms for inline code snippets by default
dav-is Jul 28, 2025
dcb6018
Rename to transformMarkdownCode
dav-is Jul 28, 2025
f3324d2
Fix rename
dav-is Jul 28, 2025
84d1af4
Fix markdown escaping
dav-is Jul 28, 2025
40678b4
Clarify inline variant defs
dav-is Jul 28, 2025
26ef082
Improve docs more
dav-is Jul 28, 2025
2a009f6
Improve useCode / useDemo
dav-is Jul 29, 2025
f362ced
File Linking, improved name + slug generation
dav-is Jul 29, 2025
900bb60
Variant and transform preference storage, improve demo and code display
dav-is Jul 29, 2025
7dc3d3c
Prettier + Cleanup
dav-is Jul 29, 2025
1ee499c
pnpm dedupe
dav-is Jul 29, 2025
78df427
pnpm dedupe again
dav-is Jul 29, 2025
9c0cda1
Parse and Pass `externals` for use in export to stackblitz
dav-is Jul 29, 2025
a2d2b95
Renaming
dav-is Jul 30, 2025
a72a30a
useDemo + CodeSandbox + StackBlitz
dav-is Jul 31, 2025
d088606
pnpm dedupe
dav-is Jul 31, 2025
afb544c
rename to transformMarkdownRelativePaths
dav-is Jul 31, 2025
9c08751
Handle highlightAt hydration / idle
dav-is Jul 31, 2025
56785b7
Formatting
dav-is Jul 31, 2025
257fd26
Refactor useLocalStorage
dav-is Jul 31, 2025
d74ca5c
Bugfixes
dav-is Jul 31, 2025
a6a9603
Move docs to davis/add-code-highlighter-docs branch
dav-is Jul 31, 2025
73f494e
Prettier
dav-is Aug 1, 2025
aeaf382
Move build-time style processes like webpack loaders, remark plugins,…
dav-is Aug 1, 2025
2e0ba37
Fix remaining pieces from move
dav-is Aug 1, 2025
49d60ae
Merge branch 'master' into davis/add-code-highlighter-loader
dav-is Aug 1, 2025
417532e
pnpm dedupe
dav-is Aug 1, 2025
0338a8a
Use MUI useLocalStorageState
dav-is Aug 1, 2025
7882897
refactor into useUrlHashState()
dav-is Aug 1, 2025
6ddf9e1
pnpm dedupe
dav-is Aug 1, 2025
27420f7
Add globalsCode and createDemoGlobal()
dav-is Aug 5, 2025
83058ae
Allow passing `demoGlobalData` in abstractCreateDemo()
dav-is Aug 5, 2025
85dfbd5
Fix tests
dav-is Aug 5, 2025
63169c6
Add merging for globalsCode
dav-is Aug 5, 2025
40c0cdb
Fix overlaid code
dav-is Aug 5, 2025
013510f
bugfixes, line count, disable js transforms for now
dav-is Aug 5, 2025
6fbfe9b
Merge branch 'master' into davis/add-code-highlighter-loader
dav-is Aug 5, 2025
e2f7f65
Add line gutters
dav-is Aug 5, 2025
e8cd8a8
Merge branch 'davis/add-code-highlighter-loader' of github.com:mui/mu…
dav-is Aug 5, 2025
dc5bfcb
Improve line count, fix codesandbox, improve types in useCode
dav-is Aug 5, 2025
81a4c45
Improve Exports API
dav-is Aug 8, 2025
a6af70f
Merge branch 'master' into davis/add-code-highlighter-loader
dav-is Aug 8, 2025
07f45b7
Add title and description suffixes and versioning for exports
dav-is Aug 8, 2025
214ca59
Fix adding `./App.tsx` bug
dav-is Aug 8, 2025
6d60131
Fix lint
dav-is Aug 8, 2025
e641ab9
variantType, usePreference, custom prefs prefix,
dav-is Aug 8, 2025
c2abda7
Fix duplicate files when moving in variant transform
dav-is Aug 8, 2025
95d7e5c
Fix HTML output with CRA
dav-is Aug 8, 2025
421e7ee
Lint
dav-is Aug 8, 2025
bfb12d6
Improve export formatting, pass vite options
dav-is Aug 8, 2025
df9c0d1
Handle Client-Side Errors
dav-is Aug 11, 2025
f4b21d3
Merge branch 'master' into davis/add-code-highlighter-loader
dav-is Aug 11, 2025
c7d7303
Update package.json version
dav-is Aug 11, 2025
295914d
Add type descriptions
dav-is Aug 11, 2025
b8e0c11
throw Error in precompute
dav-is Aug 11, 2025
d3e00c7
Add types to package.json
dav-is Aug 11, 2025
087737e
Fix hot-reload state for precomputed code blocks
dav-is Aug 12, 2025
4ad3bd3
Select initial variant properly
dav-is Aug 12, 2025
ca49142
Merge branch 'master' into davis/add-code-highlighter-loader
dav-is Aug 12, 2025
ec7367a
Merge branch 'master' into davis/add-code-highlighter-loader
dav-is Aug 13, 2025
3fe282c
Merge branch 'master' into davis/add-code-highlighter-loader
dav-is Aug 25, 2025
3432180
pnpm dedupe
dav-is Aug 25, 2025
e577ff0
Fix lint
dav-is Aug 25, 2025
584c93d
Fix build
dav-is Aug 25, 2025
bc658f4
Fix prettier
dav-is Aug 25, 2025
19d3f20
Optimize factory parse function
dav-is Aug 27, 2025
7f8e5c2
Add more js-docs, code review
dav-is Aug 27, 2025
cecad7c
Merge branch 'master' into davis/add-code-highlighter-loader
dav-is Aug 27, 2025
8881180
Move Externals Provider to a 'use client' based loader
dav-is Aug 28, 2025
72cfbce
Fix build
dav-is Aug 28, 2025
4ab4bab
Remove outdated tests
dav-is Aug 28, 2025
e6c2212
Fix webpack build
dav-is Aug 28, 2025
cb599e4
pnpm dedupe
dav-is Aug 28, 2025
df03ec3
store parser in globalThis
dav-is Aug 28, 2025
268015d
Simplify loadVariant function params
dav-is Aug 29, 2025
895da07
Simplify loadFallbackCode function params
dav-is Aug 29, 2025
6e58101
Code review
dav-is Aug 29, 2025
551d89b
Pull heavy files from the base client bundle
dav-is Aug 29, 2025
7dc6ce6
Improve applyTransform test case
dav-is Aug 29, 2025
61a399c
Add console.error if variant load error during server render
dav-is Aug 29, 2025
065df9b
parameters -> arguments
dav-is Aug 29, 2025
4255097
Remove idea for cli tool from error
dav-is Aug 29, 2025
e6cb907
Add Next.js Plugin
dav-is Aug 29, 2025
9e5730e
Merge branch 'master' into davis/add-code-highlighter-loader
dav-is Sep 2, 2025
12fdec1
Fix merge conflict
dav-is Sep 2, 2025
3e20015
Fix Fallback Bugs
dav-is Sep 3, 2025
4dbb82c
Fix unit tests
dav-is Sep 3, 2025
5a4bcc0
Updated test too soon
dav-is Sep 3, 2025
32e7519
Add bundle
Janpot Sep 3, 2025
a006dc6
Improve relative path resolution
dav-is Sep 3, 2025
4c9d5d8
Update README link
dav-is Sep 3, 2025
99e5501
Merge branch 'master' into davis/add-code-highlighter-loader
dav-is Sep 4, 2025
4a91028
Add server-only imports where helpful
dav-is Sep 4, 2025
2a59b6d
Merge branch 'master' into davis/add-code-highlighter-loader
dav-is Sep 4, 2025
fc64da5
Update package.json to fit new format
dav-is Sep 4, 2025
44292b3
Some code review changes
dav-is Sep 4, 2025
a3592a3
Cleanup deps
dav-is Sep 4, 2025
e85f81c
pnpm dedupe
dav-is Sep 4, 2025
9241cb5
Refactor useUrlHashState to improve hash synchronization and subscrib…
dav-is Sep 4, 2025
07d55d6
Revert "Add server-only imports where helpful"
dav-is Sep 4, 2025
da02cb1
Replace useOnHydrate and useOnIdle
dav-is Sep 4, 2025
3639656
Refactor useControlledCode to simplify return values and update relat…
dav-is Sep 5, 2025
03d42c1
Improve CodeHighlighter Types
dav-is Sep 5, 2025
cc5803c
Refactor renderWithInitialSource and CodeInitialSourceLoader for impr…
dav-is Sep 5, 2025
c1b2cd6
Re-add exported types
dav-is Sep 5, 2025
bc8eac6
Use `path-module` in loadVariant
dav-is Sep 5, 2025
b97fd11
Allow client loading without `forceClient` when using <CodeProvider>
dav-is Sep 5, 2025
469ab8e
Enhance error logging in CodeHighlighterClient with URL context and a…
dav-is Sep 5, 2025
dad1305
pnpm dedupe
dav-is Sep 5, 2025
b12db50
pnpm dedupe
dav-is Sep 5, 2025
16d8a23
Refactor addPathsToVariant
dav-is Sep 5, 2025
e31a6e1
Rewrite addPathsToVariant
dav-is Sep 5, 2025
394547d
Merge branch 'master' into davis/add-code-highlighter-loader
dav-is Sep 5, 2025
f48420d
Improve Error Experience
dav-is Sep 6, 2025
217e486
prettier
dav-is Sep 6, 2025
8efef8c
Simplify useUrlHashState()
dav-is Sep 8, 2025
f6ce76a
Remove markdown transformers not added in this PR
dav-is Sep 8, 2025
d47226b
Merge branch 'master' into davis/add-code-highlighter-loader
dav-is Sep 8, 2025
fee457c
prettier
dav-is Sep 8, 2025
22569df
Add 'allowExternalVariants' option to parseCreateFactoryCall
dav-is Sep 8, 2025
860a696
Merge branch 'master' into davis/add-code-highlighter-loader
dav-is Sep 9, 2025
0a3accb
Merge branch 'master' into davis/add-code-highlighter-loader
dav-is Sep 10, 2025
4dd1926
Merge branch 'master' into davis/add-code-highlighter-loader
dav-is Sep 10, 2025
d78ad51
Cleanup CodeHighlighter exports
dav-is Sep 10, 2025
abee2e4
Fix lint
dav-is Sep 10, 2025
d1e246d
pnpm dedupe
dav-is Sep 10, 2025
51c39f2
pnpm dedupe again
dav-is Sep 10, 2025
d514832
For code longer than 120 lines, only render highlighted lines when vi…
dav-is Sep 15, 2025
548b450
Merge branch 'master' into davis/add-code-highlighter-loader
dav-is Sep 16, 2025
538ad1c
pnpm dedupe
dav-is Sep 16, 2025
43f3ae4
fix lint
dav-is Sep 16, 2025
08cfb13
Merge branch 'master' into davis/add-code-highlighter-loader
dav-is Sep 16, 2025
042d5e3
Merge branch 'master' into davis/add-code-highlighter-loader
dav-is Sep 18, 2025
71f8a26
Add enhanceAfter and rename highlightAt to highlightAfter
dav-is Sep 26, 2025
dc7e87e
Compress hast in html in production
dav-is Sep 26, 2025
d21653d
Remove performance logs for now
dav-is Sep 26, 2025
2e3b047
Merge branch 'master' into davis/add-code-highlighter-loader
dav-is Sep 26, 2025
9955521
Fix Loading Component
dav-is Sep 19, 2025
3927a95
Add support for CSS @import
dav-is Sep 26, 2025
3dcfc5f
Support imports within mdx files
dav-is Sep 28, 2025
7ce59e5
Refactor parseImports
dav-is Sep 28, 2025
0975202
Collect and remove comments during import parse
dav-is Sep 29, 2025
5ed9de6
Optimize rewriteImports()
dav-is Sep 29, 2025
8e18364
Add docs-infra copilot instructions
dav-is Sep 29, 2025
78973c8
Merge branch 'master' into davis/add-code-highlighter-loader
dav-is Sep 29, 2025
8ad83f7
Merge branch 'master' into davis/add-code-highlighter-loader
dav-is Sep 29, 2025
9f6c252
Support createSnippet<typeof Component>(import.meta.url) factories
dav-is Sep 29, 2025
b143bc1
Optimize parseCreateFactoryCall
dav-is Sep 29, 2025
871853f
Add more notes to copilot instructions
dav-is Sep 29, 2025
057c877
Rename parseImports() to parseImportsAndComments()
dav-is Sep 29, 2025
68b354d
Improve semantic structure of code in html
dav-is Sep 29, 2025
c621b19
Rename transformHtmlCode to transformHtmlCodePrecomputed
dav-is Sep 29, 2025
0655ced
transformHtmlCodePrecomputed should output a <pre> tag
dav-is Sep 29, 2025
fe108c9
Parse vanilla markdown output within transformHtmlCodePrecomputed
dav-is Sep 30, 2025
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
95 changes: 93 additions & 2 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ Always reference these instructions first and fallback to search or bash command
- **Type checking**: `pnpm typescript` -- takes 10-15 seconds. **NEVER CANCEL**. Set timeout to 30+ minutes.
- **Linting**: `pnpm eslint` -- takes 5-10 seconds. **NEVER CANCEL**. Set timeout to 30+ minutes.
- **Formatting**: `pnpm prettier` -- always run before pushing code.
- **Run tests**: `pnpm test` -- takes 5-10 seconds. **NEVER CANCEL**. Set timeout to 30+ minutes.
- **Run tests**: `pnpm test --run` takes 5-10 seconds. **NEVER CANCEL**. Set timeout to 30+ minutes.
- **Run specific tests**: `pnpm test --run loadServerSource` or `pnpm test --run integration.test.ts` for targeted testing
- **ALWAYS use `--run` flag** to avoid watch mode when running tests programmatically
- **Do NOT use `--`** in test commands (e.g., avoid `pnpm test -- --run`)
- **Use VS Code Vitest extension** whenever possible for interactive test development and debugging

### Run Applications

Expand Down Expand Up @@ -116,7 +120,94 @@ test/
- **pnpm release:build**: 5-10 seconds. **NEVER CANCEL**. Set timeout to 30+ minutes.
- **pnpm typescript**: 10-15 seconds. **NEVER CANCEL**. Set timeout to 30+ minutes.
- **pnpm eslint**: 5-10 seconds. **NEVER CANCEL**. Set timeout to 30+ minutes.
- **pnpm test**: 5-10 seconds. **NEVER CANCEL**. Set timeout to 30+ minutes.
- **pnpm test --run**: 5-10 seconds. **ALWAYS use --run flag to prevent watch mode**. **NEVER CANCEL**. Set timeout to 30+ minutes.
- **Application builds**: 3-5 seconds each. **NEVER CANCEL**. Set timeout to 15+ minutes.

All commands are fast in this repository, but network issues or system load can cause delays. Always wait for completion.

## Docs Infra Conventions

Follow additional instructions when working in the `@mui/internal-docs-infra` (`packages/docs-infra`) package:

### Development Process

- **1.1** Create or modify tests `*.test.ts` files before making changes to implementation files. Confirm the test expectations are correct before touching implementation code.
- **1.2** When modifying existing code, try to maintain clean diffs and add tests in within the right `describe` blocks.
- **1.3** When creating new functionality, first write the docs, then the types, then the tests, then the implementation, then the demos. Ensure that the user explicitly reviews test cases and docs before implementation.
- **1.4** When updating functionality across multiple units, ensure that integration tests pass before updating unit tests. This ensures that the overall behavior remains correct before focusing on individual components.

### Code Architecture & Design

- **2.1** Avoid using Node.js native modules like `fs` or `path` or Browser only APIs (like `window` or `document`) when functionality can be achieved using isomorphic code that can also run in the browser and Node.js. When necessary, isolate platform specific code behind interfaces or abstractions so that it can later be replaced in browser environments.
- **2.2** Ship the package as `0.x.0` releases so you can introduce breaking changes that improve the developer experience. Work toward a stable `1.0.0` by anticipating how today’s APIs will evolve.
- Each folder’s `index.ts` should re-export from `src/{functionName}/{functionName}.ts`.
- Category exports should re-export from `src/{category}/{functionName}/{functionName}.ts`.
- **2.3** When functions within the main function file become large or complex, they should be split into separate files within the same folder. For example, if `src/useCode/useCode.ts` becomes large, a large function can be moved to `src/useCode/useFileNavigation.ts` where `useFileNavigation` is the helper function's name.
- **2.4** Value progressive complexity for developers using the library. Start with straightforward defaults and layer optional extension points or advanced behavior that teams can opt into. Keep complex internals behind simple interfaces to enable incremental adoption, easier testing, and maintainable abstractions.
- **2.5** Create functionality in a generic sense, allowing for easy reuse and adaptation in different contexts.
- **2.6** Value the idea of progressive enhancement for end users. Ensure the core experience functions in baseline browsers or runtimes, then add optional user-facing improvements that detect and leverage richer platform capabilities without breaking the fundamentals.

### Testing Strategy

- **3.1** Prioritize achieving deep unit tests first for each helper function (at `src/{functionName}/{helperFunction}.test.ts`), then integration tests (at `src/{functionName}/user.spec.ts`) for the main function.
- **3.2** Use `vitest` for testing. Use `describe`, `it`, and `expect` from `vitest`. Avoid using `beforeEach` and `afterEach` unless absolutely necessary. Each test should be independent and self-contained. Write `describe` and `it` block names prioritizing clarity and readability. Create nested describe blocks when helpful to group related tests. Use `it` blocks for individual test cases.
- **3.3** When debugging, create new test cases to reproduce issues. It's helpful to create new cases to reproduce issues and avoid regressions. If this is difficult, the bugged code might need to be extracted into it's own file to make it easier to test. Try to reproduce issues in the most specific test case possible.
- **3.4** Integration tests (`user.spec.ts`) should be written to cover real user cases and serve as supplemental documentation. Prioritize readability. Reading these tests cases should describe all user cases considered. Unit tests should cover all edges cases but may never be hit in real user cases. When in doubt add it in a unit test first. Try to avoid too much overlap between unit and integration tests. A change of an existing integration test would clearly indicate a breaking change.
- **3.5** Avoid mocks in unit tests. Use real implementations whenever possible to ensure tests are reliable and maintainable.
- **3.6** Test the performance of code within `src/{functionName}/optimization.test.ts` when performance is critical. Functions should use `performance.now()` to measure time taken. When helpful, functions should log using `performance.mark()` and `performance.measure()` which appear when profiling or can be logged with a `PerformanceObserver`.

### Documentation & Examples

- **4.1** Create documentation in `/docs/app/docs-infra` for all public functions using mdx files at `/docs/app/docs-infra/{functionName}/page.mdx`.
- **4.2** Create examples of common use cases in `/docs/app/docs-infra/{type}/{functionName}/demos/{useCaseName}`. `type`, `functionName`, `useCaseName` should be lowercase and hyphenated. Types should be documented in `/docs/app/docs-infra/{functionName}/types.ts`.
- **4.3** For demos follow the [recommended structure](../docs/app/docs-infra/functions/load-precomputed-code-highlighter/page.mdx) and [best practices](../docs/app/docs-infra/components/code-highlighter/page.mdx).
- **4.4** For types follow the [recommended structure](../docs/app/docs-infra/functions/load-precomputed-types-meta/page.mdx).
- **4.5** When looking for documentation, start at the `/README.md` and follow links inward.
- **4.6** Avoid "breaking the 3rd wall" in code comments and documentation by referring to the instructions provided when working in this repository. Instead, focus on clear, concise explanations of the code itself.
- **4.7** When writing code comments, use JSDoc style comments for all functions, but type definitions should be in TypeScript types. Avoid using JSDoc `@typedef` and `@param` tags for types. Use them only for descriptions.

### File Organization & Structure

- **5.1** When types become complex, they are used across multiple exports, or are useful to the user it might make sense to create a separate `src/{functionName}/types.ts` file to hold all types for that function. The user can import this file directly.
- **5.2** When a function has many error cases or the user might want to catch these errors, create custom error classes in `src/{functionName}/errors.ts` and throw these errors.
- **5.3** Separate large or repetitive strings into a separate `src/{functionName}/constants.ts`
- **5.4** Promote functionality to its own export when users benefit from calling it directly. Place the implementation in `src/{newFunctionName}/{newFunctionName}.ts`.
- Only extract when the function has a clear, self-contained purpose and deserves standalone documentation.
- Ship the new export with its own tests, types, docs, and demos.
- **5.5** Consider the weight of a given export. Heavy files should be imported in a separate `src/{functionName}/{heavyFunction}.ts` file and only imported when necessary.
- **5.6** Do not use barrel files except for utility exports at `src/{purpose}Utils/index.ts` where the user is likely to want to import multiple utilities at once. Utils is a suffix so that it can be sorted along with other files with the same purpose.
- **5.7** When working with React, keep `tsx` files as small as possible, keeping as much logic as possible in `ts` files. Also keep `'use client'` or Server only files as small as possible.

### Naming Conventions

- **6.1** Name functions so that they sort well alphabetically. Functions should be named by `{Purpose}{Object}`. For example, `loadX` should come before `parseX` which should come before `useX`. Some existing purposes used are `load`, `parse`, `transform`, `generate`, `save`, `create` (for factories), `abstract` (for factory factories)`use` (for React hooks), `with` (for plugins). React components should be named by `{Object}{Purpose}` where `Object` is the main object the component represents and `Purpose` is what it does. For example, `CodeHighlighter`, `ErrorBoundary`, `FileTreeView`. React components are easily identified by their `PascalCase` naming.
- **6.2** Use `camelCase` for variable and function names. Use `PascalCase` for React components, classes, and type names. Use `UPPER_SNAKE_CASE` for constants.
- **6.3** When exporting `'use-client'` behavior, for Components use the convention `{Purpose}{Object}Client` and and for functions use `{Purpose}client{Object}`. When exporting server only behavior, for Components use the convention `{Purpose}{Object}Server` and for functions use `{Purpose}server{Object}`. For example, `CodeHighlighterClient`, `loadServerPrecomputedCodeHighlighter`. Context providers can be exported as `{Object}Context`

### Code Style & Standards

- **7.1** Write type-safe code. Avoid using `any` or `unknown` unless absolutely necessary. Prefer using `unknown` over `any` and always narrow `unknown` to a specific type as soon as possible. User-facing exports should have as strong of typing as possible.
- **7.2** Use `async/await` for asynchronous code. Avoid using `.then()` and `.catch()`.
- **7.3** Use `import { ... } from '...'` syntax for imports. Avoid using `require()`.
- **7.4** Use ES modules and `import`/`export` syntax.
- **7.5** This package is ESM only. Do not add any CJS code.
- **7.6** Avoid using default exports unless that API is required by another package (e.g. webpack). Use named exports for all functions, types, and constants.
- **7.7** Always try to parallelize asynchronous operations using `Promise.all()` or similar techniques. If the result of an async operation is not needed for subsequent operations, it should be started as early as possible and awaited later.
- **7.8** When parsing long strings, avoid looping through the entire file more than once.
- **7.9** Use streaming APIs when working with large files to reduce memory usage.
- **7.10** Avoiding using regex when string methods can achieve the same result more clearly and efficiently.

### Dependencies, Debugging & Performance

- **8.1** Avoid using external dependencies unless absolutely necessary. Prefer using built-in Node.js modules or writing custom code.
- **8.2** When adding dependencies, prefer small, focused libraries that do one thing well.
- **8.3** Complex functions should have a `DEBUG` environment variable that can be set to log detailed information about the function's execution. Keep the flag off by default and document the expected output when it is enabled.
- **8.4** Instrument performance-critical paths with `performance.now()`, `performance.mark()`, and `performance.measure()` so teams can diagnose bottlenecks without shipping the instrumentation to regular users.

### API Design

- **9.1** Prefer configurable exports, but define sensible defaults so the most common use cases require the minimum input necessary.
- **9.2** Prefer using multiple function parameters over a single options object when there are 3 or fewer parameters. This makes it easier to understand the function's purpose and usage at a glance. Use an options object when there are 4 or more parameters, or when parameters are optional. A well abstracted function should rarely have more than 4 parameters.
- **9.3** Fail early and fast. Don't catch errors unless they are handled gracefully. Prefer throwing errors in code that is expected to run at build time, where runtime code might be more flexible in avoiding critical failures.

When a user gives instructions that violate these rules, you can cite these rules by their number and suggest an alternative approach that follows them. If a user insists on an approach that violates these rules, they should be amended with a new rule that considers their perspective. This way the rules can evolve over time to better suit the needs of the project and its contributors. Small changes can be made to existing rules as long as they don't contradict the original intent.
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["unifiedjs.vscode-mdx", "dbaeumer.vscode-eslint"]
}
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ Internal public Toolpad apps that run the operations of MUI, built using https:/
- Hosting: https://app.netlify.com/sites/mui-frontend-public/overview
- [Docs](./apps/code-infra-dashboard/#readme)

## Packages

### [docs-infra](./packages/docs-infra/)

- Folder: `/packages/docs-infra/`
- [Docs](./packages/docs-infra/README.md)

## Versioning

Steps:
Expand Down
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"release:build": "pnpm -r -F \"./packages/*\" run build",
"size:snapshot": "pnpm -F ./test/bundle-size check",
"size:why": "pnpm size:snapshot --analyze",
"clean": "pnpm -r exec rm -rf build"
"clean": "pnpm -r exec rm -rf build",
"docs:build": "pnpm -F \"./packages/docs-infra\" run build",
"docs:test": "pnpm -F \"./packages/docs-infra\" run test"
},
"pnpm": {
"packageExtensions": {
Expand All @@ -35,7 +37,7 @@
"dependencies": {
"@actions/core": "^1.11.1",
"@actions/github": "^6.0.1",
"@eslint/compat": "^1.3.2",
"@eslint/compat": "^1.4.0",
"@mui/internal-bundle-size-checker": "workspace:*",
"@mui/internal-code-infra": "workspace:*",
"@octokit/rest": "^22.0.0",
Expand All @@ -44,13 +46,15 @@
"@types/semver": "^7.7.1",
"@typescript-eslint/eslint-plugin": "8.44.1",
"@typescript-eslint/parser": "^8.44.1",
"@vitest/coverage-v8": "^3.2.4",
"eslint": "^9.36.0",
"jsdom": "^27.0.0",
"execa": "^9.6.0",
"lerna": "^9.0.0",
"prettier": "^3.6.2",
"pretty-quick": "^4.2.2",
"semver": "^7.7.2",
"tsx": "^4.20.5",
"tsx": "^4.20.6",
"typescript": "^5.9.2",
"vitest": "^3.2.4"
},
Expand Down
14 changes: 3 additions & 11 deletions packages/docs-infra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,8 @@

This package hosts the tools that help create the documentation.

## Installation

Install the package in your project directory with:

<!-- #npm-tag-reference -->

```bash
npm install @mui/internal-docs-infra
```

## Documentation

We have no documentation for these components.
This is stored in the `docs` directory.

[Read More](../../docs/app/docs-infra/page.mdx)
72 changes: 60 additions & 12 deletions packages/docs-infra/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
{
"name": "@mui/internal-docs-infra",
"version": "0.1.0",
"version": "0.2.0",
"author": "MUI Team",
"description": "MUI Infra - internal documentation creation tools.",
"exports": {
"./abstractCreateDemo": "./src/abstractCreateDemo/index.ts",
"./abstractCreateDemoClient": "./src/abstractCreateDemoClient/index.ts",
"./CodeControllerContext": "./src/CodeControllerContext/index.ts",
"./CodeExternalsContext": "./src/CodeExternalsContext/index.ts",
"./CodeHighlighter": "./src/CodeHighlighter/index.ts",
"./CodeHighlighter/types": "./src/CodeHighlighter/types.ts",
"./CodeHighlighter/errors": "./src/CodeHighlighter/errors.ts",
"./CodeProvider": "./src/CodeProvider/index.ts",
"./createDemoData": "./src/createDemoData/index.ts",
"./createDemoData/types": "./src/createDemoData/types.ts",
"./useCode": "./src/useCode/index.ts",
"./useCopier": "./src/useCopier/index.ts",
"./useDemo": "./src/useDemo/index.ts",
"./useErrors": "./src/useErrors/index.ts",
"./useLocalStorageState": "./src/useLocalStorageState/index.ts",
"./usePreference": "./src/usePreference/index.ts",
"./useUrlHashState": "./src/useUrlHashState/index.ts",
"./withDocsInfra": "./src/withDocsInfra/index.ts",
"./pipeline/hastUtils": "./src/pipeline/hastUtils/index.ts",
"./pipeline/loaderUtils": "./src/pipeline/loaderUtils/index.ts",
"./pipeline/loadPrecomputedCodeHighlighter": "./src/pipeline/loadPrecomputedCodeHighlighter/index.ts",
"./pipeline/loadPrecomputedCodeHighlighterClient": "./src/pipeline/loadPrecomputedCodeHighlighterClient/index.ts",
"./pipeline/loadServerCodeMeta": "./src/pipeline/loadServerCodeMeta/index.ts",
"./pipeline/loadServerSource": "./src/pipeline/loadServerSource/index.ts",
"./pipeline/parseSource": "./src/pipeline/parseSource/index.ts",
"./pipeline/transformHtmlCodePrecomputed": "./src/pipeline/transformHtmlCodePrecomputed/index.ts",
"./pipeline/transformMarkdownCode": "./src/pipeline/transformMarkdownCode/index.ts",
"./pipeline/transformTypescriptToJavascript": "./src/pipeline/transformTypescriptToJavascript/index.ts"
},
"keywords": [
"react",
"react-component",
Expand All @@ -22,23 +52,44 @@
"homepage": "https://github.com/mui/mui-public/tree/master/packages/docs-infra",
"scripts": {
"build": "code-infra build --bundle esm",
"test": "exit 0",
"release": "pnpm build && pnpm publish --no-git-checks",
"test": "pnpm -w test --project @mui/internal-docs-infra",
"test:watch": "pnpm -w test:watch --project @mui/internal-docs-infra",
"test:coverage": "pnpm -w test --project @mui/internal-docs-infra --coverage --coverage.include=packages/docs-infra --coverage.exclude=packages/docs-infra/build --coverage.exclude=packages/docs-infra/scripts",
"typescript": "tsc -p tsconfig.json"
},
"dependencies": {
"@babel/runtime": "^7.28.4",
"@types/hast": "^3.0.4",
"@babel/standalone": "^7.28.4",
"@wooorm/starry-night": "^3.8.0",
"clipboard-copy": "^4.0.1",
"hast": "^1.0.0",
"fflate": "^0.8.2",
"hast-util-to-jsx-runtime": "^2.3.6",
"hast-util-to-text": "^4.0.2",
"kebab-case": "^2.0.2"
"jsondiffpatch": "^0.7.3",
"kebab-case": "^2.0.2",
"lz-string": "^1.5.0",
"path-module": "^0.1.2",
"prettier": "^3.5.3",
"uint8-to-base64": "^0.2.1",
"unist-util-visit": "^5.0.0",
"vscode-oniguruma": "^2.0.1"
},
"devDependencies": {
"@types/node": "^22.18.6",
"@testing-library/react": "^16.3.0",
"@types/babel__standalone": "^7.1.9",
"@types/babel__traverse": "^7.20.7",
"@types/hast": "^3.0.4",
"@types/mdast": "^4.0.4",
"@types/node": "^24.5.2",
"@types/react": "^19.1.13",
"csstype": "^3.1.3",
"react": "^19.1.1"
"@types/webpack": "^5.28.5",
"react": "^19.1.1",
"rehype-parse": "^9.0.1",
"rehype-stringify": "^10.0.1",
"remark-parse": "^11.0.0",
"remark-rehype": "^11.1.2",
"unified": "^11.0.5"
},
"peerDependencies": {
"@types/react": "^17.0.0 || ^18.0.0 || ^19.0.0",
Expand All @@ -55,9 +106,6 @@
"directory": "build"
},
"engines": {
"node": ">=14.0.0"
},
"exports": {
"./*": "./src/*/index.ts"
"node": ">=22.12.0"
}
}
Loading
Loading