@mui/internal-docs-infra 0.13.1-canary.27 → 0.13.1-canary.29
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 +2 -2
- package/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.mjs +74 -9
- package/pipeline/loadServerTypesMeta/dropTypeOnlyDuplicates.d.mts +11 -0
- package/pipeline/loadServerTypesMeta/dropTypeOnlyDuplicates.mjs +31 -0
- package/pipeline/loadServerTypesMeta/processTypes.mjs +2 -1
- package/useDemo/exportVariant.d.mts +4 -3
- package/useDemo/exportVariant.mjs +13 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/internal-docs-infra",
|
|
3
|
-
"version": "0.13.1-canary.
|
|
3
|
+
"version": "0.13.1-canary.29",
|
|
4
4
|
"author": "MUI Team",
|
|
5
5
|
"description": "MUI Infra - internal documentation creation tools.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -813,5 +813,5 @@
|
|
|
813
813
|
"bin": {
|
|
814
814
|
"docs-infra": "./cli/index.mjs"
|
|
815
815
|
},
|
|
816
|
-
"gitSha": "
|
|
816
|
+
"gitSha": "86a5228c41898421f1082ea32df84fe2464f2f84"
|
|
817
817
|
}
|
|
@@ -14,6 +14,63 @@ import { createLoadServerCodeSource } from "../loadServerCodeSource/index.mjs";
|
|
|
14
14
|
import { getFileNameFromUrl, IGNORE_COMMENT_PREFIXES } from "../loaderUtils/index.mjs";
|
|
15
15
|
import { createPerformanceLogger, logPerformance, performanceMeasure } from "./performanceLogger.mjs";
|
|
16
16
|
import { fallbackToHast } from "../../CodeHighlighter/fallbackFormat.mjs";
|
|
17
|
+
// Compilation identity prevents reuse across compilers and watch rebuilds.
|
|
18
|
+
const deferredCaches = new WeakMap();
|
|
19
|
+
|
|
20
|
+
/** Rejects options whose behavior would be lost in a JSON cache key. */
|
|
21
|
+
function isSerializable(value, ancestors = new Set()) {
|
|
22
|
+
if (value === null || typeof value === 'string' || typeof value === 'boolean') {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
if (typeof value === 'number') {
|
|
26
|
+
return Number.isFinite(value);
|
|
27
|
+
}
|
|
28
|
+
if (typeof value !== 'object' || ancestors.has(value) || Object.getOwnPropertySymbols(value).length) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
const prototype = Object.getPrototypeOf(value);
|
|
32
|
+
if (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
ancestors.add(value);
|
|
36
|
+
const supported = Object.entries(Object.getOwnPropertyDescriptors(value)).every(([name, descriptor]) => {
|
|
37
|
+
if (Array.isArray(value) && name === 'length') {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
return descriptor.enumerable && 'value' in descriptor && (
|
|
41
|
+
// JSON drops undefined properties, matching how the loader treats absent options.
|
|
42
|
+
// Arrays serialize undefined as null, so elements still have to be serializable.
|
|
43
|
+
descriptor.value === undefined && !Array.isArray(value) || isSerializable(descriptor.value, ancestors));
|
|
44
|
+
});
|
|
45
|
+
ancestors.delete(value);
|
|
46
|
+
return supported;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Shares completed source only when webpack provides a compilation boundary. */
|
|
50
|
+
function getDeferredCache(context, source, options) {
|
|
51
|
+
const {
|
|
52
|
+
_compilation: compilation
|
|
53
|
+
} = context;
|
|
54
|
+
if (!options.deferPrecompute || !compilation || !isSerializable(options)) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
let entries = deferredCaches.get(compilation);
|
|
58
|
+
if (!entries) {
|
|
59
|
+
entries = new Map();
|
|
60
|
+
deferredCaches.set(compilation, entries);
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
entries,
|
|
64
|
+
key: JSON.stringify([context.resourcePath, source, options])
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Both the shell and deferred module must invalidate when imported source changes. */
|
|
69
|
+
function registerDependencies(context, dependencies) {
|
|
70
|
+
dependencies.forEach(dependency => {
|
|
71
|
+
context.addDependency(dependency.startsWith('file://') ? fileURLToPath(dependency) : dependency);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
17
74
|
|
|
18
75
|
/**
|
|
19
76
|
* Extracts a string array from structured options data.
|
|
@@ -115,6 +172,14 @@ export async function loadPrecomputedCodeHighlighter(source) {
|
|
|
115
172
|
const callback = this.async();
|
|
116
173
|
this.cacheable();
|
|
117
174
|
const options = this.getOptions();
|
|
175
|
+
const isDeferredRequest = this.resourceQuery === '?mui-deferred-precompute';
|
|
176
|
+
const deferredCache = getDeferredCache(this, source, options);
|
|
177
|
+
const cached = isDeferredRequest ? deferredCache?.entries.get(deferredCache.key) : undefined;
|
|
178
|
+
if (cached) {
|
|
179
|
+
registerDependencies(this, cached.dependencies);
|
|
180
|
+
callback(null, cached.source);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
118
183
|
const performanceNotableMs = options.performance?.notableMs ?? 100;
|
|
119
184
|
const performanceShowWrapperMeasures = options.performance?.showWrapperMeasures ?? false;
|
|
120
185
|
const relativePath = path.relative(this.rootContext || process.cwd(), this.resourcePath);
|
|
@@ -276,9 +341,16 @@ export async function loadPrecomputedCodeHighlighter(source) {
|
|
|
276
341
|
measure: 'Complete Variants Loading'
|
|
277
342
|
}, [functionName, relativePath], true);
|
|
278
343
|
const deferredRequest = `./${path.basename(this.resourcePath)}?mui-deferred-precompute`;
|
|
279
|
-
const
|
|
344
|
+
const deferredSource = isDeferredRequest || deferredCache ? `export default ${JSON.stringify(variantData)};` : undefined;
|
|
345
|
+
registerDependencies(this, allDependencies);
|
|
346
|
+
if (deferredCache && deferredSource) {
|
|
347
|
+
deferredCache.entries.set(deferredCache.key, {
|
|
348
|
+
source: deferredSource,
|
|
349
|
+
dependencies: allDependencies
|
|
350
|
+
});
|
|
351
|
+
}
|
|
280
352
|
if (isDeferredRequest) {
|
|
281
|
-
callback(null,
|
|
353
|
+
callback(null, deferredSource);
|
|
282
354
|
return;
|
|
283
355
|
}
|
|
284
356
|
|
|
@@ -293,13 +365,6 @@ export async function loadPrecomputedCodeHighlighter(source) {
|
|
|
293
365
|
measure: 'Precompute Replacement'
|
|
294
366
|
}, [functionName, relativePath]);
|
|
295
367
|
|
|
296
|
-
// Add all dependencies to webpack's watch list
|
|
297
|
-
allDependencies.forEach(dep => {
|
|
298
|
-
// Convert file:// URLs to proper file system paths for webpack's dependency tracking
|
|
299
|
-
// Using fileURLToPath handles Windows drive letters correctly (e.g., file:///C:/... → C:\...)
|
|
300
|
-
this.addDependency(dep.startsWith('file://') ? fileURLToPath(dep) : dep);
|
|
301
|
-
});
|
|
302
|
-
|
|
303
368
|
// log any pending performance entries before completing
|
|
304
369
|
observer?.takeRecords()?.forEach(entry => logPerformance(entry, performanceNotableMs, performanceShowWrapperMeasures, relativePath));
|
|
305
370
|
observer?.disconnect();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type * as tae from '@mui/internal-typescript-api-extractor';
|
|
2
|
+
/**
|
|
3
|
+
* Drops type-only exports that repeat a namespaced component re-export under its original name,
|
|
4
|
+
* such as `DialogTrigger` and `DialogTrigger.Props` (reached through `export type *`) next to
|
|
5
|
+
* `Dialog.Trigger` and `Dialog.Trigger.Props`. They would be documented twice, and the members
|
|
6
|
+
* would win the flat-name mapping over the namespaced names.
|
|
7
|
+
*
|
|
8
|
+
* Plain flat types (`ProgressStatus` next to `Progress.Status`) are kept, since the pipeline turns
|
|
9
|
+
* them into aliases of their namespaced names, and so are value exports, which are real API.
|
|
10
|
+
*/
|
|
11
|
+
export declare function dropTypeOnlyDuplicates(exports: tae.ExportNode[]): tae.ExportNode[];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { isComponentType } from "./typeGuards.mjs";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Drops type-only exports that repeat a namespaced component re-export under its original name,
|
|
5
|
+
* such as `DialogTrigger` and `DialogTrigger.Props` (reached through `export type *`) next to
|
|
6
|
+
* `Dialog.Trigger` and `Dialog.Trigger.Props`. They would be documented twice, and the members
|
|
7
|
+
* would win the flat-name mapping over the namespaced names.
|
|
8
|
+
*
|
|
9
|
+
* Plain flat types (`ProgressStatus` next to `Progress.Status`) are kept, since the pipeline turns
|
|
10
|
+
* them into aliases of their namespaced names, and so are value exports, which are real API.
|
|
11
|
+
*/
|
|
12
|
+
export function dropTypeOnlyDuplicates(exports) {
|
|
13
|
+
const names = new Set(exports.map(node => node.name));
|
|
14
|
+
const reexportNames = new Map();
|
|
15
|
+
for (const node of exports) {
|
|
16
|
+
if (node.reexportedFrom && node.name.includes('.')) {
|
|
17
|
+
reexportNames.set(node.reexportedFrom, node.name);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return exports.filter(node => {
|
|
21
|
+
const [head, ...rest] = node.name.split('.');
|
|
22
|
+
const reexportName = reexportNames.get(head);
|
|
23
|
+
if (node.isValue || reexportName === undefined) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
if (rest.length === 0) {
|
|
27
|
+
return !isComponentType(node.type);
|
|
28
|
+
}
|
|
29
|
+
return !names.has([reexportName, ...rest].join('.'));
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -5,6 +5,7 @@ import ts from 'typescript';
|
|
|
5
5
|
import { createOptimizedProgram } from "./createOptimizedProgram.mjs";
|
|
6
6
|
import { augmentComponentsWithInheritedProps } from "./inheritedExternalProps.mjs";
|
|
7
7
|
import { findConstantNamespaces, foldConstantNamespaces } from "./constantGroups.mjs";
|
|
8
|
+
import { dropTypeOnlyDuplicates } from "./dropTypeOnlyDuplicates.mjs";
|
|
8
9
|
import { PARSER_OPTIONS } from "./constants.mjs";
|
|
9
10
|
import { extractJSDocText, isJSDocNodeArray } from "./extractJSDocText.mjs";
|
|
10
11
|
import { PerformanceTracker } from "./performanceTracking.mjs";
|
|
@@ -292,7 +293,7 @@ export async function processTypes(request) {
|
|
|
292
293
|
// Modules of constants exported as a namespace (`export * as ButtonDataAttributes`)
|
|
293
294
|
// arrive flattened into one export per member; document each as a single group.
|
|
294
295
|
const constantNamespaces = findConstantNamespaces(entrypoint, program);
|
|
295
|
-
const exports = foldConstantNamespaces(parsed.exports, constantNamespaces);
|
|
296
|
+
const exports = foldConstantNamespaces(dropTypeOnlyDuplicates(parsed.exports), constantNamespaces);
|
|
296
297
|
|
|
297
298
|
// Re-add configured props that the parser dropped because they are
|
|
298
299
|
// inherited from an externally declared type in node_modules
|
|
@@ -160,7 +160,7 @@ export interface ExportConfig {
|
|
|
160
160
|
globals?: VariantExtraFiles;
|
|
161
161
|
} | undefined;
|
|
162
162
|
/**
|
|
163
|
-
* Version overrides for
|
|
163
|
+
* Version overrides for exported packages, including React and its type packages.
|
|
164
164
|
* @example
|
|
165
165
|
* versions: {
|
|
166
166
|
* '@types/react': '^19',
|
|
@@ -171,7 +171,8 @@ export interface ExportConfig {
|
|
|
171
171
|
*/
|
|
172
172
|
versions?: Record<string, string>;
|
|
173
173
|
/**
|
|
174
|
-
*
|
|
174
|
+
* Resolves imported packages and their peers, including packages pinned in `versions`.
|
|
175
|
+
* `importedModules` contains the complete imports belonging to each package.
|
|
175
176
|
* @example
|
|
176
177
|
* resolveDependencies: (packageName, envVars) => {
|
|
177
178
|
* if (packageName === '@mui/material') {
|
|
@@ -180,7 +181,7 @@ export interface ExportConfig {
|
|
|
180
181
|
* return { [packageName]: 'latest' };
|
|
181
182
|
* }
|
|
182
183
|
*/
|
|
183
|
-
resolveDependencies?: (packageName: string, envVars?: Record<string, string
|
|
184
|
+
resolveDependencies?: (packageName: string, envVars?: Record<string, string>, importedModules?: string[]) => Record<string, string>;
|
|
184
185
|
}
|
|
185
186
|
/**
|
|
186
187
|
* Export a variant as a standalone project with metadata files properly scoped
|
|
@@ -286,20 +286,25 @@ export function exportVariant(variantCode, config = {}) {
|
|
|
286
286
|
|
|
287
287
|
// Check if they're providing their own framework
|
|
288
288
|
const isFramework = 'frameworkFiles' in config;
|
|
289
|
-
const
|
|
289
|
+
const importedModules = processedVariantCode.externals || [];
|
|
290
|
+
const externalPackages = externalsToPackages(importedModules);
|
|
290
291
|
const variantDeps = Object.keys(externalPackages).reduce((acc, pkg) => {
|
|
291
|
-
|
|
292
|
-
if (
|
|
293
|
-
acc
|
|
294
|
-
} else if (resolveDependencies) {
|
|
295
|
-
const resolvedDeps = resolveDependencies(pkg);
|
|
296
|
-
Object.assign(acc, resolvedDeps);
|
|
292
|
+
const packageImports = importedModules.filter(name => name === pkg || name.startsWith(`${pkg}/`));
|
|
293
|
+
if (resolveDependencies) {
|
|
294
|
+
Object.assign(acc, resolveDependencies(pkg, undefined, packageImports));
|
|
297
295
|
} else {
|
|
298
|
-
// Simple fallback: just use 'latest' for each package
|
|
299
296
|
acc[pkg] = 'latest';
|
|
300
297
|
}
|
|
298
|
+
if (versions[pkg] !== undefined) {
|
|
299
|
+
acc[pkg] = versions[pkg];
|
|
300
|
+
}
|
|
301
301
|
return acc;
|
|
302
302
|
}, {});
|
|
303
|
+
for (const pkg of Object.keys(variantDeps)) {
|
|
304
|
+
if (versions[pkg] !== undefined) {
|
|
305
|
+
variantDeps[pkg] = versions[pkg];
|
|
306
|
+
}
|
|
307
|
+
}
|
|
303
308
|
|
|
304
309
|
// Collect metadata files to be generated
|
|
305
310
|
const metadataFiles = {};
|