Skip to content

The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.

chore: v2.0.0-canary.75

vholikdfa1056581a4
diff --git a/bun.lock b/bun.lock
index 1c87d67ac..cec879972 100644
--- a/bun.lock
+++ b/bun.lock
@@ -38,7 +38,7 @@
},
"packages/admin": {
"name": "@mercurjs/admin",
- "version": "2.0.0-canary.73",
+ "version": "2.0.0-canary.74",
"dependencies": {
"@ariakit/react": "^0.4.15",
"@babel/runtime": "^7.26.10",
@@ -98,7 +98,7 @@
},
"packages/cli": {
"name": "@mercurjs/cli",
- "version": "2.0.0-canary.73",
+ "version": "2.0.0-canary.74",
"bin": {
"mercurjs": "./dist/index.js",
},
@@ -137,7 +137,7 @@
},
"packages/client": {
"name": "@mercurjs/client",
- "version": "2.0.0-canary.73",
+ "version": "2.0.0-canary.74",
"dependencies": {
"@tanstack/react-query": "^5.64.2",
"qs": "^6.12.1",
@@ -154,7 +154,7 @@
},
"packages/core-plugin": {
"name": "@mercurjs/core-plugin",
- "version": "2.0.0-canary.73",
+ "version": "2.0.0-canary.74",
"devDependencies": {
"@medusajs/cli": "^2.13.3",
"@medusajs/core-flows": "^2.13.3",
@@ -195,11 +195,12 @@
},
"packages/dashboard-sdk": {
"name": "@mercurjs/dashboard-sdk",
- "version": "2.0.0-canary.73",
+ "version": "2.0.0-canary.74",
"dependencies": {
"@babel/parser": "7.25.6",
"@babel/traverse": "7.25.6",
"@babel/types": "7.25.6",
+ "esbuild-register": "^3.6.0",
},
"devDependencies": {
"@types/node": "^22.0.0",
@@ -211,7 +212,7 @@
},
"packages/dashboard-shared": {
"name": "@mercurjs/dashboard-shared",
- "version": "2.0.0-canary.73",
+ "version": "2.0.0-canary.74",
"dependencies": {
"@ariakit/react": "^0.4.15",
"@babel/runtime": "^7.26.10",
@@ -303,7 +304,7 @@
},
"packages/types": {
"name": "@mercurjs/types",
- "version": "2.0.0-canary.73",
+ "version": "2.0.0-canary.74",
"dependencies": {
"@medusajs/types": "2.13.3",
},
@@ -313,7 +314,7 @@
},
"packages/vendor": {
"name": "@mercurjs/vendor",
- "version": "2.0.0-canary.73",
+ "version": "2.0.0-canary.74",
"dependencies": {
"@ariakit/react": "^0.4.15",
"@babel/runtime": "^7.26.10",
diff --git a/packages/admin/package.json b/packages/admin/package.json
index e73b85853..3c1c3b5b8 100644
--- a/packages/admin/package.json
+++ b/packages/admin/package.json
@@ -1,6 +1,6 @@
{
"name": "@mercurjs/admin",
- "version": "2.0.0-canary.74",
+ "version": "2.0.0-canary.75",
"repository": {
"type": "git",
"url": "https://github.com/mercurjs/mercur",
diff --git a/packages/cli/package.json b/packages/cli/package.json
index 4a071510d..4e7f43e1a 100644
--- a/packages/cli/package.json
+++ b/packages/cli/package.json
@@ -1,6 +1,6 @@
{
"name": "@mercurjs/cli",
- "version": "2.0.0-canary.74",
+ "version": "2.0.0-canary.75",
"repository": {
"type": "git",
"url": "https://github.com/mercurjs/mercur",
diff --git a/packages/client/package.json b/packages/client/package.json
index cece4f735..ffa38a482 100644
--- a/packages/client/package.json
+++ b/packages/client/package.json
@@ -1,6 +1,6 @@
{
"name": "@mercurjs/client",
- "version": "2.0.0-canary.74",
+ "version": "2.0.0-canary.75",
"repository": {
"type": "git",
"url": "https://github.com/mercurjs/mercur",
diff --git a/packages/core-plugin/package.json b/packages/core-plugin/package.json
index ad6f48c36..1c6168147 100644
--- a/packages/core-plugin/package.json
+++ b/packages/core-plugin/package.json
@@ -1,6 +1,6 @@
{
"name": "@mercurjs/core-plugin",
- "version": "2.0.0-canary.74",
+ "version": "2.0.0-canary.75",
"repository": {
"type": "git",
"url": "https://github.com/mercurjs/mercur",
diff --git a/packages/dashboard-sdk/package.json b/packages/dashboard-sdk/package.json
index 6ab02ff6f..6cced613f 100644
--- a/packages/dashboard-sdk/package.json
+++ b/packages/dashboard-sdk/package.json
@@ -1,6 +1,6 @@
{
"name": "@mercurjs/dashboard-sdk",
- "version": "2.0.0-canary.74",
+ "version": "2.0.0-canary.75",
"repository": {
"type": "git",
"url": "https://github.com/mercurjs/mercur",
@@ -27,7 +27,8 @@
"dependencies": {
"@babel/parser": "7.25.6",
"@babel/traverse": "7.25.6",
- "@babel/types": "7.25.6"
+ "@babel/types": "7.25.6",
+ "esbuild-register": "^3.6.0"
},
"devDependencies": {
"@types/node": "^22.0.0",
diff --git a/packages/dashboard-sdk/src/menu-items.ts b/packages/dashboard-sdk/src/menu-items.ts
index 8c60d6dbe..5bc20f6de 100644
--- a/packages/dashboard-sdk/src/menu-items.ts
+++ b/packages/dashboard-sdk/src/menu-items.ts
@@ -274,12 +274,9 @@ export function generateMenuItems({ srcDir, pluginExtensions }: BuiltMercurConfi
}
}
- // Plugin extension imports (CJS modules — use namespace import)
- const pluginImports = pluginExtensions.map((ext, i) =>
- `import * as __pluginRaw${i} from "${normalizePath(ext)}"`
- )
- const pluginUnwraps = pluginExtensions.map((_, i) =>
- `const __plugin${i} = __pluginRaw${i}.default ?? __pluginRaw${i}`
+ // Plugin extensions — dynamic import to resolve .default
+ const pluginDeclarations = pluginExtensions.map((ext, i) =>
+ `const __plugin${i} = (await import("${normalizePath(ext)}")).default`
)
const pluginSpreads = pluginExtensions.map((_, i) =>
` ...(__plugin${i}.menuItemModule?.menuItems ?? [])`
@@ -288,15 +285,17 @@ export function generateMenuItems({ srcDir, pluginExtensions }: BuiltMercurConfi
const appImports = results.map((r) => r.import)
const appMenuItems = results.map((r) => formatMenuItem(r.menuItem))
- const allImports = [...appImports, ...pluginImports, ...pluginUnwraps]
+ const allImports = [...appImports]
const allMenuItems = [...appMenuItems, ...pluginSpreads]
- if (allImports.length === 0 && allMenuItems.length === 0) {
+ if (allImports.length === 0 && pluginDeclarations.length === 0 && allMenuItems.length === 0) {
return `export default { menuItems: [] }`
}
return `${allImports.join("\n")}
+${pluginDeclarations.join("\n")}
+
export default {
menuItems: [
${allMenuItems.join(",\n")}
diff --git a/packages/dashboard-sdk/src/plugin.ts b/packages/dashboard-sdk/src/plugin.ts
index dd983f2b8..4fe58d3b8 100644
--- a/packages/dashboard-sdk/src/plugin.ts
+++ b/packages/dashboard-sdk/src/plugin.ts
@@ -1,18 +1,7 @@
import type * as Vite from "vite"
import path from "path"
import fs from "fs"
-import { getParserOptions } from "./utils"
-import {
- parse,
- traverse,
- isIdentifier,
- isCallExpression,
- isObjectExpression,
- isObjectProperty,
- isStringLiteral,
- isArrayExpression,
- isMemberExpression,
-} from "./babel"
+import { getFileExports } from "./utils"
import { RESOLVED_ROUTES_MODULE } from "./constants"
import { isVirtualModule, resolveVirtualModule, loadVirtualModule } from "./virtual-modules"
import type { MercurConfig, BuiltMercurConfig } from "./types"
@@ -92,150 +81,29 @@ function resolvePluginExtensions(
return extensions
}
-function extractStringFromNode(node: any, configDir: string): string | null {
- if (isStringLiteral(node)) {
- return node.value
- }
-
- // Handle path.join(__dirname, 'relative') or path.resolve(__dirname, 'relative')
- 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")
- ) {
- const args = node.arguments
- if (args.length >= 2 && isIdentifier(args[0], { name: "__dirname" })) {
- const parts = args.slice(1)
- .filter((a: any) => isStringLiteral(a))
- .map((a: any) => a.value)
- if (parts.length > 0) {
- return path.resolve(configDir, ...parts)
- }
- }
- }
-
- return null
-}
-
-function extractObjectProperties(node: any): any[] | null {
- if (isObjectExpression(node)) {
- return node.properties
- }
- return null
-}
-
async function loadMedusaConfig(medusaConfigPath: string, root: string): Promise<{ base?: string; pluginExtensions: string[] }> {
try {
- const code = fs.readFileSync(medusaConfigPath, "utf-8")
- const ast = parse(code, getParserOptions(medusaConfigPath))
- const configDir = path.dirname(medusaConfigPath)
-
- const result: { properties: any[] | null } = { properties: null }
-
- traverse(ast, {
- // Handle: export default defineConfig({ ... })
- ExportDefaultDeclaration(nodePath: any) {
- const decl = nodePath.node.declaration
- if (isCallExpression(decl) && decl.arguments.length > 0) {
- result.properties = extractObjectProperties(decl.arguments[0])
- }
- },
- // Handle: module.exports = defineConfig({ ... }) or module.exports = { ... }
- AssignmentExpression(nodePath: any) {
- const left = nodePath.node.left
- if (
- isMemberExpression(left) &&
- isIdentifier(left.object, { name: "module" }) &&
- isIdentifier(left.property, { name: "exports" })
- ) {
- const right = nodePath.node.right
- if (isCallExpression(right) && right.arguments.length > 0) {
- result.properties = extractObjectProperties(right.arguments[0])
- } else if (isObjectExpression(right)) {
- result.properties = right.properties as any[]
- }
- }
- },
- })
-
- const configObjectProperties = result.properties
+ const mod = await getFileExports(medusaConfigPath)
+ const medusaConfig = mod.default ?? mod
- if (!configObjectProperties) {
- return { pluginExtensions: [] }
- }
+ const modules = medusaConfig?.modules ?? {}
+ const configDir = path.dirname(medusaConfigPath)
let base: string | undefined
- // Extract modules
- const modulesProp = configObjectProperties.find(
- (p: any) => isObjectProperty(p) && isIdentifier(p.key, { name: "modules" })
- )
-
- if (modulesProp && isObjectProperty(modulesProp) && isObjectExpression(modulesProp.value)) {
- for (const key of UI_MODULE_KEYS) {
- const uiProp = modulesProp.value.properties.find(
- (p: any) => isObjectProperty(p) && isIdentifier(p.key, { name: key })
- )
-
- if (!uiProp || !isObjectProperty(uiProp) || !isObjectExpression(uiProp.value)) continue
-
- const optionsProp = uiProp.value.properties.find(
- (p: any) => isObjectProperty(p) && isIdentifier(p.key, { name: "options" })
- )
-
- if (!optionsProp || !isObjectProperty(optionsProp) || !isObjectExpression(optionsProp.value)) continue
-
- const appDirProp = optionsProp.value.properties.find(
- (p: any) => isObjectProperty(p) && isIdentifier(p.key, { name: "appDir" })
- )
-
- if (!appDirProp || !isObjectProperty(appDirProp)) continue
-
- const appDir = extractStringFromNode(appDirProp.value, configDir)
- if (!appDir) continue
+ for (const key of UI_MODULE_KEYS) {
+ const value = modules[key]
+ if (!value || typeof value !== "object" || !value.options?.appDir) continue
- const resolvedAppDir = path.isAbsolute(appDir)
- ? appDir
- : path.resolve(configDir, appDir)
+ const appDir = path.resolve(configDir, value.options.appDir)
- if (resolvedAppDir === root) {
- const pathProp = optionsProp.value.properties.find(
- (p: any) => isObjectProperty(p) && isIdentifier(p.key, { name: "path" })
- )
-
- if (pathProp && isObjectProperty(pathProp) && isStringLiteral(pathProp.value)) {
- base = pathProp.value.value
- }
- break
- }
- }
- }
-
- // Extract plugins
- const plugins: any[] = []
- const pluginsProp = configObjectProperties.find(
- (p: any) => isObjectProperty(p) && isIdentifier(p.key, { name: "plugins" })
- )
-
- if (pluginsProp && isObjectProperty(pluginsProp) && isArrayExpression(pluginsProp.value)) {
- for (const element of pluginsProp.value.elements) {
- if (!element) continue
-
- if (isObjectExpression(element)) {
- const resolveProp = element.properties.find(
- (p: any) => isObjectProperty(p) && isIdentifier(p.key, { name: "resolve" })
- )
- if (resolveProp && isObjectProperty(resolveProp) && isStringLiteral(resolveProp.value)) {
- plugins.push({ resolve: resolveProp.value.value })
- }
- } else if (isStringLiteral(element)) {
- plugins.push({ resolve: element.value })
- }
+ if (appDir === root) {
+ base = value.options.path
+ break
}
}
+ const plugins = medusaConfig?.plugins ?? []
const pluginExtensions = resolvePluginExtensions(plugins, configDir)
return { base, pluginExtensions }
@@ -275,7 +143,6 @@ export function mercurDashboardPlugin(pluginConfig: MercurConfig): Vite.Plugin {
"__BASE__": JSON.stringify(config.base || "/"),
},
optimizeDeps: {
- include: pluginExtensions,
exclude: ['virtual:mercur/config', 'virtual:mercur/routes', 'virtual:mercur/components', 'virtual:mercur/menu-items', 'virtual:mercur/i18n']
},
}
diff --git a/packages/dashboard-sdk/src/routes.ts b/packages/dashboard-sdk/src/routes.ts
index c31119444..8bd3ebb5a 100644
--- a/packages/dashboard-sdk/src/routes.ts
+++ b/packages/dashboard-sdk/src/routes.ts
@@ -292,12 +292,9 @@ export function generateRoutes({ srcDir, pluginExtensions }: BuiltMercurConfig):
}
}
- // Plugin extension imports (CJS modules — use namespace import)
- const pluginImports = pluginExtensions.map((ext, i) =>
- `import * as __pluginRaw${i} from "${normalizePath(ext)}"`
- )
- const pluginUnwraps = pluginExtensions.map((_, i) =>
- `const __plugin${i} = __pluginRaw${i}.default ?? __pluginRaw${i}`
+ // Plugin extensions — dynamic import to resolve .default
+ const pluginDeclarations = pluginExtensions.map((ext, i) =>
+ `const __plugin${i} = (await import("${normalizePath(ext)}")).default`
)
const pluginSpreads = pluginExtensions.map((_, i) =>
` ...(__plugin${i}.routeModule?.routes ?? [])`
@@ -307,15 +304,17 @@ export function generateRoutes({ srcDir, pluginExtensions }: BuiltMercurConfig):
const appImports = routeTree.flatMap((r) => r.imports)
const appRoutes = routeTree.map((r) => formatRoute(r.route))
- const allImports = [...appImports, ...pluginImports, ...pluginUnwraps]
+ const allImports = [...appImports]
const allRoutes = [...appRoutes, ...pluginSpreads]
- if (allImports.length === 0 && allRoutes.length === 0) {
+ if (allImports.length === 0 && pluginDeclarations.length === 0 && allRoutes.length === 0) {
return `export const customRoutes = []`
}
return `${allImports.join("\n")}
+${pluginDeclarations.join("\n")}
+
export const customRoutes = [
${allRoutes.join(",\n")}
]`
diff --git a/packages/dashboard-sdk/src/utils.ts b/packages/dashboard-sdk/src/utils.ts
index 2df9708f7..6b9cd2b3c 100644
--- a/packages/dashboard-sdk/src/utils.ts
+++ b/packages/dashboard-sdk/src/utils.ts
@@ -18,6 +18,42 @@ export function getParserOptions(file: string): ParserOptions {
return options
}
+export function resolveExports(moduleExports: any) {
+ if (
+ "default" in moduleExports &&
+ moduleExports.default &&
+ "default" in moduleExports.default
+ ) {
+ return resolveExports(moduleExports.default)
+ }
+ return moduleExports
+}
+
+export async function getFileExports(path: string): Promise<any> {
+ const { unregister } = await safeRegister()
+ const module = require(path)
+ unregister()
+
+ return resolveExports(module)
+}
+
+export const safeRegister = async () => {
+ const { register } = await import("esbuild-register/dist/node")
+ let res: { unregister: () => void }
+ try {
+ res = register({
+ format: "cjs",
+ loader: "ts",
+ })
+ } catch {
+ res = {
+ unregister: () => {},
+ }
+ }
+
+ return res
+}
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function hasDefaultExport(ast: any): boolean {
let found = false
diff --git a/packages/dashboard-shared/package.json b/packages/dashboard-shared/package.json
index c328ff8a3..695dfe130 100644
--- a/packages/dashboard-shared/package.json
+++ b/packages/dashboard-shared/package.json
@@ -1,6 +1,6 @@
{
"name": "@mercurjs/dashboard-shared",
- "version": "2.0.0-canary.74",
+ "version": "2.0.0-canary.75",
"repository": {
"type": "git",
"url": "https://github.com/mercurjs/mercur",
diff --git a/packages/types/package.json b/packages/types/package.json
index e2a14da4c..dc74efd95 100644
--- a/packages/types/package.json
+++ b/packages/types/package.json
@@ -1,6 +1,6 @@
{
"name": "@mercurjs/types",
- "version": "2.0.0-canary.74",
+ "version": "2.0.0-canary.75",
"repository": {
"type": "git",
"url": "https://github.com/mercurjs/mercur",
diff --git a/packages/vendor/package.json b/packages/vendor/package.json
index e54cfdca2..d1fd13a7a 100644
--- a/packages/vendor/package.json
+++ b/packages/vendor/package.json
@@ -1,6 +1,6 @@
{
"name": "@mercurjs/vendor",
- "version": "2.0.0-canary.74",
+ "version": "2.0.0-canary.75",
"repository": {
"type": "git",
"url": "https://github.com/mercurjs/mercur",