@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,5 +1,3 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
1
  /**
4
2
  * Export variant functionality to add extra files like package.json, tsconfig, etc.
5
3
  * Users can pass configuration options that vary the output here.
@@ -15,21 +13,16 @@ import { mergeCodeMetadata, extractCodeMetadata } from "../pipeline/loadCodeVari
15
13
  * Similar to mergeExternals but for file structures.
16
14
  * Automatically adds metadata: false to files that don't have a metadata property.
17
15
  */
18
- function mergeFiles() {
19
- var merged = {};
20
- for (var _len = arguments.length, fileSets = new Array(_len), _key = 0; _key < _len; _key++) {
21
- fileSets[_key] = arguments[_key];
22
- }
23
- for (var _i = 0, _fileSets = fileSets; _i < _fileSets.length; _i++) {
24
- var fileSet = _fileSets[_i];
25
- for (var _i2 = 0, _Object$entries = Object.entries(fileSet); _i2 < _Object$entries.length; _i2++) {
26
- var _Object$entries$_i = _slicedToArray(_Object$entries[_i2], 2),
27
- fileName = _Object$entries$_i[0],
28
- fileData = _Object$entries$_i[1];
16
+ function mergeFiles(...fileSets) {
17
+ const merged = {};
18
+ for (const fileSet of fileSets) {
19
+ for (const [fileName, fileData] of Object.entries(fileSet)) {
29
20
  // Later files override earlier ones (similar to Object.assign behavior)
30
- var normalizedData = typeof fileData === 'string' ? {
21
+ const normalizedData = typeof fileData === 'string' ? {
31
22
  source: fileData
32
- } : _extends({}, fileData);
23
+ } : {
24
+ ...fileData
25
+ };
33
26
  // Add metadata: false if not already set (source files default to false)
34
27
  if (!('metadata' in normalizedData)) {
35
28
  normalizedData.metadata = false;
@@ -48,8 +41,9 @@ export function getFilenameFromVariant(variantCode) {
48
41
  return variantCode.fileName;
49
42
  }
50
43
  if (variantCode.url) {
51
- var _getFileNameFromUrl = getFileNameFromUrl(variantCode.url),
52
- fileName = _getFileNameFromUrl.fileName;
44
+ const {
45
+ fileName
46
+ } = getFileNameFromUrl(variantCode.url);
53
47
  return fileName || undefined;
54
48
  }
55
49
  return undefined;
@@ -58,26 +52,24 @@ export function getFilenameFromVariant(variantCode) {
58
52
  /**
59
53
  * Generate a unique entrypoint filename that doesn't conflict with existing files
60
54
  */
61
- export function generateEntrypointFilename(existingFiles, sourceFilename, useTypescript) {
62
- var pathPrefix = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
63
- var ext = useTypescript ? 'tsx' : 'jsx';
64
- var candidates = ["".concat(pathPrefix, "App.").concat(ext), "".concat(pathPrefix, "entrypoint.").concat(ext), "".concat(pathPrefix, "main.").concat(ext)];
55
+ export function generateEntrypointFilename(existingFiles, sourceFilename, useTypescript, pathPrefix = '') {
56
+ const ext = useTypescript ? 'tsx' : 'jsx';
57
+ const candidates = [`${pathPrefix}App.${ext}`, `${pathPrefix}entrypoint.${ext}`, `${pathPrefix}main.${ext}`];
65
58
 
66
59
  // If we have a source filename, also try variations
67
60
  if (sourceFilename) {
68
- var baseName = sourceFilename.replace(/\.[^.]*$/, '');
69
- candidates.push("".concat(pathPrefix).concat(baseName, "-entry.").concat(ext));
61
+ const baseName = sourceFilename.replace(/\.[^.]*$/, '');
62
+ candidates.push(`${pathPrefix}${baseName}-entry.${ext}`);
70
63
  }
71
- for (var _i3 = 0, _candidates = candidates; _i3 < _candidates.length; _i3++) {
72
- var candidate = _candidates[_i3];
73
- if (candidate !== "".concat(pathPrefix).concat(sourceFilename) && !existingFiles[candidate]) {
64
+ for (const candidate of candidates) {
65
+ if (candidate !== `${pathPrefix}${sourceFilename}` && !existingFiles[candidate]) {
74
66
  return candidate;
75
67
  }
76
68
  }
77
69
 
78
70
  // Generate with hash if all candidates are taken
79
- var hash = Math.random().toString(36).substring(2, 8);
80
- return "".concat(pathPrefix, "entrypoint-").concat(hash, ".").concat(ext);
71
+ const hash = Math.random().toString(36).substring(2, 8);
72
+ return `${pathPrefix}entrypoint-${hash}.${ext}`;
81
73
  }
82
74
 
83
75
  /**
@@ -89,100 +81,99 @@ export function getRelativeImportPath(sourceFilename) {
89
81
  }
90
82
 
91
83
  // Remove extension for import
92
- var baseName = sourceFilename.replace(/\.[^.]*$/, '');
93
- return "./".concat(baseName);
84
+ const baseName = sourceFilename.replace(/\.[^.]*$/, '');
85
+ return `./${baseName}`;
94
86
  }
95
87
 
96
88
  /**
97
89
  * Default HTML template function for Vite-based demos
98
90
  */
99
- export function defaultHtmlTemplate(_ref) {
100
- var language = _ref.language,
101
- title = _ref.title,
102
- description = _ref.description,
103
- head = _ref.head,
104
- entrypoint = _ref.entrypoint;
105
- return "<!DOCTYPE html>\n<html lang=\"".concat(language, "\">\n <head>\n <meta charset=\"utf-8\" />\n <title>").concat(title, "</title>\n ").concat(description ? "<meta name=\"description\" content=\"".concat(description, "\" />") : '', "\n <meta name=\"viewport\" content=\"initial-scale=1, width=device-width\" />").concat(head ? "\n ".concat(head.split('\n').join('\n ')) : '', "\n </head>\n <body>\n <div id=\"root\"></div>").concat(entrypoint ? "\n <script type=\"module\" src=\"".concat(entrypoint, "\"></script>") : '', "\n </body>\n</html>\n");
91
+ export function defaultHtmlTemplate({
92
+ language,
93
+ title,
94
+ description,
95
+ head,
96
+ entrypoint
97
+ }) {
98
+ return `<!DOCTYPE html>
99
+ <html lang="${language}">
100
+ <head>
101
+ <meta charset="utf-8" />
102
+ <title>${title}</title>
103
+ ${description ? `<meta name="description" content="${description}" />` : ''}
104
+ <meta name="viewport" content="initial-scale=1, width=device-width" />${head ? `\n ${head.split('\n').join('\n ')}` : ''}
105
+ </head>
106
+ <body>
107
+ <div id="root"></div>${entrypoint ? `\n <script type="module" src="${entrypoint}"></script>` : ''}
108
+ </body>
109
+ </html>
110
+ `;
106
111
  }
107
112
  /**
108
113
  * Export a variant as a standalone project with metadata files properly scoped
109
114
  */
110
- export function exportVariant(variantCode) {
111
- var _frameworkFiles$varia;
112
- var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
113
- var _config$title = config.title,
114
- title = _config$title === void 0 ? 'Demo' : _config$title,
115
- titlePrefix = config.titlePrefix,
116
- titleSuffix = config.titleSuffix,
117
- _config$description = config.description,
118
- description = _config$description === void 0 ? 'Demo created with Vite' : _config$description,
119
- descriptionPrefix = config.descriptionPrefix,
120
- descriptionSuffix = config.descriptionSuffix,
121
- variantName = config.variantName,
122
- _config$language = config.language,
123
- language = _config$language === void 0 ? 'en' : _config$language,
124
- _config$htmlPrefix = config.htmlPrefix,
125
- htmlPrefix = _config$htmlPrefix === void 0 ? '' : _config$htmlPrefix,
126
- _config$sourcePrefix = config.sourcePrefix,
127
- sourcePrefix = _config$sourcePrefix === void 0 ? 'src/' : _config$sourcePrefix,
128
- _config$assetPrefix = config.assetPrefix,
129
- assetPrefix = _config$assetPrefix === void 0 ? '' : _config$assetPrefix,
130
- _config$frameworkHand = config.frameworkHandlesEntrypoint,
131
- frameworkHandlesEntrypoint = _config$frameworkHand === void 0 ? false : _config$frameworkHand,
132
- _config$htmlSkipJsLin = config.htmlSkipJsLink,
133
- htmlSkipJsLink = _config$htmlSkipJsLin === void 0 ? false : _config$htmlSkipJsLin,
134
- htmlTemplate = config.htmlTemplate,
135
- headTemplate = config.headTemplate,
136
- rootIndexTemplate = config.rootIndexTemplate,
137
- _config$dependencies = config.dependencies,
138
- dependencies = _config$dependencies === void 0 ? {} : _config$dependencies,
139
- _config$devDependenci = config.devDependencies,
140
- devDependencies = _config$devDependenci === void 0 ? {} : _config$devDependenci,
141
- _config$scripts = config.scripts,
142
- scripts = _config$scripts === void 0 ? {} : _config$scripts,
143
- packageType = config.packageType,
144
- _config$packageJsonFi = config.packageJsonFields,
145
- packageJsonFields = _config$packageJsonFi === void 0 ? {} : _config$packageJsonFi,
146
- _config$tsconfigOptio = config.tsconfigOptions,
147
- tsconfigOptions = _config$tsconfigOptio === void 0 ? {} : _config$tsconfigOptio,
148
- _config$viteConfig = config.viteConfig,
149
- viteConfig = _config$viteConfig === void 0 ? {} : _config$viteConfig,
150
- _config$useTypescript = config.useTypescript,
151
- useTypescript = _config$useTypescript === void 0 ? false : _config$useTypescript,
152
- _config$extraMetadata = config.extraMetadataFiles,
153
- extraMetadataFiles = _config$extraMetadata === void 0 ? {} : _config$extraMetadata,
154
- _config$frameworkFile = config.frameworkFiles,
155
- frameworkFiles = _config$frameworkFile === void 0 ? {} : _config$frameworkFile,
156
- transformVariant = config.transformVariant,
157
- _config$versions = config.versions,
158
- versions = _config$versions === void 0 ? {} : _config$versions,
159
- resolveDependencies = config.resolveDependencies;
115
+ export function exportVariant(variantCode, config = {}) {
116
+ const {
117
+ title = 'Demo',
118
+ titlePrefix,
119
+ titleSuffix,
120
+ description = 'Demo created with Vite',
121
+ descriptionPrefix,
122
+ descriptionSuffix,
123
+ variantName,
124
+ language = 'en',
125
+ htmlPrefix = '',
126
+ sourcePrefix = 'src/',
127
+ assetPrefix = '',
128
+ frameworkHandlesEntrypoint = false,
129
+ htmlSkipJsLink = false,
130
+ htmlTemplate,
131
+ headTemplate,
132
+ rootIndexTemplate,
133
+ dependencies = {},
134
+ devDependencies = {},
135
+ scripts = {},
136
+ packageType,
137
+ packageJsonFields = {},
138
+ tsconfigOptions = {},
139
+ viteConfig = {},
140
+ useTypescript = false,
141
+ extraMetadataFiles = {},
142
+ frameworkFiles = {},
143
+ transformVariant,
144
+ versions = {},
145
+ resolveDependencies
146
+ } = config;
160
147
 
161
148
  // Build final title and description with prefixes and suffixes
162
- var finalTitle = [titlePrefix, title, titleSuffix].filter(Boolean).join('');
163
- var finalDescription = [descriptionPrefix, description, descriptionSuffix].filter(Boolean).join('');
149
+ const finalTitle = [titlePrefix, title, titleSuffix].filter(Boolean).join('');
150
+ const finalDescription = [descriptionPrefix, description, descriptionSuffix].filter(Boolean).join('');
164
151
 
165
152
  // Use extractCodeMetadata to properly separate metadata and non-metadata files
166
- var _extractCodeMetadata = extractCodeMetadata(variantCode),
167
- processedVariantCode = _extractCodeMetadata.variant,
168
- processedGlobals = _extractCodeMetadata.metadata;
153
+ let {
154
+ variant: processedVariantCode,
155
+ metadata: processedGlobals
156
+ } = extractCodeMetadata(variantCode);
169
157
 
170
158
  // Run optional transform hook to modify variant and globals before processing
171
159
  if (transformVariant) {
172
- var transformed = transformVariant(processedVariantCode, variantName, processedGlobals);
160
+ const transformed = transformVariant(processedVariantCode, variantName, processedGlobals);
173
161
  if (transformed) {
174
162
  // Re-extract metadata after transformation
175
- var result = transformed.variant && extractCodeMetadata(transformed.variant);
176
- processedVariantCode = (result == null ? void 0 : result.variant) || processedVariantCode;
163
+ const result = transformed.variant && extractCodeMetadata(transformed.variant);
164
+ processedVariantCode = result?.variant || processedVariantCode;
177
165
 
178
166
  // Start fresh with only the new metadata and explicitly transformed globals
179
167
  // Do NOT merge with the original processedGlobals to avoid duplication
180
- processedGlobals = _extends(_extends({}, result == null ? void 0 : result.metadata), transformed.globals);
168
+ processedGlobals = {
169
+ ...result?.metadata,
170
+ ...transformed.globals
171
+ };
181
172
  }
182
173
  }
183
174
 
184
175
  // If packageType is explicitly provided (even as undefined), use that value
185
- var finalPackageType;
176
+ let finalPackageType;
186
177
  if ('packageType' in config) {
187
178
  finalPackageType = packageType;
188
179
  } else {
@@ -190,51 +181,51 @@ export function exportVariant(variantCode) {
190
181
  }
191
182
 
192
183
  // Get existing extraFiles and source filename
193
- var sourceFilename = getFilenameFromVariant(processedVariantCode);
184
+ const sourceFilename = getFilenameFromVariant(processedVariantCode);
194
185
 
195
186
  // Get path context to understand navigation
196
- var pathContext = examineCodeVariant(variantCode);
187
+ const pathContext = examineCodeVariant(variantCode);
197
188
 
198
189
  // Determine if we need to rename the source file
199
- var ext = useTypescript ? 'tsx' : 'jsx';
200
- var isSourceFileIndex = sourceFilename === "index.".concat(ext);
201
- var hasBackNavigation = pathContext.maxSourceBackNavigation > 0;
202
- var actualSourceFilename = sourceFilename;
190
+ const ext = useTypescript ? 'tsx' : 'jsx';
191
+ const isSourceFileIndex = sourceFilename === `index.${ext}`;
192
+ const hasBackNavigation = pathContext.maxSourceBackNavigation > 0;
193
+ let actualSourceFilename = sourceFilename;
203
194
 
204
195
  // Use urlDirectory to construct the full path from src root
205
- var directoryPath = pathContext.urlDirectory.slice(1).join('/'); // Remove 'src' and join the rest
206
- var actualRootFile = directoryPath ? "".concat(sourcePrefix).concat(directoryPath, "/").concat(sourceFilename) : "".concat(sourcePrefix).concat(sourceFilename);
196
+ const directoryPath = pathContext.urlDirectory.slice(1).join('/'); // Remove 'src' and join the rest
197
+ let actualRootFile = directoryPath ? `${sourcePrefix}${directoryPath}/${sourceFilename}` : `${sourcePrefix}${sourceFilename}`;
207
198
 
208
199
  // If the source file is index.tsx and it's in the src root, we need to rename it
209
200
  if (isSourceFileIndex && !hasBackNavigation) {
210
201
  actualSourceFilename = generateEntrypointFilename(processedVariantCode.extraFiles || {}, sourceFilename, useTypescript);
211
202
  // When renaming due to conflicts, place the file in src root regardless of original location
212
- actualRootFile = "".concat(sourcePrefix).concat(actualSourceFilename);
203
+ actualRootFile = `${sourcePrefix}${actualSourceFilename}`;
213
204
  }
214
205
 
215
206
  // The main entrypoint is always src/index.tsx (or .jsx)
216
- var mainEntrypointFilename = "index.".concat(ext);
217
- var entrypoint = !htmlSkipJsLink ? "".concat(sourcePrefix).concat(mainEntrypointFilename) : undefined;
207
+ const mainEntrypointFilename = `index.${ext}`;
208
+ const entrypoint = !htmlSkipJsLink ? `${sourcePrefix}${mainEntrypointFilename}` : undefined;
218
209
 
219
210
  // Get relative import path for the main component
220
- var importPath;
211
+ let importPath;
221
212
  if (!hasBackNavigation) {
222
213
  // Component is in src root - import directly
223
214
  importPath = getRelativeImportPath(actualSourceFilename);
224
215
  } else {
225
216
  // Component is in a subdirectory - import with full path from src root
226
- var componentPath = directoryPath ? "".concat(directoryPath, "/").concat(actualSourceFilename) : actualSourceFilename;
227
- importPath = "./".concat((componentPath || '').replace(/\.[^.]*$/, '')); // Remove extension
217
+ const componentPath = directoryPath ? `${directoryPath}/${actualSourceFilename}` : actualSourceFilename;
218
+ importPath = `./${(componentPath || '').replace(/\.[^.]*$/, '')}`; // Remove extension
228
219
  }
229
220
 
230
221
  // Strip /index from the end of import paths since module resolution handles it automatically
231
222
  if (importPath.endsWith('/index')) {
232
223
  importPath = importPath.slice(0, -6); // Remove '/index'
233
224
  }
234
- var importString = processedVariantCode.namedExport ? "import { ".concat(processedVariantCode.namedExport, " as App } from '").concat(importPath, "';") : "import App from '".concat(importPath, "';");
225
+ const importString = processedVariantCode.namedExport ? `import { ${processedVariantCode.namedExport} as App } from '${importPath}';` : `import App from '${importPath}';`;
235
226
 
236
227
  // Collect all files that will be generated
237
- var generatedFiles = {};
228
+ const generatedFiles = {};
238
229
 
239
230
  // Update the variant's fileName if we renamed it
240
231
  if (isSourceFileIndex && !hasBackNavigation && actualSourceFilename && actualSourceFilename !== sourceFilename) {
@@ -242,14 +233,14 @@ export function exportVariant(variantCode) {
242
233
  }
243
234
 
244
235
  // Check if they're providing their own framework
245
- var isFramework = 'frameworkFiles' in config;
246
- var externalPackages = externalsToPackages(processedVariantCode.externals || []);
247
- var variantDeps = Object.keys(externalPackages).reduce(function (acc, pkg) {
236
+ const isFramework = 'frameworkFiles' in config;
237
+ const externalPackages = externalsToPackages(processedVariantCode.externals || []);
238
+ const variantDeps = Object.keys(externalPackages).reduce((acc, pkg) => {
248
239
  // Check if we have a specific version for this package first
249
240
  if (versions[pkg]) {
250
241
  acc[pkg] = versions[pkg];
251
242
  } else if (resolveDependencies) {
252
- var resolvedDeps = resolveDependencies(pkg);
243
+ const resolvedDeps = resolveDependencies(pkg);
253
244
  Object.assign(acc, resolvedDeps);
254
245
  } else {
255
246
  // Simple fallback: just use 'latest' for each package
@@ -259,47 +250,66 @@ export function exportVariant(variantCode) {
259
250
  }, {});
260
251
 
261
252
  // Collect metadata files to be generated
262
- var metadataFiles = {};
253
+ const metadataFiles = {};
263
254
 
264
255
  // Generate package.json
265
- var packageJson = _extends(_extends({
266
- "private": true,
256
+ const packageJson = {
257
+ private: true,
267
258
  name: finalTitle.toLowerCase().replace(/[^a-z0-9]/g, '-'),
268
259
  version: '0.0.0',
269
- description: finalDescription
270
- }, finalPackageType && {
271
- type: finalPackageType
272
- }), {}, {
260
+ description: finalDescription,
261
+ ...(finalPackageType && {
262
+ type: finalPackageType
263
+ }),
273
264
  // Add type if specified
274
- scripts: _extends(_extends({}, !isFramework && {
275
- dev: 'vite',
276
- build: 'vite build',
277
- preview: 'vite preview'
278
- }), scripts),
279
- dependencies: _extends(_extends({
265
+ scripts: {
266
+ ...(!isFramework && {
267
+ dev: 'vite',
268
+ build: 'vite build',
269
+ preview: 'vite preview'
270
+ }),
271
+ ...scripts
272
+ },
273
+ dependencies: {
280
274
  react: versions.react || 'latest',
281
- 'react-dom': versions['react-dom'] || 'latest'
282
- }, variantDeps), dependencies),
283
- devDependencies: _extends(_extends(_extends({}, !isFramework && {
284
- '@vitejs/plugin-react': 'latest',
285
- vite: 'latest'
286
- }), useTypescript && {
287
- typescript: 'latest',
288
- '@types/react': versions['@types/react'] || 'latest',
289
- '@types/react-dom': versions['@types/react-dom'] || 'latest'
290
- }), devDependencies)
291
- }, packageJsonFields);
275
+ 'react-dom': versions['react-dom'] || 'latest',
276
+ ...variantDeps,
277
+ ...dependencies
278
+ },
279
+ devDependencies: {
280
+ ...(!isFramework && {
281
+ '@vitejs/plugin-react': 'latest',
282
+ vite: 'latest'
283
+ }),
284
+ ...(useTypescript && {
285
+ typescript: 'latest',
286
+ '@types/react': versions['@types/react'] || 'latest',
287
+ '@types/react-dom': versions['@types/react-dom'] || 'latest'
288
+ }),
289
+ ...devDependencies
290
+ },
291
+ ...packageJsonFields
292
+ };
292
293
  metadataFiles['package.json'] = {
293
- source: "".concat(JSON.stringify(packageJson, null, 2), "\n")
294
+ source: `${JSON.stringify(packageJson, null, 2)}\n`
294
295
  };
295
296
 
296
297
  // Generate entrypoint and HTML files unless framework handles them
297
298
  if (!frameworkHandlesEntrypoint) {
298
299
  // Create entrypoint file that imports the main component
299
- var defaultEntrypointContent = "import * as React from 'react';\nimport * as ReactDOM from 'react-dom/client';\n".concat(importString, "\n\nReactDOM.createRoot(document.getElementById('root')").concat(useTypescript ? '!' : '', ").render(\n <React.StrictMode>\n <App />\n </React.StrictMode>\n);\n");
300
- var entrypointContent = rootIndexTemplate ? rootIndexTemplate({
301
- importString: importString,
302
- useTypescript: useTypescript
300
+ const defaultEntrypointContent = `import * as React from 'react';
301
+ import * as ReactDOM from 'react-dom/client';
302
+ ${importString}
303
+
304
+ ReactDOM.createRoot(document.getElementById('root')${useTypescript ? '!' : ''}).render(
305
+ <React.StrictMode>
306
+ <App />
307
+ </React.StrictMode>
308
+ );
309
+ `;
310
+ const entrypointContent = rootIndexTemplate ? rootIndexTemplate({
311
+ importString,
312
+ useTypescript
303
313
  }) : defaultEntrypointContent;
304
314
  generatedFiles[mainEntrypointFilename] = {
305
315
  source: entrypointContent
@@ -308,8 +318,17 @@ export function exportVariant(variantCode) {
308
318
 
309
319
  // Add Vite config file only if no framework files (Vite-specific)
310
320
  if (!isFramework) {
311
- var viteConfigContent = "import { defineConfig } from 'vite';\nimport react from '@vitejs/plugin-react';\n\n// https://vitejs.dev/config/\nexport default defineConfig({\n plugins: [react()],\n define: { 'process.env': {} },\n ...".concat(JSON.stringify(viteConfig, null, 2).split('\n').join('\n '), "\n});\n");
312
- metadataFiles["vite.config.".concat(useTypescript ? 'ts' : 'js')] = {
321
+ const viteConfigContent = `import { defineConfig } from 'vite';
322
+ import react from '@vitejs/plugin-react';
323
+
324
+ // https://vitejs.dev/config/
325
+ export default defineConfig({
326
+ plugins: [react()],
327
+ define: { 'process.env': {} },
328
+ ...${JSON.stringify(viteConfig, null, 2).split('\n').join('\n ')}
329
+ });
330
+ `;
331
+ metadataFiles[`vite.config.${useTypescript ? 'ts' : 'js'}`] = {
313
332
  source: viteConfigContent
314
333
  };
315
334
  }
@@ -317,13 +336,11 @@ export function exportVariant(variantCode) {
317
336
  // Add TypeScript configuration if requested
318
337
  if (useTypescript) {
319
338
  // Check if frameworkFiles already includes a tsconfig
320
- var hasFrameworkTsConfig = (frameworkFiles == null ? void 0 : frameworkFiles.globals) && Object.keys(frameworkFiles.globals).some(function (fileName) {
321
- return fileName.includes('tsconfig.json') && !fileName.includes('tsconfig.node.json');
322
- });
339
+ const hasFrameworkTsConfig = frameworkFiles?.globals && Object.keys(frameworkFiles.globals).some(fileName => fileName.includes('tsconfig.json') && !fileName.includes('tsconfig.node.json'));
323
340
  if (!hasFrameworkTsConfig) {
324
341
  // Main tsconfig.json (default Vite config)
325
- var defaultTsConfig = _extends({
326
- compilerOptions: _extends({
342
+ const defaultTsConfig = {
343
+ compilerOptions: {
327
344
  target: 'ES2020',
328
345
  useDefineForClassFields: true,
329
346
  lib: ['ES2020', 'DOM', 'DOM.Iterable'],
@@ -338,23 +355,25 @@ export function exportVariant(variantCode) {
338
355
  strict: true,
339
356
  noUnusedLocals: true,
340
357
  noUnusedParameters: true,
341
- noFallthroughCasesInSwitch: true
342
- }, tsconfigOptions),
343
- include: ['src']
344
- }, !isFramework && {
345
- references: [{
346
- path: './tsconfig.node.json'
347
- }]
348
- });
358
+ noFallthroughCasesInSwitch: true,
359
+ ...tsconfigOptions
360
+ },
361
+ include: ['src'],
362
+ ...(!isFramework && {
363
+ references: [{
364
+ path: './tsconfig.node.json'
365
+ }]
366
+ })
367
+ };
349
368
  metadataFiles['tsconfig.json'] = {
350
- source: "".concat(JSON.stringify(defaultTsConfig, null, 2), "\n")
369
+ source: `${JSON.stringify(defaultTsConfig, null, 2)}\n`
351
370
  };
352
371
  }
353
372
 
354
373
  // Only add tsconfig.node.json for Vite (not for framework files)
355
374
  if (!isFramework) {
356
375
  // Node tsconfig for Vite config
357
- var nodeTsConfig = {
376
+ const nodeTsConfig = {
358
377
  compilerOptions: {
359
378
  composite: true,
360
379
  skipLibCheck: true,
@@ -365,7 +384,7 @@ export function exportVariant(variantCode) {
365
384
  include: ['vite.config.ts']
366
385
  };
367
386
  metadataFiles['tsconfig.node.json'] = {
368
- source: "".concat(JSON.stringify(nodeTsConfig, null, 2), "\n")
387
+ source: `${JSON.stringify(nodeTsConfig, null, 2)}\n`
369
388
  };
370
389
  }
371
390
  }
@@ -373,46 +392,47 @@ export function exportVariant(variantCode) {
373
392
  // Generate HTML file after all files are ready
374
393
  if (!frameworkHandlesEntrypoint) {
375
394
  // Add index.html
376
- var headContent = headTemplate ? headTemplate({
377
- sourcePrefix: sourcePrefix,
378
- assetPrefix: assetPrefix,
395
+ const headContent = headTemplate ? headTemplate({
396
+ sourcePrefix,
397
+ assetPrefix,
379
398
  variant: processedVariantCode,
380
- variantName: variantName
399
+ variantName
381
400
  }) : undefined;
382
- var htmlContent = htmlTemplate ? htmlTemplate({
383
- language: language,
401
+ const htmlContent = htmlTemplate ? htmlTemplate({
402
+ language,
384
403
  title: finalTitle,
385
404
  description: finalDescription,
386
405
  head: headContent,
387
- entrypoint: entrypoint,
406
+ entrypoint,
388
407
  variant: processedVariantCode,
389
- variantName: variantName
408
+ variantName
390
409
  }) : defaultHtmlTemplate({
391
- language: language,
410
+ language,
392
411
  title: finalTitle,
393
412
  description: finalDescription,
394
413
  head: headContent,
395
- entrypoint: entrypoint
414
+ entrypoint
396
415
  });
397
- var htmlFileName = htmlPrefix ? "".concat(htmlPrefix, "index.html") : 'index.html';
416
+ const htmlFileName = htmlPrefix ? `${htmlPrefix}index.html` : 'index.html';
398
417
  metadataFiles[htmlFileName] = {
399
418
  source: htmlContent
400
419
  };
401
420
  }
402
421
 
403
422
  // Merge all metadata files including framework metadata and globals
404
- var allMetadataFiles = mergeFiles(processedGlobals || {}, metadataFiles, extraMetadataFiles, frameworkFiles.globals || {});
423
+ const allMetadataFiles = mergeFiles(processedGlobals || {}, metadataFiles, extraMetadataFiles, frameworkFiles.globals || {});
405
424
 
406
425
  // Merge all files using mergeCodeMetadata to properly position everything with 'src/' (sourcePrefix opt) prefix
407
- var allSourceFilesWithFramework = mergeFiles(processedVariantCode.extraFiles || {}, generatedFiles, ((_frameworkFiles$varia = frameworkFiles.variant) == null ? void 0 : _frameworkFiles$varia.extraFiles) || {});
426
+ const allSourceFilesWithFramework = mergeFiles(processedVariantCode.extraFiles || {}, generatedFiles, frameworkFiles.variant?.extraFiles || {});
408
427
 
409
428
  // Update the variant with all source files including framework source files
410
- var finalVariantWithSources = _extends(_extends({}, processedVariantCode), {}, {
429
+ const finalVariantWithSources = {
430
+ ...processedVariantCode,
411
431
  extraFiles: allSourceFilesWithFramework
412
- });
432
+ };
413
433
 
414
434
  // Use mergeCodeMetadata to position everything correctly
415
- var finalVariant = mergeCodeMetadata(finalVariantWithSources, allMetadataFiles, {
435
+ const finalVariant = mergeCodeMetadata(finalVariantWithSources, allMetadataFiles, {
416
436
  metadataPrefix: sourcePrefix
417
437
  });
418
438
 
@@ -1,6 +1,3 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- var _excluded = ["title", "description", "scripts", "devDependencies"];
4
1
  /**
5
2
  * Export VariantCode as Create React App template using exportVariant
6
3
  * This is a general-purpose wrapper that creates CRA-compatible templates
@@ -13,35 +10,34 @@ import { exportVariant } from "./exportVariant.js";
13
10
  * Export a VariantCode as a Create React App template
14
11
  * Returns an object with the exported VariantCode and entrypoint path
15
12
  */
16
- export function exportVariantAsCra(variantCode) {
17
- var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
18
- var _config$title = config.title,
19
- title = _config$title === void 0 ? 'Demo' : _config$title,
20
- _config$description = config.description,
21
- description = _config$description === void 0 ? 'Demo created with Create React App' : _config$description,
22
- _config$scripts = config.scripts,
23
- scripts = _config$scripts === void 0 ? {} : _config$scripts,
24
- _config$devDependenci = config.devDependencies,
25
- devDependencies = _config$devDependenci === void 0 ? {} : _config$devDependenci,
26
- otherConfig = _objectWithoutPropertiesLoose(config, _excluded);
13
+ export function exportVariantAsCra(variantCode, config = {}) {
14
+ const {
15
+ title = 'Demo',
16
+ description = 'Demo created with Create React App',
17
+ scripts = {},
18
+ devDependencies = {},
19
+ ...otherConfig
20
+ } = config;
27
21
 
28
22
  // Default CRA scripts
29
- var craScripts = _extends({
23
+ const craScripts = {
30
24
  start: 'react-scripts start',
31
25
  build: 'react-scripts build',
32
26
  test: 'react-scripts test',
33
- eject: 'react-scripts eject'
34
- }, scripts);
27
+ eject: 'react-scripts eject',
28
+ ...scripts
29
+ };
35
30
 
36
31
  // CRA only needs react-scripts, other deps are handled by exportVariant
37
- var craDevDependencies = _extends({
38
- 'react-scripts': 'latest'
39
- }, devDependencies);
32
+ const craDevDependencies = {
33
+ 'react-scripts': 'latest',
34
+ ...devDependencies
35
+ };
40
36
 
41
37
  // Create export configuration for CRA
42
- var exportConfig = _extends({
43
- title: title,
44
- description: description,
38
+ const exportConfig = {
39
+ title,
40
+ description,
45
41
  htmlPrefix: 'public/',
46
42
  packageType: undefined,
47
43
  // CRA should not have 'type: module'
@@ -49,8 +45,9 @@ export function exportVariantAsCra(variantCode) {
49
45
  frameworkFiles: {},
50
46
  // Prevent Vite-specific files from being generated
51
47
  devDependencies: craDevDependencies,
52
- scripts: craScripts
53
- }, otherConfig);
48
+ scripts: craScripts,
49
+ ...otherConfig
50
+ };
54
51
 
55
52
  // Use exportVariant to generate the final result
56
53
  return exportVariant(variantCode, exportConfig);