@mercurjs/dashboard-sdk 2.0.0-canary.74 → 2.0.0-canary.76
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/index.cjs +56 -112
- package/dist/index.js +62 -112
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -38,6 +38,9 @@ module.exports = __toCommonJS(index_exports);
|
|
|
38
38
|
var import_path5 = __toESM(require("path"), 1);
|
|
39
39
|
var import_fs4 = __toESM(require("fs"), 1);
|
|
40
40
|
|
|
41
|
+
// src/utils.ts
|
|
42
|
+
var import_node_module = require("module");
|
|
43
|
+
|
|
41
44
|
// src/babel.ts
|
|
42
45
|
var import_parser = require("@babel/parser");
|
|
43
46
|
var import_traverse = __toESM(require("@babel/traverse"), 1);
|
|
@@ -50,6 +53,7 @@ if (typeof import_traverse.default === "function") {
|
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
// src/utils.ts
|
|
56
|
+
var import_meta = {};
|
|
53
57
|
function normalizePath(filePath) {
|
|
54
58
|
return filePath.replace(/\\/g, "/");
|
|
55
59
|
}
|
|
@@ -63,6 +67,35 @@ function getParserOptions(file) {
|
|
|
63
67
|
}
|
|
64
68
|
return options;
|
|
65
69
|
}
|
|
70
|
+
function resolveExports(moduleExports) {
|
|
71
|
+
if ("default" in moduleExports && moduleExports.default && "default" in moduleExports.default) {
|
|
72
|
+
return resolveExports(moduleExports.default);
|
|
73
|
+
}
|
|
74
|
+
return moduleExports;
|
|
75
|
+
}
|
|
76
|
+
var esmRequire = typeof require !== "undefined" ? require : (0, import_node_module.createRequire)(import_meta.url);
|
|
77
|
+
async function getFileExports(filePath) {
|
|
78
|
+
const { unregister } = await safeRegister();
|
|
79
|
+
const module2 = esmRequire(filePath);
|
|
80
|
+
unregister();
|
|
81
|
+
return resolveExports(module2);
|
|
82
|
+
}
|
|
83
|
+
var safeRegister = async () => {
|
|
84
|
+
const { register } = await import("esbuild-register/dist/node");
|
|
85
|
+
let res;
|
|
86
|
+
try {
|
|
87
|
+
res = register({
|
|
88
|
+
format: "cjs",
|
|
89
|
+
loader: "ts"
|
|
90
|
+
});
|
|
91
|
+
} catch {
|
|
92
|
+
res = {
|
|
93
|
+
unregister: () => {
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return res;
|
|
98
|
+
};
|
|
66
99
|
function hasDefaultExport(ast) {
|
|
67
100
|
let found = false;
|
|
68
101
|
traverse(ast, {
|
|
@@ -309,11 +342,8 @@ function generateRoutes({ srcDir, pluginExtensions }) {
|
|
|
309
342
|
index++;
|
|
310
343
|
}
|
|
311
344
|
}
|
|
312
|
-
const
|
|
313
|
-
(ext, i) => `
|
|
314
|
-
);
|
|
315
|
-
const pluginUnwraps = pluginExtensions.map(
|
|
316
|
-
(_, i) => `const __plugin${i} = __pluginRaw${i}.default ?? __pluginRaw${i}`
|
|
345
|
+
const pluginDeclarations = pluginExtensions.map(
|
|
346
|
+
(ext, i) => `const __plugin${i} = (await import("${normalizePath(ext)}")).default`
|
|
317
347
|
);
|
|
318
348
|
const pluginSpreads = pluginExtensions.map(
|
|
319
349
|
(_, i) => ` ...(__plugin${i}.routeModule?.routes ?? [])`
|
|
@@ -321,13 +351,15 @@ function generateRoutes({ srcDir, pluginExtensions }) {
|
|
|
321
351
|
const routeTree = buildRouteTree(results);
|
|
322
352
|
const appImports = routeTree.flatMap((r) => r.imports);
|
|
323
353
|
const appRoutes = routeTree.map((r) => formatRoute(r.route));
|
|
324
|
-
const allImports = [...appImports
|
|
354
|
+
const allImports = [...appImports];
|
|
325
355
|
const allRoutes = [...appRoutes, ...pluginSpreads];
|
|
326
|
-
if (allImports.length === 0 && allRoutes.length === 0) {
|
|
356
|
+
if (allImports.length === 0 && pluginDeclarations.length === 0 && allRoutes.length === 0) {
|
|
327
357
|
return `export const customRoutes = []`;
|
|
328
358
|
}
|
|
329
359
|
return `${allImports.join("\n")}
|
|
330
360
|
|
|
361
|
+
${pluginDeclarations.join("\n")}
|
|
362
|
+
|
|
331
363
|
export const customRoutes = [
|
|
332
364
|
${allRoutes.join(",\n")}
|
|
333
365
|
]`;
|
|
@@ -506,24 +538,23 @@ function generateMenuItems({ srcDir, pluginExtensions }) {
|
|
|
506
538
|
index++;
|
|
507
539
|
}
|
|
508
540
|
}
|
|
509
|
-
const
|
|
510
|
-
(ext, i) => `
|
|
511
|
-
);
|
|
512
|
-
const pluginUnwraps = pluginExtensions.map(
|
|
513
|
-
(_, i) => `const __plugin${i} = __pluginRaw${i}.default ?? __pluginRaw${i}`
|
|
541
|
+
const pluginDeclarations = pluginExtensions.map(
|
|
542
|
+
(ext, i) => `const __plugin${i} = (await import("${normalizePath(ext)}")).default`
|
|
514
543
|
);
|
|
515
544
|
const pluginSpreads = pluginExtensions.map(
|
|
516
545
|
(_, i) => ` ...(__plugin${i}.menuItemModule?.menuItems ?? [])`
|
|
517
546
|
);
|
|
518
547
|
const appImports = results.map((r) => r.import);
|
|
519
548
|
const appMenuItems = results.map((r) => formatMenuItem(r.menuItem));
|
|
520
|
-
const allImports = [...appImports
|
|
549
|
+
const allImports = [...appImports];
|
|
521
550
|
const allMenuItems = [...appMenuItems, ...pluginSpreads];
|
|
522
|
-
if (allImports.length === 0 && allMenuItems.length === 0) {
|
|
551
|
+
if (allImports.length === 0 && pluginDeclarations.length === 0 && allMenuItems.length === 0) {
|
|
523
552
|
return `export default { menuItems: [] }`;
|
|
524
553
|
}
|
|
525
554
|
return `${allImports.join("\n")}
|
|
526
555
|
|
|
556
|
+
${pluginDeclarations.join("\n")}
|
|
557
|
+
|
|
527
558
|
export default {
|
|
528
559
|
menuItems: [
|
|
529
560
|
${allMenuItems.join(",\n")}
|
|
@@ -673,109 +704,23 @@ function resolvePluginExtensions(plugins, configDir) {
|
|
|
673
704
|
}
|
|
674
705
|
return extensions;
|
|
675
706
|
}
|
|
676
|
-
function extractStringFromNode(node, configDir) {
|
|
677
|
-
if ((0, import_types.isStringLiteral)(node)) {
|
|
678
|
-
return node.value;
|
|
679
|
-
}
|
|
680
|
-
if ((0, import_types.isCallExpression)(node) && (0, import_types.isMemberExpression)(node.callee) && (0, import_types.isIdentifier)(node.callee.object, { name: "path" }) && (0, import_types.isIdentifier)(node.callee.property) && (node.callee.property.name === "join" || node.callee.property.name === "resolve")) {
|
|
681
|
-
const args = node.arguments;
|
|
682
|
-
if (args.length >= 2 && (0, import_types.isIdentifier)(args[0], { name: "__dirname" })) {
|
|
683
|
-
const parts = args.slice(1).filter((a) => (0, import_types.isStringLiteral)(a)).map((a) => a.value);
|
|
684
|
-
if (parts.length > 0) {
|
|
685
|
-
return import_path5.default.resolve(configDir, ...parts);
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
return null;
|
|
690
|
-
}
|
|
691
|
-
function extractObjectProperties(node) {
|
|
692
|
-
if ((0, import_types.isObjectExpression)(node)) {
|
|
693
|
-
return node.properties;
|
|
694
|
-
}
|
|
695
|
-
return null;
|
|
696
|
-
}
|
|
697
707
|
async function loadMedusaConfig(medusaConfigPath, root) {
|
|
698
708
|
try {
|
|
699
|
-
const
|
|
700
|
-
const
|
|
709
|
+
const mod = await getFileExports(medusaConfigPath);
|
|
710
|
+
const medusaConfig = mod.default ?? mod;
|
|
711
|
+
const modules = medusaConfig?.modules ?? {};
|
|
701
712
|
const configDir = import_path5.default.dirname(medusaConfigPath);
|
|
702
|
-
const result = { properties: null };
|
|
703
|
-
traverse(ast, {
|
|
704
|
-
// Handle: export default defineConfig({ ... })
|
|
705
|
-
ExportDefaultDeclaration(nodePath) {
|
|
706
|
-
const decl = nodePath.node.declaration;
|
|
707
|
-
if ((0, import_types.isCallExpression)(decl) && decl.arguments.length > 0) {
|
|
708
|
-
result.properties = extractObjectProperties(decl.arguments[0]);
|
|
709
|
-
}
|
|
710
|
-
},
|
|
711
|
-
// Handle: module.exports = defineConfig({ ... }) or module.exports = { ... }
|
|
712
|
-
AssignmentExpression(nodePath) {
|
|
713
|
-
const left = nodePath.node.left;
|
|
714
|
-
if ((0, import_types.isMemberExpression)(left) && (0, import_types.isIdentifier)(left.object, { name: "module" }) && (0, import_types.isIdentifier)(left.property, { name: "exports" })) {
|
|
715
|
-
const right = nodePath.node.right;
|
|
716
|
-
if ((0, import_types.isCallExpression)(right) && right.arguments.length > 0) {
|
|
717
|
-
result.properties = extractObjectProperties(right.arguments[0]);
|
|
718
|
-
} else if ((0, import_types.isObjectExpression)(right)) {
|
|
719
|
-
result.properties = right.properties;
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
});
|
|
724
|
-
const configObjectProperties = result.properties;
|
|
725
|
-
if (!configObjectProperties) {
|
|
726
|
-
return { pluginExtensions: [] };
|
|
727
|
-
}
|
|
728
713
|
let base;
|
|
729
|
-
const
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
);
|
|
737
|
-
if (!uiProp || !(0, import_types.isObjectProperty)(uiProp) || !(0, import_types.isObjectExpression)(uiProp.value)) continue;
|
|
738
|
-
const optionsProp = uiProp.value.properties.find(
|
|
739
|
-
(p) => (0, import_types.isObjectProperty)(p) && (0, import_types.isIdentifier)(p.key, { name: "options" })
|
|
740
|
-
);
|
|
741
|
-
if (!optionsProp || !(0, import_types.isObjectProperty)(optionsProp) || !(0, import_types.isObjectExpression)(optionsProp.value)) continue;
|
|
742
|
-
const appDirProp = optionsProp.value.properties.find(
|
|
743
|
-
(p) => (0, import_types.isObjectProperty)(p) && (0, import_types.isIdentifier)(p.key, { name: "appDir" })
|
|
744
|
-
);
|
|
745
|
-
if (!appDirProp || !(0, import_types.isObjectProperty)(appDirProp)) continue;
|
|
746
|
-
const appDir = extractStringFromNode(appDirProp.value, configDir);
|
|
747
|
-
if (!appDir) continue;
|
|
748
|
-
const resolvedAppDir = import_path5.default.isAbsolute(appDir) ? appDir : import_path5.default.resolve(configDir, appDir);
|
|
749
|
-
if (resolvedAppDir === root) {
|
|
750
|
-
const pathProp = optionsProp.value.properties.find(
|
|
751
|
-
(p) => (0, import_types.isObjectProperty)(p) && (0, import_types.isIdentifier)(p.key, { name: "path" })
|
|
752
|
-
);
|
|
753
|
-
if (pathProp && (0, import_types.isObjectProperty)(pathProp) && (0, import_types.isStringLiteral)(pathProp.value)) {
|
|
754
|
-
base = pathProp.value.value;
|
|
755
|
-
}
|
|
756
|
-
break;
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
const plugins = [];
|
|
761
|
-
const pluginsProp = configObjectProperties.find(
|
|
762
|
-
(p) => (0, import_types.isObjectProperty)(p) && (0, import_types.isIdentifier)(p.key, { name: "plugins" })
|
|
763
|
-
);
|
|
764
|
-
if (pluginsProp && (0, import_types.isObjectProperty)(pluginsProp) && (0, import_types.isArrayExpression)(pluginsProp.value)) {
|
|
765
|
-
for (const element of pluginsProp.value.elements) {
|
|
766
|
-
if (!element) continue;
|
|
767
|
-
if ((0, import_types.isObjectExpression)(element)) {
|
|
768
|
-
const resolveProp = element.properties.find(
|
|
769
|
-
(p) => (0, import_types.isObjectProperty)(p) && (0, import_types.isIdentifier)(p.key, { name: "resolve" })
|
|
770
|
-
);
|
|
771
|
-
if (resolveProp && (0, import_types.isObjectProperty)(resolveProp) && (0, import_types.isStringLiteral)(resolveProp.value)) {
|
|
772
|
-
plugins.push({ resolve: resolveProp.value.value });
|
|
773
|
-
}
|
|
774
|
-
} else if ((0, import_types.isStringLiteral)(element)) {
|
|
775
|
-
plugins.push({ resolve: element.value });
|
|
776
|
-
}
|
|
714
|
+
for (const key of UI_MODULE_KEYS) {
|
|
715
|
+
const value = modules[key];
|
|
716
|
+
if (!value || typeof value !== "object" || !value.options?.appDir) continue;
|
|
717
|
+
const appDir = import_path5.default.resolve(configDir, value.options.appDir);
|
|
718
|
+
if (appDir === root) {
|
|
719
|
+
base = value.options.path;
|
|
720
|
+
break;
|
|
777
721
|
}
|
|
778
722
|
}
|
|
723
|
+
const plugins = medusaConfig?.plugins ?? [];
|
|
779
724
|
const pluginExtensions = resolvePluginExtensions(plugins, configDir);
|
|
780
725
|
return { base, pluginExtensions };
|
|
781
726
|
} catch {
|
|
@@ -808,7 +753,6 @@ function mercurDashboardPlugin(pluginConfig) {
|
|
|
808
753
|
"__BASE__": JSON.stringify(config.base || "/")
|
|
809
754
|
},
|
|
810
755
|
optimizeDeps: {
|
|
811
|
-
include: pluginExtensions,
|
|
812
756
|
exclude: ["virtual:mercur/config", "virtual:mercur/routes", "virtual:mercur/components", "virtual:mercur/menu-items", "virtual:mercur/i18n"]
|
|
813
757
|
}
|
|
814
758
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
1
8
|
// src/plugin.ts
|
|
2
9
|
import path5 from "path";
|
|
3
10
|
import fs4 from "fs";
|
|
4
11
|
|
|
12
|
+
// src/utils.ts
|
|
13
|
+
import { createRequire } from "module";
|
|
14
|
+
|
|
5
15
|
// src/babel.ts
|
|
6
16
|
import { parse } from "@babel/parser";
|
|
7
17
|
import _traverse from "@babel/traverse";
|
|
@@ -40,6 +50,35 @@ function getParserOptions(file) {
|
|
|
40
50
|
}
|
|
41
51
|
return options;
|
|
42
52
|
}
|
|
53
|
+
function resolveExports(moduleExports) {
|
|
54
|
+
if ("default" in moduleExports && moduleExports.default && "default" in moduleExports.default) {
|
|
55
|
+
return resolveExports(moduleExports.default);
|
|
56
|
+
}
|
|
57
|
+
return moduleExports;
|
|
58
|
+
}
|
|
59
|
+
var esmRequire = typeof __require !== "undefined" ? __require : createRequire(import.meta.url);
|
|
60
|
+
async function getFileExports(filePath) {
|
|
61
|
+
const { unregister } = await safeRegister();
|
|
62
|
+
const module = esmRequire(filePath);
|
|
63
|
+
unregister();
|
|
64
|
+
return resolveExports(module);
|
|
65
|
+
}
|
|
66
|
+
var safeRegister = async () => {
|
|
67
|
+
const { register } = await import("esbuild-register/dist/node");
|
|
68
|
+
let res;
|
|
69
|
+
try {
|
|
70
|
+
res = register({
|
|
71
|
+
format: "cjs",
|
|
72
|
+
loader: "ts"
|
|
73
|
+
});
|
|
74
|
+
} catch {
|
|
75
|
+
res = {
|
|
76
|
+
unregister: () => {
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return res;
|
|
81
|
+
};
|
|
43
82
|
function hasDefaultExport(ast) {
|
|
44
83
|
let found = false;
|
|
45
84
|
traverse(ast, {
|
|
@@ -286,11 +325,8 @@ function generateRoutes({ srcDir, pluginExtensions }) {
|
|
|
286
325
|
index++;
|
|
287
326
|
}
|
|
288
327
|
}
|
|
289
|
-
const
|
|
290
|
-
(ext, i) => `
|
|
291
|
-
);
|
|
292
|
-
const pluginUnwraps = pluginExtensions.map(
|
|
293
|
-
(_, i) => `const __plugin${i} = __pluginRaw${i}.default ?? __pluginRaw${i}`
|
|
328
|
+
const pluginDeclarations = pluginExtensions.map(
|
|
329
|
+
(ext, i) => `const __plugin${i} = (await import("${normalizePath(ext)}")).default`
|
|
294
330
|
);
|
|
295
331
|
const pluginSpreads = pluginExtensions.map(
|
|
296
332
|
(_, i) => ` ...(__plugin${i}.routeModule?.routes ?? [])`
|
|
@@ -298,13 +334,15 @@ function generateRoutes({ srcDir, pluginExtensions }) {
|
|
|
298
334
|
const routeTree = buildRouteTree(results);
|
|
299
335
|
const appImports = routeTree.flatMap((r) => r.imports);
|
|
300
336
|
const appRoutes = routeTree.map((r) => formatRoute(r.route));
|
|
301
|
-
const allImports = [...appImports
|
|
337
|
+
const allImports = [...appImports];
|
|
302
338
|
const allRoutes = [...appRoutes, ...pluginSpreads];
|
|
303
|
-
if (allImports.length === 0 && allRoutes.length === 0) {
|
|
339
|
+
if (allImports.length === 0 && pluginDeclarations.length === 0 && allRoutes.length === 0) {
|
|
304
340
|
return `export const customRoutes = []`;
|
|
305
341
|
}
|
|
306
342
|
return `${allImports.join("\n")}
|
|
307
343
|
|
|
344
|
+
${pluginDeclarations.join("\n")}
|
|
345
|
+
|
|
308
346
|
export const customRoutes = [
|
|
309
347
|
${allRoutes.join(",\n")}
|
|
310
348
|
]`;
|
|
@@ -483,24 +521,23 @@ function generateMenuItems({ srcDir, pluginExtensions }) {
|
|
|
483
521
|
index++;
|
|
484
522
|
}
|
|
485
523
|
}
|
|
486
|
-
const
|
|
487
|
-
(ext, i) => `
|
|
488
|
-
);
|
|
489
|
-
const pluginUnwraps = pluginExtensions.map(
|
|
490
|
-
(_, i) => `const __plugin${i} = __pluginRaw${i}.default ?? __pluginRaw${i}`
|
|
524
|
+
const pluginDeclarations = pluginExtensions.map(
|
|
525
|
+
(ext, i) => `const __plugin${i} = (await import("${normalizePath(ext)}")).default`
|
|
491
526
|
);
|
|
492
527
|
const pluginSpreads = pluginExtensions.map(
|
|
493
528
|
(_, i) => ` ...(__plugin${i}.menuItemModule?.menuItems ?? [])`
|
|
494
529
|
);
|
|
495
530
|
const appImports = results.map((r) => r.import);
|
|
496
531
|
const appMenuItems = results.map((r) => formatMenuItem(r.menuItem));
|
|
497
|
-
const allImports = [...appImports
|
|
532
|
+
const allImports = [...appImports];
|
|
498
533
|
const allMenuItems = [...appMenuItems, ...pluginSpreads];
|
|
499
|
-
if (allImports.length === 0 && allMenuItems.length === 0) {
|
|
534
|
+
if (allImports.length === 0 && pluginDeclarations.length === 0 && allMenuItems.length === 0) {
|
|
500
535
|
return `export default { menuItems: [] }`;
|
|
501
536
|
}
|
|
502
537
|
return `${allImports.join("\n")}
|
|
503
538
|
|
|
539
|
+
${pluginDeclarations.join("\n")}
|
|
540
|
+
|
|
504
541
|
export default {
|
|
505
542
|
menuItems: [
|
|
506
543
|
${allMenuItems.join(",\n")}
|
|
@@ -650,109 +687,23 @@ function resolvePluginExtensions(plugins, configDir) {
|
|
|
650
687
|
}
|
|
651
688
|
return extensions;
|
|
652
689
|
}
|
|
653
|
-
function extractStringFromNode(node, configDir) {
|
|
654
|
-
if (isStringLiteral(node)) {
|
|
655
|
-
return node.value;
|
|
656
|
-
}
|
|
657
|
-
if (isCallExpression(node) && isMemberExpression(node.callee) && isIdentifier(node.callee.object, { name: "path" }) && isIdentifier(node.callee.property) && (node.callee.property.name === "join" || node.callee.property.name === "resolve")) {
|
|
658
|
-
const args = node.arguments;
|
|
659
|
-
if (args.length >= 2 && isIdentifier(args[0], { name: "__dirname" })) {
|
|
660
|
-
const parts = args.slice(1).filter((a) => isStringLiteral(a)).map((a) => a.value);
|
|
661
|
-
if (parts.length > 0) {
|
|
662
|
-
return path5.resolve(configDir, ...parts);
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
return null;
|
|
667
|
-
}
|
|
668
|
-
function extractObjectProperties(node) {
|
|
669
|
-
if (isObjectExpression(node)) {
|
|
670
|
-
return node.properties;
|
|
671
|
-
}
|
|
672
|
-
return null;
|
|
673
|
-
}
|
|
674
690
|
async function loadMedusaConfig(medusaConfigPath, root) {
|
|
675
691
|
try {
|
|
676
|
-
const
|
|
677
|
-
const
|
|
692
|
+
const mod = await getFileExports(medusaConfigPath);
|
|
693
|
+
const medusaConfig = mod.default ?? mod;
|
|
694
|
+
const modules = medusaConfig?.modules ?? {};
|
|
678
695
|
const configDir = path5.dirname(medusaConfigPath);
|
|
679
|
-
const result = { properties: null };
|
|
680
|
-
traverse(ast, {
|
|
681
|
-
// Handle: export default defineConfig({ ... })
|
|
682
|
-
ExportDefaultDeclaration(nodePath) {
|
|
683
|
-
const decl = nodePath.node.declaration;
|
|
684
|
-
if (isCallExpression(decl) && decl.arguments.length > 0) {
|
|
685
|
-
result.properties = extractObjectProperties(decl.arguments[0]);
|
|
686
|
-
}
|
|
687
|
-
},
|
|
688
|
-
// Handle: module.exports = defineConfig({ ... }) or module.exports = { ... }
|
|
689
|
-
AssignmentExpression(nodePath) {
|
|
690
|
-
const left = nodePath.node.left;
|
|
691
|
-
if (isMemberExpression(left) && isIdentifier(left.object, { name: "module" }) && isIdentifier(left.property, { name: "exports" })) {
|
|
692
|
-
const right = nodePath.node.right;
|
|
693
|
-
if (isCallExpression(right) && right.arguments.length > 0) {
|
|
694
|
-
result.properties = extractObjectProperties(right.arguments[0]);
|
|
695
|
-
} else if (isObjectExpression(right)) {
|
|
696
|
-
result.properties = right.properties;
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
});
|
|
701
|
-
const configObjectProperties = result.properties;
|
|
702
|
-
if (!configObjectProperties) {
|
|
703
|
-
return { pluginExtensions: [] };
|
|
704
|
-
}
|
|
705
696
|
let base;
|
|
706
|
-
const
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
);
|
|
714
|
-
if (!uiProp || !isObjectProperty(uiProp) || !isObjectExpression(uiProp.value)) continue;
|
|
715
|
-
const optionsProp = uiProp.value.properties.find(
|
|
716
|
-
(p) => isObjectProperty(p) && isIdentifier(p.key, { name: "options" })
|
|
717
|
-
);
|
|
718
|
-
if (!optionsProp || !isObjectProperty(optionsProp) || !isObjectExpression(optionsProp.value)) continue;
|
|
719
|
-
const appDirProp = optionsProp.value.properties.find(
|
|
720
|
-
(p) => isObjectProperty(p) && isIdentifier(p.key, { name: "appDir" })
|
|
721
|
-
);
|
|
722
|
-
if (!appDirProp || !isObjectProperty(appDirProp)) continue;
|
|
723
|
-
const appDir = extractStringFromNode(appDirProp.value, configDir);
|
|
724
|
-
if (!appDir) continue;
|
|
725
|
-
const resolvedAppDir = path5.isAbsolute(appDir) ? appDir : path5.resolve(configDir, appDir);
|
|
726
|
-
if (resolvedAppDir === root) {
|
|
727
|
-
const pathProp = optionsProp.value.properties.find(
|
|
728
|
-
(p) => isObjectProperty(p) && isIdentifier(p.key, { name: "path" })
|
|
729
|
-
);
|
|
730
|
-
if (pathProp && isObjectProperty(pathProp) && isStringLiteral(pathProp.value)) {
|
|
731
|
-
base = pathProp.value.value;
|
|
732
|
-
}
|
|
733
|
-
break;
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
const plugins = [];
|
|
738
|
-
const pluginsProp = configObjectProperties.find(
|
|
739
|
-
(p) => isObjectProperty(p) && isIdentifier(p.key, { name: "plugins" })
|
|
740
|
-
);
|
|
741
|
-
if (pluginsProp && isObjectProperty(pluginsProp) && isArrayExpression(pluginsProp.value)) {
|
|
742
|
-
for (const element of pluginsProp.value.elements) {
|
|
743
|
-
if (!element) continue;
|
|
744
|
-
if (isObjectExpression(element)) {
|
|
745
|
-
const resolveProp = element.properties.find(
|
|
746
|
-
(p) => isObjectProperty(p) && isIdentifier(p.key, { name: "resolve" })
|
|
747
|
-
);
|
|
748
|
-
if (resolveProp && isObjectProperty(resolveProp) && isStringLiteral(resolveProp.value)) {
|
|
749
|
-
plugins.push({ resolve: resolveProp.value.value });
|
|
750
|
-
}
|
|
751
|
-
} else if (isStringLiteral(element)) {
|
|
752
|
-
plugins.push({ resolve: element.value });
|
|
753
|
-
}
|
|
697
|
+
for (const key of UI_MODULE_KEYS) {
|
|
698
|
+
const value = modules[key];
|
|
699
|
+
if (!value || typeof value !== "object" || !value.options?.appDir) continue;
|
|
700
|
+
const appDir = path5.resolve(configDir, value.options.appDir);
|
|
701
|
+
if (appDir === root) {
|
|
702
|
+
base = value.options.path;
|
|
703
|
+
break;
|
|
754
704
|
}
|
|
755
705
|
}
|
|
706
|
+
const plugins = medusaConfig?.plugins ?? [];
|
|
756
707
|
const pluginExtensions = resolvePluginExtensions(plugins, configDir);
|
|
757
708
|
return { base, pluginExtensions };
|
|
758
709
|
} catch {
|
|
@@ -785,7 +736,6 @@ function mercurDashboardPlugin(pluginConfig) {
|
|
|
785
736
|
"__BASE__": JSON.stringify(config.base || "/")
|
|
786
737
|
},
|
|
787
738
|
optimizeDeps: {
|
|
788
|
-
include: pluginExtensions,
|
|
789
739
|
exclude: ["virtual:mercur/config", "virtual:mercur/routes", "virtual:mercur/components", "virtual:mercur/menu-items", "virtual:mercur/i18n"]
|
|
790
740
|
}
|
|
791
741
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mercurjs/dashboard-sdk",
|
|
3
|
-
"version": "2.0.0-canary.
|
|
3
|
+
"version": "2.0.0-canary.76",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/mercurjs/mercur",
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@babel/parser": "7.25.6",
|
|
29
29
|
"@babel/traverse": "7.25.6",
|
|
30
|
-
"@babel/types": "7.25.6"
|
|
30
|
+
"@babel/types": "7.25.6",
|
|
31
|
+
"esbuild-register": "^3.6.0"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
34
|
"@types/node": "^22.0.0",
|