@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,6 +1,3 @@
|
|
|
1
|
-
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
2
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
3
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
1
|
import { rewriteImports } from "./rewriteImports.js";
|
|
5
2
|
import { isJavaScriptModule } from "./resolveModulePath.js";
|
|
6
3
|
import { getFileNameFromUrl } from "./getFileNameFromUrl.js";
|
|
@@ -9,22 +6,19 @@ import { fileUrlToPortablePath, portablePathToFileUrl } from "./fileUrlToPortabl
|
|
|
9
6
|
* Processes flat mode with intelligent conflict resolution
|
|
10
7
|
*/
|
|
11
8
|
function processFlatMode(importResult, resolvedPathsMap) {
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
const extraFiles = {};
|
|
10
|
+
const fileMapping = [];
|
|
14
11
|
|
|
15
12
|
// First pass: collect all files and their path segments
|
|
16
|
-
Object.entries(importResult).forEach(
|
|
17
|
-
|
|
18
|
-
relativePath = _ref2[0],
|
|
19
|
-
importInfo = _ref2[1];
|
|
20
|
-
var resolvedUrl = resolvedPathsMap.get(importInfo.url);
|
|
13
|
+
Object.entries(importResult).forEach(([relativePath, importInfo]) => {
|
|
14
|
+
const resolvedUrl = resolvedPathsMap.get(importInfo.url);
|
|
21
15
|
if (resolvedUrl) {
|
|
22
16
|
// Convert file URL to portable path for path manipulation
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
const resolvedPath = resolvedUrl.startsWith('file://') ? fileUrlToPortablePath(resolvedUrl) : resolvedUrl;
|
|
18
|
+
const fileExtension = getFileNameFromUrl(resolvedUrl).extension;
|
|
19
|
+
const pathSegments = resolvedPath.split('/').filter(Boolean);
|
|
26
20
|
fileMapping.push({
|
|
27
|
-
resolvedPath
|
|
21
|
+
resolvedPath,
|
|
28
22
|
extension: fileExtension,
|
|
29
23
|
segments: pathSegments,
|
|
30
24
|
originalImportPath: relativePath
|
|
@@ -33,29 +27,28 @@ function processFlatMode(importResult, resolvedPathsMap) {
|
|
|
33
27
|
});
|
|
34
28
|
|
|
35
29
|
// Second pass: determine candidate names and group by conflicts
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
for (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var candidateName = void 0;
|
|
30
|
+
const candidateNames = new Map();
|
|
31
|
+
const nameGroups = new Map();
|
|
32
|
+
for (const file of fileMapping) {
|
|
33
|
+
const fileName = file.segments[file.segments.length - 1];
|
|
34
|
+
const isIndexFile = fileName.startsWith('index.');
|
|
35
|
+
const isUnderscoreIndexFile = fileName.startsWith('_index.');
|
|
36
|
+
let candidateName;
|
|
44
37
|
if (isUnderscoreIndexFile) {
|
|
45
38
|
// Files starting with "_index." should be treated as direct index imports
|
|
46
39
|
// e.g., "../../dir/_index.module.css" -> "index.module.css"
|
|
47
|
-
candidateName =
|
|
40
|
+
candidateName = `index${file.extension}`;
|
|
48
41
|
} else if (isIndexFile) {
|
|
49
42
|
// Check if the original import was a direct index file (e.g., "./index.ext")
|
|
50
|
-
|
|
51
|
-
|
|
43
|
+
const originalImportParts = file.originalImportPath.split('/');
|
|
44
|
+
const isDirectIndexImport = originalImportParts.length === 2 && originalImportParts[0] === '.' && originalImportParts[1].startsWith('index.');
|
|
52
45
|
if (isDirectIndexImport) {
|
|
53
46
|
// For direct index imports like "./index.ext", keep the original name
|
|
54
|
-
candidateName =
|
|
47
|
+
candidateName = `index${file.extension}`;
|
|
55
48
|
} else {
|
|
56
49
|
// For nested index files like "./test/index.ext", use parent directory + extension
|
|
57
|
-
|
|
58
|
-
candidateName =
|
|
50
|
+
const parentDir = file.segments[file.segments.length - 2];
|
|
51
|
+
candidateName = `${parentDir}${file.extension}`;
|
|
59
52
|
}
|
|
60
53
|
} else {
|
|
61
54
|
candidateName = fileName;
|
|
@@ -68,116 +61,79 @@ function processFlatMode(importResult, resolvedPathsMap) {
|
|
|
68
61
|
}
|
|
69
62
|
|
|
70
63
|
// Third pass: resolve conflicts for all files in conflicting groups
|
|
71
|
-
|
|
72
|
-
nameGroups.forEach(
|
|
64
|
+
const finalNames = new Map();
|
|
65
|
+
nameGroups.forEach((paths, candidateName) => {
|
|
73
66
|
if (paths.length === 1) {
|
|
74
67
|
// No conflict, use the candidate name
|
|
75
68
|
finalNames.set(paths[0], candidateName);
|
|
76
69
|
} else {
|
|
77
70
|
// Conflict detected, find optimal minimal distinguishing paths for all files
|
|
78
|
-
|
|
79
|
-
return fileMapping.find(function (f) {
|
|
80
|
-
return f.resolvedPath === resolvedPath;
|
|
81
|
-
});
|
|
82
|
-
});
|
|
71
|
+
const conflictingFiles = paths.map(resolvedPath => fileMapping.find(f => f.resolvedPath === resolvedPath));
|
|
83
72
|
|
|
84
73
|
// Check if we can resolve conflicts by treating some files differently
|
|
85
74
|
// This specifically handles cases like:
|
|
86
75
|
// - /path/to/a/Component.js and /path/to/Component.js (parent-child relationship)
|
|
87
76
|
|
|
88
77
|
// Find files that are "shorter" (parent level) compared to others
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
})));
|
|
92
|
-
var maxLengthForSmart = Math.max.apply(Math, _toConsumableArray(conflictingFiles.map(function (f) {
|
|
93
|
-
return f.segments.length;
|
|
94
|
-
})));
|
|
78
|
+
const minLength = Math.min(...conflictingFiles.map(f => f.segments.length));
|
|
79
|
+
const maxLengthForSmart = Math.max(...conflictingFiles.map(f => f.segments.length));
|
|
95
80
|
if (maxLengthForSmart > minLength) {
|
|
96
81
|
// We have files at different depths, check if it's a parent-child scenario
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
});
|
|
100
|
-
var longerFiles = conflictingFiles.filter(function (file) {
|
|
101
|
-
return file.segments.length > minLength;
|
|
102
|
-
});
|
|
82
|
+
const shorterFiles = conflictingFiles.filter(file => file.segments.length === minLength);
|
|
83
|
+
const longerFiles = conflictingFiles.filter(file => file.segments.length > minLength);
|
|
103
84
|
if (shorterFiles.length === 1 && longerFiles.length >= 1) {
|
|
104
85
|
// Check if the shorter file is truly a "parent" of the longer files
|
|
105
|
-
|
|
106
|
-
|
|
86
|
+
const shorterFile = shorterFiles[0];
|
|
87
|
+
const shorterPath = shorterFile.segments.slice(0, -1).join('/'); // Remove filename
|
|
107
88
|
|
|
108
89
|
// Check if all longer files share the same prefix as the shorter file
|
|
109
|
-
|
|
110
|
-
|
|
90
|
+
const allLongerFilesAreChildren = longerFiles.every(longerFile => {
|
|
91
|
+
const longerPath = longerFile.segments.slice(0, shorterFile.segments.length - 1).join('/');
|
|
111
92
|
return longerPath === shorterPath;
|
|
112
93
|
});
|
|
113
94
|
if (allLongerFilesAreChildren) {
|
|
114
95
|
// This is a true parent-child scenario, apply smart resolution
|
|
115
96
|
|
|
116
97
|
// For longer files, find distinguishing index
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
var _loop = function _loop(i) {
|
|
122
|
-
var segmentsAtIndex = new Set(longerFiles.map(function (f) {
|
|
123
|
-
return f.segments[i];
|
|
124
|
-
}).filter(Boolean));
|
|
98
|
+
let distinguishingIndex = -1;
|
|
99
|
+
const maxLongerLength = Math.max(...longerFiles.map(f => f.segments.length));
|
|
100
|
+
for (let i = 0; i < maxLongerLength; i += 1) {
|
|
101
|
+
const segmentsAtIndex = new Set(longerFiles.map(f => f.segments[i]).filter(Boolean));
|
|
125
102
|
if (segmentsAtIndex.size === longerFiles.length) {
|
|
126
|
-
|
|
127
|
-
|
|
103
|
+
distinguishingIndex = i;
|
|
104
|
+
break;
|
|
128
105
|
}
|
|
129
|
-
};
|
|
130
|
-
for (var i = 0; i < maxLongerLength; i += 1) {
|
|
131
|
-
if (_loop(i)) break;
|
|
132
106
|
}
|
|
133
|
-
if (
|
|
107
|
+
if (distinguishingIndex !== -1) {
|
|
134
108
|
// Generate names for longer files using distinguishing segment
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
if
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
var _originalImportParts = _file.originalImportPath.split('/');
|
|
151
|
-
var _isDirectIndexImport = _originalImportParts.length === 2 && _originalImportParts[0] === '.' && _originalImportParts[1].startsWith('index.');
|
|
152
|
-
if (_isDirectIndexImport) {
|
|
153
|
-
finalName = "".concat(distinguishingSegment, "/index").concat(_file.extension);
|
|
154
|
-
} else {
|
|
155
|
-
var _parentDir = _file.segments[_file.segments.length - 2];
|
|
156
|
-
finalName = "".concat(distinguishingSegment, "/").concat(_parentDir).concat(_file.extension);
|
|
157
|
-
}
|
|
109
|
+
for (const file of longerFiles) {
|
|
110
|
+
const fileName = file.segments[file.segments.length - 1];
|
|
111
|
+
const isIndexFile = fileName.startsWith('index.');
|
|
112
|
+
const isUnderscoreIndexFile = fileName.startsWith('_index.');
|
|
113
|
+
const distinguishingSegment = file.segments[distinguishingIndex];
|
|
114
|
+
let finalName;
|
|
115
|
+
if (isUnderscoreIndexFile) {
|
|
116
|
+
// Files starting with "_index." should always use "index" as the base name
|
|
117
|
+
finalName = `${distinguishingSegment}/index${file.extension}`;
|
|
118
|
+
} else if (isIndexFile) {
|
|
119
|
+
// Check if this was a direct index import
|
|
120
|
+
const originalImportParts = file.originalImportPath.split('/');
|
|
121
|
+
const isDirectIndexImport = originalImportParts.length === 2 && originalImportParts[0] === '.' && originalImportParts[1].startsWith('index.');
|
|
122
|
+
if (isDirectIndexImport) {
|
|
123
|
+
finalName = `${distinguishingSegment}/index${file.extension}`;
|
|
158
124
|
} else {
|
|
159
|
-
|
|
125
|
+
const parentDir = file.segments[file.segments.length - 2];
|
|
126
|
+
finalName = `${distinguishingSegment}/${parentDir}${file.extension}`;
|
|
160
127
|
}
|
|
161
|
-
|
|
128
|
+
} else {
|
|
129
|
+
finalName = `${distinguishingSegment}/${fileName}`;
|
|
162
130
|
}
|
|
163
|
-
|
|
164
|
-
// For shorter files, use the candidate name as-is (no conflicts after disambiguation)
|
|
165
|
-
} catch (err) {
|
|
166
|
-
_iterator.e(err);
|
|
167
|
-
} finally {
|
|
168
|
-
_iterator.f();
|
|
131
|
+
finalNames.set(file.resolvedPath, finalName);
|
|
169
132
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
var shortFile = _step2.value;
|
|
175
|
-
finalNames.set(shortFile.resolvedPath, candidateName);
|
|
176
|
-
}
|
|
177
|
-
} catch (err) {
|
|
178
|
-
_iterator2.e(err);
|
|
179
|
-
} finally {
|
|
180
|
-
_iterator2.f();
|
|
133
|
+
|
|
134
|
+
// For shorter files, use the candidate name as-is (no conflicts after disambiguation)
|
|
135
|
+
for (const shortFile of shorterFiles) {
|
|
136
|
+
finalNames.set(shortFile.resolvedPath, candidateName);
|
|
181
137
|
}
|
|
182
138
|
return; // Successfully resolved
|
|
183
139
|
}
|
|
@@ -186,71 +142,55 @@ function processFlatMode(importResult, resolvedPathsMap) {
|
|
|
186
142
|
}
|
|
187
143
|
|
|
188
144
|
// Fallback to original algorithm if smart resolution fails
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
var _loop2 = function _loop2(_i2) {
|
|
194
|
-
var segmentsAtIndex = new Set(conflictingFiles.map(function (f) {
|
|
195
|
-
return f.segments[_i2];
|
|
196
|
-
}).filter(Boolean));
|
|
145
|
+
let distinguishingIndex = -1;
|
|
146
|
+
const maxLength = Math.max(...conflictingFiles.map(f => f.segments.length));
|
|
147
|
+
for (let i = 0; i < maxLength; i += 1) {
|
|
148
|
+
const segmentsAtIndex = new Set(conflictingFiles.map(f => f.segments[i]).filter(Boolean));
|
|
197
149
|
if (segmentsAtIndex.size === conflictingFiles.length) {
|
|
198
|
-
distinguishingIndex =
|
|
199
|
-
|
|
150
|
+
distinguishingIndex = i;
|
|
151
|
+
break;
|
|
200
152
|
}
|
|
201
|
-
};
|
|
202
|
-
for (var _i2 = 0; _i2 < maxLength; _i2 += 1) {
|
|
203
|
-
if (_loop2(_i2)) break;
|
|
204
153
|
}
|
|
205
154
|
if (distinguishingIndex === -1) {
|
|
206
|
-
throw new Error(
|
|
155
|
+
throw new Error(`Cannot find distinguishing segment for files: ${paths.join(', ')}`);
|
|
207
156
|
}
|
|
208
157
|
|
|
209
158
|
// Generate names using the distinguishing segment
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
if
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
var _originalImportParts2 = _file2.originalImportPath.split('/');
|
|
226
|
-
var _isDirectIndexImport2 = _originalImportParts2.length === 2 && _originalImportParts2[0] === '.' && _originalImportParts2[1].startsWith('index.');
|
|
227
|
-
if (_isDirectIndexImport2) {
|
|
228
|
-
_finalName = "".concat(_distinguishingSegment, "/index").concat(_file2.extension);
|
|
229
|
-
} else {
|
|
230
|
-
var _parentDir2 = _file2.segments[_file2.segments.length - 2];
|
|
231
|
-
_finalName = "".concat(_distinguishingSegment, "/").concat(_parentDir2).concat(_file2.extension);
|
|
232
|
-
}
|
|
159
|
+
for (const file of conflictingFiles) {
|
|
160
|
+
const fileName = file.segments[file.segments.length - 1];
|
|
161
|
+
const isIndexFile = fileName.startsWith('index.');
|
|
162
|
+
const isUnderscoreIndexFile = fileName.startsWith('_index.');
|
|
163
|
+
const distinguishingSegment = file.segments[distinguishingIndex];
|
|
164
|
+
let finalName;
|
|
165
|
+
if (isUnderscoreIndexFile) {
|
|
166
|
+
// Files starting with "_index." should always use "index" as the base name
|
|
167
|
+
finalName = `${distinguishingSegment}/index${file.extension}`;
|
|
168
|
+
} else if (isIndexFile) {
|
|
169
|
+
// Check if this was a direct index import
|
|
170
|
+
const originalImportParts = file.originalImportPath.split('/');
|
|
171
|
+
const isDirectIndexImport = originalImportParts.length === 2 && originalImportParts[0] === '.' && originalImportParts[1].startsWith('index.');
|
|
172
|
+
if (isDirectIndexImport) {
|
|
173
|
+
finalName = `${distinguishingSegment}/index${file.extension}`;
|
|
233
174
|
} else {
|
|
234
|
-
|
|
175
|
+
const parentDir = file.segments[file.segments.length - 2];
|
|
176
|
+
finalName = `${distinguishingSegment}/${parentDir}${file.extension}`;
|
|
235
177
|
}
|
|
236
|
-
|
|
178
|
+
} else {
|
|
179
|
+
finalName = `${distinguishingSegment}/${fileName}`;
|
|
237
180
|
}
|
|
238
|
-
|
|
239
|
-
_iterator3.e(err);
|
|
240
|
-
} finally {
|
|
241
|
-
_iterator3.f();
|
|
181
|
+
finalNames.set(file.resolvedPath, finalName);
|
|
242
182
|
}
|
|
243
183
|
}
|
|
244
184
|
});
|
|
245
185
|
|
|
246
186
|
// Fourth pass: build the extraFiles mapping
|
|
247
|
-
finalNames.forEach(
|
|
248
|
-
extraFiles[
|
|
187
|
+
finalNames.forEach((finalName, resolvedPath) => {
|
|
188
|
+
extraFiles[`./${finalName}`] = portablePathToFileUrl(resolvedPath);
|
|
249
189
|
});
|
|
250
190
|
return {
|
|
251
191
|
processedSource: '',
|
|
252
192
|
// Will be set by caller after rewriting
|
|
253
|
-
extraFiles
|
|
193
|
+
extraFiles
|
|
254
194
|
};
|
|
255
195
|
}
|
|
256
196
|
|
|
@@ -259,28 +199,26 @@ function processFlatMode(importResult, resolvedPathsMap) {
|
|
|
259
199
|
* Used for CSS, JSON, and other simple file types that don't require complex module resolution.
|
|
260
200
|
*/
|
|
261
201
|
function processBasicImports(source, importResult, storeAt) {
|
|
262
|
-
|
|
202
|
+
const extraFiles = {};
|
|
263
203
|
if (storeAt === 'flat') {
|
|
264
|
-
|
|
265
|
-
|
|
204
|
+
const finalNames = new Map();
|
|
205
|
+
const usedNames = new Set();
|
|
266
206
|
|
|
267
207
|
// Process each import to determine final names with simple conflict resolution
|
|
268
|
-
Object.entries(importResult).forEach(
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
var finalName = fileName;
|
|
278
|
-
var counter = 1;
|
|
208
|
+
Object.entries(importResult).forEach(([_relativePath, importInfo]) => {
|
|
209
|
+
const resolvedPath = importInfo.url; // For CSS, this is already resolved by parseImports
|
|
210
|
+
const fileUrl = portablePathToFileUrl(resolvedPath);
|
|
211
|
+
const {
|
|
212
|
+
fileName,
|
|
213
|
+
extension
|
|
214
|
+
} = getFileNameFromUrl(fileUrl);
|
|
215
|
+
let finalName = fileName;
|
|
216
|
+
let counter = 1;
|
|
279
217
|
|
|
280
218
|
// Handle naming conflicts by appending numbers
|
|
281
219
|
while (usedNames.has(finalName)) {
|
|
282
|
-
|
|
283
|
-
finalName =
|
|
220
|
+
const baseName = fileName.replace(extension, '');
|
|
221
|
+
finalName = `${baseName}-${counter}${extension}`;
|
|
284
222
|
counter += 1;
|
|
285
223
|
}
|
|
286
224
|
usedNames.add(finalName);
|
|
@@ -288,38 +226,33 @@ function processBasicImports(source, importResult, storeAt) {
|
|
|
288
226
|
});
|
|
289
227
|
|
|
290
228
|
// Create the import path mapping for rewriting
|
|
291
|
-
|
|
292
|
-
Object.entries(importResult).forEach(
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
importInfo = _ref6[1];
|
|
296
|
-
var resolvedPath = importInfo.url;
|
|
297
|
-
var finalName = finalNames.get(resolvedPath);
|
|
229
|
+
const importPathMapping = new Map();
|
|
230
|
+
Object.entries(importResult).forEach(([relativePath, importInfo]) => {
|
|
231
|
+
const resolvedPath = importInfo.url;
|
|
232
|
+
const finalName = finalNames.get(resolvedPath);
|
|
298
233
|
if (finalName) {
|
|
299
234
|
importPathMapping.set(relativePath, finalName);
|
|
300
235
|
}
|
|
301
236
|
});
|
|
302
237
|
|
|
303
238
|
// Create extraFiles entries
|
|
304
|
-
finalNames.forEach(
|
|
305
|
-
extraFiles[
|
|
239
|
+
finalNames.forEach((finalName, resolvedPath) => {
|
|
240
|
+
extraFiles[`./${finalName}`] = portablePathToFileUrl(resolvedPath);
|
|
306
241
|
});
|
|
307
242
|
|
|
308
243
|
// Apply import path replacements using position-based rewriting
|
|
309
244
|
// Only rewrite if positions are available
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
});
|
|
313
|
-
var processedSource = hasPositions ? rewriteImports(source, importPathMapping, importResult) : source;
|
|
245
|
+
const hasPositions = Object.values(importResult).some(imp => imp.positions && imp.positions.length > 0);
|
|
246
|
+
const processedSource = hasPositions ? rewriteImports(source, importPathMapping, importResult) : source;
|
|
314
247
|
return {
|
|
315
|
-
processedSource
|
|
316
|
-
extraFiles
|
|
248
|
+
processedSource,
|
|
249
|
+
extraFiles
|
|
317
250
|
};
|
|
318
251
|
}
|
|
319
252
|
if (storeAt === 'import') {
|
|
320
253
|
// Create a mapping for import mode: remove ./ prefix from relative paths
|
|
321
|
-
|
|
322
|
-
Object.keys(importResult).forEach(
|
|
254
|
+
const importModeMapping = new Map();
|
|
255
|
+
Object.keys(importResult).forEach(relativePath => {
|
|
323
256
|
if (relativePath.startsWith('./')) {
|
|
324
257
|
importModeMapping.set(relativePath, relativePath.slice(2));
|
|
325
258
|
}
|
|
@@ -327,38 +260,30 @@ function processBasicImports(source, importResult, storeAt) {
|
|
|
327
260
|
});
|
|
328
261
|
|
|
329
262
|
// Process each import for extraFiles
|
|
330
|
-
Object.entries(importResult).forEach(
|
|
331
|
-
|
|
332
|
-
relativePath = _ref8[0],
|
|
333
|
-
importInfo = _ref8[1];
|
|
334
|
-
var resolvedPath = importInfo.url;
|
|
263
|
+
Object.entries(importResult).forEach(([relativePath, importInfo]) => {
|
|
264
|
+
const resolvedPath = importInfo.url;
|
|
335
265
|
extraFiles[relativePath] = portablePathToFileUrl(resolvedPath); // Always use original path for extraFiles
|
|
336
266
|
});
|
|
337
267
|
|
|
338
268
|
// Apply import path replacements using position-based rewriting
|
|
339
269
|
// Only rewrite if positions are available
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
});
|
|
343
|
-
var _processedSource = _hasPositions ? rewriteImports(source, importModeMapping, importResult) : source;
|
|
270
|
+
const hasPositions = Object.values(importResult).some(imp => imp.positions && imp.positions.length > 0);
|
|
271
|
+
const processedSource = hasPositions ? rewriteImports(source, importModeMapping, importResult) : source;
|
|
344
272
|
return {
|
|
345
|
-
processedSource
|
|
346
|
-
extraFiles
|
|
273
|
+
processedSource,
|
|
274
|
+
extraFiles
|
|
347
275
|
};
|
|
348
276
|
}
|
|
349
277
|
|
|
350
278
|
// Canonical mode - no rewriting needed
|
|
351
|
-
Object.entries(importResult).forEach(
|
|
352
|
-
|
|
353
|
-
relativePath = _ref0[0],
|
|
354
|
-
importInfo = _ref0[1];
|
|
355
|
-
var resolvedPath = importInfo.url;
|
|
279
|
+
Object.entries(importResult).forEach(([relativePath, importInfo]) => {
|
|
280
|
+
const resolvedPath = importInfo.url;
|
|
356
281
|
extraFiles[relativePath] = portablePathToFileUrl(resolvedPath); // Use original import path
|
|
357
282
|
});
|
|
358
283
|
return {
|
|
359
284
|
processedSource: source,
|
|
360
285
|
// No rewriting needed for canonical mode
|
|
361
|
-
extraFiles
|
|
286
|
+
extraFiles
|
|
362
287
|
};
|
|
363
288
|
}
|
|
364
289
|
|
|
@@ -366,36 +291,30 @@ function processBasicImports(source, importResult, storeAt) {
|
|
|
366
291
|
* Processes JavaScript imports with complex conflict resolution and module handling
|
|
367
292
|
*/
|
|
368
293
|
function processJsImports(source, importResult, storeAt, resolvedPathsMap) {
|
|
369
|
-
|
|
294
|
+
const extraFiles = {};
|
|
370
295
|
if (storeAt === 'flat') {
|
|
371
|
-
|
|
296
|
+
const result = processFlatMode(importResult, resolvedPathsMap);
|
|
372
297
|
|
|
373
298
|
// Build a reverse mapping from resolved paths to extraFiles keys
|
|
374
|
-
|
|
375
|
-
Object.entries(result.extraFiles).forEach(
|
|
376
|
-
var _ref10 = _slicedToArray(_ref1, 2),
|
|
377
|
-
extraFileKey = _ref10[0],
|
|
378
|
-
fileUrl = _ref10[1];
|
|
299
|
+
const resolvedToExtraFile = new Map();
|
|
300
|
+
Object.entries(result.extraFiles).forEach(([extraFileKey, fileUrl]) => {
|
|
379
301
|
// Convert file URL to portable path for lookup
|
|
380
|
-
|
|
302
|
+
const resolvedPath = fileUrl.startsWith('file://') ? fileUrlToPortablePath(fileUrl) : fileUrl;
|
|
381
303
|
resolvedToExtraFile.set(resolvedPath, extraFileKey);
|
|
382
304
|
});
|
|
383
305
|
|
|
384
306
|
// For each import, find its resolved path and map to the corresponding extraFile key
|
|
385
|
-
|
|
386
|
-
Object.entries(importResult).forEach(
|
|
387
|
-
|
|
388
|
-
relativePath = _ref12[0],
|
|
389
|
-
importInfo = _ref12[1];
|
|
390
|
-
var resolvedUrl = resolvedPathsMap.get(importInfo.url);
|
|
307
|
+
const importPathMapping = new Map();
|
|
308
|
+
Object.entries(importResult).forEach(([relativePath, importInfo]) => {
|
|
309
|
+
const resolvedUrl = resolvedPathsMap.get(importInfo.url);
|
|
391
310
|
if (resolvedUrl) {
|
|
392
311
|
// Convert file URL to portable path for lookup
|
|
393
|
-
|
|
394
|
-
|
|
312
|
+
const resolvedPath = resolvedUrl.startsWith('file://') ? fileUrlToPortablePath(resolvedUrl) : resolvedUrl;
|
|
313
|
+
const extraFileKey = resolvedToExtraFile.get(resolvedPath);
|
|
395
314
|
if (extraFileKey) {
|
|
396
315
|
// For JavaScript modules, remove the extension; for other files (CSS, JSON, etc.), keep it
|
|
397
|
-
|
|
398
|
-
|
|
316
|
+
const isJavascriptModule = isJavaScriptModule(relativePath);
|
|
317
|
+
let newPath = extraFileKey;
|
|
399
318
|
if (isJavascriptModule) {
|
|
400
319
|
// Handle TypeScript declaration files (.d.ts) properly
|
|
401
320
|
if (newPath.endsWith('.d.ts')) {
|
|
@@ -412,28 +331,25 @@ function processJsImports(source, importResult, storeAt, resolvedPathsMap) {
|
|
|
412
331
|
});
|
|
413
332
|
|
|
414
333
|
// Apply import path replacements using position-based rewriting
|
|
415
|
-
|
|
334
|
+
const processedSource = rewriteImports(source, importPathMapping, importResult);
|
|
416
335
|
return {
|
|
417
|
-
processedSource
|
|
336
|
+
processedSource,
|
|
418
337
|
extraFiles: result.extraFiles
|
|
419
338
|
};
|
|
420
339
|
}
|
|
421
340
|
|
|
422
341
|
// Non-flat modes (canonical and import)
|
|
423
|
-
Object.entries(importResult).forEach(
|
|
424
|
-
|
|
425
|
-
relativePath = _ref14[0],
|
|
426
|
-
importInfo = _ref14[1];
|
|
427
|
-
var resolvedUrl = resolvedPathsMap.get(importInfo.url);
|
|
342
|
+
Object.entries(importResult).forEach(([relativePath, importInfo]) => {
|
|
343
|
+
const resolvedUrl = resolvedPathsMap.get(importInfo.url);
|
|
428
344
|
if (!resolvedUrl) {
|
|
429
345
|
return;
|
|
430
346
|
}
|
|
431
347
|
|
|
432
348
|
// Convert file URL to portable path for path manipulation
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
349
|
+
const resolvedPath = resolvedUrl.startsWith('file://') ? fileUrlToPortablePath(resolvedUrl) : resolvedUrl;
|
|
350
|
+
const fileExtension = getFileNameFromUrl(resolvedUrl).extension;
|
|
351
|
+
const isJavascriptModule = isJavaScriptModule(relativePath);
|
|
352
|
+
let keyPath;
|
|
437
353
|
if (!isJavascriptModule) {
|
|
438
354
|
// For static assets (CSS, JSON, etc.), use the original import path as-is
|
|
439
355
|
keyPath = relativePath;
|
|
@@ -442,14 +358,14 @@ function processJsImports(source, importResult, storeAt, resolvedPathsMap) {
|
|
|
442
358
|
switch (storeAt) {
|
|
443
359
|
case 'canonical':
|
|
444
360
|
// Show the full resolved path including index files when they exist
|
|
445
|
-
keyPath =
|
|
361
|
+
keyPath = `${relativePath}${resolvedPath.endsWith(`/index${fileExtension}`) ? `/index${fileExtension}` : fileExtension}`;
|
|
446
362
|
break;
|
|
447
363
|
case 'import':
|
|
448
364
|
// Use the original import path with the actual file extension
|
|
449
|
-
keyPath =
|
|
365
|
+
keyPath = `${relativePath}${fileExtension}`;
|
|
450
366
|
break;
|
|
451
367
|
default:
|
|
452
|
-
keyPath =
|
|
368
|
+
keyPath = `${relativePath}${fileExtension}`;
|
|
453
369
|
}
|
|
454
370
|
}
|
|
455
371
|
extraFiles[keyPath] = portablePathToFileUrl(resolvedPath);
|
|
@@ -457,7 +373,7 @@ function processJsImports(source, importResult, storeAt, resolvedPathsMap) {
|
|
|
457
373
|
return {
|
|
458
374
|
processedSource: source,
|
|
459
375
|
// No rewriting needed for non-flat modes
|
|
460
|
-
extraFiles
|
|
376
|
+
extraFiles
|
|
461
377
|
};
|
|
462
378
|
}
|
|
463
379
|
|
|
@@ -472,9 +388,7 @@ function processJsImports(source, importResult, storeAt, resolvedPathsMap) {
|
|
|
472
388
|
* @param resolvedPathsMap - Map from import paths to resolved file paths (only needed for JavaScript files)
|
|
473
389
|
* @returns Object with processed source and extraFiles mapping
|
|
474
390
|
*/
|
|
475
|
-
export function processRelativeImports(source, importResult, storeAt) {
|
|
476
|
-
var isJsFile = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
477
|
-
var resolvedPathsMap = arguments.length > 4 ? arguments[4] : undefined;
|
|
391
|
+
export function processRelativeImports(source, importResult, storeAt, isJsFile = false, resolvedPathsMap) {
|
|
478
392
|
if (!isJsFile) {
|
|
479
393
|
// Use basic processing mode for CSS, JSON, and other simple file types
|
|
480
394
|
return processBasicImports(source, importResult, storeAt);
|