@mui/internal-docs-infra 0.3.1-canary.3 → 0.3.1-canary.5
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,7 +1,3 @@
|
|
|
1
|
-
import _regenerator from "@babel/runtime/helpers/esm/regenerator";
|
|
2
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
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 { readFile } from 'fs/promises';
|
|
@@ -17,7 +13,7 @@ import { isJavaScriptModule } from "../loaderUtils/resolveModulePath.js";
|
|
|
17
13
|
* It reads the source file, resolves its imports, and returns the processed source along with any
|
|
18
14
|
* additional files and dependencies that were found.
|
|
19
15
|
*/
|
|
20
|
-
export
|
|
16
|
+
export const loadServerSource = createLoadServerSource();
|
|
21
17
|
|
|
22
18
|
/**
|
|
23
19
|
* Creates a loadSource function that reads a file and extracts its dependencies.
|
|
@@ -27,151 +23,128 @@ export var loadServerSource = createLoadServerSource();
|
|
|
27
23
|
* - 'import': Import path with file extension (e.g., '../Component.js')
|
|
28
24
|
* - 'flat': Flattened to current directory with rewritten imports (e.g., './Component.js')
|
|
29
25
|
*/
|
|
30
|
-
export function createLoadServerSource() {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return _regenerator().w(function (_context) {
|
|
40
|
-
while (1) switch (_context.n) {
|
|
41
|
-
case 0:
|
|
42
|
-
// Convert file:// URL to proper file system path for reading the file
|
|
43
|
-
// Using fileURLToPath handles Windows drive letters correctly (e.g., file:///C:/... → C:\...)
|
|
44
|
-
filePath = url.startsWith('file://') ? fileURLToPath(url) : url; // Read the file
|
|
45
|
-
_context.n = 1;
|
|
46
|
-
return readFile(filePath, 'utf8');
|
|
47
|
-
case 1:
|
|
48
|
-
source = _context.v;
|
|
49
|
-
if (includeDependencies) {
|
|
50
|
-
_context.n = 2;
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
return _context.a(2, {
|
|
54
|
-
source: source
|
|
55
|
-
});
|
|
56
|
-
case 2:
|
|
57
|
-
// Check if this is a static asset file (non-JS/TS modules)
|
|
58
|
-
isJavascriptModuleFile = isJavaScriptModule(filePath);
|
|
59
|
-
isCssFile = filePath.toLowerCase().endsWith('.css');
|
|
60
|
-
if (!(!isJavascriptModuleFile && !isCssFile)) {
|
|
61
|
-
_context.n = 3;
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
return _context.a(2, {
|
|
65
|
-
source: source
|
|
66
|
-
});
|
|
67
|
-
case 3:
|
|
68
|
-
_context.n = 4;
|
|
69
|
-
return parseImportsAndComments(source, url);
|
|
70
|
-
case 4:
|
|
71
|
-
_yield$parseImportsAn = _context.v;
|
|
72
|
-
importResult = _yield$parseImportsAn.relative;
|
|
73
|
-
externals = _yield$parseImportsAn.externals;
|
|
74
|
-
// Transform externals from parseImportsAndComments format to simplified format
|
|
75
|
-
transformedExternals = {};
|
|
76
|
-
for (_i = 0, _Object$entries = Object.entries(externals); _i < _Object$entries.length; _i++) {
|
|
77
|
-
_Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), modulePath = _Object$entries$_i[0], externalImport = _Object$entries$_i[1];
|
|
78
|
-
transformedExternals[modulePath] = externalImport.names.map(function (importName) {
|
|
79
|
-
return {
|
|
80
|
-
name: importName.name,
|
|
81
|
-
type: importName.type,
|
|
82
|
-
isType: importName.isType
|
|
83
|
-
};
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
if (!(Object.keys(importResult).length === 0)) {
|
|
87
|
-
_context.n = 5;
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
return _context.a(2, {
|
|
91
|
-
source: source,
|
|
92
|
-
externals: Object.keys(transformedExternals).length > 0 ? transformedExternals : undefined
|
|
93
|
-
});
|
|
94
|
-
case 5:
|
|
95
|
-
// Convert import result to the format expected by processImports, preserving position data
|
|
96
|
-
importsCompatible = {};
|
|
97
|
-
for (_i2 = 0, _Object$entries2 = Object.entries(importResult); _i2 < _Object$entries2.length; _i2++) {
|
|
98
|
-
_Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2), importPath = _Object$entries2$_i[0], _Object$entries2$_i$ = _Object$entries2$_i[1], importUrl = _Object$entries2$_i$.url, names = _Object$entries2$_i$.names, positions = _Object$entries2$_i$.positions;
|
|
99
|
-
importsCompatible[importPath] = {
|
|
100
|
-
url: importUrl,
|
|
101
|
-
names: names.map(function (_ref) {
|
|
102
|
-
var name = _ref.name,
|
|
103
|
-
alias = _ref.alias;
|
|
104
|
-
return alias || name;
|
|
105
|
-
}),
|
|
106
|
-
positions: positions
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
if (!isCssFile) {
|
|
110
|
-
_context.n = 6;
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
// For CSS files, we don't need complex path resolution
|
|
114
|
-
// The parseImportsAndComments function already resolved paths for CSS
|
|
115
|
-
result = processRelativeImports(source, importsCompatible, storeAt);
|
|
116
|
-
processedSource = result.processedSource;
|
|
117
|
-
extraFiles = result.extraFiles;
|
|
26
|
+
export function createLoadServerSource(options = {}) {
|
|
27
|
+
const {
|
|
28
|
+
includeDependencies = true,
|
|
29
|
+
storeAt = 'flat'
|
|
30
|
+
} = options;
|
|
31
|
+
return async function loadSource(url) {
|
|
32
|
+
// Convert file:// URL to proper file system path for reading the file
|
|
33
|
+
// Using fileURLToPath handles Windows drive letters correctly (e.g., file:///C:/... → C:\...)
|
|
34
|
+
const filePath = url.startsWith('file://') ? fileURLToPath(url) : url;
|
|
118
35
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
36
|
+
// Read the file
|
|
37
|
+
const source = await readFile(filePath, 'utf8');
|
|
38
|
+
if (!includeDependencies) {
|
|
39
|
+
return {
|
|
40
|
+
source
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Check if this is a static asset file (non-JS/TS modules)
|
|
45
|
+
const isJavascriptModuleFile = isJavaScriptModule(filePath);
|
|
46
|
+
const isCssFile = filePath.toLowerCase().endsWith('.css');
|
|
47
|
+
if (!isJavascriptModuleFile && !isCssFile) {
|
|
48
|
+
// Static assets (CSS, JSON, etc.) don't have imports to resolve
|
|
49
|
+
return {
|
|
50
|
+
source
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Get all relative imports from this file
|
|
55
|
+
// Pass the original URL to parseImportsAndComments for cross-platform path handling
|
|
56
|
+
const {
|
|
57
|
+
relative: importResult,
|
|
58
|
+
externals
|
|
59
|
+
} = await parseImportsAndComments(source, url);
|
|
60
|
+
|
|
61
|
+
// Transform externals from parseImportsAndComments format to simplified format
|
|
62
|
+
const transformedExternals = {};
|
|
63
|
+
for (const [modulePath, externalImport] of Object.entries(externals)) {
|
|
64
|
+
transformedExternals[modulePath] = externalImport.names.map(importName => ({
|
|
65
|
+
name: importName.name,
|
|
66
|
+
type: importName.type,
|
|
67
|
+
isType: importName.isType
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
if (Object.keys(importResult).length === 0) {
|
|
71
|
+
return {
|
|
72
|
+
source,
|
|
73
|
+
externals: Object.keys(transformedExternals).length > 0 ? transformedExternals : undefined
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
let processedSource;
|
|
77
|
+
let extraFiles;
|
|
78
|
+
let extraDependencies;
|
|
79
|
+
|
|
80
|
+
// Convert import result to the format expected by processImports, preserving position data
|
|
81
|
+
const importsCompatible = {};
|
|
82
|
+
for (const [importPath, {
|
|
83
|
+
url: importUrl,
|
|
84
|
+
names,
|
|
85
|
+
positions
|
|
86
|
+
}] of Object.entries(importResult)) {
|
|
87
|
+
importsCompatible[importPath] = {
|
|
88
|
+
url: importUrl,
|
|
89
|
+
names: names.map(({
|
|
90
|
+
name,
|
|
91
|
+
alias
|
|
92
|
+
}) => alias || name),
|
|
93
|
+
positions
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (isCssFile) {
|
|
97
|
+
// For CSS files, we don't need complex path resolution
|
|
98
|
+
// The parseImportsAndComments function already resolved paths for CSS
|
|
99
|
+
const result = processRelativeImports(source, importsCompatible, storeAt);
|
|
100
|
+
processedSource = result.processedSource;
|
|
101
|
+
extraFiles = result.extraFiles;
|
|
102
|
+
|
|
103
|
+
// Build dependencies list for recursive loading (CSS files use direct paths)
|
|
104
|
+
extraDependencies = Object.values(importResult).map(({
|
|
105
|
+
url: importUrl
|
|
106
|
+
}) => importUrl);
|
|
107
|
+
} else {
|
|
108
|
+
// For JavaScript/TypeScript files, resolve paths first
|
|
109
|
+
const relativeImportsCompatible = {};
|
|
110
|
+
for (const [importPath, {
|
|
111
|
+
url: importUrl,
|
|
112
|
+
names,
|
|
113
|
+
includeTypeDefs,
|
|
114
|
+
positions
|
|
115
|
+
}] of Object.entries(importResult)) {
|
|
116
|
+
relativeImportsCompatible[importPath] = {
|
|
117
|
+
url: importUrl,
|
|
118
|
+
names: names.map(({
|
|
119
|
+
name,
|
|
120
|
+
alias
|
|
121
|
+
}) => alias || name),
|
|
122
|
+
// Use alias if available
|
|
123
|
+
positions,
|
|
124
|
+
...(includeTypeDefs && {
|
|
125
|
+
includeTypeDefs
|
|
126
|
+
})
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Resolve import paths, handling JS/TS modules and static assets appropriately
|
|
131
|
+
const resolvedPathsMap = await resolveImportResultWithFs(relativeImportsCompatible);
|
|
144
132
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
resolvedPathsMap = _context.v;
|
|
150
|
-
// Process imports using the unified helper function
|
|
151
|
-
_result = processRelativeImports(source, importsCompatible, storeAt, true, resolvedPathsMap);
|
|
152
|
-
processedSource = _result.processedSource;
|
|
153
|
-
extraFiles = _result.extraFiles;
|
|
133
|
+
// Process imports using the unified helper function
|
|
134
|
+
const result = processRelativeImports(source, importsCompatible, storeAt, true, resolvedPathsMap);
|
|
135
|
+
processedSource = result.processedSource;
|
|
136
|
+
extraFiles = result.extraFiles;
|
|
154
137
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}).filter(function (resolved) {
|
|
160
|
-
return resolved !== undefined;
|
|
161
|
-
});
|
|
162
|
-
case 8:
|
|
163
|
-
return _context.a(2, {
|
|
164
|
-
source: processedSource,
|
|
165
|
-
extraFiles: Object.keys(extraFiles).length > 0 ? extraFiles : undefined,
|
|
166
|
-
extraDependencies: extraDependencies.length > 0 ? extraDependencies : undefined,
|
|
167
|
-
externals: Object.keys(transformedExternals).length > 0 ? transformedExternals : undefined
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
}, _callee);
|
|
171
|
-
}));
|
|
172
|
-
function loadSource(_x) {
|
|
173
|
-
return _loadSource.apply(this, arguments);
|
|
138
|
+
// Build dependencies list for recursive loading
|
|
139
|
+
extraDependencies = Object.values(importResult).map(({
|
|
140
|
+
url: importUrl
|
|
141
|
+
}) => resolvedPathsMap.get(importUrl)).filter(resolved => resolved !== undefined);
|
|
174
142
|
}
|
|
175
|
-
return
|
|
176
|
-
|
|
143
|
+
return {
|
|
144
|
+
source: processedSource,
|
|
145
|
+
extraFiles: Object.keys(extraFiles).length > 0 ? extraFiles : undefined,
|
|
146
|
+
extraDependencies: extraDependencies.length > 0 ? extraDependencies : undefined,
|
|
147
|
+
externals: Object.keys(transformedExternals).length > 0 ? transformedExternals : undefined
|
|
148
|
+
};
|
|
149
|
+
};
|
|
177
150
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export function externalsToPackages(externals) {
|
|
2
|
-
|
|
3
|
-
externals.forEach(
|
|
2
|
+
const packages = {};
|
|
3
|
+
externals.forEach(external => {
|
|
4
4
|
// Filter out path aliases that start with @/
|
|
5
5
|
if (external.startsWith('@/')) {
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
// Extract package name from import path
|
|
10
|
-
|
|
10
|
+
const packageName = extractPackageName(external);
|
|
11
11
|
if (packageName) {
|
|
12
12
|
packages[packageName] = true;
|
|
13
13
|
}
|
|
@@ -32,15 +32,15 @@ function extractPackageName(importPath) {
|
|
|
32
32
|
|
|
33
33
|
// Handle scoped packages (starting with @)
|
|
34
34
|
if (importPath.startsWith('@')) {
|
|
35
|
-
|
|
36
|
-
if (
|
|
35
|
+
const parts = importPath.split('/');
|
|
36
|
+
if (parts.length >= 2) {
|
|
37
37
|
// Return @scope/package-name
|
|
38
|
-
return
|
|
38
|
+
return `${parts[0]}/${parts[1]}`;
|
|
39
39
|
}
|
|
40
40
|
return null;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// Handle regular packages
|
|
44
|
-
|
|
44
|
+
const parts = importPath.split('/');
|
|
45
45
|
return parts[0] || null;
|
|
46
46
|
}
|
|
@@ -39,9 +39,7 @@ function camelToTitleCase(camelCase) {
|
|
|
39
39
|
// Insert spaces before letters that follow numbers
|
|
40
40
|
.replace(/([0-9])([a-zA-Z])/g, '$1 $2')
|
|
41
41
|
// Capitalize the first letter
|
|
42
|
-
.replace(/^./,
|
|
43
|
-
return str.toUpperCase();
|
|
44
|
-
});
|
|
42
|
+
.replace(/^./, str => str.toUpperCase());
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
/**
|
|
@@ -51,9 +49,7 @@ function camelToTitleCase(camelCase) {
|
|
|
51
49
|
*/
|
|
52
50
|
function kebabToTitleCase(kebabCase) {
|
|
53
51
|
return kebabCase.split(/[-_]/) // Split on both hyphens and underscores
|
|
54
|
-
.map(
|
|
55
|
-
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
56
|
-
}).join(' ');
|
|
52
|
+
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(' ');
|
|
57
53
|
}
|
|
58
54
|
|
|
59
55
|
/**
|
|
@@ -86,19 +82,19 @@ function toKebabCase(str) {
|
|
|
86
82
|
function extractLastSegment(url) {
|
|
87
83
|
// Convert to portable path format for consistent handling across platforms
|
|
88
84
|
// This handles file:// URLs, Windows paths with backslashes, and regular paths
|
|
89
|
-
|
|
85
|
+
const path = fileUrlToPortablePath(url);
|
|
90
86
|
|
|
91
87
|
// Strip query parameters and hash fragments before processing
|
|
92
|
-
|
|
88
|
+
const cleanPath = path.split('?')[0].split('#')[0];
|
|
93
89
|
|
|
94
90
|
// Split the path into segments and filter out empty ones
|
|
95
|
-
|
|
91
|
+
const segments = cleanPath.split('/').filter(Boolean);
|
|
96
92
|
if (segments.length === 0) {
|
|
97
93
|
throw new Error('Could not extract meaningful segment from URL');
|
|
98
94
|
}
|
|
99
95
|
|
|
100
96
|
// Get the last segment
|
|
101
|
-
|
|
97
|
+
let lastSegment = segments[segments.length - 1];
|
|
102
98
|
|
|
103
99
|
// Handle index files - any file that starts with 'index.'
|
|
104
100
|
if (lastSegment.startsWith('index.')) {
|
|
@@ -110,7 +106,7 @@ function extractLastSegment(url) {
|
|
|
110
106
|
} else {
|
|
111
107
|
// Strip everything after the first dot from non-index files
|
|
112
108
|
// This handles all extensions: .js, .d.ts, .module.css, .config.dev.js, etc.
|
|
113
|
-
|
|
109
|
+
const firstDotIndex = lastSegment.indexOf('.');
|
|
114
110
|
if (firstDotIndex !== -1) {
|
|
115
111
|
lastSegment = lastSegment.substring(0, firstDotIndex);
|
|
116
112
|
}
|
|
@@ -143,7 +139,7 @@ function extractLastSegment(url) {
|
|
|
143
139
|
* // Returns: { name: 'Getting Started', slug: 'getting-started' }
|
|
144
140
|
*/
|
|
145
141
|
export function extractNameAndSlugFromUrl(url) {
|
|
146
|
-
|
|
142
|
+
const segment = extractLastSegment(url);
|
|
147
143
|
|
|
148
144
|
// Check if the segment is camelCase and handle it appropriately
|
|
149
145
|
if (isCamelCase(segment)) {
|
|
@@ -28,10 +28,10 @@ export function fileUrlToPortablePath(fileUrl) {
|
|
|
28
28
|
// If it's not a file:// URL, check if it's already a portable path
|
|
29
29
|
if (!fileUrl.startsWith('file://')) {
|
|
30
30
|
// Normalize backslashes to forward slashes
|
|
31
|
-
|
|
31
|
+
const normalized = fileUrl.replace(/\\/g, '/');
|
|
32
32
|
// If it doesn't start with /, it's likely a Windows path - add leading slash
|
|
33
33
|
if (!normalized.startsWith('/') && /^[a-zA-Z]:\//.test(normalized)) {
|
|
34
|
-
return
|
|
34
|
+
return `/${normalized}`;
|
|
35
35
|
}
|
|
36
36
|
return normalized;
|
|
37
37
|
}
|
|
@@ -39,14 +39,14 @@ export function fileUrlToPortablePath(fileUrl) {
|
|
|
39
39
|
// Strip the file:// prefix
|
|
40
40
|
// file:///home/user/file.ts => /home/user/file.ts (Unix)
|
|
41
41
|
// file:///C:/Users/file.ts => /C:/Users/file.ts (Windows - keep the leading slash)
|
|
42
|
-
|
|
42
|
+
let path = fileUrl.slice(7); // Remove 'file://'
|
|
43
43
|
|
|
44
44
|
// Normalize any backslashes that might have snuck in
|
|
45
45
|
path = path.replace(/\\/g, '/');
|
|
46
46
|
|
|
47
47
|
// If it doesn't start with /, add one (should already have one for valid file:// URLs)
|
|
48
48
|
if (!path.startsWith('/')) {
|
|
49
|
-
path =
|
|
49
|
+
path = `/${path}`;
|
|
50
50
|
}
|
|
51
51
|
return path;
|
|
52
52
|
}
|
|
@@ -76,5 +76,5 @@ export function portablePathToFileUrl(portablePath) {
|
|
|
76
76
|
// For Windows portable paths like /C:/Users/..., we need file:// + path
|
|
77
77
|
// For Unix paths like /home/user/..., we need file:// + path
|
|
78
78
|
// Both cases: file:// + /path = file:///path
|
|
79
|
-
return
|
|
79
|
+
return `file://${portablePath}`;
|
|
80
80
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
2
1
|
/**
|
|
3
2
|
* Known compound extensions that should be treated as a single unit
|
|
4
3
|
*/
|
|
5
|
-
|
|
4
|
+
const COMPOUND_EXTENSIONS = ['.module.css', '.module.scss', '.module.sass', '.module.less', '.d.ts', '.test.js', '.test.jsx', '.test.ts', '.test.tsx', '.spec.js', '.spec.jsx', '.spec.ts', '.spec.tsx', '.config.js', '.config.ts', '.setup.js', '.setup.ts', '.stories.js', '.stories.jsx', '.stories.ts', '.stories.tsx'];
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Extracts the filename and extension from a URL or file path.
|
|
@@ -15,14 +14,14 @@ var COMPOUND_EXTENSIONS = ['.module.css', '.module.scss', '.module.sass', '.modu
|
|
|
15
14
|
export function getFileNameFromUrl(url) {
|
|
16
15
|
try {
|
|
17
16
|
// Use URL constructor to handle various URL formats
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
const urlObj = new URL(url);
|
|
18
|
+
const pathname = urlObj.pathname;
|
|
19
|
+
const fileName = pathname.split('/').pop() || '';
|
|
21
20
|
return extractFileNameAndExtension(fileName);
|
|
22
|
-
} catch
|
|
21
|
+
} catch {
|
|
23
22
|
// If URL parsing fails, fall back to simple string manipulation
|
|
24
|
-
|
|
25
|
-
return extractFileNameAndExtension(
|
|
23
|
+
const fileName = url.split('/').pop() || url;
|
|
24
|
+
return extractFileNameAndExtension(fileName);
|
|
26
25
|
}
|
|
27
26
|
}
|
|
28
27
|
|
|
@@ -38,29 +37,20 @@ function extractFileNameAndExtension(fileName) {
|
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
// Check for compound extensions first
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
fileName: fileName,
|
|
49
|
-
extension: compoundExt
|
|
50
|
-
};
|
|
51
|
-
}
|
|
40
|
+
for (const compoundExt of COMPOUND_EXTENSIONS) {
|
|
41
|
+
if (fileName.endsWith(compoundExt)) {
|
|
42
|
+
return {
|
|
43
|
+
fileName,
|
|
44
|
+
extension: compoundExt
|
|
45
|
+
};
|
|
52
46
|
}
|
|
53
|
-
|
|
54
|
-
// Fall back to simple extension detection
|
|
55
|
-
} catch (err) {
|
|
56
|
-
_iterator.e(err);
|
|
57
|
-
} finally {
|
|
58
|
-
_iterator.f();
|
|
59
47
|
}
|
|
60
|
-
|
|
61
|
-
|
|
48
|
+
|
|
49
|
+
// Fall back to simple extension detection
|
|
50
|
+
const lastDotIndex = fileName.lastIndexOf('.');
|
|
51
|
+
const extension = lastDotIndex > 0 ? fileName.substring(lastDotIndex) : '';
|
|
62
52
|
return {
|
|
63
|
-
fileName
|
|
64
|
-
extension
|
|
53
|
+
fileName,
|
|
54
|
+
extension
|
|
65
55
|
};
|
|
66
56
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Maps file extensions to language names.
|
|
3
3
|
* These are user-friendly names that can be used in the `language` prop.
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
5
|
+
export const languageMap = {
|
|
6
6
|
'.js': 'javascript',
|
|
7
7
|
'.ts': 'typescript',
|
|
8
8
|
'.jsx': 'jsx',
|
|
@@ -22,7 +22,7 @@ export var languageMap = {
|
|
|
22
22
|
* Used to normalize short language names (e.g., from className like 'language-js')
|
|
23
23
|
* to their full names.
|
|
24
24
|
*/
|
|
25
|
-
export
|
|
25
|
+
export const languageAliasMap = {
|
|
26
26
|
js: 'javascript',
|
|
27
27
|
ts: 'typescript',
|
|
28
28
|
javascript: 'javascript',
|
|
@@ -58,6 +58,5 @@ export function getLanguageFromExtension(extension) {
|
|
|
58
58
|
* @returns The canonical language name, or the input if not a known alias
|
|
59
59
|
*/
|
|
60
60
|
export function normalizeLanguage(language) {
|
|
61
|
-
|
|
62
|
-
return (_languageAliasMap$lan = languageAliasMap[language]) != null ? _languageAliasMap$lan : language;
|
|
61
|
+
return languageAliasMap[language] ?? language;
|
|
63
62
|
}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
-
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
4
1
|
/**
|
|
5
2
|
* Merges multiple externals objects into a single object, combining imports from the same module.
|
|
6
3
|
* Deduplicates imports by name and type within each module.
|
|
@@ -32,41 +29,24 @@ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIt
|
|
|
32
29
|
* ```
|
|
33
30
|
*/
|
|
34
31
|
export function mergeExternals(externalsArray) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
} else {
|
|
49
|
-
// Module already exists, merge imports and deduplicate
|
|
50
|
-
var existingImports = merged[modulePath];
|
|
51
|
-
var newImports = imports.filter(function (newImport) {
|
|
52
|
-
// Check if this import already exists (same name, type, and isType)
|
|
53
|
-
return !existingImports.some(function (existingImport) {
|
|
54
|
-
return existingImport.name === newImport.name && existingImport.type === newImport.type && existingImport.isType === newImport.isType;
|
|
55
|
-
});
|
|
56
|
-
});
|
|
32
|
+
const merged = {};
|
|
33
|
+
for (const externals of externalsArray) {
|
|
34
|
+
for (const [modulePath, imports] of Object.entries(externals)) {
|
|
35
|
+
if (!merged[modulePath]) {
|
|
36
|
+
// First time seeing this module, copy all imports
|
|
37
|
+
merged[modulePath] = [...imports];
|
|
38
|
+
} else {
|
|
39
|
+
// Module already exists, merge imports and deduplicate
|
|
40
|
+
const existingImports = merged[modulePath];
|
|
41
|
+
const newImports = imports.filter(newImport => {
|
|
42
|
+
// Check if this import already exists (same name, type, and isType)
|
|
43
|
+
return !existingImports.some(existingImport => existingImport.name === newImport.name && existingImport.type === newImport.type && existingImport.isType === newImport.isType);
|
|
44
|
+
});
|
|
57
45
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
for (var _i = 0, _Object$entries = Object.entries(externals); _i < _Object$entries.length; _i++) {
|
|
63
|
-
_loop();
|
|
46
|
+
// Add only the new imports that don't already exist
|
|
47
|
+
merged[modulePath] = [...existingImports, ...newImports];
|
|
64
48
|
}
|
|
65
49
|
}
|
|
66
|
-
} catch (err) {
|
|
67
|
-
_iterator.e(err);
|
|
68
|
-
} finally {
|
|
69
|
-
_iterator.f();
|
|
70
50
|
}
|
|
71
51
|
return merged;
|
|
72
52
|
}
|