@mui/internal-docs-infra 0.12.1-canary.34 → 0.12.1-canary.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/internal-docs-infra",
3
- "version": "0.12.1-canary.34",
3
+ "version": "0.12.1-canary.35",
4
4
  "author": "MUI Team",
5
5
  "description": "MUI Infra - internal documentation creation tools.",
6
6
  "license": "MIT",
@@ -30,8 +30,8 @@
30
30
  "homepage": "https://github.com/mui/mui-public/tree/master/packages/docs-infra",
31
31
  "dependencies": {
32
32
  "@babel/runtime": "^7.29.7",
33
- "@csstools/postcss-light-dark-function": "^3.0.2",
34
- "@csstools/postcss-relative-color-syntax": "^4.0.7",
33
+ "@csstools/postcss-light-dark-function": "^3.0.3",
34
+ "@csstools/postcss-relative-color-syntax": "^4.0.8",
35
35
  "@csstools/postcss-stepped-value-functions": "^5.0.4",
36
36
  "@orama/orama": "^3.1.18",
37
37
  "@orama/plugin-qps": "^3.1.18",
@@ -41,7 +41,7 @@
41
41
  "autoprefixer": "^10.5.4",
42
42
  "chalk": "^6.0.0",
43
43
  "clipboard-copy": "^4.0.1",
44
- "es-toolkit": "^1.49.0",
44
+ "es-toolkit": "^1.51.0",
45
45
  "fflate": "^0.8.3",
46
46
  "hast-util-to-jsx-runtime": "^2.3.6",
47
47
  "hast-util-to-text": "^4.0.2",
@@ -52,7 +52,7 @@
52
52
  "kebab-case": "^2.0.2",
53
53
  "lz-string": "^1.5.0",
54
54
  "path-module": "^0.1.2",
55
- "postcss": "^8.5.22",
55
+ "postcss": "^8.5.26",
56
56
  "postcss-modules-extract-imports": "^3.1.0",
57
57
  "postcss-modules-local-by-default": "^4.2.0",
58
58
  "postcss-modules-scope": "^3.2.1",
@@ -62,14 +62,14 @@
62
62
  "remark-mdx": "^3.1.1",
63
63
  "remark-parse": "^11.0.0",
64
64
  "remark-stringify": "^11.0.0",
65
- "remark-typography": "^0.7.3",
65
+ "remark-typography": "^0.8.1",
66
66
  "sucrase": "^3.35.1",
67
67
  "typescript-api-extractor": "1.0.0-beta.6",
68
68
  "uint8-to-base64": "^0.2.1",
69
69
  "unified": "^11.0.5",
70
70
  "unist-util-visit": "^5.1.0",
71
71
  "vscode-oniguruma": "^2.0.1",
72
- "yargs": "^18.0.0",
72
+ "yargs": "^18.1.0",
73
73
  "zx": "^8.8.5"
74
74
  },
75
75
  "peerDependencies": {
@@ -804,5 +804,5 @@
804
804
  "bin": {
805
805
  "docs-infra": "./cli/index.mjs"
806
806
  },
807
- "gitSha": "c7ecd7d0578f1fd06710d507fcd4e155afc8bde7"
807
+ "gitSha": "621d2be80da48abdbfaeb85f498580416be78c9a"
808
808
  }
@@ -190,7 +190,7 @@ export function extractTypeParameters(type, typeNameMap = {}) {
190
190
  * while preserving all markdown features and applying syntax highlighting to code blocks.
191
191
  */
192
192
  export async function parseMarkdownToHast(markdown) {
193
- const processor = unified().use(remarkParse).use(remarkGfm).use(transformMarkdownCode).use(remarkTypography, []).use(remarkRehype).freeze();
193
+ const processor = unified().use(remarkParse).use(remarkGfm).use(transformMarkdownCode).use(remarkTypography).use(remarkRehype).freeze();
194
194
  const mdast = processor.parse(markdown);
195
195
  const result = await processor.run(mdast);
196
196
  return result;
@@ -4,6 +4,7 @@ import { parseFromProgram } from 'typescript-api-extractor';
4
4
  import ts from 'typescript';
5
5
  import { createOptimizedProgram } from "./createOptimizedProgram.mjs";
6
6
  import { augmentComponentsWithInheritedProps } from "./inheritedExternalProps.mjs";
7
+ import { transformConstantGroup } from "./transformConstantGroup.mjs";
7
8
  import { extractJSDocText, isJSDocNodeArray } from "./extractJSDocText.mjs";
8
9
  import { PerformanceTracker } from "./performanceTracking.mjs";
9
10
  import { nameMark } from "../loadPrecomputedCodeHighlighter/performanceLogger.mjs";
@@ -343,8 +344,12 @@ export async function processTypes(request) {
343
344
  const {
344
345
  exports: internalExport
345
346
  } = parseFromProgram(file, program, parserOptions);
346
- internalTypesCache[file] = internalExport;
347
- return internalExport;
347
+
348
+ // Metadata files may declare their members as an enum or as named constants;
349
+ // normalize both to a single constant group named after the file.
350
+ const groupExports = transformConstantGroup(file, internalExport);
351
+ internalTypesCache[file] = groupExports;
352
+ return groupExports;
348
353
  });
349
354
  const internalTypes = allInternalTypes.reduce((acc, cur) => {
350
355
  acc.push(...cur);
@@ -0,0 +1,14 @@
1
+ import type * as tae from 'typescript-api-extractor';
2
+ /**
3
+ * Normalizes a metadata file's exports into a single constant group named after the file.
4
+ *
5
+ * A constant group is a named, documented set of key/value constants belonging to one
6
+ * component — the data attributes it sets, or the CSS variables it reads. Authors may
7
+ * declare it as an enum named after the file, or as named literal constants; both end up
8
+ * as the same enum-shaped export so the rest of the pipeline sees one representation.
9
+ *
10
+ * Exports matching no known authoring style are returned unchanged. Once a group is formed
11
+ * it replaces the file's exports, so a metadata file that also exports something which is
12
+ * not a constant is a mistake: it throws rather than dropping those exports silently.
13
+ */
14
+ export declare function transformConstantGroup(filePath: string, exports: tae.ExportNode[]): tae.ExportNode[];
@@ -0,0 +1,80 @@
1
+ import { EnumMember, EnumNode, ExportNode, TypeName } from 'typescript-api-extractor';
2
+ import { fileUrlToPortablePath } from "../loaderUtils/fileUrlToPortablePath.mjs";
3
+ import { getFileNameFromUrl } from "../loaderUtils/getFileNameFromUrl.mjs";
4
+ import { isEnumType, isLiteralType } from "./typeGuards.mjs";
5
+
6
+ /**
7
+ * Derives a constant group's name from its file path, e.g.
8
+ * `/src/accordion/panel/AccordionPanelCssVars.ts` becomes `AccordionPanelCssVars`.
9
+ */
10
+ function getGroupName(filePath) {
11
+ const {
12
+ fileName,
13
+ extension
14
+ } = getFileNameFromUrl(fileUrlToPortablePath(filePath));
15
+ return extension ? fileName.slice(0, -extension.length) : fileName;
16
+ }
17
+
18
+ /**
19
+ * Reads a constant's value from its literal type.
20
+ *
21
+ * String literals arrive wrapped in quotes (`"data-open"`) while numeric literals do not,
22
+ * so both are normalized to the bare string an enum member would have carried. Anything
23
+ * else — objects, functions, booleans — is not a documentable constant.
24
+ */
25
+ function readLiteralValue(value) {
26
+ if (typeof value === 'number') {
27
+ return String(value);
28
+ }
29
+ if (typeof value === 'string' && value.length >= 2 && value.startsWith('"') && value.endsWith('"')) {
30
+ return value.slice(1, -1);
31
+ }
32
+ return undefined;
33
+ }
34
+
35
+ /**
36
+ * Normalizes a metadata file's exports into a single constant group named after the file.
37
+ *
38
+ * A constant group is a named, documented set of key/value constants belonging to one
39
+ * component — the data attributes it sets, or the CSS variables it reads. Authors may
40
+ * declare it as an enum named after the file, or as named literal constants; both end up
41
+ * as the same enum-shaped export so the rest of the pipeline sees one representation.
42
+ *
43
+ * Exports matching no known authoring style are returned unchanged. Once a group is formed
44
+ * it replaces the file's exports, so a metadata file that also exports something which is
45
+ * not a constant is a mistake: it throws rather than dropping those exports silently.
46
+ */
47
+ export function transformConstantGroup(filePath, exports) {
48
+ const groupName = getGroupName(filePath);
49
+
50
+ // Already an enum declaration named after its file, so there is nothing to normalize.
51
+ if (exports.some(node => node.name === groupName && isEnumType(node.type))) {
52
+ return exports;
53
+ }
54
+
55
+ // Literal constants are folded into members of a single group rather than left alongside
56
+ // it: names this generic (`open`, `index`, `disabled`) would shadow real types when
57
+ // resolving `{@link}` references.
58
+ const members = [];
59
+ const discarded = [];
60
+ for (const node of exports) {
61
+ const value = isLiteralType(node.type) ? readLiteralValue(node.type.value) : undefined;
62
+ if (value === undefined) {
63
+ discarded.push(node.name);
64
+ } else {
65
+ members.push(new EnumMember(node.name, value, node.documentation));
66
+ }
67
+ }
68
+ if (members.length === 0) {
69
+ return exports;
70
+ }
71
+
72
+ // The group replaces the file's exports wholesale, so anything that is not a constant —
73
+ // a helper function, a type alias, an enum under another name, a constant widened off its
74
+ // literal type — would be documented nowhere. Metadata files are expected to hold
75
+ // constants only, so fail the build rather than drop these exports silently.
76
+ if (discarded.length > 0) {
77
+ throw new Error(`[transformConstantGroup] ${groupName} - metadata files must export only constants, but these are not: ${discarded.join(', ')}`);
78
+ }
79
+ return [new ExportNode(groupName, new EnumNode(new TypeName(groupName), members, undefined), undefined)];
80
+ }
@@ -144,7 +144,7 @@ function stripPositions(node) {
144
144
  * on mdast nodes that were already parsed, avoiding a redundant text → mdast re-parse.
145
145
  */
146
146
  async function convertDescriptions(targets) {
147
- const processor = unified().use(transformMarkdownCode).use(remarkTypography, []).use(remarkRehype);
147
+ const processor = unified().use(transformMarkdownCode).use(remarkTypography).use(remarkRehype);
148
148
  await Promise.all(targets.map(async ([setter, children]) => {
149
149
  const root = {
150
150
  type: 'root',