@mercurjs/dashboard-sdk 2.0.0-canary.8 → 2.0.0-canary.80

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 CHANGED
@@ -30,15 +30,39 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
- dashboardPlugin: () => dashboardPlugin,
34
- defineConfig: () => defineConfig
33
+ mercurDashboardPlugin: () => mercurDashboardPlugin
35
34
  });
36
35
  module.exports = __toCommonJS(index_exports);
37
36
 
38
37
  // src/plugin.ts
39
38
  var import_path5 = __toESM(require("path"), 1);
39
+ var import_fs4 = __toESM(require("fs"), 1);
40
+
41
+ // src/babel.ts
42
+ var import_parser = require("@babel/parser");
43
+ var import_traverse = __toESM(require("@babel/traverse"), 1);
44
+ var import_types = require("@babel/types");
45
+ var traverse;
46
+ if (typeof import_traverse.default === "function") {
47
+ traverse = import_traverse.default;
48
+ } else {
49
+ traverse = import_traverse.default.default;
50
+ }
40
51
 
41
52
  // src/utils.ts
53
+ function normalizePath(filePath) {
54
+ return filePath.replace(/\\/g, "/");
55
+ }
56
+ function getParserOptions(file) {
57
+ const options = {
58
+ sourceType: "module",
59
+ plugins: ["jsx"]
60
+ };
61
+ if (file.endsWith(".ts") || file.endsWith(".tsx")) {
62
+ options.plugins.push("typescript");
63
+ }
64
+ return options;
65
+ }
42
66
  function resolveExports(moduleExports) {
43
67
  if ("default" in moduleExports && moduleExports.default && "default" in moduleExports.default) {
44
68
  return resolveExports(moduleExports.default);
@@ -67,13 +91,31 @@ var safeRegister = async () => {
67
91
  }
68
92
  return res;
69
93
  };
70
- function normalizePath(filePath) {
71
- return filePath.replace(/\\/g, "/");
94
+ function hasDefaultExport(ast) {
95
+ let found = false;
96
+ traverse(ast, {
97
+ ExportDefaultDeclaration() {
98
+ found = true;
99
+ },
100
+ AssignmentExpression(path6) {
101
+ if (path6.node.left.type === "MemberExpression" && path6.node.left.object.type === "Identifier" && path6.node.left.object.name === "exports" && path6.node.left.property.type === "Identifier" && path6.node.left.property.name === "default") {
102
+ found = true;
103
+ }
104
+ },
105
+ ExportNamedDeclaration(path6) {
106
+ const specifiers = path6.node.specifiers;
107
+ if (specifiers?.some(
108
+ (s) => s.type === "ExportSpecifier" && s.exported.type === "Identifier" && s.exported.name === "default"
109
+ )) {
110
+ found = true;
111
+ }
112
+ }
113
+ });
114
+ return found;
72
115
  }
73
116
 
74
117
  // src/constants.ts
75
118
  var VALID_FILE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js"];
76
- var CONFIG_NAME = "mercur.config.ts";
77
119
  var CONFIG_VIRTUAL_MODULE = "virtual:mercur/config";
78
120
  var ROUTES_VIRTUAL_MODULE = "virtual:mercur/routes";
79
121
  var COMPONENTS_VIRTUAL_MODULE = "virtual:mercur/components";
@@ -128,31 +170,51 @@ function crawlPages(dir, pattern = "page") {
128
170
  }
129
171
  return files;
130
172
  }
131
- function hasDefaultExport(filePath) {
132
- try {
133
- const content = import_fs.default.readFileSync(filePath, "utf-8");
134
- return /export\s+default\s+/.test(content) || /export\s*\{\s*[^}]*\s+as\s+default\s*[,}]/.test(content);
135
- } catch {
136
- return false;
137
- }
138
- }
139
- function hasConfigPublic(filePath) {
140
- try {
141
- const content = import_fs.default.readFileSync(filePath, "utf-8");
142
- return /export\s+const\s+config\s*=\s*\{[^}]*public\s*:\s*true/.test(content);
143
- } catch {
144
- return false;
145
- }
146
- }
147
- function getNamedExports(filePath) {
148
- try {
149
- const content = import_fs.default.readFileSync(filePath, "utf-8");
150
- const hasHandle = /export\s+(const|function|async\s+function)\s+handle\b/.test(content) || /export\s*\{[^}]*\bhandle\b[^}]*\}/.test(content);
151
- const hasLoader = /export\s+(const|function|async\s+function)\s+loader\b/.test(content) || /export\s*\{[^}]*\bloader\b[^}]*\}/.test(content);
152
- return { hasHandle, hasLoader };
153
- } catch {
154
- return { hasHandle: false, hasLoader: false };
155
- }
173
+ function hasConfigPublic(ast) {
174
+ let found = false;
175
+ traverse(ast, {
176
+ ExportNamedDeclaration(path6) {
177
+ const declaration = path6.node.declaration;
178
+ if (!(0, import_types.isVariableDeclaration)(declaration)) return;
179
+ for (const decl of declaration.declarations) {
180
+ if ((0, import_types.isVariableDeclarator)(decl) && (0, import_types.isIdentifier)(decl.id, { name: "config" }) && decl.init?.type === "ObjectExpression") {
181
+ const publicProp = decl.init.properties.find(
182
+ (prop) => (0, import_types.isObjectProperty)(prop) && (0, import_types.isIdentifier)(prop.key, { name: "public" }) && (0, import_types.isBooleanLiteral)(prop.value, { value: true })
183
+ );
184
+ if (publicProp) {
185
+ found = true;
186
+ }
187
+ }
188
+ }
189
+ }
190
+ });
191
+ return found;
192
+ }
193
+ function getNamedExports(ast) {
194
+ let hasHandle = false;
195
+ let hasLoader = false;
196
+ traverse(ast, {
197
+ ExportNamedDeclaration(path6) {
198
+ const declaration = path6.node.declaration;
199
+ if (declaration?.type === "VariableDeclaration") {
200
+ declaration.declarations.forEach((decl) => {
201
+ if (decl.id.type === "Identifier" && decl.id.name === "handle") {
202
+ hasHandle = true;
203
+ }
204
+ if (decl.id.type === "Identifier" && decl.id.name === "loader") {
205
+ hasLoader = true;
206
+ }
207
+ });
208
+ }
209
+ if (declaration?.type === "FunctionDeclaration" && declaration.id?.name === "loader") {
210
+ hasLoader = true;
211
+ }
212
+ if (declaration?.type === "FunctionDeclaration" && declaration.id?.name === "handle") {
213
+ hasHandle = true;
214
+ }
215
+ }
216
+ });
217
+ return { hasHandle, hasLoader };
156
218
  }
157
219
  function generateRouteComponentName(index) {
158
220
  return `RouteComponent${index}`;
@@ -218,18 +280,24 @@ ${indent}}`;
218
280
  return result;
219
281
  }
220
282
  function parseFile(file, pagesDir, index) {
221
- if (!hasDefaultExport(file)) {
283
+ try {
284
+ const code = import_fs.default.readFileSync(file, "utf-8");
285
+ const ast = (0, import_parser.parse)(code, getParserOptions(file));
286
+ if (!hasDefaultExport(ast)) {
287
+ return null;
288
+ }
289
+ const { hasHandle, hasLoader } = getNamedExports(ast);
290
+ const isPublic = hasConfigPublic(ast);
291
+ const routePath = getRoute(file, pagesDir);
292
+ const imports = generateImports(file, index, hasHandle, hasLoader);
293
+ const route = generateRouteObject(routePath, index, hasHandle, hasLoader, isPublic);
294
+ return {
295
+ imports,
296
+ route
297
+ };
298
+ } catch {
222
299
  return null;
223
300
  }
224
- const { hasHandle, hasLoader } = getNamedExports(file);
225
- const isPublic = hasConfigPublic(file);
226
- const routePath = getRoute(file, pagesDir);
227
- const imports = generateImports(file, index, hasHandle, hasLoader);
228
- const route = generateRouteObject(routePath, index, hasHandle, hasLoader, isPublic);
229
- return {
230
- imports,
231
- route
232
- };
233
301
  }
234
302
  function buildRouteTree(results) {
235
303
  const routeMap = /* @__PURE__ */ new Map();
@@ -243,7 +311,7 @@ function buildRouteTree(results) {
243
311
  const parentPath = routePath.split("/@")[0];
244
312
  const parent = routeMap.get(parentPath);
245
313
  if (parent) {
246
- parent.route.children = parent.route.children || [];
314
+ parent.route.children = parent.route.children ?? [];
247
315
  parent.route.children.push({
248
316
  ...result.route,
249
317
  path: result.route.path.replace("/@", "/")
@@ -258,31 +326,37 @@ function buildRouteTree(results) {
258
326
  }
259
327
  return Array.from(routeMap.values());
260
328
  }
261
- function generateRoutes({ srcDir }) {
329
+ function generateRoutes({ srcDir, pluginExtensions }) {
262
330
  const pagesDir = import_path.default.join(srcDir, "pages");
263
- const files = crawlPages(pagesDir);
264
- if (files.length === 0) {
265
- return `export const customRoutes = []`;
266
- }
267
331
  let index = 0;
268
332
  const results = [];
269
- for (const file of files) {
333
+ for (const file of crawlPages(pagesDir)) {
270
334
  const result = parseFile(file, pagesDir, index);
271
335
  if (result) {
272
336
  results.push(result);
273
337
  index++;
274
338
  }
275
339
  }
276
- if (results.length === 0) {
340
+ const pluginDeclarations = pluginExtensions.map(
341
+ (ext, i) => `const __plugin${i} = (await import("${normalizePath(ext)}")).default`
342
+ );
343
+ const pluginSpreads = pluginExtensions.map(
344
+ (_, i) => ` ...(__plugin${i}.routeModule?.routes ?? [])`
345
+ );
346
+ const routeTree = buildRouteTree(results);
347
+ const appImports = routeTree.flatMap((r) => r.imports);
348
+ const appRoutes = routeTree.map((r) => formatRoute(r.route));
349
+ const allImports = [...appImports];
350
+ const allRoutes = [...appRoutes, ...pluginSpreads];
351
+ if (allImports.length === 0 && pluginDeclarations.length === 0 && allRoutes.length === 0) {
277
352
  return `export const customRoutes = []`;
278
353
  }
279
- const routeTree = buildRouteTree(results);
280
- const imports = routeTree.flatMap((result) => result.imports);
281
- const routes = routeTree.map((result) => formatRoute(result.route));
282
- return `${imports.join("\n")}
354
+ return `${allImports.join("\n")}
355
+
356
+ ${pluginDeclarations.join("\n")}
283
357
 
284
358
  export const customRoutes = [
285
- ${routes.join(",\n")}
359
+ ${allRoutes.join(",\n")}
286
360
  ]`;
287
361
  }
288
362
 
@@ -319,29 +393,90 @@ function getRoute2(file, pagesDir) {
319
393
  ""
320
394
  ) || "/";
321
395
  }
322
- function hasConfigExport(filePath) {
323
- try {
324
- const content = import_fs2.default.readFileSync(filePath, "utf-8");
325
- return /export\s+(const|let|var)\s+config\b/.test(content) || /export\s*\{[^}]*\bconfig\b[^}]*\}/.test(content);
326
- } catch {
327
- return false;
396
+ function getConfigObjectProperties(path6) {
397
+ if ((0, import_types.isVariableDeclarator)(path6.node)) {
398
+ const decl = (0, import_types.isIdentifier)(path6.node.id, { name: "config" }) ? path6.node : null;
399
+ if (!decl) return null;
400
+ if ((0, import_types.isCallExpression)(decl.init) && decl.init.arguments.length > 0 && (0, import_types.isObjectExpression)(decl.init.arguments[0])) {
401
+ return decl.init.arguments[0].properties;
402
+ }
403
+ if ((0, import_types.isObjectExpression)(decl.init)) {
404
+ return decl.init.properties;
405
+ }
406
+ return null;
407
+ }
408
+ const declaration = path6.node.declaration;
409
+ if ((0, import_types.isVariableDeclaration)(declaration)) {
410
+ const configDecl = declaration.declarations.find(
411
+ (d) => (0, import_types.isVariableDeclarator)(d) && (0, import_types.isIdentifier)(d.id, { name: "config" })
412
+ );
413
+ if (configDecl && (0, import_types.isCallExpression)(configDecl.init) && configDecl.init.arguments.length > 0 && (0, import_types.isObjectExpression)(configDecl.init.arguments[0])) {
414
+ return configDecl.init.arguments[0].properties;
415
+ }
416
+ const directDecl = declaration.declarations.find(
417
+ (d) => (0, import_types.isVariableDeclarator)(d) && (0, import_types.isIdentifier)(d.id, { name: "config" })
418
+ );
419
+ if (directDecl && (0, import_types.isObjectExpression)(directDecl.init)) {
420
+ return directDecl.init.properties;
421
+ }
328
422
  }
423
+ return null;
329
424
  }
330
- function getConfigProperties(filePath) {
425
+ function processConfigProperties(properties) {
426
+ const hasProperty = (name) => properties.some(
427
+ (prop) => (0, import_types.isObjectProperty)(prop) && (0, import_types.isIdentifier)(prop.key, { name })
428
+ );
429
+ const hasLabel = hasProperty("label");
430
+ if (!hasLabel) {
431
+ return null;
432
+ }
433
+ const hasIcon = hasProperty("icon");
434
+ const nested = properties.find(
435
+ (prop) => (0, import_types.isObjectProperty)(prop) && (0, import_types.isIdentifier)(prop.key, { name: "nested" })
436
+ );
437
+ let nestedValue;
438
+ if (nested && (0, import_types.isObjectProperty)(nested) && (0, import_types.isStringLiteral)(nested.value)) {
439
+ nestedValue = nested.value.value;
440
+ }
441
+ const translationNs = properties.find(
442
+ (prop) => (0, import_types.isObjectProperty)(prop) && (0, import_types.isIdentifier)(prop.key, { name: "translationNs" })
443
+ );
444
+ let translationNsValue;
445
+ if (translationNs && (0, import_types.isObjectProperty)(translationNs) && (0, import_types.isStringLiteral)(translationNs.value)) {
446
+ translationNsValue = translationNs.value.value;
447
+ }
448
+ const rank = properties.find(
449
+ (prop) => (0, import_types.isObjectProperty)(prop) && (0, import_types.isIdentifier)(prop.key, { name: "rank" })
450
+ );
451
+ let rankValue;
452
+ if (rank && (0, import_types.isObjectProperty)(rank) && (0, import_types.isNumericLiteral)(rank.value)) {
453
+ rankValue = rank.value.value;
454
+ }
455
+ return { label: hasLabel, icon: hasIcon, rank: rankValue, nested: nestedValue, translationNs: translationNsValue };
456
+ }
457
+ function getRouteConfig(file) {
331
458
  try {
332
- const content = import_fs2.default.readFileSync(filePath, "utf-8");
333
- const hasLabel = /\blabel\s*[:=]/.test(content);
334
- if (!hasLabel) {
335
- return null;
336
- }
337
- const hasIcon = /\bicon\s*[:=]/.test(content);
338
- const rankMatch = content.match(/\brank\s*:\s*(\d+)/);
339
- const rank = rankMatch ? parseInt(rankMatch[1], 10) : void 0;
340
- const nestedMatch = content.match(/\bnested\s*:\s*["']([^"']+)["']/);
341
- const nested = nestedMatch ? nestedMatch[1] : void 0;
342
- const translationNsMatch = content.match(/\btranslationNs\s*:\s*["']([^"']+)["']/);
343
- const translationNs = translationNsMatch ? translationNsMatch[1] : void 0;
344
- return { label: hasLabel, icon: hasIcon, rank, nested, translationNs };
459
+ const code = import_fs2.default.readFileSync(file, "utf-8");
460
+ const ast = (0, import_parser.parse)(code, getParserOptions(file));
461
+ let config = null;
462
+ let configFound = false;
463
+ traverse(ast, {
464
+ VariableDeclarator(path6) {
465
+ if (configFound) return;
466
+ const properties = getConfigObjectProperties(path6);
467
+ if (!properties) return;
468
+ config = processConfigProperties(properties);
469
+ if (config) configFound = true;
470
+ },
471
+ ExportNamedDeclaration(path6) {
472
+ if (configFound) return;
473
+ const properties = getConfigObjectProperties(path6);
474
+ if (!properties) return;
475
+ config = processConfigProperties(properties);
476
+ if (config) configFound = true;
477
+ }
478
+ });
479
+ return config;
345
480
  } catch {
346
481
  return null;
347
482
  }
@@ -378,10 +513,7 @@ ${parts.join(",\n")}
378
513
  }`;
379
514
  }
380
515
  function parseFile2(file, pagesDir, index) {
381
- if (!hasConfigExport(file)) {
382
- return null;
383
- }
384
- const config = getConfigProperties(file);
516
+ const config = getRouteConfig(file);
385
517
  if (!config) {
386
518
  return null;
387
519
  }
@@ -390,31 +522,37 @@ function parseFile2(file, pagesDir, index) {
390
522
  menuItem: generateMenuItem(config, file, pagesDir, index)
391
523
  };
392
524
  }
393
- function generateMenuItems({ srcDir }) {
525
+ function generateMenuItems({ srcDir, pluginExtensions }) {
394
526
  const pagesDir = import_path2.default.join(srcDir, "pages");
395
- const files = crawlPages2(pagesDir);
396
- if (files.length === 0) {
397
- return `export default { menuItems: [] }`;
398
- }
399
527
  let index = 0;
400
528
  const results = [];
401
- for (const file of files) {
529
+ for (const file of crawlPages2(pagesDir)) {
402
530
  const result = parseFile2(file, pagesDir, index);
403
531
  if (result) {
404
532
  results.push(result);
405
533
  index++;
406
534
  }
407
535
  }
408
- if (results.length === 0) {
536
+ const pluginDeclarations = pluginExtensions.map(
537
+ (ext, i) => `const __plugin${i} = (await import("${normalizePath(ext)}")).default`
538
+ );
539
+ const pluginSpreads = pluginExtensions.map(
540
+ (_, i) => ` ...(__plugin${i}.menuItemModule?.menuItems ?? [])`
541
+ );
542
+ const appImports = results.map((r) => r.import);
543
+ const appMenuItems = results.map((r) => formatMenuItem(r.menuItem));
544
+ const allImports = [...appImports];
545
+ const allMenuItems = [...appMenuItems, ...pluginSpreads];
546
+ if (allImports.length === 0 && pluginDeclarations.length === 0 && allMenuItems.length === 0) {
409
547
  return `export default { menuItems: [] }`;
410
548
  }
411
- const imports = results.map((r) => r.import);
412
- const menuItems = results.map((r) => formatMenuItem(r.menuItem));
413
- return `${imports.join("\n")}
549
+ return `${allImports.join("\n")}
550
+
551
+ ${pluginDeclarations.join("\n")}
414
552
 
415
553
  export default {
416
554
  menuItems: [
417
- ${menuItems.join(",\n")}
555
+ ${allMenuItems.join(",\n")}
418
556
  ]
419
557
  }`;
420
558
  }
@@ -506,47 +644,111 @@ function loadI18nModule(mercurConfig) {
506
644
  }
507
645
 
508
646
  // src/plugin.ts
509
- function buildConfig(config, root) {
510
- const srcDir = import_path5.default.join(root, "src");
511
- return {
512
- ...config,
513
- backendUrl: config.backendUrl ?? "http://localhost:9000",
514
- root,
515
- srcDir,
516
- configPath: import_path5.default.resolve(root, CONFIG_NAME)
517
- };
647
+ function isPageFile(file) {
648
+ const basename = import_path5.default.basename(file, import_path5.default.extname(file));
649
+ return basename === "page";
650
+ }
651
+ var UI_MODULE_KEYS = [
652
+ "admin_ui",
653
+ "vendor_ui"
654
+ ];
655
+ function findNodeModulesRoot(configDir) {
656
+ let dir = configDir;
657
+ while (dir !== import_path5.default.dirname(dir)) {
658
+ const candidate = import_path5.default.join(dir, "node_modules");
659
+ if (import_fs4.default.existsSync(candidate) && import_fs4.default.statSync(candidate).isDirectory()) {
660
+ return candidate;
661
+ }
662
+ dir = import_path5.default.dirname(dir);
663
+ }
664
+ return import_path5.default.join(configDir, "node_modules");
518
665
  }
519
- async function loadMercurConfig(root) {
520
- const configPath = import_path5.default.resolve(root, CONFIG_NAME);
666
+ function resolvePluginRoot(resolve, configDir, nodeModulesRoot) {
521
667
  try {
522
- const mod = await getFileExports(configPath);
523
- const content = mod.default ?? mod;
524
- return buildConfig(content, root);
525
- } catch (error) {
526
- console.error(error);
527
- throw new Error(
528
- `[@mercurjs/dashboard-sdk] Could not find or load ${CONFIG_NAME} in ${root}`
529
- );
668
+ if (resolve.startsWith(".")) {
669
+ const resolved = import_path5.default.resolve(configDir, resolve);
670
+ if (import_fs4.default.existsSync(resolved)) {
671
+ return import_fs4.default.realpathSync(resolved);
672
+ }
673
+ return null;
674
+ }
675
+ const packagePath = import_path5.default.join(nodeModulesRoot, resolve);
676
+ if (!import_fs4.default.existsSync(packagePath)) {
677
+ return null;
678
+ }
679
+ return import_fs4.default.realpathSync(packagePath);
680
+ } catch {
681
+ return null;
530
682
  }
531
683
  }
532
- function isPageFile(file) {
533
- const basename = import_path5.default.basename(file, import_path5.default.extname(file));
534
- return basename === "page";
684
+ function resolvePluginExtensions(plugins, configDir) {
685
+ const nodeModulesRoot = findNodeModulesRoot(configDir);
686
+ const extensions = [];
687
+ const appTypes = ["admin", "vendor"];
688
+ for (const plugin of plugins) {
689
+ const resolve = typeof plugin === "string" ? plugin : plugin?.resolve;
690
+ if (!resolve || typeof resolve !== "string") continue;
691
+ const pluginRoot = resolvePluginRoot(resolve, configDir, nodeModulesRoot);
692
+ if (!pluginRoot) continue;
693
+ for (const appType of appTypes) {
694
+ const extFile = import_path5.default.join(pluginRoot, ".medusa/server/src", appType, "index.mjs");
695
+ if (import_fs4.default.existsSync(extFile)) {
696
+ extensions.push(extFile);
697
+ }
698
+ }
699
+ }
700
+ return extensions;
701
+ }
702
+ async function loadMedusaConfig(medusaConfigPath, root) {
703
+ try {
704
+ const mod = await getFileExports(medusaConfigPath);
705
+ const medusaConfig = mod.default ?? mod;
706
+ const modules = medusaConfig?.modules ?? {};
707
+ const configDir = import_path5.default.dirname(medusaConfigPath);
708
+ let base;
709
+ for (const key of UI_MODULE_KEYS) {
710
+ const value = modules[key];
711
+ if (!value || typeof value !== "object" || !value.options?.appDir) continue;
712
+ const appDir = import_path5.default.resolve(configDir, value.options.appDir);
713
+ if (appDir === root) {
714
+ base = value.options.path;
715
+ break;
716
+ }
717
+ }
718
+ const plugins = medusaConfig?.plugins?.filter((plugin) => plugin.resolve !== "@medusajs/draft-order") ?? [];
719
+ const pluginExtensions = resolvePluginExtensions(plugins, configDir);
720
+ return { base, pluginExtensions };
721
+ } catch {
722
+ return { pluginExtensions: [] };
723
+ }
535
724
  }
536
- function dashboardPlugin() {
725
+ function mercurDashboardPlugin(pluginConfig) {
537
726
  let root;
538
727
  let config;
539
728
  return {
540
729
  name: "@mercurjs/dashboard-sdk",
541
730
  async config(viteConfig) {
542
731
  root = viteConfig.root || process.cwd();
543
- config = await loadMercurConfig(root);
732
+ const medusaConfigPath = import_path5.default.resolve(root, pluginConfig.medusaConfigPath);
733
+ const { base, pluginExtensions } = await loadMedusaConfig(medusaConfigPath, root);
734
+ const srcDir = import_path5.default.join(root, "src");
735
+ const backendUrl = pluginConfig.backendUrl ?? "http://localhost:9000";
736
+ config = {
737
+ ...pluginConfig,
738
+ backendUrl,
739
+ base,
740
+ root,
741
+ srcDir,
742
+ pluginExtensions
743
+ };
544
744
  return {
745
+ base: config.base,
545
746
  define: {
546
- "__BACKEND_URL__": JSON.stringify(config.backendUrl)
747
+ "__BACKEND_URL__": JSON.stringify(config.backendUrl),
748
+ "__BASE__": JSON.stringify(config.base || "/")
547
749
  },
548
750
  optimizeDeps: {
549
- exclude: ["@mercurjs/vendor", "virtual:mercur/config"]
751
+ exclude: ["virtual:mercur/config", "virtual:mercur/routes", "virtual:mercur/components", "virtual:mercur/menu-items", "virtual:mercur/i18n"]
550
752
  }
551
753
  };
552
754
  },
@@ -575,11 +777,6 @@ function dashboardPlugin() {
575
777
  server.watcher.on("unlink", handlePageChange);
576
778
  },
577
779
  handleHotUpdate({ file, server }) {
578
- const configPath = import_path5.default.resolve(root, CONFIG_NAME);
579
- if (file === configPath) {
580
- server.restart();
581
- return;
582
- }
583
780
  if (isPageFile(file)) {
584
781
  const mod = server.moduleGraph.getModuleById(RESOLVED_ROUTES_MODULE);
585
782
  if (mod) {
@@ -589,13 +786,7 @@ function dashboardPlugin() {
589
786
  }
590
787
  };
591
788
  }
592
-
593
- // src/define-config.ts
594
- function defineConfig(config) {
595
- return config;
596
- }
597
789
  // Annotate the CommonJS export names for ESM import in node:
598
790
  0 && (module.exports = {
599
- dashboardPlugin,
600
- defineConfig
791
+ mercurDashboardPlugin
601
792
  });
package/dist/index.d.cts CHANGED
@@ -1,9 +1,9 @@
1
1
  import * as Vite from 'vite';
2
2
  import { ComponentType } from 'react';
3
3
 
4
- declare function dashboardPlugin(): Vite.Plugin;
5
-
6
4
  interface MercurConfig {
5
+ medusaConfigPath: string;
6
+ backendUrl?: string;
7
7
  name?: string;
8
8
  logo?: string;
9
9
  components?: {
@@ -14,13 +14,14 @@ interface MercurConfig {
14
14
  i18n?: {
15
15
  defaultLanguage: string;
16
16
  };
17
- backendUrl?: string;
17
+ enableSellerRegistration?: boolean;
18
18
  }
19
19
  interface BuiltMercurConfig extends MercurConfig {
20
20
  backendUrl: string;
21
+ base?: string;
21
22
  root: string;
22
23
  srcDir: string;
23
- configPath: string;
24
+ pluginExtensions: string[];
24
25
  }
25
26
  type RouteConfig = {
26
27
  label: string;
@@ -31,6 +32,6 @@ type RouteConfig = {
31
32
  public?: boolean;
32
33
  };
33
34
 
34
- declare function defineConfig(config: MercurConfig): MercurConfig;
35
+ declare function mercurDashboardPlugin(pluginConfig: MercurConfig): Vite.Plugin;
35
36
 
36
- export { type BuiltMercurConfig, type MercurConfig, type RouteConfig, dashboardPlugin, defineConfig };
37
+ export { type BuiltMercurConfig, type MercurConfig, type RouteConfig, mercurDashboardPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mercurjs/dashboard-sdk",
3
- "version": "2.0.0-canary.8",
3
+ "version": "2.0.0-canary.80",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/mercurjs/mercur",
@@ -25,6 +25,9 @@
25
25
  "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0"
26
26
  },
27
27
  "dependencies": {
28
+ "@babel/parser": "7.25.6",
29
+ "@babel/traverse": "7.25.6",
30
+ "@babel/types": "7.25.6",
28
31
  "esbuild-register": "^3.6.0"
29
32
  },
30
33
  "devDependencies": {