@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.
Files changed (102) hide show
  1. package/esm/CodeControllerContext/CodeControllerContext.js +2 -2
  2. package/esm/CodeExternalsContext/CodeExternalsContext.js +1 -1
  3. package/esm/CodeHighlighter/CodeHighlighter.js +247 -329
  4. package/esm/CodeHighlighter/CodeHighlighterClient.js +447 -653
  5. package/esm/CodeHighlighter/CodeHighlighterContext.js +2 -2
  6. package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +2 -2
  7. package/esm/CodeHighlighter/codeToFallbackProps.js +21 -37
  8. package/esm/CodeHighlighter/errors.js +248 -400
  9. package/esm/CodeHighlighter/parseControlledCode.js +12 -20
  10. package/esm/CodeProvider/CodeContext.js +3 -3
  11. package/esm/CodeProvider/CodeProvider.js +31 -40
  12. package/esm/abstractCreateDemo/abstractCreateDemo.js +13 -17
  13. package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +12 -12
  14. package/esm/cli/index.js +1 -1
  15. package/esm/cli/runValidate.js +160 -264
  16. package/esm/createDemoData/createDemoData.js +11 -12
  17. package/esm/createSitemap/createSitemap.js +2 -2
  18. package/esm/pipeline/getFileConventions/fileConventions.js +1 -1
  19. package/esm/pipeline/getFileConventions/getFileConventions.js +2 -15
  20. package/esm/pipeline/hastUtils/hastUtils.js +16 -17
  21. package/esm/pipeline/loadCodeVariant/addCodeVariantPaths.js +24 -24
  22. package/esm/pipeline/loadCodeVariant/applyCodeTransform.js +12 -22
  23. package/esm/pipeline/loadCodeVariant/calculateMainFilePath.js +30 -37
  24. package/esm/pipeline/loadCodeVariant/computeHastDeltas.js +107 -185
  25. package/esm/pipeline/loadCodeVariant/diffHast.js +18 -53
  26. package/esm/pipeline/loadCodeVariant/examineCodeVariant.js +24 -27
  27. package/esm/pipeline/loadCodeVariant/flattenCodeVariant.js +9 -10
  28. package/esm/pipeline/loadCodeVariant/hasAllCodeVariants.js +5 -5
  29. package/esm/pipeline/loadCodeVariant/loadCodeFallback.js +516 -731
  30. package/esm/pipeline/loadCodeVariant/loadCodeVariant.js +679 -1079
  31. package/esm/pipeline/loadCodeVariant/maybeCodeInitialData.js +14 -20
  32. package/esm/pipeline/loadCodeVariant/mergeCodeMetadata.js +53 -63
  33. package/esm/pipeline/loadCodeVariant/parseCode.js +40 -48
  34. package/esm/pipeline/loadCodeVariant/pathUtils.js +43 -64
  35. package/esm/pipeline/loadCodeVariant/transformSource.js +55 -125
  36. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +160 -221
  37. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +377 -479
  38. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +171 -173
  39. package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +14 -30
  40. package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +19 -21
  41. package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +37 -71
  42. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +3 -9
  43. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +54 -80
  44. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +71 -98
  45. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +5 -5
  46. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +161 -211
  47. package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +159 -207
  48. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +42 -64
  49. package/esm/pipeline/loadServerCodeMeta/resolveModulePathWithFs.js +20 -96
  50. package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +66 -85
  51. package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +71 -118
  52. package/esm/pipeline/loadServerSource/loadServerSource.js +121 -148
  53. package/esm/pipeline/loaderUtils/externalsToPackages.js +7 -7
  54. package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +8 -12
  55. package/esm/pipeline/loaderUtils/fileUrlToPortablePath.js +5 -5
  56. package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +19 -29
  57. package/esm/pipeline/loaderUtils/getLanguageFromExtension.js +3 -4
  58. package/esm/pipeline/loaderUtils/mergeExternals.js +15 -35
  59. package/esm/pipeline/loaderUtils/parseImportsAndComments.js +413 -433
  60. package/esm/pipeline/loaderUtils/processRelativeImports.js +153 -239
  61. package/esm/pipeline/loaderUtils/resolveModulePath.js +544 -1303
  62. package/esm/pipeline/loaderUtils/rewriteImports.js +73 -111
  63. package/esm/pipeline/parseSource/addLineGutters.js +33 -45
  64. package/esm/pipeline/parseSource/grammars.js +3 -3
  65. package/esm/pipeline/parseSource/parseSource.js +13 -31
  66. package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +32 -55
  67. package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +107 -160
  68. package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +846 -1033
  69. package/esm/pipeline/syncPageIndex/syncPageIndex.js +291 -438
  70. package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +213 -311
  71. package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +10 -10
  72. package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +133 -193
  73. package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +25 -27
  74. package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +572 -717
  75. package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +8 -8
  76. package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +84 -113
  77. package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +10 -26
  78. package/esm/useCode/Pre.js +58 -62
  79. package/esm/useCode/useCode.js +59 -61
  80. package/esm/useCode/useCodeUtils.js +54 -63
  81. package/esm/useCode/useCopyFunctionality.js +10 -9
  82. package/esm/useCode/useFileNavigation.js +150 -212
  83. package/esm/useCode/useSourceEditing.js +17 -14
  84. package/esm/useCode/useTransformManagement.js +23 -26
  85. package/esm/useCode/useUIState.js +12 -20
  86. package/esm/useCode/useVariantSelection.js +62 -79
  87. package/esm/useCopier/index.js +29 -56
  88. package/esm/useDemo/createCodeSandbox.js +12 -15
  89. package/esm/useDemo/createStackBlitz.js +14 -20
  90. package/esm/useDemo/exportVariant.js +200 -180
  91. package/esm/useDemo/exportVariantAsCra.js +22 -25
  92. package/esm/useDemo/useDemo.js +80 -84
  93. package/esm/useErrors/ErrorsContext.js +1 -1
  94. package/esm/useErrors/useErrors.js +3 -3
  95. package/esm/useLocalStorageState/useLocalStorageState.js +23 -39
  96. package/esm/usePreference/PreferencesProvider.js +1 -1
  97. package/esm/usePreference/usePreference.js +9 -11
  98. package/esm/useSearch/useSearch.js +290 -387
  99. package/esm/useUrlHashState/useUrlHashState.js +11 -14
  100. package/esm/withDocsInfra/withDeploymentConfig.js +26 -21
  101. package/esm/withDocsInfra/withDocsInfra.js +99 -101
  102. 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
- var extraFiles = {};
13
- var fileMapping = [];
9
+ const extraFiles = {};
10
+ const fileMapping = [];
14
11
 
15
12
  // First pass: collect all files and their path segments
16
- Object.entries(importResult).forEach(function (_ref) {
17
- var _ref2 = _slicedToArray(_ref, 2),
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
- var resolvedPath = resolvedUrl.startsWith('file://') ? fileUrlToPortablePath(resolvedUrl) : resolvedUrl;
24
- var fileExtension = getFileNameFromUrl(resolvedUrl).extension;
25
- var pathSegments = resolvedPath.split('/').filter(Boolean);
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: 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
- var candidateNames = new Map();
37
- var nameGroups = new Map();
38
- for (var _i = 0, _fileMapping = fileMapping; _i < _fileMapping.length; _i++) {
39
- var file = _fileMapping[_i];
40
- var fileName = file.segments[file.segments.length - 1];
41
- var isIndexFile = fileName.startsWith('index.');
42
- var isUnderscoreIndexFile = fileName.startsWith('_index.');
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 = "index".concat(file.extension);
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
- var originalImportParts = file.originalImportPath.split('/');
51
- var isDirectIndexImport = originalImportParts.length === 2 && originalImportParts[0] === '.' && originalImportParts[1].startsWith('index.');
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 = "index".concat(file.extension);
47
+ candidateName = `index${file.extension}`;
55
48
  } else {
56
49
  // For nested index files like "./test/index.ext", use parent directory + extension
57
- var parentDir = file.segments[file.segments.length - 2];
58
- candidateName = "".concat(parentDir).concat(file.extension);
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
- var finalNames = new Map();
72
- nameGroups.forEach(function (paths, candidateName) {
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
- var conflictingFiles = paths.map(function (resolvedPath) {
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
- var minLength = Math.min.apply(Math, _toConsumableArray(conflictingFiles.map(function (f) {
90
- return f.segments.length;
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
- var shorterFiles = conflictingFiles.filter(function (file) {
98
- return file.segments.length === minLength;
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
- var shorterFile = shorterFiles[0];
106
- var shorterPath = shorterFile.segments.slice(0, -1).join('/'); // Remove filename
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
- var allLongerFilesAreChildren = longerFiles.every(function (longerFile) {
110
- var longerPath = longerFile.segments.slice(0, shorterFile.segments.length - 1).join('/');
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
- var _distinguishingIndex = -1;
118
- var maxLongerLength = Math.max.apply(Math, _toConsumableArray(longerFiles.map(function (f) {
119
- return f.segments.length;
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
- _distinguishingIndex = i;
127
- return 1; // break
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 (_distinguishingIndex !== -1) {
107
+ if (distinguishingIndex !== -1) {
134
108
  // Generate names for longer files using distinguishing segment
135
- var _iterator = _createForOfIteratorHelper(longerFiles),
136
- _step;
137
- try {
138
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
139
- var _file = _step.value;
140
- var _fileName = _file.segments[_file.segments.length - 1];
141
- var _isIndexFile = _fileName.startsWith('index.');
142
- var _isUnderscoreIndexFile = _fileName.startsWith('_index.');
143
- var distinguishingSegment = _file.segments[_distinguishingIndex];
144
- var finalName = void 0;
145
- if (_isUnderscoreIndexFile) {
146
- // Files starting with "_index." should always use "index" as the base name
147
- finalName = "".concat(distinguishingSegment, "/index").concat(_file.extension);
148
- } else if (_isIndexFile) {
149
- // Check if this was a direct index import
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
- finalName = "".concat(distinguishingSegment, "/").concat(_fileName);
125
+ const parentDir = file.segments[file.segments.length - 2];
126
+ finalName = `${distinguishingSegment}/${parentDir}${file.extension}`;
160
127
  }
161
- finalNames.set(_file.resolvedPath, finalName);
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
- var _iterator2 = _createForOfIteratorHelper(shorterFiles),
171
- _step2;
172
- try {
173
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
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
- var distinguishingIndex = -1;
190
- var maxLength = Math.max.apply(Math, _toConsumableArray(conflictingFiles.map(function (f) {
191
- return f.segments.length;
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 = _i2;
199
- return 1; // break
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("Cannot find distinguishing segment for files: ".concat(paths.join(', ')));
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
- var _iterator3 = _createForOfIteratorHelper(conflictingFiles),
211
- _step3;
212
- try {
213
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
214
- var _file2 = _step3.value;
215
- var _fileName2 = _file2.segments[_file2.segments.length - 1];
216
- var _isIndexFile2 = _fileName2.startsWith('index.');
217
- var _isUnderscoreIndexFile2 = _fileName2.startsWith('_index.');
218
- var _distinguishingSegment = _file2.segments[distinguishingIndex];
219
- var _finalName = void 0;
220
- if (_isUnderscoreIndexFile2) {
221
- // Files starting with "_index." should always use "index" as the base name
222
- _finalName = "".concat(_distinguishingSegment, "/index").concat(_file2.extension);
223
- } else if (_isIndexFile2) {
224
- // Check if this was a direct index import
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
- _finalName = "".concat(_distinguishingSegment, "/").concat(_fileName2);
175
+ const parentDir = file.segments[file.segments.length - 2];
176
+ finalName = `${distinguishingSegment}/${parentDir}${file.extension}`;
235
177
  }
236
- finalNames.set(_file2.resolvedPath, _finalName);
178
+ } else {
179
+ finalName = `${distinguishingSegment}/${fileName}`;
237
180
  }
238
- } catch (err) {
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(function (finalName, resolvedPath) {
248
- extraFiles["./".concat(finalName)] = portablePathToFileUrl(resolvedPath);
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: 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
- var extraFiles = {};
202
+ const extraFiles = {};
263
203
  if (storeAt === 'flat') {
264
- var finalNames = new Map();
265
- var usedNames = new Set();
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(function (_ref3) {
269
- var _ref4 = _slicedToArray(_ref3, 2),
270
- _relativePath = _ref4[0],
271
- importInfo = _ref4[1];
272
- var resolvedPath = importInfo.url; // For CSS, this is already resolved by parseImports
273
- var fileUrl = portablePathToFileUrl(resolvedPath);
274
- var _getFileNameFromUrl = getFileNameFromUrl(fileUrl),
275
- fileName = _getFileNameFromUrl.fileName,
276
- extension = _getFileNameFromUrl.extension;
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
- var baseName = fileName.replace(extension, '');
283
- finalName = "".concat(baseName, "-").concat(counter).concat(extension);
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
- var importPathMapping = new Map();
292
- Object.entries(importResult).forEach(function (_ref5) {
293
- var _ref6 = _slicedToArray(_ref5, 2),
294
- relativePath = _ref6[0],
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(function (finalName, resolvedPath) {
305
- extraFiles["./".concat(finalName)] = portablePathToFileUrl(resolvedPath);
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
- var hasPositions = Object.values(importResult).some(function (imp) {
311
- return imp.positions && imp.positions.length > 0;
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: processedSource,
316
- extraFiles: 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
- var importModeMapping = new Map();
322
- Object.keys(importResult).forEach(function (relativePath) {
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(function (_ref7) {
331
- var _ref8 = _slicedToArray(_ref7, 2),
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
- var _hasPositions = Object.values(importResult).some(function (imp) {
341
- return imp.positions && imp.positions.length > 0;
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: _processedSource,
346
- extraFiles: extraFiles
273
+ processedSource,
274
+ extraFiles
347
275
  };
348
276
  }
349
277
 
350
278
  // Canonical mode - no rewriting needed
351
- Object.entries(importResult).forEach(function (_ref9) {
352
- var _ref0 = _slicedToArray(_ref9, 2),
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: 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
- var extraFiles = {};
294
+ const extraFiles = {};
370
295
  if (storeAt === 'flat') {
371
- var result = processFlatMode(importResult, resolvedPathsMap);
296
+ const result = processFlatMode(importResult, resolvedPathsMap);
372
297
 
373
298
  // Build a reverse mapping from resolved paths to extraFiles keys
374
- var resolvedToExtraFile = new Map();
375
- Object.entries(result.extraFiles).forEach(function (_ref1) {
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
- var resolvedPath = fileUrl.startsWith('file://') ? fileUrlToPortablePath(fileUrl) : fileUrl;
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
- var importPathMapping = new Map();
386
- Object.entries(importResult).forEach(function (_ref11) {
387
- var _ref12 = _slicedToArray(_ref11, 2),
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
- var resolvedPath = resolvedUrl.startsWith('file://') ? fileUrlToPortablePath(resolvedUrl) : resolvedUrl;
394
- var extraFileKey = resolvedToExtraFile.get(resolvedPath);
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
- var isJavascriptModule = isJavaScriptModule(relativePath);
398
- var newPath = extraFileKey;
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
- var processedSource = rewriteImports(source, importPathMapping, importResult);
334
+ const processedSource = rewriteImports(source, importPathMapping, importResult);
416
335
  return {
417
- processedSource: 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(function (_ref13) {
424
- var _ref14 = _slicedToArray(_ref13, 2),
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
- var resolvedPath = resolvedUrl.startsWith('file://') ? fileUrlToPortablePath(resolvedUrl) : resolvedUrl;
434
- var fileExtension = getFileNameFromUrl(resolvedUrl).extension;
435
- var isJavascriptModule = isJavaScriptModule(relativePath);
436
- var keyPath;
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 = "".concat(relativePath).concat(resolvedPath.endsWith("/index".concat(fileExtension)) ? "/index".concat(fileExtension) : fileExtension);
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 = "".concat(relativePath).concat(fileExtension);
365
+ keyPath = `${relativePath}${fileExtension}`;
450
366
  break;
451
367
  default:
452
- keyPath = "".concat(relativePath).concat(fileExtension);
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: 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);