@mui/internal-docs-infra 0.1.0 → 0.1.1-alpha.0
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/README.md +3 -1
- package/build/CodeControllerContext/CodeControllerContext.d.ts +22 -0
- package/build/CodeControllerContext/CodeControllerContext.js +21 -0
- package/build/CodeControllerContext/index.d.ts +1 -0
- package/build/CodeControllerContext/index.js +16 -0
- package/build/CodeHighlighter/CodeHighlighter.d.ts +2 -0
- package/build/CodeHighlighter/CodeHighlighter.js +329 -0
- package/build/CodeHighlighter/CodeHighlighterClient.d.ts +2 -0
- package/build/CodeHighlighter/CodeHighlighterClient.js +406 -0
- package/build/CodeHighlighter/CodeHighlighterContext.d.ts +14 -0
- package/build/CodeHighlighter/CodeHighlighterContext.js +22 -0
- package/build/CodeHighlighter/CodeHighlighterFallbackContext.d.ts +7 -0
- package/build/CodeHighlighter/CodeHighlighterFallbackContext.js +18 -0
- package/build/CodeHighlighter/applyTransform.d.ts +19 -0
- package/build/CodeHighlighter/applyTransform.js +83 -0
- package/build/CodeHighlighter/codeToFallbackProps.d.ts +2 -0
- package/build/CodeHighlighter/codeToFallbackProps.js +77 -0
- package/build/CodeHighlighter/errors.d.ts +0 -0
- package/build/CodeHighlighter/errors.js +2 -0
- package/build/CodeHighlighter/hasAllVariants.d.ts +2 -0
- package/build/CodeHighlighter/hasAllVariants.js +37 -0
- package/build/CodeHighlighter/index.d.ts +4 -0
- package/build/CodeHighlighter/index.js +49 -0
- package/build/CodeHighlighter/loadFallbackCode.d.ts +9 -0
- package/build/CodeHighlighter/loadFallbackCode.js +474 -0
- package/build/CodeHighlighter/loadVariant.d.ts +11 -0
- package/build/CodeHighlighter/loadVariant.js +715 -0
- package/build/CodeHighlighter/maybeInitialData.d.ts +10 -0
- package/build/CodeHighlighter/maybeInitialData.js +101 -0
- package/build/CodeHighlighter/parseCode.d.ts +6 -0
- package/build/CodeHighlighter/parseCode.js +129 -0
- package/build/CodeHighlighter/parseControlledCode.d.ts +6 -0
- package/build/CodeHighlighter/parseControlledCode.js +83 -0
- package/build/CodeHighlighter/transformCode.d.ts +20 -0
- package/build/CodeHighlighter/transformCode.js +231 -0
- package/build/CodeHighlighter/transformParsedSource.d.ts +3 -0
- package/build/CodeHighlighter/transformParsedSource.js +73 -0
- package/build/CodeHighlighter/transformSource.d.ts +2 -0
- package/build/CodeHighlighter/transformSource.js +114 -0
- package/build/CodeHighlighter/types.d.ts +138 -0
- package/build/CodeHighlighter/types.js +5 -0
- package/build/CodeProvider/CodeContext.d.ts +12 -0
- package/build/CodeProvider/CodeContext.js +14 -0
- package/build/CodeProvider/CodeProvider.d.ts +13 -0
- package/build/CodeProvider/CodeProvider.js +57 -0
- package/build/CodeProvider/index.d.ts +2 -0
- package/build/CodeProvider/index.js +27 -0
- package/build/README.md +19 -0
- package/build/esm/CodeControllerContext/CodeControllerContext.d.ts +22 -0
- package/build/esm/CodeControllerContext/CodeControllerContext.d.ts.map +1 -0
- package/build/esm/CodeControllerContext/CodeControllerContext.js +14 -0
- package/build/esm/CodeControllerContext/index.d.ts +1 -0
- package/build/esm/CodeControllerContext/index.d.ts.map +1 -0
- package/build/esm/CodeControllerContext/index.js +1 -0
- package/build/esm/CodeHighlighter/CodeHighlighter.d.ts +2 -0
- package/build/esm/CodeHighlighter/CodeHighlighter.d.ts.map +1 -0
- package/build/esm/CodeHighlighter/CodeHighlighter.js +321 -0
- package/build/esm/CodeHighlighter/CodeHighlighterClient.d.ts +2 -0
- package/build/esm/CodeHighlighter/CodeHighlighterClient.d.ts.map +1 -0
- package/build/esm/CodeHighlighter/CodeHighlighterClient.js +399 -0
- package/build/esm/CodeHighlighter/CodeHighlighterContext.d.ts +14 -0
- package/build/esm/CodeHighlighter/CodeHighlighterContext.d.ts.map +1 -0
- package/build/esm/CodeHighlighter/CodeHighlighterContext.js +14 -0
- package/build/esm/CodeHighlighter/CodeHighlighterFallbackContext.d.ts +7 -0
- package/build/esm/CodeHighlighter/CodeHighlighterFallbackContext.d.ts.map +1 -0
- package/build/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +11 -0
- package/build/esm/CodeHighlighter/applyTransform.d.ts +19 -0
- package/build/esm/CodeHighlighter/applyTransform.d.ts.map +1 -0
- package/build/esm/CodeHighlighter/applyTransform.js +75 -0
- package/build/esm/CodeHighlighter/codeToFallbackProps.d.ts +2 -0
- package/build/esm/CodeHighlighter/codeToFallbackProps.d.ts.map +1 -0
- package/build/esm/CodeHighlighter/codeToFallbackProps.js +70 -0
- package/build/esm/CodeHighlighter/errors.d.ts +0 -0
- package/build/esm/CodeHighlighter/errors.d.ts.map +1 -0
- package/build/esm/CodeHighlighter/errors.js +1 -0
- package/build/esm/CodeHighlighter/hasAllVariants.d.ts +2 -0
- package/build/esm/CodeHighlighter/hasAllVariants.d.ts.map +1 -0
- package/build/esm/CodeHighlighter/hasAllVariants.js +31 -0
- package/build/esm/CodeHighlighter/index.d.ts +4 -0
- package/build/esm/CodeHighlighter/index.d.ts.map +1 -0
- package/build/esm/CodeHighlighter/index.js +4 -0
- package/build/esm/CodeHighlighter/loadFallbackCode.d.ts +9 -0
- package/build/esm/CodeHighlighter/loadFallbackCode.d.ts.map +1 -0
- package/build/esm/CodeHighlighter/loadFallbackCode.js +468 -0
- package/build/esm/CodeHighlighter/loadVariant.d.ts +11 -0
- package/build/esm/CodeHighlighter/loadVariant.d.ts.map +1 -0
- package/build/esm/CodeHighlighter/loadVariant.js +708 -0
- package/build/esm/CodeHighlighter/maybeInitialData.d.ts +10 -0
- package/build/esm/CodeHighlighter/maybeInitialData.d.ts.map +1 -0
- package/build/esm/CodeHighlighter/maybeInitialData.js +94 -0
- package/build/esm/CodeHighlighter/parseCode.d.ts +6 -0
- package/build/esm/CodeHighlighter/parseCode.d.ts.map +1 -0
- package/build/esm/CodeHighlighter/parseCode.js +122 -0
- package/build/esm/CodeHighlighter/parseControlledCode.d.ts +6 -0
- package/build/esm/CodeHighlighter/parseControlledCode.d.ts.map +1 -0
- package/build/esm/CodeHighlighter/parseControlledCode.js +76 -0
- package/build/esm/CodeHighlighter/transformCode.d.ts +20 -0
- package/build/esm/CodeHighlighter/transformCode.d.ts.map +1 -0
- package/build/esm/CodeHighlighter/transformCode.js +223 -0
- package/build/esm/CodeHighlighter/transformParsedSource.d.ts +3 -0
- package/build/esm/CodeHighlighter/transformParsedSource.d.ts.map +1 -0
- package/build/esm/CodeHighlighter/transformParsedSource.js +66 -0
- package/build/esm/CodeHighlighter/transformSource.d.ts +2 -0
- package/build/esm/CodeHighlighter/transformSource.d.ts.map +1 -0
- package/build/esm/CodeHighlighter/transformSource.js +107 -0
- package/build/esm/CodeHighlighter/types.d.ts +138 -0
- package/build/esm/CodeHighlighter/types.d.ts.map +1 -0
- package/build/esm/CodeHighlighter/types.js +1 -0
- package/build/esm/CodeProvider/CodeContext.d.ts +12 -0
- package/build/esm/CodeProvider/CodeContext.d.ts.map +1 -0
- package/build/esm/CodeProvider/CodeContext.js +8 -0
- package/build/esm/CodeProvider/CodeProvider.d.ts +13 -0
- package/build/esm/CodeProvider/CodeProvider.d.ts.map +1 -0
- package/build/esm/CodeProvider/CodeProvider.js +50 -0
- package/build/esm/CodeProvider/index.d.ts +2 -0
- package/build/esm/CodeProvider/index.d.ts.map +1 -0
- package/build/esm/CodeProvider/index.js +2 -0
- package/build/esm/hast/hast.d.ts +11 -0
- package/build/esm/hast/hast.d.ts.map +1 -0
- package/build/esm/hast/hast.js +66 -0
- package/build/esm/hast/index.d.ts +1 -0
- package/build/esm/hast/index.d.ts.map +1 -0
- package/build/esm/hast/index.js +1 -0
- package/build/esm/loadPrecomputedCodeHighlighter/index.d.ts +2 -0
- package/build/esm/loadPrecomputedCodeHighlighter/index.d.ts.map +1 -0
- package/build/esm/loadPrecomputedCodeHighlighter/index.js +4 -0
- package/build/esm/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts +57 -0
- package/build/esm/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts.map +1 -0
- package/build/esm/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +194 -0
- package/build/esm/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.d.ts +20 -0
- package/build/esm/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.d.ts.map +1 -0
- package/build/esm/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +243 -0
- package/build/esm/loadPrecomputedCodeHighlighter/parseFunctionParameters.d.ts +15 -0
- package/build/esm/loadPrecomputedCodeHighlighter/parseFunctionParameters.d.ts.map +1 -0
- package/build/esm/loadPrecomputedCodeHighlighter/parseFunctionParameters.js +168 -0
- package/build/esm/loadPrecomputedCodeHighlighter/replacePrecomputeValue.d.ts +27 -0
- package/build/esm/loadPrecomputedCodeHighlighter/replacePrecomputeValue.d.ts.map +1 -0
- package/build/esm/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +37 -0
- package/build/esm/loadServerCodeMeta/index.d.ts +1 -0
- package/build/esm/loadServerCodeMeta/index.d.ts.map +1 -0
- package/build/esm/loadServerCodeMeta/index.js +1 -0
- package/build/esm/loadServerCodeMeta/serverLoadCodeMeta.d.ts +24 -0
- package/build/esm/loadServerCodeMeta/serverLoadCodeMeta.d.ts.map +1 -0
- package/build/esm/loadServerCodeMeta/serverLoadCodeMeta.js +77 -0
- package/build/esm/loadServerSource/index.d.ts +1 -0
- package/build/esm/loadServerSource/index.d.ts.map +1 -0
- package/build/esm/loadServerSource/index.js +1 -0
- package/build/esm/loadServerSource/serverLoadSource.d.ts +25 -0
- package/build/esm/loadServerSource/serverLoadSource.d.ts.map +1 -0
- package/build/esm/loadServerSource/serverLoadSource.js +100 -0
- package/build/esm/loaderUtils/getFileNameFromUrl.d.ts +11 -0
- package/build/esm/loaderUtils/getFileNameFromUrl.d.ts.map +1 -0
- package/build/esm/loaderUtils/getFileNameFromUrl.js +32 -0
- package/build/esm/loaderUtils/index.d.ts +5 -0
- package/build/esm/loaderUtils/index.d.ts.map +1 -0
- package/build/esm/loaderUtils/index.js +5 -0
- package/build/esm/loaderUtils/processImports.d.ts +19 -0
- package/build/esm/loaderUtils/processImports.d.ts.map +1 -0
- package/build/esm/loaderUtils/processImports.js +82 -0
- package/build/esm/loaderUtils/resolveImports.d.ts +4 -0
- package/build/esm/loaderUtils/resolveImports.d.ts.map +1 -0
- package/build/esm/loaderUtils/resolveImports.js +71 -0
- package/build/esm/loaderUtils/resolveModulePath.d.ts +74 -0
- package/build/esm/loaderUtils/resolveModulePath.d.ts.map +1 -0
- package/build/esm/loaderUtils/resolveModulePath.js +827 -0
- package/build/esm/loaderUtils/resolveModulePathWithFs.d.ts +44 -0
- package/build/esm/loaderUtils/resolveModulePathWithFs.d.ts.map +1 -0
- package/build/esm/loaderUtils/resolveModulePathWithFs.js +159 -0
- package/build/esm/loaderUtils/rewriteImports.d.ts +9 -0
- package/build/esm/loaderUtils/rewriteImports.d.ts.map +1 -0
- package/build/esm/loaderUtils/rewriteImports.js +57 -0
- package/build/esm/parseSource/grammars.d.ts +2 -0
- package/build/esm/parseSource/grammars.d.ts.map +1 -0
- package/build/esm/parseSource/grammars.js +27 -0
- package/build/esm/parseSource/index.d.ts +1 -0
- package/build/esm/parseSource/index.d.ts.map +1 -0
- package/build/esm/parseSource/index.js +1 -0
- package/build/esm/parseSource/parseSource.d.ts +3 -0
- package/build/esm/parseSource/parseSource.d.ts.map +1 -0
- package/build/esm/parseSource/parseSource.js +37 -0
- package/build/esm/transformRelativeMarkdownPaths/index.d.ts +2 -0
- package/build/esm/transformRelativeMarkdownPaths/index.d.ts.map +1 -0
- package/build/esm/transformRelativeMarkdownPaths/index.js +4 -0
- package/build/esm/transformRelativeMarkdownPaths/transformRelativeMarkdownPaths.d.ts +12 -0
- package/build/esm/transformRelativeMarkdownPaths/transformRelativeMarkdownPaths.d.ts.map +1 -0
- package/build/esm/transformRelativeMarkdownPaths/transformRelativeMarkdownPaths.js +30 -0
- package/build/esm/transformTsToJs/index.d.ts +1 -0
- package/build/esm/transformTsToJs/index.d.ts.map +1 -0
- package/build/esm/transformTsToJs/index.js +1 -0
- package/build/esm/transformTsToJs/removeTypes.d.ts +13 -0
- package/build/esm/transformTsToJs/removeTypes.d.ts.map +1 -0
- package/build/esm/transformTsToJs/removeTypes.js +134 -0
- package/build/esm/transformTsToJs/transformTsToJs.d.ts +3 -0
- package/build/esm/transformTsToJs/transformTsToJs.d.ts.map +1 -0
- package/build/esm/transformTsToJs/transformTsToJs.js +34 -0
- package/build/esm/useCode/index.d.ts +1 -0
- package/build/esm/useCode/index.d.ts.map +1 -0
- package/build/esm/useCode/index.js +1 -0
- package/build/esm/useCode/useCode.d.ts +37 -0
- package/build/esm/useCode/useCode.d.ts.map +1 -0
- package/build/esm/useCode/useCode.js +393 -0
- package/{esm → build/esm}/useDemo/index.d.ts +12 -24
- package/build/esm/useDemo/index.d.ts.map +1 -0
- package/build/esm/useDemo/index.js +17 -0
- package/build/esm/useOnHydrate/index.d.ts +1 -0
- package/build/esm/useOnHydrate/index.d.ts.map +1 -0
- package/build/esm/useOnHydrate/index.js +1 -0
- package/build/esm/useOnHydrate/useOnHydrate.d.ts +1 -0
- package/build/esm/useOnHydrate/useOnHydrate.d.ts.map +1 -0
- package/build/esm/useOnHydrate/useOnHydrate.js +18 -0
- package/build/esm/useOnIdle/index.d.ts +1 -0
- package/build/esm/useOnIdle/index.d.ts.map +1 -0
- package/build/esm/useOnIdle/index.js +1 -0
- package/build/esm/useOnIdle/useOnIdle.d.ts +1 -0
- package/build/esm/useOnIdle/useOnIdle.d.ts.map +1 -0
- package/build/esm/useOnIdle/useOnIdle.js +39 -0
- package/build/hast/hast.d.ts +11 -0
- package/build/hast/hast.js +75 -0
- package/build/hast/index.d.ts +1 -0
- package/build/hast/index.js +16 -0
- package/build/loadPrecomputedCodeHighlighter/index.d.ts +2 -0
- package/build/loadPrecomputedCodeHighlighter/index.js +9 -0
- package/build/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts +57 -0
- package/build/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +201 -0
- package/build/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.d.ts +20 -0
- package/build/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +248 -0
- package/build/loadPrecomputedCodeHighlighter/parseFunctionParameters.d.ts +15 -0
- package/build/loadPrecomputedCodeHighlighter/parseFunctionParameters.js +174 -0
- package/build/loadPrecomputedCodeHighlighter/replacePrecomputeValue.d.ts +27 -0
- package/build/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +43 -0
- package/build/loadServerCodeMeta/index.d.ts +1 -0
- package/build/loadServerCodeMeta/index.js +16 -0
- package/build/loadServerCodeMeta/serverLoadCodeMeta.d.ts +24 -0
- package/build/loadServerCodeMeta/serverLoadCodeMeta.js +85 -0
- package/build/loadServerSource/index.d.ts +1 -0
- package/build/loadServerSource/index.js +16 -0
- package/build/loadServerSource/serverLoadSource.d.ts +25 -0
- package/build/loadServerSource/serverLoadSource.js +108 -0
- package/build/loaderUtils/getFileNameFromUrl.d.ts +11 -0
- package/build/loaderUtils/getFileNameFromUrl.js +38 -0
- package/build/loaderUtils/index.d.ts +5 -0
- package/build/loaderUtils/index.js +60 -0
- package/build/loaderUtils/processImports.d.ts +19 -0
- package/build/loaderUtils/processImports.js +89 -0
- package/build/loaderUtils/resolveImports.d.ts +4 -0
- package/build/loaderUtils/resolveImports.js +78 -0
- package/build/loaderUtils/resolveModulePath.d.ts +74 -0
- package/build/loaderUtils/resolveModulePath.js +835 -0
- package/build/loaderUtils/resolveModulePathWithFs.d.ts +44 -0
- package/build/loaderUtils/resolveModulePathWithFs.js +163 -0
- package/build/loaderUtils/rewriteImports.d.ts +9 -0
- package/build/loaderUtils/rewriteImports.js +62 -0
- package/build/package.json +101 -0
- package/build/parseSource/grammars.d.ts +2 -0
- package/build/parseSource/grammars.js +34 -0
- package/build/parseSource/index.d.ts +1 -0
- package/build/parseSource/index.js +16 -0
- package/build/parseSource/parseSource.d.ts +3 -0
- package/build/parseSource/parseSource.js +44 -0
- package/build/transformRelativeMarkdownPaths/index.d.ts +2 -0
- package/build/transformRelativeMarkdownPaths/index.js +9 -0
- package/build/transformRelativeMarkdownPaths/transformRelativeMarkdownPaths.d.ts +12 -0
- package/build/transformRelativeMarkdownPaths/transformRelativeMarkdownPaths.js +36 -0
- package/build/transformTsToJs/index.d.ts +1 -0
- package/build/transformTsToJs/index.js +16 -0
- package/build/transformTsToJs/removeTypes.d.ts +13 -0
- package/build/transformTsToJs/removeTypes.js +141 -0
- package/build/transformTsToJs/transformTsToJs.d.ts +3 -0
- package/build/transformTsToJs/transformTsToJs.js +41 -0
- package/build/useCode/index.d.ts +1 -0
- package/build/useCode/index.js +16 -0
- package/build/useCode/useCode.d.ts +37 -0
- package/build/useCode/useCode.js +401 -0
- package/{useDemo → build/useDemo}/index.d.ts +12 -24
- package/build/useDemo/index.js +25 -0
- package/build/useOnHydrate/index.d.ts +1 -0
- package/build/useOnHydrate/index.js +16 -0
- package/build/useOnHydrate/useOnHydrate.d.ts +1 -0
- package/build/useOnHydrate/useOnHydrate.js +26 -0
- package/build/useOnIdle/index.d.ts +1 -0
- package/build/useOnIdle/index.js +16 -0
- package/build/useOnIdle/useOnIdle.d.ts +1 -0
- package/build/useOnIdle/useOnIdle.js +47 -0
- package/package.json +86 -14
- package/esm/useDemo/index.d.ts.map +0 -1
- package/esm/useDemo/index.js +0 -104
- package/useDemo/index.js +0 -112
- /package/{LICENSE → build/LICENSE} +0 -0
- /package/{esm → build/esm}/package.json +0 -0
- /package/{esm → build/esm}/useCopier/index.d.ts +0 -0
- /package/{esm → build/esm}/useCopier/index.d.ts.map +0 -0
- /package/{esm → build/esm}/useCopier/index.js +0 -0
- /package/{useCopier → build/useCopier}/index.d.ts +0 -0
- /package/{useCopier → build/useCopier}/index.js +0 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replaces 'precompute: true' with the actual precomputed data in source code.
|
|
3
|
+
*
|
|
4
|
+
* This function performs a precise replacement of the boolean true value in
|
|
5
|
+
* 'precompute: true' expressions with the provided data object, keeping the
|
|
6
|
+
* rest of the source code unchanged.
|
|
7
|
+
*
|
|
8
|
+
* @param source - The source code string containing 'precompute: true'
|
|
9
|
+
* @param precomputeData - The data object to replace the true value with
|
|
10
|
+
* @returns The modified source code with precompute data injected
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const source = `
|
|
15
|
+
* export const demo = createDemo(
|
|
16
|
+
* import.meta.url,
|
|
17
|
+
* { Component },
|
|
18
|
+
* { precompute: true }
|
|
19
|
+
* );
|
|
20
|
+
* `;
|
|
21
|
+
*
|
|
22
|
+
* const data = { variants: { default: { code: "..." } } };
|
|
23
|
+
* const result = replacePrecomputeValue(source, data);
|
|
24
|
+
* // Result will have 'precompute: true' replaced with 'precompute: { variants: { default: { code: "..." } } }'
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function replacePrecomputeValue(source, precomputeData) {
|
|
28
|
+
// Regex to match 'precompute: true' with optional whitespace
|
|
29
|
+
var precomputeRegex = /precompute\s*:\s*true/g;
|
|
30
|
+
|
|
31
|
+
// Convert the data to a properly formatted JSON string
|
|
32
|
+
var precomputeDataString = JSON.stringify(precomputeData, null, 2);
|
|
33
|
+
|
|
34
|
+
// Replace 'precompute: true' with 'precompute: {data}'
|
|
35
|
+
// The regex will match the exact pattern and we replace just that part
|
|
36
|
+
return source.replace(precomputeRegex, "precompute: ".concat(precomputeDataString));
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./serverLoadCodeMeta.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/loadServerCodeMeta/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./serverLoadCodeMeta.js";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { LoadCodeMeta } from "../CodeHighlighter/types.js";
|
|
2
|
+
export interface CreateLoadCodeMetaOptions {}
|
|
3
|
+
/**
|
|
4
|
+
* Default serverLoadCodeMeta function that resolves variant paths from demo files.
|
|
5
|
+
* This function is used to load code metadata for demos, specifically resolving paths for variants defined in the demo files.
|
|
6
|
+
* It reads the demo file, parses it to find `createDemo` calls with variants, and resolves the paths for those variants.
|
|
7
|
+
* It returns a Code object mapping variant names to their resolved file URLs.
|
|
8
|
+
*/
|
|
9
|
+
export declare const serverLoadCodeMeta: LoadCodeMeta;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a loadCodeMeta function that resolves variant paths from demo files.
|
|
12
|
+
*
|
|
13
|
+
* This factory function creates a LoadCodeMeta implementation that:
|
|
14
|
+
* 1. Parses the demo file to find createDemo calls with variants
|
|
15
|
+
* 2. Resolves all variant entry point paths using resolveVariantPaths
|
|
16
|
+
* 3. Returns a Code object mapping variant names to their resolved file URLs
|
|
17
|
+
*
|
|
18
|
+
* The actual loading, parsing, and transformation of the variants is handled
|
|
19
|
+
* elsewhere by the CodeHighlighter component using loadVariant.
|
|
20
|
+
*
|
|
21
|
+
* @param options - Configuration options (currently unused)
|
|
22
|
+
* @returns LoadCodeMeta function that takes a URL and returns Promise<Code>
|
|
23
|
+
*/
|
|
24
|
+
export declare function createServerLoadCodeMeta(_options?: CreateLoadCodeMetaOptions): LoadCodeMeta;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverLoadCodeMeta.d.ts","sourceRoot":"","sources":["../../../src/loadServerCodeMeta/serverLoadCodeMeta.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAQ,MAAM,0BAA0B,CAAC;AAInE,MAAM,WAAW,yBAAyB;CAEzC;AAED;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,cAA6B,CAAC;AAE7D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,GAAE,yBAA8B,GAAG,YAAY,CA4B/F"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
4
|
+
import { readFile } from 'node:fs/promises';
|
|
5
|
+
import { resolveVariantPathsWithFs } from "../loaderUtils/resolveModulePathWithFs.js";
|
|
6
|
+
import { parseCreateFactoryCall } from "../loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js";
|
|
7
|
+
/**
|
|
8
|
+
* Default serverLoadCodeMeta function that resolves variant paths from demo files.
|
|
9
|
+
* This function is used to load code metadata for demos, specifically resolving paths for variants defined in the demo files.
|
|
10
|
+
* It reads the demo file, parses it to find `createDemo` calls with variants, and resolves the paths for those variants.
|
|
11
|
+
* It returns a Code object mapping variant names to their resolved file URLs.
|
|
12
|
+
*/
|
|
13
|
+
export var serverLoadCodeMeta = createServerLoadCodeMeta();
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Creates a loadCodeMeta function that resolves variant paths from demo files.
|
|
17
|
+
*
|
|
18
|
+
* This factory function creates a LoadCodeMeta implementation that:
|
|
19
|
+
* 1. Parses the demo file to find createDemo calls with variants
|
|
20
|
+
* 2. Resolves all variant entry point paths using resolveVariantPaths
|
|
21
|
+
* 3. Returns a Code object mapping variant names to their resolved file URLs
|
|
22
|
+
*
|
|
23
|
+
* The actual loading, parsing, and transformation of the variants is handled
|
|
24
|
+
* elsewhere by the CodeHighlighter component using loadVariant.
|
|
25
|
+
*
|
|
26
|
+
* @param options - Configuration options (currently unused)
|
|
27
|
+
* @returns LoadCodeMeta function that takes a URL and returns Promise<Code>
|
|
28
|
+
*/
|
|
29
|
+
export function createServerLoadCodeMeta() {
|
|
30
|
+
var _options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
31
|
+
return /*#__PURE__*/function () {
|
|
32
|
+
var _loadCodeMeta = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(url) {
|
|
33
|
+
var filePath, source, demoCall, code, resolvedVariantMap;
|
|
34
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
35
|
+
while (1) switch (_context.prev = _context.next) {
|
|
36
|
+
case 0:
|
|
37
|
+
// Remove file:// prefix if present to get file path
|
|
38
|
+
filePath = url.replace('file://', ''); // Read the source file to find createDemo calls
|
|
39
|
+
_context.next = 3;
|
|
40
|
+
return readFile(filePath, 'utf-8');
|
|
41
|
+
case 3:
|
|
42
|
+
source = _context.sent;
|
|
43
|
+
_context.next = 6;
|
|
44
|
+
return parseCreateFactoryCall(source, filePath);
|
|
45
|
+
case 6:
|
|
46
|
+
demoCall = _context.sent;
|
|
47
|
+
if (!(!demoCall || !demoCall.variants)) {
|
|
48
|
+
_context.next = 9;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
return _context.abrupt("return", {});
|
|
52
|
+
case 9:
|
|
53
|
+
code = {}; // Resolve all variant paths and get them as file URLs
|
|
54
|
+
_context.next = 12;
|
|
55
|
+
return resolveVariantPathsWithFs(demoCall.variants);
|
|
56
|
+
case 12:
|
|
57
|
+
resolvedVariantMap = _context.sent;
|
|
58
|
+
// Build Code object from the resolved variant map
|
|
59
|
+
Array.from(resolvedVariantMap.entries()).forEach(function (_ref) {
|
|
60
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
61
|
+
variantName = _ref2[0],
|
|
62
|
+
fileUrl = _ref2[1];
|
|
63
|
+
code[variantName] = fileUrl;
|
|
64
|
+
});
|
|
65
|
+
return _context.abrupt("return", code);
|
|
66
|
+
case 15:
|
|
67
|
+
case "end":
|
|
68
|
+
return _context.stop();
|
|
69
|
+
}
|
|
70
|
+
}, _callee);
|
|
71
|
+
}));
|
|
72
|
+
function loadCodeMeta(_x) {
|
|
73
|
+
return _loadCodeMeta.apply(this, arguments);
|
|
74
|
+
}
|
|
75
|
+
return loadCodeMeta;
|
|
76
|
+
}();
|
|
77
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./serverLoadSource.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/loadServerSource/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./serverLoadSource.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { LoadSource } from "../CodeHighlighter/types.js";
|
|
2
|
+
import { type StoreAtMode } from "../loaderUtils/processImports.js";
|
|
3
|
+
interface LoadSourceOptions {
|
|
4
|
+
maxDepth?: number;
|
|
5
|
+
maxFiles?: number;
|
|
6
|
+
includeDependencies?: boolean;
|
|
7
|
+
storeAt?: StoreAtMode;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Default serverLoadSource function that reads a file and extracts its dependencies.
|
|
11
|
+
* This function is used to load source files for demos, resolving their imports and dependencies.
|
|
12
|
+
* It reads the source file, resolves its imports, and returns the processed source along with any
|
|
13
|
+
* additional files and dependencies that were found.
|
|
14
|
+
*/
|
|
15
|
+
export declare const serverLoadSource: LoadSource;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a loadSource function that reads a file and extracts its dependencies.
|
|
18
|
+
*
|
|
19
|
+
* @param options.storeAt - Controls how imports are stored in extraFiles:
|
|
20
|
+
* - 'canonical': Full resolved path (e.g., '../Component/index.js')
|
|
21
|
+
* - 'import': Import path with file extension (e.g., '../Component.js')
|
|
22
|
+
* - 'flat': Flattened to current directory with rewritten imports (e.g., './Component.js')
|
|
23
|
+
*/
|
|
24
|
+
export declare function createServerLoadSource(options?: LoadSourceOptions): LoadSource;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverLoadSource.d.ts","sourceRoot":"","sources":["../../../src/loadServerSource/serverLoadSource.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAG3D,OAAO,EAA6B,KAAK,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAG5F,UAAU,iBAAiB;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB;AAED;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,YAA2B,CAAC;AAEzD;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,GAAE,iBAAsB,GAAG,UAAU,CAmDlF"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
|
+
import { readFile } from 'node:fs/promises';
|
|
4
|
+
import { resolveImports } from "../loaderUtils/resolveImports.js";
|
|
5
|
+
import { resolveImportResultWithFs } from "../loaderUtils/resolveModulePathWithFs.js";
|
|
6
|
+
import { processImportsWithStoreAt } from "../loaderUtils/processImports.js";
|
|
7
|
+
import { isJavaScriptModule } from "../loaderUtils/resolveModulePath.js";
|
|
8
|
+
/**
|
|
9
|
+
* Default serverLoadSource function that reads a file and extracts its dependencies.
|
|
10
|
+
* This function is used to load source files for demos, resolving their imports and dependencies.
|
|
11
|
+
* It reads the source file, resolves its imports, and returns the processed source along with any
|
|
12
|
+
* additional files and dependencies that were found.
|
|
13
|
+
*/
|
|
14
|
+
export var serverLoadSource = createServerLoadSource();
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Creates a loadSource function that reads a file and extracts its dependencies.
|
|
18
|
+
*
|
|
19
|
+
* @param options.storeAt - Controls how imports are stored in extraFiles:
|
|
20
|
+
* - 'canonical': Full resolved path (e.g., '../Component/index.js')
|
|
21
|
+
* - 'import': Import path with file extension (e.g., '../Component.js')
|
|
22
|
+
* - 'flat': Flattened to current directory with rewritten imports (e.g., './Component.js')
|
|
23
|
+
*/
|
|
24
|
+
export function createServerLoadSource() {
|
|
25
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
26
|
+
var _options$includeDepen = options.includeDependencies,
|
|
27
|
+
includeDependencies = _options$includeDepen === void 0 ? true : _options$includeDepen,
|
|
28
|
+
_options$storeAt = options.storeAt,
|
|
29
|
+
storeAt = _options$storeAt === void 0 ? 'flat' : _options$storeAt;
|
|
30
|
+
return /*#__PURE__*/function () {
|
|
31
|
+
var _loadSource = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(url) {
|
|
32
|
+
var filePath, source, isJavascriptModuleFile, importResult, resolvedPathsMap, _processImportsWithSt, processedSource, extraFiles, extraDependencies;
|
|
33
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
34
|
+
while (1) switch (_context.prev = _context.next) {
|
|
35
|
+
case 0:
|
|
36
|
+
// Remove file:// prefix if present
|
|
37
|
+
filePath = url.replace('file://', ''); // Read the file
|
|
38
|
+
_context.next = 3;
|
|
39
|
+
return readFile(filePath, 'utf8');
|
|
40
|
+
case 3:
|
|
41
|
+
source = _context.sent;
|
|
42
|
+
if (includeDependencies) {
|
|
43
|
+
_context.next = 6;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
return _context.abrupt("return", {
|
|
47
|
+
source: source
|
|
48
|
+
});
|
|
49
|
+
case 6:
|
|
50
|
+
// Check if this is a static asset file (non-JS/TS modules)
|
|
51
|
+
isJavascriptModuleFile = isJavaScriptModule(filePath);
|
|
52
|
+
if (isJavascriptModuleFile) {
|
|
53
|
+
_context.next = 9;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
return _context.abrupt("return", {
|
|
57
|
+
source: source
|
|
58
|
+
});
|
|
59
|
+
case 9:
|
|
60
|
+
_context.next = 11;
|
|
61
|
+
return resolveImports(source, filePath);
|
|
62
|
+
case 11:
|
|
63
|
+
importResult = _context.sent;
|
|
64
|
+
if (!(Object.keys(importResult).length === 0)) {
|
|
65
|
+
_context.next = 14;
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
return _context.abrupt("return", {
|
|
69
|
+
source: source
|
|
70
|
+
});
|
|
71
|
+
case 14:
|
|
72
|
+
_context.next = 16;
|
|
73
|
+
return resolveImportResultWithFs(importResult);
|
|
74
|
+
case 16:
|
|
75
|
+
resolvedPathsMap = _context.sent;
|
|
76
|
+
// Process imports using the consolidated helper function
|
|
77
|
+
_processImportsWithSt = processImportsWithStoreAt(source, importResult, resolvedPathsMap, storeAt), processedSource = _processImportsWithSt.processedSource, extraFiles = _processImportsWithSt.extraFiles; // Build dependencies list for recursive loading
|
|
78
|
+
extraDependencies = Object.values(importResult).map(function (_ref) {
|
|
79
|
+
var path = _ref.path;
|
|
80
|
+
return resolvedPathsMap.get(path);
|
|
81
|
+
}).filter(function (path) {
|
|
82
|
+
return path !== undefined;
|
|
83
|
+
});
|
|
84
|
+
return _context.abrupt("return", {
|
|
85
|
+
source: processedSource,
|
|
86
|
+
extraFiles: Object.keys(extraFiles).length > 0 ? extraFiles : undefined,
|
|
87
|
+
extraDependencies: extraDependencies.length > 0 ? extraDependencies : undefined
|
|
88
|
+
});
|
|
89
|
+
case 20:
|
|
90
|
+
case "end":
|
|
91
|
+
return _context.stop();
|
|
92
|
+
}
|
|
93
|
+
}, _callee);
|
|
94
|
+
}));
|
|
95
|
+
function loadSource(_x) {
|
|
96
|
+
return _loadSource.apply(this, arguments);
|
|
97
|
+
}
|
|
98
|
+
return loadSource;
|
|
99
|
+
}();
|
|
100
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts the filename and extension from a URL or file path.
|
|
3
|
+
* This function is isomorphic and works in both Node.js and browser environments.
|
|
4
|
+
*
|
|
5
|
+
* @param url - The URL or file path to extract the filename from
|
|
6
|
+
* @returns An object containing the filename and extension
|
|
7
|
+
*/
|
|
8
|
+
export declare function getFileNameFromUrl(url: string): {
|
|
9
|
+
fileName: string;
|
|
10
|
+
extension: string;
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFileNameFromUrl.d.ts","sourceRoot":"","sources":["../../../src/loaderUtils/getFileNameFromUrl.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAoBvF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts the filename and extension from a URL or file path.
|
|
3
|
+
* This function is isomorphic and works in both Node.js and browser environments.
|
|
4
|
+
*
|
|
5
|
+
* @param url - The URL or file path to extract the filename from
|
|
6
|
+
* @returns An object containing the filename and extension
|
|
7
|
+
*/
|
|
8
|
+
export function getFileNameFromUrl(url) {
|
|
9
|
+
try {
|
|
10
|
+
// Use URL constructor to handle various URL formats
|
|
11
|
+
var urlObj = new URL(url);
|
|
12
|
+
var pathname = urlObj.pathname;
|
|
13
|
+
var fileName = pathname.split('/').pop() || '';
|
|
14
|
+
|
|
15
|
+
// Extract extension (including the dot)
|
|
16
|
+
var lastDotIndex = fileName.lastIndexOf('.');
|
|
17
|
+
var extension = lastDotIndex > 0 ? fileName.substring(lastDotIndex) : '';
|
|
18
|
+
return {
|
|
19
|
+
fileName: fileName,
|
|
20
|
+
extension: extension
|
|
21
|
+
};
|
|
22
|
+
} catch (_unused) {
|
|
23
|
+
// If URL parsing fails, fall back to simple string manipulation
|
|
24
|
+
var _fileName = url.split('/').pop() || url;
|
|
25
|
+
var _lastDotIndex = _fileName.lastIndexOf('.');
|
|
26
|
+
var _extension = _lastDotIndex > 0 ? _fileName.substring(_lastDotIndex) : '';
|
|
27
|
+
return {
|
|
28
|
+
fileName: _fileName,
|
|
29
|
+
extension: _extension
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/loaderUtils/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type StoreAtMode = 'canonical' | 'import' | 'flat';
|
|
2
|
+
export interface ProcessImportsResult {
|
|
3
|
+
processedSource: string;
|
|
4
|
+
extraFiles: Record<string, string>;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Processes imports based on the specified storage mode, automatically handling
|
|
8
|
+
* source rewriting when needed (e.g., for 'flat' mode).
|
|
9
|
+
*
|
|
10
|
+
* @param source - The original source code
|
|
11
|
+
* @param importResult - The result from resolveImports
|
|
12
|
+
* @param resolvedPathsMap - Map from import paths to resolved file paths
|
|
13
|
+
* @param storeAt - How to process the imports
|
|
14
|
+
* @returns Object with processed source and extraFiles mapping
|
|
15
|
+
*/
|
|
16
|
+
export declare function processImportsWithStoreAt(source: string, importResult: Record<string, {
|
|
17
|
+
path: string;
|
|
18
|
+
names: string[];
|
|
19
|
+
}>, resolvedPathsMap: Map<string, string>, storeAt: StoreAtMode): ProcessImportsResult;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processImports.d.ts","sourceRoot":"","sources":["../../../src/loaderUtils/processImports.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE1D,MAAM,WAAW,oBAAoB;IACnC,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACpC;AAED;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,EAC/D,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACrC,OAAO,EAAE,WAAW,GACnB,oBAAoB,CAsEtB"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import { rewriteImportsToSameDirectory } from "./rewriteImports.js";
|
|
3
|
+
import { isJavaScriptModule } from "./resolveModulePath.js";
|
|
4
|
+
import { getFileNameFromUrl } from "./getFileNameFromUrl.js";
|
|
5
|
+
/**
|
|
6
|
+
* Processes imports based on the specified storage mode, automatically handling
|
|
7
|
+
* source rewriting when needed (e.g., for 'flat' mode).
|
|
8
|
+
*
|
|
9
|
+
* @param source - The original source code
|
|
10
|
+
* @param importResult - The result from resolveImports
|
|
11
|
+
* @param resolvedPathsMap - Map from import paths to resolved file paths
|
|
12
|
+
* @param storeAt - How to process the imports
|
|
13
|
+
* @returns Object with processed source and extraFiles mapping
|
|
14
|
+
*/
|
|
15
|
+
export function processImportsWithStoreAt(source, importResult, resolvedPathsMap, storeAt) {
|
|
16
|
+
var processedSource = source;
|
|
17
|
+
var extraFiles = {};
|
|
18
|
+
|
|
19
|
+
// For flat mode, automatically rewrite imports to same directory
|
|
20
|
+
if (storeAt === 'flat') {
|
|
21
|
+
var allResolvedPaths = new Set(resolvedPathsMap.values());
|
|
22
|
+
processedSource = rewriteImportsToSameDirectory(source, allResolvedPaths);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Process each import and generate extraFiles
|
|
26
|
+
Object.entries(importResult).forEach(function (_ref) {
|
|
27
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
28
|
+
relativePath = _ref2[0],
|
|
29
|
+
importInfo = _ref2[1];
|
|
30
|
+
var resolvedPath = resolvedPathsMap.get(importInfo.path);
|
|
31
|
+
if (resolvedPath) {
|
|
32
|
+
var fileExtension = getFileNameFromUrl(resolvedPath).extension;
|
|
33
|
+
var isJavascriptModule = isJavaScriptModule(relativePath);
|
|
34
|
+
var keyPath;
|
|
35
|
+
if (!isJavascriptModule) {
|
|
36
|
+
// For static assets (CSS, JSON, etc.), use the original import path as-is since it already has the extension
|
|
37
|
+
switch (storeAt) {
|
|
38
|
+
case 'canonical':
|
|
39
|
+
case 'import':
|
|
40
|
+
keyPath = relativePath;
|
|
41
|
+
break;
|
|
42
|
+
case 'flat':
|
|
43
|
+
// For flat mode, use just the filename from the original import
|
|
44
|
+
keyPath = "./".concat(getFileNameFromUrl(relativePath).fileName);
|
|
45
|
+
break;
|
|
46
|
+
default:
|
|
47
|
+
keyPath = relativePath;
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
// For JS/TS modules, apply the existing logic
|
|
51
|
+
switch (storeAt) {
|
|
52
|
+
case 'canonical':
|
|
53
|
+
// Show the full resolved path including index files when they exist
|
|
54
|
+
// e.g., import '../Component' resolved to '/src/Component/index.js'
|
|
55
|
+
// becomes extraFiles: { '../Component/index.js': 'file:///src/Component/index.js' }
|
|
56
|
+
keyPath = "".concat(relativePath).concat(resolvedPath.endsWith("/index".concat(fileExtension)) ? "/index".concat(fileExtension) : fileExtension);
|
|
57
|
+
break;
|
|
58
|
+
case 'import':
|
|
59
|
+
// Use the original import path with the actual file extension
|
|
60
|
+
// e.g., import '../Component' with '/src/Component/index.js'
|
|
61
|
+
// becomes extraFiles: { '../Component.js': 'file:///src/Component/index.js' }
|
|
62
|
+
keyPath = "".concat(relativePath).concat(fileExtension);
|
|
63
|
+
break;
|
|
64
|
+
case 'flat':
|
|
65
|
+
// Flatten all files to current directory using just the filename
|
|
66
|
+
// e.g., import '../Component' with '/src/Component/index.js'
|
|
67
|
+
// becomes extraFiles: { './index.js': 'file:///src/Component/index.js' }
|
|
68
|
+
// Note: This mode also requires rewriting imports in the source code (handled above)
|
|
69
|
+
keyPath = "./".concat(getFileNameFromUrl(resolvedPath).fileName);
|
|
70
|
+
break;
|
|
71
|
+
default:
|
|
72
|
+
keyPath = "".concat(relativePath).concat(fileExtension);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
extraFiles[keyPath] = "file://".concat(resolvedPath);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
processedSource: processedSource,
|
|
80
|
+
extraFiles: extraFiles
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveImports.d.ts","sourceRoot":"","sources":["../../../src/loaderUtils/resolveImports.ts"],"names":[],"mappings":"AAAA,wBAAsB,cAAc,CAClC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CAAC,CAkC5D"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
4
|
+
export function resolveImports(_x, _x2) {
|
|
5
|
+
return _resolveImports.apply(this, arguments);
|
|
6
|
+
}
|
|
7
|
+
function _resolveImports() {
|
|
8
|
+
_resolveImports = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(code, filePath) {
|
|
9
|
+
var result, importRegex, importMatch, _loop;
|
|
10
|
+
return _regeneratorRuntime().wrap(function _callee$(_context2) {
|
|
11
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
12
|
+
case 0:
|
|
13
|
+
result = {};
|
|
14
|
+
importRegex = /import\s+(?:(\w+)|\*\s+as\s+(\w+)|{([^}]+)})\s+from\s+['"]([^'"]+)['"]/g;
|
|
15
|
+
importMatch = importRegex.exec(code);
|
|
16
|
+
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
|
17
|
+
var _importMatch, _importMatch2, defaultImport, namespaceImport, namedImportsStr, modulePath, basePath, resolvedPath, namedImports;
|
|
18
|
+
return _regeneratorRuntime().wrap(function _loop$(_context) {
|
|
19
|
+
while (1) switch (_context.prev = _context.next) {
|
|
20
|
+
case 0:
|
|
21
|
+
_importMatch = importMatch, _importMatch2 = _slicedToArray(_importMatch, 5), defaultImport = _importMatch2[1], namespaceImport = _importMatch2[2], namedImportsStr = _importMatch2[3], modulePath = _importMatch2[4]; // Only process relative imports
|
|
22
|
+
if (modulePath.startsWith('.')) {
|
|
23
|
+
basePath = filePath.substring(0, filePath.lastIndexOf('/'));
|
|
24
|
+
resolvedPath = new URL(modulePath, "file://".concat(basePath, "/")).pathname;
|
|
25
|
+
if (!result[modulePath]) {
|
|
26
|
+
result[modulePath] = {
|
|
27
|
+
path: resolvedPath,
|
|
28
|
+
names: []
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
if (defaultImport) {
|
|
32
|
+
result[modulePath].names.push(defaultImport);
|
|
33
|
+
} else if (namespaceImport) {
|
|
34
|
+
result[modulePath].names.push(namespaceImport);
|
|
35
|
+
} else if (namedImportsStr) {
|
|
36
|
+
// Handle named imports like { ComponentName, Component2 as Alias }
|
|
37
|
+
namedImports = namedImportsStr.split(',').map(function (s) {
|
|
38
|
+
return s.trim();
|
|
39
|
+
});
|
|
40
|
+
namedImports.forEach(function (namedImport) {
|
|
41
|
+
var cleanImport = namedImport.split(' as ')[0].trim();
|
|
42
|
+
result[modulePath].names.push(cleanImport);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
importMatch = importRegex.exec(code);
|
|
47
|
+
case 3:
|
|
48
|
+
case "end":
|
|
49
|
+
return _context.stop();
|
|
50
|
+
}
|
|
51
|
+
}, _loop);
|
|
52
|
+
});
|
|
53
|
+
case 4:
|
|
54
|
+
if (!(importMatch !== null)) {
|
|
55
|
+
_context2.next = 8;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
return _context2.delegateYield(_loop(), "t0", 6);
|
|
59
|
+
case 6:
|
|
60
|
+
_context2.next = 4;
|
|
61
|
+
break;
|
|
62
|
+
case 8:
|
|
63
|
+
return _context2.abrupt("return", result);
|
|
64
|
+
case 9:
|
|
65
|
+
case "end":
|
|
66
|
+
return _context2.stop();
|
|
67
|
+
}
|
|
68
|
+
}, _callee);
|
|
69
|
+
}));
|
|
70
|
+
return _resolveImports.apply(this, arguments);
|
|
71
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default file extensions for JavaScript/TypeScript modules that can be resolved
|
|
3
|
+
*/
|
|
4
|
+
export declare const JAVASCRIPT_MODULE_EXTENSIONS: readonly [".ts", ".tsx", ".js", ".jsx"];
|
|
5
|
+
/**
|
|
6
|
+
* Checks if a file path or import path represents a JavaScript/TypeScript module
|
|
7
|
+
* @param path - The file path or import path to check
|
|
8
|
+
* @returns true if it's a JS/TS module, false otherwise
|
|
9
|
+
*/
|
|
10
|
+
export declare function isJavaScriptModule(path: string): boolean;
|
|
11
|
+
export interface DirectoryEntry {
|
|
12
|
+
name: string;
|
|
13
|
+
isFile: boolean;
|
|
14
|
+
isDirectory: boolean;
|
|
15
|
+
}
|
|
16
|
+
export type DirectoryReader = (path: string) => Promise<DirectoryEntry[]>;
|
|
17
|
+
export interface ResolveModulePathOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Array of file extensions to try when resolving modules.
|
|
20
|
+
* Default: ['.ts', '.tsx', '.js', '.jsx']
|
|
21
|
+
*/
|
|
22
|
+
extensions?: string[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Resolves a module path by reading directory contents to find matching files.
|
|
26
|
+
* This is more efficient than checking each file individually with stat calls.
|
|
27
|
+
*
|
|
28
|
+
* Given a path like `/Code/mui-public/packages/docs-infra/docs/app/components/code-highlighter/demos/code/BasicCode`,
|
|
29
|
+
* this function will try to find the actual file by checking for:
|
|
30
|
+
* - `BasicCode.ts`, `BasicCode.tsx`, `BasicCode.js`, `BasicCode.jsx`
|
|
31
|
+
* - `BasicCode/index.ts`, `BasicCode/index.tsx`, `BasicCode/index.js`, `BasicCode/index.jsx`
|
|
32
|
+
*
|
|
33
|
+
* @param modulePath - The module path to resolve (without file extension)
|
|
34
|
+
* @param readDirectory - Function to read directory contents
|
|
35
|
+
* @param options - Configuration options
|
|
36
|
+
* @returns Promise<string> - The resolved file path, or throws if not found
|
|
37
|
+
*/
|
|
38
|
+
export declare function resolveModulePath(modulePath: string, readDirectory: DirectoryReader, options?: ResolveModulePathOptions): Promise<string>;
|
|
39
|
+
/**
|
|
40
|
+
* Resolves multiple module paths efficiently by grouping them by directory
|
|
41
|
+
* and performing batch directory lookups.
|
|
42
|
+
*
|
|
43
|
+
* @param modulePaths - Array of module paths to resolve (without file extensions)
|
|
44
|
+
* @param readDirectory - Function to read directory contents
|
|
45
|
+
* @param options - Configuration options
|
|
46
|
+
* @returns Promise<Map<string, string>> - Map from input path to resolved file path
|
|
47
|
+
*/
|
|
48
|
+
export declare function resolveModulePaths(modulePaths: string[], readDirectory: DirectoryReader, options?: ResolveModulePathOptions): Promise<Map<string, string>>;
|
|
49
|
+
/**
|
|
50
|
+
* Resolves import result by separating JavaScript modules from static assets,
|
|
51
|
+
* only resolving JavaScript modules and returning a combined map.
|
|
52
|
+
* This function uses the resolveModulePaths function internally but requires
|
|
53
|
+
* a DirectoryReader to be provided.
|
|
54
|
+
*
|
|
55
|
+
* @param importResult - The result from resolveImports containing all imports
|
|
56
|
+
* @param readDirectory - Function to read directory contents
|
|
57
|
+
* @param options - Configuration options for module resolution
|
|
58
|
+
* @returns Promise<Map<string, string>> - Map from import path to resolved file path
|
|
59
|
+
*/
|
|
60
|
+
export declare function resolveImportResult(importResult: Record<string, {
|
|
61
|
+
path: string;
|
|
62
|
+
names: string[];
|
|
63
|
+
}>, readDirectory: DirectoryReader, options?: ResolveModulePathOptions): Promise<Map<string, string>>;
|
|
64
|
+
/**
|
|
65
|
+
* Resolves variant paths from a variants object mapping variant names to their file paths.
|
|
66
|
+
* This function extracts the paths, resolves them using resolveModulePaths, and returns
|
|
67
|
+
* a map from variant name to resolved file URL.
|
|
68
|
+
*
|
|
69
|
+
* @param variants - Object mapping variant names to their file paths
|
|
70
|
+
* @param readDirectory - Function to read directory contents
|
|
71
|
+
* @param options - Configuration options for module resolution
|
|
72
|
+
* @returns Promise<Map<string, string>> - Map from variant name to resolved file URL
|
|
73
|
+
*/
|
|
74
|
+
export declare function resolveVariantPaths(variants: Record<string, string>, readDirectory: DirectoryReader, options?: ResolveModulePathOptions): Promise<Map<string, string>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveModulePath.d.ts","sourceRoot":"","sources":["../../../src/loaderUtils/resolveModulePath.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,4BAA4B,yCAA0C,CAAC;AAEpF;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAOxD;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;AAE1E,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,eAAe,EAC9B,OAAO,GAAE,wBAA6B,GACrC,OAAO,CAAC,MAAM,CAAC,CAyFjB;AAED;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CACtC,WAAW,EAAE,MAAM,EAAE,EACrB,aAAa,EAAE,eAAe,EAC9B,OAAO,GAAE,wBAA6B,GACrC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CA+I9B;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,mBAAmB,CACvC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,EAC/D,aAAa,EAAE,eAAe,EAC9B,OAAO,GAAE,wBAA6B,GACrC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAmC9B;AAED;;;;;;;;;GASG;AACH,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAChC,aAAa,EAAE,eAAe,EAC9B,OAAO,GAAE,wBAA6B,GACrC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAgB9B"}
|