@qualcomm-ui/mdx-vite 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +259 -211
- package/dist/cli.js.map +4 -4
- package/dist/docs-plugin/docs-plugin.d.ts.map +1 -1
- package/dist/docs-plugin/generate-page-map.d.ts +2 -0
- package/dist/docs-plugin/generate-page-map.d.ts.map +1 -0
- package/dist/index.js +60 -646
- package/dist/index.js.map +3 -3
- package/dist/react-demo-plugin/demo-plugin-utils.d.ts +0 -21
- package/dist/react-demo-plugin/demo-plugin-utils.d.ts.map +1 -1
- package/dist/react-demo-plugin/react-demo-plugin.d.ts +5 -1
- package/dist/react-demo-plugin/react-demo-plugin.d.ts.map +1 -1
- package/dist/react-demo-plugin/virtual.d.ts +0 -12
- package/dist/tsbuildinfo +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -2685,6 +2685,7 @@ var SearchIndexer = class {
|
|
|
2685
2685
|
|
|
2686
2686
|
// src/docs-plugin/docs-plugin.ts
|
|
2687
2687
|
var isDev = process.env.NODE_ENV === "development";
|
|
2688
|
+
var VIRTUAL_MODULE_ID2 = "\0@qualcomm-ui/mdx-vite-plugin";
|
|
2688
2689
|
var PluginState = class {
|
|
2689
2690
|
buildCount = 0;
|
|
2690
2691
|
configFilePath = "";
|
|
@@ -2695,12 +2696,7 @@ var PluginState = class {
|
|
|
2695
2696
|
servers = [];
|
|
2696
2697
|
timeout = void 0;
|
|
2697
2698
|
watching = false;
|
|
2698
|
-
resolvedVirtualModuleId;
|
|
2699
|
-
virtualModuleId = "@qualcomm-ui/mdx-vite-plugin";
|
|
2700
2699
|
cwd;
|
|
2701
|
-
constructor() {
|
|
2702
|
-
this.resolvedVirtualModuleId = `\0${this.virtualModuleId}`;
|
|
2703
|
-
}
|
|
2704
2700
|
init(cwd) {
|
|
2705
2701
|
this.cwd = cwd;
|
|
2706
2702
|
}
|
|
@@ -2756,27 +2752,25 @@ var PluginState = class {
|
|
|
2756
2752
|
}
|
|
2757
2753
|
}
|
|
2758
2754
|
/**
|
|
2759
|
-
* When the user
|
|
2760
|
-
*
|
|
2761
|
-
*
|
|
2755
|
+
* When the user adds or removes mdx files, we re-index the site. This function
|
|
2756
|
+
* handles module invalidation so that virtual file imports are refreshed as
|
|
2757
|
+
* expected by the consumer's dev server.
|
|
2762
2758
|
*/
|
|
2763
2759
|
sendUpdate() {
|
|
2764
2760
|
for (const server of this.servers) {
|
|
2765
|
-
const virtualModule = server.moduleGraph.getModuleById(
|
|
2766
|
-
this.resolvedVirtualModuleId
|
|
2767
|
-
);
|
|
2761
|
+
const virtualModule = server.moduleGraph.getModuleById(VIRTUAL_MODULE_ID2);
|
|
2768
2762
|
if (virtualModule) {
|
|
2769
2763
|
server.moduleGraph.invalidateModule(virtualModule);
|
|
2770
2764
|
server.reloadModule(virtualModule);
|
|
2771
2765
|
}
|
|
2772
2766
|
}
|
|
2773
2767
|
}
|
|
2774
|
-
handleChange(
|
|
2768
|
+
handleChange(opts = {}) {
|
|
2775
2769
|
clearTimeout(this.timeout);
|
|
2776
2770
|
this.timeout = setTimeout(() => {
|
|
2777
2771
|
this.buildIndex(true);
|
|
2778
2772
|
this.sendUpdate();
|
|
2779
|
-
|
|
2773
|
+
opts?.onComplete?.();
|
|
2780
2774
|
}, 300);
|
|
2781
2775
|
}
|
|
2782
2776
|
initWatchers(configFile) {
|
|
@@ -2821,41 +2815,51 @@ function quiDocsPlugin(opts) {
|
|
|
2821
2815
|
state.initWatchers(opts?.configFile);
|
|
2822
2816
|
server.watcher.on("add", (path) => {
|
|
2823
2817
|
if (path.endsWith(".mdx")) {
|
|
2824
|
-
state.handleChange(
|
|
2825
|
-
|
|
2818
|
+
state.handleChange({
|
|
2819
|
+
onComplete: () => {
|
|
2820
|
+
server.ws.send({ type: "full-reload" });
|
|
2821
|
+
}
|
|
2826
2822
|
});
|
|
2827
2823
|
}
|
|
2828
2824
|
});
|
|
2829
2825
|
server.watcher.on("unlink", (path) => {
|
|
2830
2826
|
if (path.endsWith(".mdx")) {
|
|
2831
|
-
state.handleChange(
|
|
2832
|
-
|
|
2827
|
+
state.handleChange({
|
|
2828
|
+
onComplete: () => {
|
|
2829
|
+
server.ws.send({ type: "full-reload" });
|
|
2830
|
+
}
|
|
2833
2831
|
});
|
|
2834
2832
|
}
|
|
2835
2833
|
});
|
|
2836
2834
|
state.servers.push(server);
|
|
2837
2835
|
},
|
|
2838
|
-
handleHotUpdate: async ({ file: updateFile }) => {
|
|
2836
|
+
handleHotUpdate: async ({ file: updateFile, modules, server }) => {
|
|
2839
2837
|
const file = fixPath(updateFile);
|
|
2840
2838
|
if ((!config.hotUpdateIgnore || !config.hotUpdateIgnore.test(file)) && // ignore watched files. We watch for these separately.
|
|
2841
2839
|
file !== state.configFilePath) {
|
|
2842
2840
|
if (state.docPropsDirectory && file.startsWith(state.docPropsFilePath)) {
|
|
2843
2841
|
return [];
|
|
2844
2842
|
}
|
|
2845
|
-
state.
|
|
2843
|
+
state.buildIndex(true);
|
|
2844
|
+
if (updateFile.endsWith(".mdx")) {
|
|
2845
|
+
const virtualModule = server.moduleGraph.getModuleById(VIRTUAL_MODULE_ID2);
|
|
2846
|
+
if (virtualModule) {
|
|
2847
|
+
server.moduleGraph.invalidateModule(virtualModule);
|
|
2848
|
+
}
|
|
2849
|
+
}
|
|
2846
2850
|
}
|
|
2847
|
-
return
|
|
2851
|
+
return modules;
|
|
2848
2852
|
},
|
|
2849
2853
|
load: (id) => {
|
|
2850
|
-
if (id ===
|
|
2854
|
+
if (id === VIRTUAL_MODULE_ID2) {
|
|
2851
2855
|
return `export const siteData = ${JSON.stringify({ navItems: state.indexer.navItems, pageDocProps: state.indexer.pageDocProps, pageMap: state.indexer.pageMap, searchIndex: state.indexer.searchIndex })}`;
|
|
2852
2856
|
}
|
|
2853
2857
|
return void 0;
|
|
2854
2858
|
},
|
|
2855
2859
|
name: "qui-mdx-vite-plugin",
|
|
2856
2860
|
resolveId: (id) => {
|
|
2857
|
-
if (id ===
|
|
2858
|
-
return
|
|
2861
|
+
if (id === "@qualcomm-ui/mdx-vite-plugin") {
|
|
2862
|
+
return VIRTUAL_MODULE_ID2;
|
|
2859
2863
|
}
|
|
2860
2864
|
return void 0;
|
|
2861
2865
|
}
|
|
@@ -3285,7 +3289,6 @@ var NODE_BUILTINS = [
|
|
|
3285
3289
|
|
|
3286
3290
|
// src/react-demo-plugin/demo-plugin-utils.ts
|
|
3287
3291
|
import chalk5 from "chalk";
|
|
3288
|
-
import { createHash as createHash2 } from "node:crypto";
|
|
3289
3292
|
import { existsSync as existsSync2, readFileSync as readFileSync3 } from "node:fs";
|
|
3290
3293
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
3291
3294
|
import { dirname as dirname2, join as join3, relative as relative2, resolve as resolve3, sep } from "node:path";
|
|
@@ -3314,21 +3317,6 @@ async function extractFileImports(filePath) {
|
|
|
3314
3317
|
return null;
|
|
3315
3318
|
}
|
|
3316
3319
|
}
|
|
3317
|
-
function mergeImports(importMap, imports) {
|
|
3318
|
-
for (const { source, specifiers } of imports) {
|
|
3319
|
-
if (isNodeBuiltin(source)) {
|
|
3320
|
-
continue;
|
|
3321
|
-
}
|
|
3322
|
-
let sourceSpecifiers = importMap.get(source);
|
|
3323
|
-
if (!sourceSpecifiers) {
|
|
3324
|
-
sourceSpecifiers = /* @__PURE__ */ new Set();
|
|
3325
|
-
importMap.set(source, sourceSpecifiers);
|
|
3326
|
-
}
|
|
3327
|
-
for (const spec of specifiers) {
|
|
3328
|
-
sourceSpecifiers.add(spec);
|
|
3329
|
-
}
|
|
3330
|
-
}
|
|
3331
|
-
}
|
|
3332
3320
|
function extractImports(code, fileName) {
|
|
3333
3321
|
const sourceFile = ts2.createSourceFile(
|
|
3334
3322
|
fileName,
|
|
@@ -3442,18 +3430,6 @@ function resolveRelativeImport(source, fromFile) {
|
|
|
3442
3430
|
}
|
|
3443
3431
|
return resolved;
|
|
3444
3432
|
}
|
|
3445
|
-
async function extractAllImports(files) {
|
|
3446
|
-
const importMap = /* @__PURE__ */ new Map();
|
|
3447
|
-
const relativeImports = [];
|
|
3448
|
-
for (const filePath of files) {
|
|
3449
|
-
const result = await extractFileImports(filePath);
|
|
3450
|
-
if (result) {
|
|
3451
|
-
mergeImports(importMap, result.thirdPartyImports);
|
|
3452
|
-
relativeImports.push(...result.relativeImports);
|
|
3453
|
-
}
|
|
3454
|
-
}
|
|
3455
|
-
return { importMap, relativeImports };
|
|
3456
|
-
}
|
|
3457
3433
|
function isRelativeImport(source) {
|
|
3458
3434
|
return source.startsWith("./") || source.startsWith("../");
|
|
3459
3435
|
}
|
|
@@ -3588,90 +3564,6 @@ function resolvePathAlias2(source, pathAliases) {
|
|
|
3588
3564
|
}
|
|
3589
3565
|
return null;
|
|
3590
3566
|
}
|
|
3591
|
-
function sanitizeSourceName(source) {
|
|
3592
|
-
return source.replace(/@/g, "at_").replace(/\//g, "_").replace(/[^a-zA-Z0-9_]/g, "_").replace(/_+/g, "_").replace(/^_|_$/g, "");
|
|
3593
|
-
}
|
|
3594
|
-
function sanitizeIdentifier(str) {
|
|
3595
|
-
return str.replace(/[^a-zA-Z0-9]/g, "_");
|
|
3596
|
-
}
|
|
3597
|
-
function createUniqueModuleName(source) {
|
|
3598
|
-
const hash = createHash2("sha256").update(source).digest("hex").substring(0, 8);
|
|
3599
|
-
const baseName = source.split("/").pop()?.replace(/[^a-zA-Z0-9]/g, "_")?.replace(/^_+|_+$/g, "")?.replace(/^(\d)/, "_$1") || "module";
|
|
3600
|
-
return `mod_${baseName}_${hash}`;
|
|
3601
|
-
}
|
|
3602
|
-
function addReactImports(imports, scopeEntries) {
|
|
3603
|
-
imports.push(`import React from "react"`);
|
|
3604
|
-
imports.push(`import {
|
|
3605
|
-
${REACT_IMPORTS.join(", ")}
|
|
3606
|
-
} from "react"`);
|
|
3607
|
-
scopeEntries.push("React", ...REACT_IMPORTS);
|
|
3608
|
-
}
|
|
3609
|
-
function addThirdPartyImports(importMap, imports, scopeEntries) {
|
|
3610
|
-
const sortedImports = Array.from(importMap.entries()).sort(
|
|
3611
|
-
([a], [b]) => a.localeCompare(b)
|
|
3612
|
-
);
|
|
3613
|
-
const usedNames = /* @__PURE__ */ new Set(["React", ...REACT_IMPORTS]);
|
|
3614
|
-
for (const [source, specifiers] of sortedImports) {
|
|
3615
|
-
const moduleName = createUniqueModuleName(source);
|
|
3616
|
-
imports.push(`import * as ${moduleName} from "${source}"`);
|
|
3617
|
-
addModuleToScope(source, specifiers, moduleName, scopeEntries, usedNames);
|
|
3618
|
-
}
|
|
3619
|
-
}
|
|
3620
|
-
function addThirdPartyImportsNamespaced(importMap, imports, scopeEntries, demoName) {
|
|
3621
|
-
const sortedImports = Array.from(importMap.entries()).sort(
|
|
3622
|
-
([a], [b]) => a.localeCompare(b)
|
|
3623
|
-
);
|
|
3624
|
-
const usedNames = /* @__PURE__ */ new Set(["React", ...REACT_IMPORTS]);
|
|
3625
|
-
for (const [source, specifiers] of sortedImports) {
|
|
3626
|
-
const moduleName = `${sanitizeIdentifier(demoName)}_${createUniqueModuleName(source)}`;
|
|
3627
|
-
imports.push(`import * as ${moduleName} from "${source}"`);
|
|
3628
|
-
addModuleToScope(source, specifiers, moduleName, scopeEntries, usedNames);
|
|
3629
|
-
}
|
|
3630
|
-
}
|
|
3631
|
-
function addRelativeImportsNamespaced(relativeImports, imports, scopeEntries, demoName) {
|
|
3632
|
-
const processedPaths = /* @__PURE__ */ new Set();
|
|
3633
|
-
for (const { resolvedPath, specifiers } of relativeImports) {
|
|
3634
|
-
if (processedPaths.has(resolvedPath)) {
|
|
3635
|
-
continue;
|
|
3636
|
-
}
|
|
3637
|
-
processedPaths.add(resolvedPath);
|
|
3638
|
-
const moduleName = `${sanitizeIdentifier(demoName)}_${createUniqueModuleName(resolvedPath)}`;
|
|
3639
|
-
imports.push(`import * as ${moduleName} from "${resolvedPath}"`);
|
|
3640
|
-
for (const { imported, local } of specifiers) {
|
|
3641
|
-
if (imported === "default") {
|
|
3642
|
-
scopeEntries.push(`${local}: ${moduleName}.default`);
|
|
3643
|
-
} else if (imported === "*") {
|
|
3644
|
-
scopeEntries.push(`...${moduleName}`);
|
|
3645
|
-
} else {
|
|
3646
|
-
scopeEntries.push(`${local}: ${moduleName}.${imported}`);
|
|
3647
|
-
}
|
|
3648
|
-
}
|
|
3649
|
-
}
|
|
3650
|
-
}
|
|
3651
|
-
function addModuleToScope(source, specifiers, moduleName, scopeEntries, usedNames) {
|
|
3652
|
-
const specArray = Array.from(specifiers);
|
|
3653
|
-
const hasDefault = specArray.some((spec) => spec.imported === "default");
|
|
3654
|
-
const hasNamespace = specArray.some((spec) => spec.imported === "*");
|
|
3655
|
-
const namedImports = specArray.filter(
|
|
3656
|
-
(spec) => spec.imported !== "default" && spec.imported !== "*"
|
|
3657
|
-
);
|
|
3658
|
-
if (hasNamespace) {
|
|
3659
|
-
scopeEntries.push(`...${moduleName}`);
|
|
3660
|
-
return;
|
|
3661
|
-
}
|
|
3662
|
-
const sanitizedSource = sanitizeSourceName(source);
|
|
3663
|
-
if (hasDefault) {
|
|
3664
|
-
scopeEntries.push(`"${sanitizedSource}__default": ${moduleName}.default`);
|
|
3665
|
-
}
|
|
3666
|
-
for (const { imported, local } of namedImports) {
|
|
3667
|
-
const sanitizedKey = `${sanitizedSource}__${imported}`;
|
|
3668
|
-
scopeEntries.push(`"${sanitizedKey}": ${moduleName}.${imported}`);
|
|
3669
|
-
if (!usedNames.has(local)) {
|
|
3670
|
-
scopeEntries.push(`${local}: ${moduleName}.${imported}`);
|
|
3671
|
-
usedNames.add(local);
|
|
3672
|
-
}
|
|
3673
|
-
}
|
|
3674
|
-
}
|
|
3675
3567
|
function extractPageId(filePath, routesDir) {
|
|
3676
3568
|
const relativePath = relative2(routesDir, filePath);
|
|
3677
3569
|
const pathParts = relativePath.split(sep);
|
|
@@ -3686,20 +3578,15 @@ function isCssAsset(filePath) {
|
|
|
3686
3578
|
}
|
|
3687
3579
|
function isDemoFile(filePath) {
|
|
3688
3580
|
try {
|
|
3689
|
-
return filePath.includes("/demos/") && filePath.endsWith(".tsx") &&
|
|
3690
|
-
readFileSync3(filePath, "utf-8").includes("export default");
|
|
3581
|
+
return filePath.includes("/demos/") && filePath.endsWith(".tsx") && !readFileSync3(filePath).includes("export default");
|
|
3691
3582
|
} catch (error) {
|
|
3692
3583
|
return false;
|
|
3693
3584
|
}
|
|
3694
3585
|
}
|
|
3695
|
-
function createEmptyScopeModule() {
|
|
3696
|
-
return "export const createDemoScope = () => ({})";
|
|
3697
|
-
}
|
|
3698
3586
|
|
|
3699
3587
|
// src/react-demo-plugin/react-demo-plugin.ts
|
|
3700
3588
|
import { transformerRenderIndentGuides as transformerRenderIndentGuides2 } from "@shikijs/transformers";
|
|
3701
3589
|
import chalk6 from "chalk";
|
|
3702
|
-
import { watch as watch2 } from "chokidar";
|
|
3703
3590
|
import { glob as glob3 } from "glob";
|
|
3704
3591
|
import { readFile as readFile3 } from "node:fs/promises";
|
|
3705
3592
|
import { basename as basename2, resolve as resolve4 } from "node:path";
|
|
@@ -3707,27 +3594,12 @@ import { createHighlighter as createHighlighter2 } from "shiki";
|
|
|
3707
3594
|
import * as ts3 from "typescript";
|
|
3708
3595
|
import { quiCustomDarkTheme as quiCustomDarkTheme3 } from "@qualcomm-ui/mdx-common";
|
|
3709
3596
|
import { dedent } from "@qualcomm-ui/utils/dedent";
|
|
3710
|
-
import { debounce } from "@qualcomm-ui/utils/functions";
|
|
3711
|
-
var isDev2 = process.env.NODE_ENV === "development";
|
|
3712
3597
|
var highlighter2 = null;
|
|
3713
|
-
var initCount2 = 0;
|
|
3714
|
-
var hmrState = {
|
|
3715
|
-
windowScrollY: 0
|
|
3716
|
-
};
|
|
3717
3598
|
var demoRegistry2 = /* @__PURE__ */ new Map();
|
|
3718
|
-
var pageScopes = /* @__PURE__ */ new Map();
|
|
3719
3599
|
var pageFiles = /* @__PURE__ */ new Map();
|
|
3720
3600
|
var relativeImportDependents = /* @__PURE__ */ new Map();
|
|
3721
|
-
var hasWatcherInitialized2 = false;
|
|
3722
|
-
function logDev2(...args) {
|
|
3723
|
-
if (!hasWatcherInitialized2) {
|
|
3724
|
-
return;
|
|
3725
|
-
}
|
|
3726
|
-
console.log(...args);
|
|
3727
|
-
}
|
|
3728
3601
|
function reactDemoPlugin({
|
|
3729
3602
|
demoPattern = "src/routes/**/demos/*.tsx",
|
|
3730
|
-
lazyLoadDevModules = true,
|
|
3731
3603
|
routesDir = "src/routes",
|
|
3732
3604
|
theme = {
|
|
3733
3605
|
dark: quiCustomDarkTheme3,
|
|
@@ -3736,20 +3608,8 @@ function reactDemoPlugin({
|
|
|
3736
3608
|
transformers = [],
|
|
3737
3609
|
transformLine
|
|
3738
3610
|
} = {}) {
|
|
3739
|
-
let watcher = null;
|
|
3740
3611
|
return {
|
|
3741
|
-
async buildEnd() {
|
|
3742
|
-
if (watcher) {
|
|
3743
|
-
await watcher.close();
|
|
3744
|
-
watcher = null;
|
|
3745
|
-
hasWatcherInitialized2 = false;
|
|
3746
|
-
}
|
|
3747
|
-
},
|
|
3748
3612
|
async buildStart() {
|
|
3749
|
-
if (initCount2 === 0) {
|
|
3750
|
-
initCount2++;
|
|
3751
|
-
return;
|
|
3752
|
-
}
|
|
3753
3613
|
if (!highlighter2) {
|
|
3754
3614
|
try {
|
|
3755
3615
|
highlighter2 = await createHighlighter2({
|
|
@@ -3766,135 +3626,49 @@ function reactDemoPlugin({
|
|
|
3766
3626
|
);
|
|
3767
3627
|
}
|
|
3768
3628
|
}
|
|
3769
|
-
|
|
3770
|
-
await collectReactDemos();
|
|
3771
|
-
if (isDev2 && !hasWatcherInitialized2) {
|
|
3772
|
-
hasWatcherInitialized2 = true;
|
|
3773
|
-
await setupFileWatcher();
|
|
3774
|
-
} else if (isDev2) {
|
|
3775
|
-
logDev2(
|
|
3776
|
-
`${chalk6.magenta.bold(LOG_PREFIX2)} skipping watch: watcher already initialized by another instance`
|
|
3777
|
-
);
|
|
3778
|
-
}
|
|
3779
|
-
} catch (error) {
|
|
3780
|
-
if (watcher) {
|
|
3781
|
-
await watcher.close();
|
|
3782
|
-
watcher = null;
|
|
3783
|
-
hasWatcherInitialized2 = false;
|
|
3784
|
-
}
|
|
3785
|
-
throw error;
|
|
3786
|
-
}
|
|
3787
|
-
},
|
|
3788
|
-
configureServer(server) {
|
|
3789
|
-
const debouncedRestore = debounce((data) => {
|
|
3790
|
-
hmrState.windowScrollY = data.scrollY;
|
|
3791
|
-
}, 100);
|
|
3792
|
-
server.ws.on("custom:store-scroll-position", debouncedRestore);
|
|
3793
|
-
server.ws.on("custom:request-scroll-position", () => {
|
|
3794
|
-
server.ws.send({
|
|
3795
|
-
data: hmrState.windowScrollY,
|
|
3796
|
-
event: "custom:restore-scroll-position",
|
|
3797
|
-
type: "custom"
|
|
3798
|
-
});
|
|
3799
|
-
});
|
|
3629
|
+
await collectReactDemos();
|
|
3800
3630
|
},
|
|
3801
|
-
|
|
3631
|
+
enforce: "pre",
|
|
3632
|
+
async handleHotUpdate({ file, modules, server }) {
|
|
3802
3633
|
if (isCssAsset(file)) {
|
|
3803
|
-
return
|
|
3804
|
-
}
|
|
3805
|
-
if (!lazyLoadDevModules) {
|
|
3806
|
-
let shouldUpdate = false;
|
|
3807
|
-
if (isDemoFile(file)) {
|
|
3808
|
-
await handleFileAdditionOrUpdate(file, false);
|
|
3809
|
-
shouldUpdate = true;
|
|
3810
|
-
}
|
|
3811
|
-
const normalizedFile = resolve4(file);
|
|
3812
|
-
const dependents = relativeImportDependents.get(normalizedFile);
|
|
3813
|
-
if (dependents) {
|
|
3814
|
-
shouldUpdate = true;
|
|
3815
|
-
}
|
|
3816
|
-
if (shouldUpdate) {
|
|
3817
|
-
const autoModule = server.moduleGraph.getModuleById(
|
|
3818
|
-
VIRTUAL_MODULE_IDS.AUTO
|
|
3819
|
-
);
|
|
3820
|
-
if (autoModule) {
|
|
3821
|
-
server.moduleGraph.invalidateModule(autoModule);
|
|
3822
|
-
await server.reloadModule(autoModule);
|
|
3823
|
-
}
|
|
3824
|
-
return [];
|
|
3825
|
-
}
|
|
3634
|
+
return modules;
|
|
3826
3635
|
}
|
|
3827
3636
|
if (isDemoFile(file)) {
|
|
3828
|
-
|
|
3829
|
-
`${chalk6.magenta.bold(LOG_PREFIX2)} Processing change: ${chalk6.blueBright.bold(file)}`
|
|
3830
|
-
);
|
|
3831
|
-
const pageId = extractPageId(file, routesDir);
|
|
3832
|
-
const demoName = createDemoName(file);
|
|
3833
|
-
const wasNew = !demoRegistry2.has(demoName);
|
|
3834
|
-
await handleFileAdditionOrUpdate(file, false);
|
|
3835
|
-
const pageModule = server.moduleGraph.getModuleById(
|
|
3836
|
-
`${VIRTUAL_MODULE_IDS.PAGE_PREFIX}${pageId}`
|
|
3837
|
-
);
|
|
3838
|
-
if (pageModule) {
|
|
3839
|
-
console.debug(
|
|
3840
|
-
"invalidating:",
|
|
3841
|
-
`virtual:qui-demo-scope/page:${pageId}`
|
|
3842
|
-
);
|
|
3843
|
-
server.moduleGraph.invalidateModule(pageModule);
|
|
3844
|
-
await server.reloadModule(pageModule);
|
|
3845
|
-
}
|
|
3846
|
-
if (wasNew) {
|
|
3847
|
-
const autoModule = server.moduleGraph.getModuleById(
|
|
3848
|
-
VIRTUAL_MODULE_IDS.AUTO
|
|
3849
|
-
);
|
|
3850
|
-
if (autoModule) {
|
|
3851
|
-
server.moduleGraph.invalidateModule(autoModule);
|
|
3852
|
-
await server.reloadModule(autoModule);
|
|
3853
|
-
}
|
|
3854
|
-
}
|
|
3855
|
-
server.ws.send({
|
|
3856
|
-
data: demoRegistry2.get(createDemoName(file)),
|
|
3857
|
-
event: "qui-demo-update",
|
|
3858
|
-
type: "custom"
|
|
3859
|
-
});
|
|
3637
|
+
await handleDemoAdditionOrUpdate({ filePath: file });
|
|
3860
3638
|
} else {
|
|
3861
3639
|
const normalizedFile = resolve4(file);
|
|
3862
|
-
const
|
|
3863
|
-
if (
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3640
|
+
const dependentDemos = relativeImportDependents.get(normalizedFile);
|
|
3641
|
+
if (!dependentDemos?.size) {
|
|
3642
|
+
return modules;
|
|
3643
|
+
}
|
|
3644
|
+
for (const demoName of Array.from(dependentDemos)) {
|
|
3645
|
+
const demo = demoRegistry2.get(demoName);
|
|
3646
|
+
if (demo) {
|
|
3647
|
+
await handleDemoAdditionOrUpdate({
|
|
3648
|
+
filePath: demo.filePath
|
|
3869
3649
|
});
|
|
3870
3650
|
}
|
|
3871
3651
|
}
|
|
3872
3652
|
}
|
|
3873
|
-
|
|
3653
|
+
const autoModule = server.moduleGraph.getModuleById(
|
|
3654
|
+
VIRTUAL_MODULE_IDS.AUTO
|
|
3655
|
+
);
|
|
3656
|
+
if (autoModule) {
|
|
3657
|
+
server.moduleGraph.invalidateModule(autoModule);
|
|
3658
|
+
await server.reloadModule(autoModule);
|
|
3659
|
+
}
|
|
3660
|
+
return modules;
|
|
3874
3661
|
},
|
|
3875
3662
|
async load(id) {
|
|
3876
3663
|
if (id === VIRTUAL_MODULE_IDS.AUTO) {
|
|
3877
3664
|
return generateAutoScopeModule();
|
|
3878
3665
|
}
|
|
3879
|
-
if (id.startsWith(VIRTUAL_MODULE_IDS.PAGE_PREFIX)) {
|
|
3880
|
-
const pageId = id.replace(VIRTUAL_MODULE_IDS.PAGE_PREFIX, "");
|
|
3881
|
-
return pageScopes.get(pageId) || createEmptyScopeModule();
|
|
3882
|
-
}
|
|
3883
|
-
if (id === VIRTUAL_MODULE_IDS.CONFIG) {
|
|
3884
|
-
return generateConfigModule();
|
|
3885
|
-
}
|
|
3886
3666
|
},
|
|
3887
3667
|
name: "auto-demo-scope",
|
|
3888
3668
|
resolveId(id) {
|
|
3889
3669
|
if (id === "virtual:qui-demo-scope/auto") {
|
|
3890
3670
|
return VIRTUAL_MODULE_IDS.AUTO;
|
|
3891
3671
|
}
|
|
3892
|
-
if (id.startsWith("virtual:qui-demo-scope/page:")) {
|
|
3893
|
-
return `\0${id}`;
|
|
3894
|
-
}
|
|
3895
|
-
if (id === "virtual:qui-demo-scope/config") {
|
|
3896
|
-
return VIRTUAL_MODULE_IDS.CONFIG;
|
|
3897
|
-
}
|
|
3898
3672
|
},
|
|
3899
3673
|
writeBundle() {
|
|
3900
3674
|
console.log(
|
|
@@ -3902,43 +3676,9 @@ function reactDemoPlugin({
|
|
|
3902
3676
|
);
|
|
3903
3677
|
}
|
|
3904
3678
|
};
|
|
3905
|
-
async function
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
persistent: true
|
|
3909
|
-
});
|
|
3910
|
-
watcher.on("ready", () => {
|
|
3911
|
-
logDev2(
|
|
3912
|
-
`${chalk6.blue.bold(LOG_PREFIX2)} Registered ${chalk6.green(demoRegistry2.size)} demo files. Watching for file changes...`
|
|
3913
|
-
);
|
|
3914
|
-
});
|
|
3915
|
-
watcher.on("addDir", (dirPath) => {
|
|
3916
|
-
if (dirPath.endsWith("/demos")) {
|
|
3917
|
-
logDev2(
|
|
3918
|
-
`${chalk6.magenta.bold(LOG_PREFIX2)} ${chalk6.greenBright("New demo directory detected:")} ${chalk6.blueBright.bold(dirPath)}`
|
|
3919
|
-
);
|
|
3920
|
-
}
|
|
3921
|
-
});
|
|
3922
|
-
watcher.on("unlink", async (filePath) => {
|
|
3923
|
-
if (isDemoFile(filePath)) {
|
|
3924
|
-
logDev2(
|
|
3925
|
-
`${chalk6.magenta.bold(LOG_PREFIX2)} ${chalk6.redBright("Demo file deleted:")} ${chalk6.blueBright.bold(filePath)}`
|
|
3926
|
-
);
|
|
3927
|
-
await handleFileDeletion(filePath);
|
|
3928
|
-
}
|
|
3929
|
-
});
|
|
3930
|
-
watcher.on("add", async (filePath) => {
|
|
3931
|
-
if (isDemoFile(filePath)) {
|
|
3932
|
-
logDev2(
|
|
3933
|
-
`${chalk6.magenta.bold(LOG_PREFIX2)} ${chalk6.greenBright("Demo file added:")} ${chalk6.blueBright.bold(filePath)}`
|
|
3934
|
-
);
|
|
3935
|
-
await handleFileAdditionOrUpdate(filePath, true).catch(() => {
|
|
3936
|
-
console.debug("failed to add file", filePath);
|
|
3937
|
-
});
|
|
3938
|
-
}
|
|
3939
|
-
});
|
|
3940
|
-
}
|
|
3941
|
-
async function handleFileAdditionOrUpdate(filePath, isAdd) {
|
|
3679
|
+
async function handleDemoAdditionOrUpdate({
|
|
3680
|
+
filePath
|
|
3681
|
+
}) {
|
|
3942
3682
|
const pageId = extractPageId(filePath, routesDir);
|
|
3943
3683
|
const demoName = createDemoName(filePath);
|
|
3944
3684
|
const existingFiles = pageFiles.get(pageId) ?? [];
|
|
@@ -3962,43 +3702,6 @@ function reactDemoPlugin({
|
|
|
3962
3702
|
}
|
|
3963
3703
|
}
|
|
3964
3704
|
}
|
|
3965
|
-
const previousScope = pageScopes.get(pageId);
|
|
3966
|
-
const allPageFiles = pageFiles.get(pageId);
|
|
3967
|
-
const scope = await generateScopeForPage(pageId, allPageFiles);
|
|
3968
|
-
pageScopes.set(pageId, scope);
|
|
3969
|
-
logDev2(
|
|
3970
|
-
`${chalk6.magenta.bold(LOG_PREFIX2)} ${chalk6.greenBright(isAdd ? "Added demo:" : "Updated demo:")} ${chalk6.greenBright.bold(demoName)}`
|
|
3971
|
-
);
|
|
3972
|
-
return previousScope !== scope;
|
|
3973
|
-
}
|
|
3974
|
-
async function handleFileDeletion(deletedFile) {
|
|
3975
|
-
const demoName = createDemoName(deletedFile);
|
|
3976
|
-
const pageId = extractPageId(deletedFile, routesDir);
|
|
3977
|
-
demoRegistry2.delete(demoName);
|
|
3978
|
-
for (const [importPath, dependents] of relativeImportDependents.entries()) {
|
|
3979
|
-
dependents.delete(demoName);
|
|
3980
|
-
if (dependents.size === 0) {
|
|
3981
|
-
relativeImportDependents.delete(importPath);
|
|
3982
|
-
}
|
|
3983
|
-
}
|
|
3984
|
-
const files = pageFiles.get(pageId);
|
|
3985
|
-
if (files) {
|
|
3986
|
-
const updatedFiles = files.filter((f) => f !== deletedFile);
|
|
3987
|
-
if (updatedFiles.length === 0) {
|
|
3988
|
-
pageFiles.delete(pageId);
|
|
3989
|
-
pageScopes.delete(pageId);
|
|
3990
|
-
logDev2(
|
|
3991
|
-
`${chalk6.magenta.bold(LOG_PREFIX2)} ${chalk6.redBright("Removed empty page:")} ${chalk6.blueBright.bold(pageId)}`
|
|
3992
|
-
);
|
|
3993
|
-
} else {
|
|
3994
|
-
pageFiles.set(pageId, updatedFiles);
|
|
3995
|
-
const scope = await generateScopeForPage(pageId, updatedFiles);
|
|
3996
|
-
pageScopes.set(pageId, scope);
|
|
3997
|
-
}
|
|
3998
|
-
}
|
|
3999
|
-
logDev2(
|
|
4000
|
-
`${chalk6.magenta.bold(LOG_PREFIX2)} ${chalk6.redBright("Cleaned up deleted file:")} ${chalk6.blueBright.bold(deletedFile)}`
|
|
4001
|
-
);
|
|
4002
3705
|
}
|
|
4003
3706
|
function isPreviewLine(trimmedLine) {
|
|
4004
3707
|
return trimmedLine === "// preview" || /^\{\s*\/\*\s*preview\s*\*\/\s*\}$/.test(trimmedLine);
|
|
@@ -4059,10 +3762,7 @@ function reactDemoPlugin({
|
|
|
4059
3762
|
}
|
|
4060
3763
|
}
|
|
4061
3764
|
async function collectReactDemos() {
|
|
4062
|
-
if (demoRegistry2.size
|
|
4063
|
-
logDev2(
|
|
4064
|
-
`${chalk6.magenta.bold(LOG_PREFIX2)} Using cached ${chalk6.cyanBright.bold(demoRegistry2.size)} demos`
|
|
4065
|
-
);
|
|
3765
|
+
if (demoRegistry2.size) {
|
|
4066
3766
|
return;
|
|
4067
3767
|
}
|
|
4068
3768
|
const demoFiles = (await glob3(demoPattern)).filter(isDemoFile);
|
|
@@ -4089,243 +3789,15 @@ function reactDemoPlugin({
|
|
|
4089
3789
|
}
|
|
4090
3790
|
}
|
|
4091
3791
|
}
|
|
4092
|
-
for (const [pageId, files] of pageFiles.entries()) {
|
|
4093
|
-
const scope = await generateScopeForPage(pageId, files);
|
|
4094
|
-
pageScopes.set(pageId, scope);
|
|
4095
|
-
}
|
|
4096
|
-
}
|
|
4097
|
-
async function generateScopeForPage(pageId, files) {
|
|
4098
|
-
const demosData = [];
|
|
4099
|
-
const allThirdPartyImports = /* @__PURE__ */ new Map();
|
|
4100
|
-
const allRelativeImports = [];
|
|
4101
|
-
const demoImportData = /* @__PURE__ */ new Map();
|
|
4102
|
-
for (const file of files) {
|
|
4103
|
-
const demoName = createDemoName(file);
|
|
4104
|
-
const demo = demoRegistry2.get(demoName);
|
|
4105
|
-
if (!demo) {
|
|
4106
|
-
continue;
|
|
4107
|
-
}
|
|
4108
|
-
demosData.push({
|
|
4109
|
-
demoName,
|
|
4110
|
-
fileName: demo.fileName,
|
|
4111
|
-
imports: demo.imports,
|
|
4112
|
-
pageId: demo.pageId,
|
|
4113
|
-
sourceCode: demo.sourceCode
|
|
4114
|
-
});
|
|
4115
|
-
const { importMap, relativeImports } = await extractAllImports([file]);
|
|
4116
|
-
demoImportData.set(demoName, {
|
|
4117
|
-
relative: relativeImports.map((r) => ({
|
|
4118
|
-
resolvedPath: r.resolvedPath,
|
|
4119
|
-
specifiers: r.specifiers
|
|
4120
|
-
})),
|
|
4121
|
-
thirdParty: Array.from(importMap.entries()).map(([source, specs]) => ({
|
|
4122
|
-
source,
|
|
4123
|
-
specifiers: Array.from(specs)
|
|
4124
|
-
}))
|
|
4125
|
-
});
|
|
4126
|
-
for (const [source, specifiers] of importMap) {
|
|
4127
|
-
if (!allThirdPartyImports.has(source)) {
|
|
4128
|
-
allThirdPartyImports.set(source, /* @__PURE__ */ new Set());
|
|
4129
|
-
}
|
|
4130
|
-
for (const spec of specifiers) {
|
|
4131
|
-
allThirdPartyImports.get(source).add(spec);
|
|
4132
|
-
}
|
|
4133
|
-
}
|
|
4134
|
-
for (const relImport of relativeImports) {
|
|
4135
|
-
if (!allRelativeImports.some(
|
|
4136
|
-
(r) => r.resolvedPath === relImport.resolvedPath
|
|
4137
|
-
)) {
|
|
4138
|
-
allRelativeImports.push(relImport);
|
|
4139
|
-
}
|
|
4140
|
-
}
|
|
4141
|
-
}
|
|
4142
|
-
const pageImports = [];
|
|
4143
|
-
const reactScopeEntries = [];
|
|
4144
|
-
addReactImports(pageImports, reactScopeEntries);
|
|
4145
|
-
const moduleNames = /* @__PURE__ */ new Map();
|
|
4146
|
-
const moduleRegistryEntries = [];
|
|
4147
|
-
for (const [source] of Array.from(allThirdPartyImports.entries()).sort(
|
|
4148
|
-
([a], [b]) => a.localeCompare(b)
|
|
4149
|
-
)) {
|
|
4150
|
-
const moduleName = createUniqueModuleName(source);
|
|
4151
|
-
moduleNames.set(source, moduleName);
|
|
4152
|
-
pageImports.push(`import * as ${moduleName} from "${source}"`);
|
|
4153
|
-
moduleRegistryEntries.push(` "${source}": ${moduleName}`);
|
|
4154
|
-
}
|
|
4155
|
-
for (const { resolvedPath } of allRelativeImports) {
|
|
4156
|
-
const moduleName = createUniqueModuleName(resolvedPath);
|
|
4157
|
-
moduleNames.set(resolvedPath, moduleName);
|
|
4158
|
-
pageImports.push(`import * as ${moduleName} from "${resolvedPath}"`);
|
|
4159
|
-
moduleRegistryEntries.push(` "${resolvedPath}": ${moduleName}`);
|
|
4160
|
-
}
|
|
4161
|
-
const demosJson = JSON.stringify(demosData);
|
|
4162
|
-
const demoImportDataJson = JSON.stringify(
|
|
4163
|
-
Array.from(demoImportData.entries())
|
|
4164
|
-
);
|
|
4165
|
-
const reactScopeEntriesCode = reactScopeEntries.map((e) => ` ${e}`).join(",\n");
|
|
4166
|
-
return `// Auto-generated page scope for ${pageId}
|
|
4167
|
-
${pageImports.join("\n")}
|
|
4168
|
-
|
|
4169
|
-
const modules = {
|
|
4170
|
-
${moduleRegistryEntries.join(",\n")}
|
|
4171
|
-
}
|
|
4172
|
-
|
|
4173
|
-
const demosData = ${demosJson}
|
|
4174
|
-
const demoImportData = new Map(${demoImportDataJson})
|
|
4175
|
-
|
|
4176
|
-
const reactScope = {
|
|
4177
|
-
${reactScopeEntriesCode}
|
|
4178
|
-
}
|
|
4179
|
-
|
|
4180
|
-
const scopeCache = new Map()
|
|
4181
|
-
|
|
4182
|
-
function createScope(demoName) {
|
|
4183
|
-
if (scopeCache.has(demoName)) {
|
|
4184
|
-
return scopeCache.get(demoName)
|
|
4185
|
-
}
|
|
4186
|
-
|
|
4187
|
-
const imports = demoImportData.get(demoName)
|
|
4188
|
-
if (!imports) return {}
|
|
4189
|
-
|
|
4190
|
-
const scope = {...reactScope}
|
|
4191
|
-
|
|
4192
|
-
for (const {source, specifiers} of imports.thirdParty) {
|
|
4193
|
-
const mod = modules[source]
|
|
4194
|
-
if (!mod) continue
|
|
4195
|
-
|
|
4196
|
-
for (const {imported, local} of specifiers) {
|
|
4197
|
-
if (imported === 'default') {
|
|
4198
|
-
scope[local] = mod.default
|
|
4199
|
-
} else if (imported === '*') {
|
|
4200
|
-
Object.assign(scope, mod)
|
|
4201
|
-
} else {
|
|
4202
|
-
scope[local] = mod[imported]
|
|
4203
|
-
}
|
|
4204
|
-
}
|
|
4205
|
-
}
|
|
4206
|
-
|
|
4207
|
-
for (const {resolvedPath, specifiers} of imports.relative) {
|
|
4208
|
-
const mod = modules[resolvedPath]
|
|
4209
|
-
if (!mod) continue
|
|
4210
|
-
|
|
4211
|
-
for (const {imported, local} of specifiers) {
|
|
4212
|
-
if (imported === 'default') {
|
|
4213
|
-
scope[local] = mod.default
|
|
4214
|
-
} else if (imported === '*') {
|
|
4215
|
-
Object.assign(scope, mod)
|
|
4216
|
-
} else {
|
|
4217
|
-
scope[local] = mod[imported]
|
|
4218
|
-
}
|
|
4219
|
-
}
|
|
4220
|
-
}
|
|
4221
|
-
|
|
4222
|
-
scopeCache.set(demoName, scope)
|
|
4223
|
-
return scope
|
|
4224
|
-
}
|
|
4225
|
-
|
|
4226
|
-
export function getDemo(demoName) {
|
|
4227
|
-
const demo = demosData.find(d => d.demoName === demoName)
|
|
4228
|
-
if (!demo) return null
|
|
4229
|
-
return {
|
|
4230
|
-
...demo,
|
|
4231
|
-
scope: createScope(demoName)
|
|
4232
|
-
}
|
|
4233
|
-
}
|
|
4234
|
-
|
|
4235
|
-
export function getDemos() {
|
|
4236
|
-
return demosData.map(demo => ({
|
|
4237
|
-
...demo,
|
|
4238
|
-
scope: createScope(demo.demoName)
|
|
4239
|
-
}))
|
|
4240
|
-
}
|
|
4241
|
-
`;
|
|
4242
3792
|
}
|
|
4243
|
-
|
|
4244
|
-
if (isDev2 && lazyLoadDevModules) {
|
|
4245
|
-
return [
|
|
4246
|
-
"// Auto-generated demo scope resolver (DEV MODE - Lazy by Page)",
|
|
4247
|
-
generateLazyPageLoaders(),
|
|
4248
|
-
generateDemoToPageMap(),
|
|
4249
|
-
generateDevGetDemo()
|
|
4250
|
-
].join("\n\n");
|
|
4251
|
-
}
|
|
3793
|
+
function generateAutoScopeModule() {
|
|
4252
3794
|
const registryCode = generateDemoRegistry(demoRegistry2);
|
|
4253
3795
|
return [
|
|
4254
3796
|
"// Auto-generated demo scope resolver (PROD MODE)",
|
|
4255
|
-
generatePageImports(),
|
|
4256
|
-
generateScopeMap(),
|
|
4257
3797
|
registryCode,
|
|
4258
3798
|
generateExportedFunctions()
|
|
4259
3799
|
].join("\n\n");
|
|
4260
3800
|
}
|
|
4261
|
-
function generateConfigModule() {
|
|
4262
|
-
return dedent`
|
|
4263
|
-
export function getReactDemoConfig() {
|
|
4264
|
-
return {lazyLoadDevModules: ${lazyLoadDevModules}}
|
|
4265
|
-
}
|
|
4266
|
-
`;
|
|
4267
|
-
}
|
|
4268
|
-
function generateLazyPageLoaders() {
|
|
4269
|
-
const pageIds = Array.from(pageFiles.keys()).sort();
|
|
4270
|
-
if (pageIds.length === 0) {
|
|
4271
|
-
return "export const lazyDemoLoader = {}";
|
|
4272
|
-
}
|
|
4273
|
-
const entries = pageIds.map((pageId) => {
|
|
4274
|
-
return ` "${pageId}": () => import("virtual:qui-demo-scope/page:${pageId}")`;
|
|
4275
|
-
}).join(",\n");
|
|
4276
|
-
return `export const lazyDemoLoader = {
|
|
4277
|
-
${entries}
|
|
4278
|
-
}`;
|
|
4279
|
-
}
|
|
4280
|
-
function generateDemoToPageMap() {
|
|
4281
|
-
const entries = Array.from(demoRegistry2.entries()).map(([demoName, { pageId }]) => {
|
|
4282
|
-
return ` "${demoName}": "${pageId}"`;
|
|
4283
|
-
}).join(",\n");
|
|
4284
|
-
return `const demoToPageMap = {
|
|
4285
|
-
${entries}
|
|
4286
|
-
}`;
|
|
4287
|
-
}
|
|
4288
|
-
function generateDevGetDemo() {
|
|
4289
|
-
return dedent`
|
|
4290
|
-
export async function getDemo(demoName) {
|
|
4291
|
-
const pageId = demoToPageMap[demoName]
|
|
4292
|
-
if (!pageId) {
|
|
4293
|
-
return {
|
|
4294
|
-
fileName: "",
|
|
4295
|
-
imports: [],
|
|
4296
|
-
errorMessage: \`Demo "\${demoName}" not found.\`,
|
|
4297
|
-
scope: {},
|
|
4298
|
-
pageId: "",
|
|
4299
|
-
sourceCode: [],
|
|
4300
|
-
}
|
|
4301
|
-
}
|
|
4302
|
-
|
|
4303
|
-
const loader = lazyDemoLoader[pageId]
|
|
4304
|
-
if (!loader) {
|
|
4305
|
-
return {
|
|
4306
|
-
fileName: "",
|
|
4307
|
-
imports: [],
|
|
4308
|
-
errorMessage: \`Page "\${pageId}" not found.\`,
|
|
4309
|
-
scope: {},
|
|
4310
|
-
pageId: "",
|
|
4311
|
-
sourceCode: [],
|
|
4312
|
-
}
|
|
4313
|
-
}
|
|
4314
|
-
|
|
4315
|
-
const pageModule = await loader()
|
|
4316
|
-
const demo = pageModule.getDemo(demoName)
|
|
4317
|
-
|
|
4318
|
-
return demo || {
|
|
4319
|
-
fileName: "",
|
|
4320
|
-
imports: [],
|
|
4321
|
-
errorMessage: \`Demo "\${demoName}" not found in page.\`,
|
|
4322
|
-
scope: {},
|
|
4323
|
-
pageId: "",
|
|
4324
|
-
sourceCode: [],
|
|
4325
|
-
}
|
|
4326
|
-
}
|
|
4327
|
-
`;
|
|
4328
|
-
}
|
|
4329
3801
|
function extractHighlightedVariants(highlightedHtml) {
|
|
4330
3802
|
const preMatch = highlightedHtml.match(/^<pre[^>]*><code>/)?.[0] || "";
|
|
4331
3803
|
const postMatch = highlightedHtml.match(/<\/code><\/pre>$/)?.[0] || "";
|
|
@@ -4454,23 +3926,18 @@ ${entries}
|
|
|
4454
3926
|
withoutImports: importedCodeWithoutImports
|
|
4455
3927
|
}
|
|
4456
3928
|
});
|
|
4457
|
-
} catch
|
|
4458
|
-
logDev2(
|
|
4459
|
-
`${chalk6.magenta.bold(LOG_PREFIX2)} ${chalk6.yellowBright("Failed to process relative import:")} ${chalk6.blueBright.bold(relativeImport.resolvedPath)}`
|
|
4460
|
-
);
|
|
3929
|
+
} catch {
|
|
4461
3930
|
}
|
|
4462
3931
|
}
|
|
4463
3932
|
}
|
|
4464
3933
|
return {
|
|
4465
3934
|
demoName: createDemoName(filePath),
|
|
4466
3935
|
fileName,
|
|
3936
|
+
filePath,
|
|
4467
3937
|
imports,
|
|
4468
3938
|
sourceCode
|
|
4469
3939
|
};
|
|
4470
|
-
} catch
|
|
4471
|
-
logDev2(
|
|
4472
|
-
`${chalk6.magenta.bold(LOG_PREFIX2)} ${chalk6.yellowBright("Failed to parse")} ${chalk6.blueBright.bold(filePath)}. ${chalk6.yellowBright("Removing from registry")}`
|
|
4473
|
-
);
|
|
3940
|
+
} catch {
|
|
4474
3941
|
return null;
|
|
4475
3942
|
}
|
|
4476
3943
|
}
|
|
@@ -4517,36 +3984,12 @@ ${entries}
|
|
|
4517
3984
|
strippedCode: strippedCode.replace(/^\n+/, "")
|
|
4518
3985
|
};
|
|
4519
3986
|
} catch (error) {
|
|
4520
|
-
logDev2(
|
|
4521
|
-
`${chalk6.magenta.bold(LOG_PREFIX2)} ${chalk6.redBright("Failed to strip imports from")} ${chalk6.blueBright.bold(fileName)}:`,
|
|
4522
|
-
error
|
|
4523
|
-
);
|
|
4524
3987
|
return {
|
|
4525
3988
|
imports: [],
|
|
4526
3989
|
strippedCode: code
|
|
4527
3990
|
};
|
|
4528
3991
|
}
|
|
4529
3992
|
}
|
|
4530
|
-
function generatePageImports() {
|
|
4531
|
-
const pageIds = Array.from(pageScopes.keys());
|
|
4532
|
-
return pageIds.map((pageId) => {
|
|
4533
|
-
const safeName = sanitizeIdentifier(pageId);
|
|
4534
|
-
return `import * as page_${safeName} from "virtual:qui-demo-scope/page:${pageId}"`;
|
|
4535
|
-
}).join("\n");
|
|
4536
|
-
}
|
|
4537
|
-
function generateScopeMap() {
|
|
4538
|
-
const pageIds = Array.from(pageScopes.keys());
|
|
4539
|
-
if (pageIds.length === 0) {
|
|
4540
|
-
return "const pageModules = {}";
|
|
4541
|
-
}
|
|
4542
|
-
const entries = pageIds.map((pageId) => {
|
|
4543
|
-
const safeName = sanitizeIdentifier(pageId);
|
|
4544
|
-
return ` "${pageId}": page_${safeName}`;
|
|
4545
|
-
}).join(",\n");
|
|
4546
|
-
return `const pageModules = {
|
|
4547
|
-
${entries}
|
|
4548
|
-
}`;
|
|
4549
|
-
}
|
|
4550
3993
|
function generateDemoRegistry(registry) {
|
|
4551
3994
|
const entries = Array.from(registry.entries()).map(([demoName, { fileName, imports, pageId, sourceCode }]) => {
|
|
4552
3995
|
return ` ["${demoName}", { fileName: "${fileName}", imports: ${JSON.stringify(imports)}, pageId: "${pageId}", sourceCode: ${JSON.stringify(sourceCode)}, demoName: "${demoName}" }]`;
|
|
@@ -4564,31 +4007,11 @@ ${entries}
|
|
|
4564
4007
|
fileName: "",
|
|
4565
4008
|
imports: [],
|
|
4566
4009
|
errorMessage: \`Demo "\${demoName}" not found.\`,
|
|
4567
|
-
scope: {},
|
|
4568
4010
|
pageId: "",
|
|
4569
4011
|
sourceCode: [],
|
|
4570
4012
|
}
|
|
4571
4013
|
}
|
|
4572
|
-
|
|
4573
|
-
const pageModule = pageModules[demo.pageId]
|
|
4574
|
-
if (!pageModule) {
|
|
4575
|
-
return {
|
|
4576
|
-
fileName: "",
|
|
4577
|
-
imports: [],
|
|
4578
|
-
errorMessage: \`Page module not found.\`,
|
|
4579
|
-
scope: {},
|
|
4580
|
-
pageId: demo.pageId,
|
|
4581
|
-
sourceCode: [],
|
|
4582
|
-
}
|
|
4583
|
-
}
|
|
4584
|
-
|
|
4585
|
-
return pageModule.getDemo(demoName) || {
|
|
4586
|
-
fileName: demo.fileName,
|
|
4587
|
-
imports: demo.imports,
|
|
4588
|
-
scope: {},
|
|
4589
|
-
pageId: demo.pageId,
|
|
4590
|
-
sourceCode: demo.sourceCode,
|
|
4591
|
-
}
|
|
4014
|
+
return demo
|
|
4592
4015
|
}
|
|
4593
4016
|
`;
|
|
4594
4017
|
}
|
|
@@ -4598,15 +4021,8 @@ export {
|
|
|
4598
4021
|
NODE_BUILTINS,
|
|
4599
4022
|
REACT_IMPORTS,
|
|
4600
4023
|
VIRTUAL_MODULE_IDS,
|
|
4601
|
-
addReactImports,
|
|
4602
|
-
addRelativeImportsNamespaced,
|
|
4603
|
-
addThirdPartyImports,
|
|
4604
|
-
addThirdPartyImportsNamespaced,
|
|
4605
4024
|
angularDemoPlugin,
|
|
4606
4025
|
createDemoName,
|
|
4607
|
-
createEmptyScopeModule,
|
|
4608
|
-
createUniqueModuleName,
|
|
4609
|
-
extractAllImports,
|
|
4610
4026
|
extractFileImports,
|
|
4611
4027
|
extractPageId,
|
|
4612
4028
|
getAlertIcon,
|
|
@@ -4628,8 +4044,6 @@ export {
|
|
|
4628
4044
|
remarkGfm2 as remarkGfm,
|
|
4629
4045
|
remarkMdxFrontmatter,
|
|
4630
4046
|
remarkSelfLinkHeadings,
|
|
4631
|
-
remarkSpoilers
|
|
4632
|
-
sanitizeIdentifier,
|
|
4633
|
-
sanitizeSourceName
|
|
4047
|
+
remarkSpoilers
|
|
4634
4048
|
};
|
|
4635
4049
|
//# sourceMappingURL=index.js.map
|