@mui/internal-docs-infra 0.3.1-canary.3 → 0.3.1-canary.4
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/esm/CodeControllerContext/CodeControllerContext.js +2 -2
- package/esm/CodeExternalsContext/CodeExternalsContext.js +1 -1
- package/esm/CodeHighlighter/CodeHighlighter.js +247 -329
- package/esm/CodeHighlighter/CodeHighlighterClient.js +447 -653
- package/esm/CodeHighlighter/CodeHighlighterContext.js +2 -2
- package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +2 -2
- package/esm/CodeHighlighter/codeToFallbackProps.js +21 -37
- package/esm/CodeHighlighter/errors.js +248 -400
- package/esm/CodeHighlighter/parseControlledCode.js +12 -20
- package/esm/CodeProvider/CodeContext.js +3 -3
- package/esm/CodeProvider/CodeProvider.js +31 -40
- package/esm/abstractCreateDemo/abstractCreateDemo.js +13 -17
- package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +12 -12
- package/esm/cli/index.js +1 -1
- package/esm/cli/runValidate.js +160 -264
- package/esm/createDemoData/createDemoData.js +11 -12
- package/esm/createSitemap/createSitemap.js +2 -2
- package/esm/pipeline/getFileConventions/fileConventions.js +1 -1
- package/esm/pipeline/getFileConventions/getFileConventions.js +2 -15
- package/esm/pipeline/hastUtils/hastUtils.js +16 -17
- package/esm/pipeline/loadCodeVariant/addCodeVariantPaths.js +24 -24
- package/esm/pipeline/loadCodeVariant/applyCodeTransform.js +12 -22
- package/esm/pipeline/loadCodeVariant/calculateMainFilePath.js +30 -37
- package/esm/pipeline/loadCodeVariant/computeHastDeltas.js +107 -185
- package/esm/pipeline/loadCodeVariant/diffHast.js +18 -53
- package/esm/pipeline/loadCodeVariant/examineCodeVariant.js +24 -27
- package/esm/pipeline/loadCodeVariant/flattenCodeVariant.js +9 -10
- package/esm/pipeline/loadCodeVariant/hasAllCodeVariants.js +5 -5
- package/esm/pipeline/loadCodeVariant/loadCodeFallback.js +516 -731
- package/esm/pipeline/loadCodeVariant/loadCodeVariant.js +679 -1079
- package/esm/pipeline/loadCodeVariant/maybeCodeInitialData.js +14 -20
- package/esm/pipeline/loadCodeVariant/mergeCodeMetadata.js +53 -63
- package/esm/pipeline/loadCodeVariant/parseCode.js +40 -48
- package/esm/pipeline/loadCodeVariant/pathUtils.js +43 -64
- package/esm/pipeline/loadCodeVariant/transformSource.js +55 -125
- package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +160 -221
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +377 -479
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +171 -173
- package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +14 -30
- package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +19 -21
- package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +37 -71
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +3 -9
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +54 -80
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +71 -98
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +5 -5
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +161 -211
- package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +159 -207
- package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +42 -64
- package/esm/pipeline/loadServerCodeMeta/resolveModulePathWithFs.js +20 -96
- package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +66 -85
- package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +71 -118
- package/esm/pipeline/loadServerSource/loadServerSource.js +121 -148
- package/esm/pipeline/loaderUtils/externalsToPackages.js +7 -7
- package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +8 -12
- package/esm/pipeline/loaderUtils/fileUrlToPortablePath.js +5 -5
- package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +19 -29
- package/esm/pipeline/loaderUtils/getLanguageFromExtension.js +3 -4
- package/esm/pipeline/loaderUtils/mergeExternals.js +15 -35
- package/esm/pipeline/loaderUtils/parseImportsAndComments.js +413 -433
- package/esm/pipeline/loaderUtils/processRelativeImports.js +153 -239
- package/esm/pipeline/loaderUtils/resolveModulePath.js +544 -1303
- package/esm/pipeline/loaderUtils/rewriteImports.js +73 -111
- package/esm/pipeline/parseSource/addLineGutters.js +33 -45
- package/esm/pipeline/parseSource/grammars.js +3 -3
- package/esm/pipeline/parseSource/parseSource.js +13 -31
- package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +32 -55
- package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +107 -160
- package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +846 -1033
- package/esm/pipeline/syncPageIndex/syncPageIndex.js +291 -438
- package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +213 -311
- package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +10 -10
- package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +133 -193
- package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +25 -27
- package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +572 -717
- package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +8 -8
- package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +84 -113
- package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +10 -26
- package/esm/useCode/Pre.js +58 -62
- package/esm/useCode/useCode.js +59 -61
- package/esm/useCode/useCodeUtils.js +54 -63
- package/esm/useCode/useCopyFunctionality.js +10 -9
- package/esm/useCode/useFileNavigation.js +150 -212
- package/esm/useCode/useSourceEditing.js +17 -14
- package/esm/useCode/useTransformManagement.js +23 -26
- package/esm/useCode/useUIState.js +12 -20
- package/esm/useCode/useVariantSelection.js +62 -79
- package/esm/useCopier/index.js +29 -56
- package/esm/useDemo/createCodeSandbox.js +12 -15
- package/esm/useDemo/createStackBlitz.js +14 -20
- package/esm/useDemo/exportVariant.js +200 -180
- package/esm/useDemo/exportVariantAsCra.js +22 -25
- package/esm/useDemo/useDemo.js +80 -84
- package/esm/useErrors/ErrorsContext.js +1 -1
- package/esm/useErrors/useErrors.js +3 -3
- package/esm/useLocalStorageState/useLocalStorageState.js +23 -39
- package/esm/usePreference/PreferencesProvider.js +1 -1
- package/esm/usePreference/usePreference.js +9 -11
- package/esm/useSearch/useSearch.js +290 -387
- package/esm/useUrlHashState/useUrlHashState.js +11 -14
- package/esm/withDocsInfra/withDeploymentConfig.js +26 -21
- package/esm/withDocsInfra/withDocsInfra.js +99 -101
- package/package.json +7 -4
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
import _regenerator from "@babel/runtime/helpers/esm/regenerator";
|
|
3
|
-
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
4
1
|
import { create } from 'jsondiffpatch';
|
|
5
2
|
import { toText } from 'hast-util-to-text';
|
|
6
3
|
import { decompress, strFromU8 } from 'fflate';
|
|
7
4
|
import { decode } from 'uint8-to-base64';
|
|
8
|
-
|
|
5
|
+
const differ = create({
|
|
9
6
|
omitRemovedValues: true,
|
|
10
7
|
cloneDiffValues: true
|
|
11
8
|
});
|
|
12
|
-
function decompressAsync(input) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
decompress(input, options, function (err, output) {
|
|
9
|
+
function decompressAsync(input, options = {}) {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
decompress(input, options, (err, output) => {
|
|
16
12
|
if (err) {
|
|
17
13
|
reject(err);
|
|
18
14
|
} else {
|
|
@@ -21,123 +17,57 @@ function decompressAsync(input) {
|
|
|
21
17
|
});
|
|
22
18
|
});
|
|
23
19
|
}
|
|
24
|
-
export function transformSource(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
case 2:
|
|
58
|
-
if (!('hastJson' in source)) {
|
|
59
|
-
_context.n = 3;
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
sourceString = toText(JSON.parse(source.hastJson));
|
|
63
|
-
_context.n = 6;
|
|
64
|
-
break;
|
|
65
|
-
case 3:
|
|
66
|
-
if (!('hastGzip' in source)) {
|
|
67
|
-
_context.n = 5;
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
_t = strFromU8;
|
|
71
|
-
_context.n = 4;
|
|
72
|
-
return decompressAsync(decode(source.hastGzip), {
|
|
73
|
-
consume: true
|
|
74
|
-
});
|
|
75
|
-
case 4:
|
|
76
|
-
decompressed = _t(_context.v);
|
|
77
|
-
sourceString = toText(JSON.parse(decompressed));
|
|
78
|
-
_context.n = 6;
|
|
79
|
-
break;
|
|
80
|
-
case 5:
|
|
81
|
-
sourceString = toText(source);
|
|
82
|
-
case 6:
|
|
83
|
-
_context.n = 7;
|
|
84
|
-
return transformer(sourceString, fileName);
|
|
85
|
-
case 7:
|
|
86
|
-
transformed = _context.v;
|
|
87
|
-
if (!transformed) {
|
|
88
|
-
_context.n = 8;
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
splitSource = sourceString.split('\n');
|
|
92
|
-
return _context.a(2, Object.keys(transformed).reduce(function (acc, key) {
|
|
93
|
-
var delta = differ.diff(splitSource, transformed[key].source.split('\n'));
|
|
94
|
-
acc[key] = {
|
|
95
|
-
delta: delta,
|
|
96
|
-
fileName: transformed[key].fileName
|
|
97
|
-
};
|
|
98
|
-
return acc;
|
|
99
|
-
}, {}));
|
|
100
|
-
case 8:
|
|
101
|
-
return _context.a(2, undefined);
|
|
102
|
-
case 9:
|
|
103
|
-
_context.p = 9;
|
|
104
|
-
_t2 = _context.v;
|
|
105
|
-
throw new Error("Failed to transform source code (file: ".concat(fileName, "): ").concat(_t2 instanceof Error && _t2.message));
|
|
106
|
-
case 10:
|
|
107
|
-
return _context.a(2);
|
|
108
|
-
}
|
|
109
|
-
}, _callee, null, [[1, 9]]);
|
|
110
|
-
}));
|
|
111
|
-
return function (_x4) {
|
|
112
|
-
return _ref2.apply(this, arguments);
|
|
113
|
-
};
|
|
114
|
-
}()));
|
|
115
|
-
case 1:
|
|
116
|
-
transforms = _context2.v;
|
|
117
|
-
if (!(transforms.length === 0 || transforms.every(function (t) {
|
|
118
|
-
return t === undefined;
|
|
119
|
-
}))) {
|
|
120
|
-
_context2.n = 2;
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
return _context2.a(2, undefined);
|
|
124
|
-
case 2:
|
|
125
|
-
return _context2.a(2, transforms.reduce(function (acc, transform) {
|
|
126
|
-
if (transform) {
|
|
127
|
-
Object.entries(transform).forEach(function (_ref3) {
|
|
128
|
-
var _ref4 = _slicedToArray(_ref3, 2),
|
|
129
|
-
key = _ref4[0],
|
|
130
|
-
value = _ref4[1];
|
|
131
|
-
if (acc[key]) {
|
|
132
|
-
throw new Error("Duplicate key found in source transformations: ".concat(key));
|
|
133
|
-
}
|
|
134
|
-
acc[key] = value;
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
return acc;
|
|
138
|
-
}, {}));
|
|
20
|
+
export async function transformSource(source, fileName, sourceTransformers) {
|
|
21
|
+
const transforms = await Promise.all(sourceTransformers.map(async ({
|
|
22
|
+
extensions,
|
|
23
|
+
transformer
|
|
24
|
+
}) => {
|
|
25
|
+
if (!extensions.some(ext => fileName.endsWith(`.${ext}`))) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
let sourceString;
|
|
30
|
+
if (typeof source === 'string') {
|
|
31
|
+
sourceString = source;
|
|
32
|
+
} else if ('hastJson' in source) {
|
|
33
|
+
sourceString = toText(JSON.parse(source.hastJson));
|
|
34
|
+
} else if ('hastGzip' in source) {
|
|
35
|
+
const decompressed = strFromU8(await decompressAsync(decode(source.hastGzip), {
|
|
36
|
+
consume: true
|
|
37
|
+
}));
|
|
38
|
+
sourceString = toText(JSON.parse(decompressed));
|
|
39
|
+
} else {
|
|
40
|
+
sourceString = toText(source);
|
|
41
|
+
}
|
|
42
|
+
const transformed = await transformer(sourceString, fileName);
|
|
43
|
+
if (transformed) {
|
|
44
|
+
const splitSource = sourceString.split('\n');
|
|
45
|
+
return Object.keys(transformed).reduce((acc, key) => {
|
|
46
|
+
const delta = differ.diff(splitSource, transformed[key].source.split('\n'));
|
|
47
|
+
acc[key] = {
|
|
48
|
+
delta,
|
|
49
|
+
fileName: transformed[key].fileName
|
|
50
|
+
};
|
|
51
|
+
return acc;
|
|
52
|
+
}, {});
|
|
139
53
|
}
|
|
140
|
-
|
|
54
|
+
return undefined;
|
|
55
|
+
} catch (error) {
|
|
56
|
+
throw new Error(`Failed to transform source code (file: ${fileName}): ${error instanceof Error && error.message}`);
|
|
57
|
+
}
|
|
141
58
|
}));
|
|
142
|
-
|
|
59
|
+
if (transforms.length === 0 || transforms.every(t => t === undefined)) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
return transforms.reduce((acc, transform) => {
|
|
63
|
+
if (transform) {
|
|
64
|
+
Object.entries(transform).forEach(([key, value]) => {
|
|
65
|
+
if (acc[key]) {
|
|
66
|
+
throw new Error(`Duplicate key found in source transformations: ${key}`);
|
|
67
|
+
}
|
|
68
|
+
acc[key] = value;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return acc;
|
|
72
|
+
}, {});
|
|
143
73
|
}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
2
|
-
import _regenerator from "@babel/runtime/helpers/esm/regenerator";
|
|
3
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
|
-
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
5
1
|
// webpack does not like node: imports
|
|
6
2
|
// eslint-disable-next-line n/prefer-node-protocol
|
|
7
3
|
import path from 'path';
|
|
@@ -18,7 +14,7 @@ import { replacePrecomputeValue } from "./replacePrecomputeValue.js";
|
|
|
18
14
|
import { createLoadServerSource } from "../loadServerSource/index.js";
|
|
19
15
|
import { getFileNameFromUrl } from "../loaderUtils/index.js";
|
|
20
16
|
import { createPerformanceLogger, logPerformance, performanceMeasure } from "./performanceLogger.js";
|
|
21
|
-
|
|
17
|
+
const functionName = 'Load Precomputed Code Highlighter';
|
|
22
18
|
|
|
23
19
|
/**
|
|
24
20
|
* Webpack loader that processes demo files and precomputes variant data.
|
|
@@ -31,227 +27,170 @@ var functionName = 'Load Precomputed Code Highlighter';
|
|
|
31
27
|
*
|
|
32
28
|
* Automatically skips processing if skipPrecompute: true is set.
|
|
33
29
|
*/
|
|
34
|
-
export function loadPrecomputedCodeHighlighter(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
performanceNotableMs = (_options$performance$ = (_options$performance = options.performance) == null ? void 0 : _options$performance.notableMs) != null ? _options$performance$ : 100;
|
|
53
|
-
performanceShowWrapperMeasures = (_options$performance$2 = (_options$performance2 = options.performance) == null ? void 0 : _options$performance2.showWrapperMeasures) != null ? _options$performance$2 : false;
|
|
54
|
-
relativePath = path.relative(this.rootContext || process.cwd(), this.resourcePath);
|
|
55
|
-
observer = undefined;
|
|
56
|
-
if ((_options$performance3 = options.performance) != null && _options$performance3.logging) {
|
|
57
|
-
observer = new PerformanceObserver(createPerformanceLogger(performanceNotableMs, performanceShowWrapperMeasures, relativePath));
|
|
58
|
-
observer.observe({
|
|
59
|
-
entryTypes: ['measure']
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
currentMark = performanceMeasure(undefined, {
|
|
63
|
-
mark: 'Start',
|
|
64
|
-
measure: 'Start'
|
|
65
|
-
}, [functionName, relativePath], true); // Convert the filesystem path to a file:// URL for cross-platform compatibility
|
|
66
|
-
// pathToFileURL handles Windows drive letters correctly (e.g., C:\... → file:///C:/...)
|
|
67
|
-
resourceFileUrl = pathToFileURL(this.resourcePath).toString();
|
|
68
|
-
_context2.p = 1;
|
|
69
|
-
_context2.n = 2;
|
|
70
|
-
return parseCreateFactoryCall(source, resourceFileUrl);
|
|
71
|
-
case 2:
|
|
72
|
-
demoCall = _context2.v;
|
|
73
|
-
currentMark = performanceMeasure(currentMark, {
|
|
74
|
-
mark: 'Parsed Factory',
|
|
75
|
-
measure: 'Factory Parsing'
|
|
76
|
-
}, [functionName, relativePath]);
|
|
30
|
+
export async function loadPrecomputedCodeHighlighter(source) {
|
|
31
|
+
const callback = this.async();
|
|
32
|
+
this.cacheable();
|
|
33
|
+
const options = this.getOptions();
|
|
34
|
+
const performanceNotableMs = options.performance?.notableMs ?? 100;
|
|
35
|
+
const performanceShowWrapperMeasures = options.performance?.showWrapperMeasures ?? false;
|
|
36
|
+
const relativePath = path.relative(this.rootContext || process.cwd(), this.resourcePath);
|
|
37
|
+
let observer = undefined;
|
|
38
|
+
if (options.performance?.logging) {
|
|
39
|
+
observer = new PerformanceObserver(createPerformanceLogger(performanceNotableMs, performanceShowWrapperMeasures, relativePath));
|
|
40
|
+
observer.observe({
|
|
41
|
+
entryTypes: ['measure']
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
let currentMark = performanceMeasure(undefined, {
|
|
45
|
+
mark: 'Start',
|
|
46
|
+
measure: 'Start'
|
|
47
|
+
}, [functionName, relativePath], true);
|
|
77
48
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
callback(null, source);
|
|
91
|
-
return _context2.a(2);
|
|
92
|
-
case 4:
|
|
93
|
-
// Load variant data for all variants
|
|
94
|
-
variantData = {};
|
|
95
|
-
allDependencies = []; // Resolve all variant entry point paths using resolveVariantPathsWithFs
|
|
96
|
-
_context2.n = 5;
|
|
97
|
-
return resolveVariantPathsWithFs(demoCall.variants || {});
|
|
98
|
-
case 5:
|
|
99
|
-
resolvedVariantMap = _context2.v;
|
|
100
|
-
currentMark = performanceMeasure(currentMark, {
|
|
101
|
-
mark: 'Paths Resolved',
|
|
102
|
-
measure: 'Path Resolution'
|
|
103
|
-
}, [functionName, relativePath]);
|
|
49
|
+
// Convert the filesystem path to a file:// URL for cross-platform compatibility
|
|
50
|
+
// pathToFileURL handles Windows drive letters correctly (e.g., C:\... → file:///C:/...)
|
|
51
|
+
const resourceFileUrl = pathToFileURL(this.resourcePath).toString();
|
|
52
|
+
try {
|
|
53
|
+
// Parse the source to find a single createDemo call
|
|
54
|
+
const demoCall = await parseCreateFactoryCall(source, resourceFileUrl);
|
|
55
|
+
currentMark = performanceMeasure(currentMark, {
|
|
56
|
+
mark: 'Parsed Factory',
|
|
57
|
+
measure: 'Factory Parsing'
|
|
58
|
+
}, [functionName, relativePath]);
|
|
104
59
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
// const sourceTransformers: SourceTransformers = [TypescriptToJavascriptTransformer];
|
|
111
|
-
// TODO: maybe we should have `loadPrecomputedCodeHighlighterWithJsToTs`
|
|
112
|
-
sourceTransformers = []; // Create sourceParser promise for syntax highlighting
|
|
113
|
-
sourceParser = createParseSource();
|
|
114
|
-
functionsInitMark = performanceMeasure(currentMark, {
|
|
115
|
-
mark: 'Functions Init',
|
|
116
|
-
measure: 'Functions Init'
|
|
117
|
-
}, [functionName, relativePath]);
|
|
118
|
-
currentMark = functionsInitMark;
|
|
60
|
+
// If no createDemo call found, return the source unchanged
|
|
61
|
+
if (!demoCall) {
|
|
62
|
+
callback(null, source);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
119
65
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return _regenerator().w(function (_context) {
|
|
126
|
-
while (1) switch (_context.p = _context.n) {
|
|
127
|
-
case 0:
|
|
128
|
-
_ref3 = _slicedToArray(_ref, 2), variantName = _ref3[0], fileUrl = _ref3[1];
|
|
129
|
-
variantMark = performanceMeasure(functionsInitMark, {
|
|
130
|
-
mark: 'Variant Started',
|
|
131
|
-
measure: 'Variant Start'
|
|
132
|
-
}, [functionName, variantName, relativePath], true);
|
|
133
|
-
namedExport = (_demoCall$namedExport = demoCall.namedExports) == null ? void 0 : _demoCall$namedExport[variantName];
|
|
134
|
-
variant = fileUrl;
|
|
135
|
-
if (!namedExport) {
|
|
136
|
-
_context.n = 2;
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
_getFileNameFromUrl = getFileNameFromUrl(variant), fileName = _getFileNameFromUrl.fileName;
|
|
140
|
-
if (fileName) {
|
|
141
|
-
_context.n = 1;
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
throw new Error("Cannot determine fileName from URL \"".concat(variant, "\" for variant \"").concat(variantName, "\". ") + "Please ensure the URL has a valid file extension.");
|
|
145
|
-
case 1:
|
|
146
|
-
variant = {
|
|
147
|
-
url: fileUrl,
|
|
148
|
-
fileName: fileName,
|
|
149
|
-
namedExport: namedExport
|
|
150
|
-
};
|
|
151
|
-
case 2:
|
|
152
|
-
_context.p = 2;
|
|
153
|
-
_context.n = 3;
|
|
154
|
-
return loadCodeVariant(fileUrl,
|
|
155
|
-
// URL for the variant entry point (already includes file://)
|
|
156
|
-
variantName, variant, {
|
|
157
|
-
sourceParser: sourceParser,
|
|
158
|
-
// For syntax highlighting
|
|
159
|
-
loadSource: loadSource,
|
|
160
|
-
// For loading source files and dependencies
|
|
161
|
-
loadVariantMeta: undefined,
|
|
162
|
-
sourceTransformers: sourceTransformers,
|
|
163
|
-
// For TypeScript to JavaScript conversion
|
|
164
|
-
maxDepth: 5,
|
|
165
|
-
output: _this.getOptions().output || 'hastGzip'
|
|
166
|
-
});
|
|
167
|
-
case 3:
|
|
168
|
-
_yield$loadCodeVarian = _context.v;
|
|
169
|
-
processedVariant = _yield$loadCodeVarian.code;
|
|
170
|
-
dependencies = _yield$loadCodeVarian.dependencies;
|
|
171
|
-
performanceMeasure(variantMark, {
|
|
172
|
-
mark: 'Variant Loaded',
|
|
173
|
-
measure: 'Variant Loading'
|
|
174
|
-
}, [functionName, variantName, relativePath], true);
|
|
175
|
-
return _context.a(2, {
|
|
176
|
-
variantName: variantName,
|
|
177
|
-
variantData: processedVariant,
|
|
178
|
-
// processedVariant is a complete VariantCode
|
|
179
|
-
dependencies: dependencies // All files that were loaded
|
|
180
|
-
});
|
|
181
|
-
case 4:
|
|
182
|
-
_context.p = 4;
|
|
183
|
-
_t = _context.v;
|
|
184
|
-
throw new Error("Failed to load variant ".concat(variantName, " from ").concat(fileUrl, ": ").concat(_t));
|
|
185
|
-
case 5:
|
|
186
|
-
return _context.a(2);
|
|
187
|
-
}
|
|
188
|
-
}, _callee, null, [[2, 4]]);
|
|
189
|
-
}));
|
|
190
|
-
return function (_x2) {
|
|
191
|
-
return _ref2.apply(this, arguments);
|
|
192
|
-
};
|
|
193
|
-
}());
|
|
194
|
-
_context2.n = 6;
|
|
195
|
-
return Promise.all(variantPromises);
|
|
196
|
-
case 6:
|
|
197
|
-
variantResults = _context2.v;
|
|
198
|
-
// Process results and collect dependencies
|
|
199
|
-
_iterator = _createForOfIteratorHelper(variantResults);
|
|
200
|
-
try {
|
|
201
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
202
|
-
result = _step.value;
|
|
203
|
-
if (result) {
|
|
204
|
-
variantData[result.variantName] = result.variantData;
|
|
205
|
-
result.dependencies.forEach(function (file) {
|
|
206
|
-
allDependencies.push(file);
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
} catch (err) {
|
|
211
|
-
_iterator.e(err);
|
|
212
|
-
} finally {
|
|
213
|
-
_iterator.f();
|
|
214
|
-
}
|
|
215
|
-
currentMark = performanceMeasure(functionsInitMark, {
|
|
216
|
-
mark: 'All Variants Loaded',
|
|
217
|
-
measure: 'Complete Variants Loading'
|
|
218
|
-
}, [functionName, relativePath], true);
|
|
66
|
+
// If skipPrecompute is true, return the source unchanged
|
|
67
|
+
if (demoCall.options.skipPrecompute) {
|
|
68
|
+
callback(null, source);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
219
71
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
mark: 'Replaced Precompute',
|
|
224
|
-
measure: 'Precompute Replacement'
|
|
225
|
-
}, [functionName, relativePath]);
|
|
72
|
+
// Load variant data for all variants
|
|
73
|
+
const variantData = {};
|
|
74
|
+
const allDependencies = [];
|
|
226
75
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
76
|
+
// Resolve all variant entry point paths using resolveVariantPathsWithFs
|
|
77
|
+
const resolvedVariantMap = await resolveVariantPathsWithFs(demoCall.variants || {});
|
|
78
|
+
currentMark = performanceMeasure(currentMark, {
|
|
79
|
+
mark: 'Paths Resolved',
|
|
80
|
+
measure: 'Path Resolution'
|
|
81
|
+
}, [functionName, relativePath]);
|
|
233
82
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
83
|
+
// Create loader functions
|
|
84
|
+
const loadSource = createLoadServerSource({
|
|
85
|
+
includeDependencies: true,
|
|
86
|
+
storeAt: 'flat' // TODO: this should be configurable
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Setup source transformers for TypeScript to JavaScript conversion
|
|
90
|
+
// const sourceTransformers: SourceTransformers = [TypescriptToJavascriptTransformer];
|
|
91
|
+
// TODO: maybe we should have `loadPrecomputedCodeHighlighterWithJsToTs`
|
|
92
|
+
const sourceTransformers = [];
|
|
93
|
+
|
|
94
|
+
// Create sourceParser promise for syntax highlighting
|
|
95
|
+
const sourceParser = createParseSource();
|
|
96
|
+
const functionsInitMark = performanceMeasure(currentMark, {
|
|
97
|
+
mark: 'Functions Init',
|
|
98
|
+
measure: 'Functions Init'
|
|
99
|
+
}, [functionName, relativePath]);
|
|
100
|
+
currentMark = functionsInitMark;
|
|
101
|
+
|
|
102
|
+
// Process variants in parallel
|
|
103
|
+
const variantPromises = Array.from(resolvedVariantMap.entries()).map(async ([variantName, fileUrl]) => {
|
|
104
|
+
const variantMark = performanceMeasure(functionsInitMark, {
|
|
105
|
+
mark: 'Variant Started',
|
|
106
|
+
measure: 'Variant Start'
|
|
107
|
+
}, [functionName, variantName, relativePath], true);
|
|
108
|
+
const namedExport = demoCall.namedExports?.[variantName];
|
|
109
|
+
let variant = fileUrl;
|
|
110
|
+
if (namedExport) {
|
|
111
|
+
const {
|
|
112
|
+
fileName
|
|
113
|
+
} = getFileNameFromUrl(variant);
|
|
114
|
+
if (!fileName) {
|
|
115
|
+
throw new Error(`Cannot determine fileName from URL "${variant}" for variant "${variantName}". ` + `Please ensure the URL has a valid file extension.`);
|
|
116
|
+
}
|
|
117
|
+
variant = {
|
|
118
|
+
url: fileUrl,
|
|
119
|
+
fileName,
|
|
120
|
+
namedExport
|
|
121
|
+
};
|
|
253
122
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
123
|
+
try {
|
|
124
|
+
// Use loadCodeVariant to handle all loading, parsing, and transformation
|
|
125
|
+
// This will recursively load all dependencies using loadSource
|
|
126
|
+
const {
|
|
127
|
+
code: processedVariant,
|
|
128
|
+
dependencies
|
|
129
|
+
} = await loadCodeVariant(fileUrl,
|
|
130
|
+
// URL for the variant entry point (already includes file://)
|
|
131
|
+
variantName, variant, {
|
|
132
|
+
sourceParser,
|
|
133
|
+
// For syntax highlighting
|
|
134
|
+
loadSource,
|
|
135
|
+
// For loading source files and dependencies
|
|
136
|
+
loadVariantMeta: undefined,
|
|
137
|
+
sourceTransformers,
|
|
138
|
+
// For TypeScript to JavaScript conversion
|
|
139
|
+
maxDepth: 5,
|
|
140
|
+
output: this.getOptions().output || 'hastGzip'
|
|
141
|
+
});
|
|
142
|
+
performanceMeasure(variantMark, {
|
|
143
|
+
mark: 'Variant Loaded',
|
|
144
|
+
measure: 'Variant Loading'
|
|
145
|
+
}, [functionName, variantName, relativePath], true);
|
|
146
|
+
return {
|
|
147
|
+
variantName,
|
|
148
|
+
variantData: processedVariant,
|
|
149
|
+
// processedVariant is a complete VariantCode
|
|
150
|
+
dependencies // All files that were loaded
|
|
151
|
+
};
|
|
152
|
+
} catch (error) {
|
|
153
|
+
throw new Error(`Failed to load variant ${variantName} from ${fileUrl}: ${error}`);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
const variantResults = await Promise.all(variantPromises);
|
|
157
|
+
|
|
158
|
+
// Process results and collect dependencies
|
|
159
|
+
for (const result of variantResults) {
|
|
160
|
+
if (result) {
|
|
161
|
+
variantData[result.variantName] = result.variantData;
|
|
162
|
+
result.dependencies.forEach(file => {
|
|
163
|
+
allDependencies.push(file);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
currentMark = performanceMeasure(functionsInitMark, {
|
|
168
|
+
mark: 'All Variants Loaded',
|
|
169
|
+
measure: 'Complete Variants Loading'
|
|
170
|
+
}, [functionName, relativePath], true);
|
|
171
|
+
|
|
172
|
+
// Replace the factory function call with the actual precomputed data
|
|
173
|
+
const modifiedSource = replacePrecomputeValue(source, variantData, demoCall);
|
|
174
|
+
currentMark = performanceMeasure(currentMark, {
|
|
175
|
+
mark: 'Replaced Precompute',
|
|
176
|
+
measure: 'Precompute Replacement'
|
|
177
|
+
}, [functionName, relativePath]);
|
|
178
|
+
|
|
179
|
+
// Add all dependencies to webpack's watch list
|
|
180
|
+
allDependencies.forEach(dep => {
|
|
181
|
+
// Convert file:// URLs to proper file system paths for webpack's dependency tracking
|
|
182
|
+
// Using fileURLToPath handles Windows drive letters correctly (e.g., file:///C:/... → C:\...)
|
|
183
|
+
this.addDependency(dep.startsWith('file://') ? fileURLToPath(dep) : dep);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
// log any pending performance entries before completing
|
|
187
|
+
observer?.takeRecords()?.forEach(entry => logPerformance(entry, performanceNotableMs, performanceShowWrapperMeasures, relativePath));
|
|
188
|
+
observer?.disconnect();
|
|
189
|
+
callback(null, modifiedSource);
|
|
190
|
+
} catch (error) {
|
|
191
|
+
// log any pending performance entries before completing
|
|
192
|
+
observer?.takeRecords()?.forEach(entry => logPerformance(entry, performanceNotableMs, performanceShowWrapperMeasures, relativePath));
|
|
193
|
+
observer?.disconnect();
|
|
194
|
+
callback(error instanceof Error ? error : new Error(String(error)));
|
|
195
|
+
}
|
|
257
196
|
}
|