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.68

vholikadcc9a9a222d
diff --git a/packages/admin/package.json b/packages/admin/package.json
index a883c74b6..a87aa3b9a 100644
--- a/packages/admin/package.json
+++ b/packages/admin/package.json
@@ -1,6 +1,6 @@
{
"name": "@mercurjs/admin",
- "version": "2.0.0-canary.67",
+ "version": "2.0.0-canary.68",
"repository": {
"type": "git",
"url": "https://github.com/mercurjs/mercur",
diff --git a/packages/cli/package.json b/packages/cli/package.json
index 4708d8f60..bf071848f 100644
--- a/packages/cli/package.json
+++ b/packages/cli/package.json
@@ -1,6 +1,6 @@
{
"name": "@mercurjs/cli",
- "version": "2.0.0-canary.67",
+ "version": "2.0.0-canary.68",
"repository": {
"type": "git",
"url": "https://github.com/mercurjs/mercur",
diff --git a/packages/client/package.json b/packages/client/package.json
index 2ec67c5fe..e4d7604bf 100644
--- a/packages/client/package.json
+++ b/packages/client/package.json
@@ -1,6 +1,6 @@
{
"name": "@mercurjs/client",
- "version": "2.0.0-canary.67",
+ "version": "2.0.0-canary.68",
"repository": {
"type": "git",
"url": "https://github.com/mercurjs/mercur",
diff --git a/packages/core-plugin/package.json b/packages/core-plugin/package.json
index c08335f30..961b82823 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.67",
+ "version": "2.0.0-canary.68",
"repository": {
"type": "git",
"url": "https://github.com/mercurjs/mercur",
diff --git a/packages/dashboard-sdk/package.json b/packages/dashboard-sdk/package.json
index 5f2e685bc..390fea30b 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.67",
+ "version": "2.0.0-canary.68",
"repository": {
"type": "git",
"url": "https://github.com/mercurjs/mercur",
diff --git a/packages/dashboard-sdk/src/menu-items.ts b/packages/dashboard-sdk/src/menu-items.ts
index 2e354c5b3..680532453 100644
--- a/packages/dashboard-sdk/src/menu-items.ts
+++ b/packages/dashboard-sdk/src/menu-items.ts
@@ -172,18 +172,14 @@ function parseFile(
}
}
-export function generateMenuItems({ srcDir }: BuiltMercurConfig): string {
+export function generateMenuItems({ srcDir, pluginDirs }: BuiltMercurConfig): string {
const pagesDir = path.join(srcDir, "pages")
- const files = crawlPages(pagesDir)
-
- if (files.length === 0) {
- return `export default { menuItems: [] }`
- }
let index = 0
const results: MenuItemResult[] = []
- for (const file of files) {
+ // App's own pages
+ for (const file of crawlPages(pagesDir)) {
const result = parseFile(file, pagesDir, index)
if (result) {
results.push(result)
@@ -191,6 +187,17 @@ export function generateMenuItems({ srcDir }: BuiltMercurConfig): string {
}
}
+ // Plugin pages
+ for (const pluginDir of pluginDirs) {
+ for (const file of crawlPages(pluginDir)) {
+ const result = parseFile(file, pluginDir, index)
+ if (result) {
+ results.push(result)
+ index++
+ }
+ }
+ }
+
if (results.length === 0) {
return `export default { menuItems: [] }`
}
diff --git a/packages/dashboard-sdk/src/plugin.ts b/packages/dashboard-sdk/src/plugin.ts
index ccb1603cc..39be77cd9 100644
--- a/packages/dashboard-sdk/src/plugin.ts
+++ b/packages/dashboard-sdk/src/plugin.ts
@@ -1,5 +1,6 @@
import type * as Vite from "vite"
import path from "path"
+import fs from "fs"
import { getFileExports } from "./utils"
import { RESOLVED_ROUTES_MODULE } from "./constants"
import { isVirtualModule, resolveVirtualModule, loadVirtualModule } from "./virtual-modules"
@@ -15,29 +16,79 @@ const UI_MODULE_KEYS = [
"vendor_ui",
]
-async function loadMedusaConfig(medusaConfigPath: string, root: string): Promise<{ base?: string }> {
+function resolvePluginRoot(resolve: string, configDir: string): string | null {
+ try {
+ if (resolve.startsWith(".")) {
+ return path.resolve(configDir, resolve)
+ }
+
+ const pkgJsonPath = require.resolve(path.join(resolve, "package.json"), {
+ paths: [configDir],
+ })
+ return path.dirname(pkgJsonPath)
+ } catch {
+ return null
+ }
+}
+
+function resolvePluginDirs(
+ plugins: any[],
+ configDir: string,
+ appType: "admin" | "vendor"
+): string[] {
+ const dirs: string[] = []
+
+ for (const plugin of plugins) {
+ const resolve = typeof plugin === "string"
+ ? plugin
+ : plugin?.resolve
+
+ if (!resolve || typeof resolve !== "string") continue
+
+ const pluginRoot = resolvePluginRoot(resolve, configDir)
+ if (!pluginRoot) continue
+
+ const extDir = path.join(pluginRoot, appType)
+ if (fs.existsSync(extDir) && fs.statSync(extDir).isDirectory()) {
+ dirs.push(extDir)
+ }
+ }
+
+ return dirs
+}
+
+async function loadMedusaConfig(medusaConfigPath: string, root: string): Promise<{ base?: string; pluginDirs: string[] }> {
try {
const mod = await getFileExports(medusaConfigPath)
const medusaConfig = mod.default ?? mod
const modules = medusaConfig?.modules ?? {}
+ const configDir = path.dirname(medusaConfigPath)
+
+ let base: string | undefined
+ let appType: "admin" | "vendor" | undefined
for (const key of UI_MODULE_KEYS) {
const value = modules[key]
if (!value || typeof value !== "object" || !value.options?.appDir) continue
- const appDir = path.resolve(path.dirname(medusaConfigPath), value.options.appDir)
+ const appDir = path.resolve(configDir, value.options.appDir)
if (appDir === root) {
- return {
- base: value.options.path,
- }
+ base = value.options.path
+ appType = key === "admin_ui" ? "admin" : "vendor"
+ break
}
}
- return {}
+ const plugins = medusaConfig?.plugins ?? []
+ const pluginDirs = appType
+ ? resolvePluginDirs(plugins, configDir, appType)
+ : []
+
+ return { base, pluginDirs }
} catch {
- return {}
+ return { pluginDirs: [] }
}
}
@@ -51,7 +102,7 @@ export function mercurDashboardPlugin(pluginConfig: MercurConfig): Vite.Plugin {
root = viteConfig.root || process.cwd()
const medusaConfigPath = path.resolve(root, pluginConfig.medusaConfigPath)
- const { base } = await loadMedusaConfig(medusaConfigPath, root)
+ const { base, pluginDirs } = await loadMedusaConfig(medusaConfigPath, root)
const srcDir = path.join(root, "src")
const backendUrl = pluginConfig.backendUrl ?? "http://localhost:9000"
@@ -62,6 +113,7 @@ export function mercurDashboardPlugin(pluginConfig: MercurConfig): Vite.Plugin {
base,
root,
srcDir,
+ pluginDirs,
}
return {
diff --git a/packages/dashboard-sdk/src/routes.ts b/packages/dashboard-sdk/src/routes.ts
index d7de0aabc..2766bfdaf 100644
--- a/packages/dashboard-sdk/src/routes.ts
+++ b/packages/dashboard-sdk/src/routes.ts
@@ -237,18 +237,14 @@ function buildRouteTree(results: RouteResult[]): RouteResult[] {
return Array.from(routeMap.values())
}
-export function generateRoutes({ srcDir }: BuiltMercurConfig): string {
+export function generateRoutes({ srcDir, pluginDirs }: BuiltMercurConfig): string {
const pagesDir = path.join(srcDir, "pages")
- const files = crawlPages(pagesDir)
-
- if (files.length === 0) {
- return `export const customRoutes = []`
- }
let index = 0
const results: RouteResult[] = []
- for (const file of files) {
+ // App's own pages
+ for (const file of crawlPages(pagesDir)) {
const result = parseFile(file, pagesDir, index)
if (result) {
results.push(result)
@@ -256,6 +252,16 @@ export function generateRoutes({ srcDir }: BuiltMercurConfig): string {
}
}
+ for (const pluginDir of pluginDirs) {
+ for (const file of crawlPages(pluginDir)) {
+ const result = parseFile(file, pluginDir, index)
+ if (result) {
+ results.push(result)
+ index++
+ }
+ }
+ }
+
if (results.length === 0) {
return `export const customRoutes = []`
}
diff --git a/packages/dashboard-sdk/src/types.ts b/packages/dashboard-sdk/src/types.ts
index 3b3b1e78d..96b596323 100644
--- a/packages/dashboard-sdk/src/types.ts
+++ b/packages/dashboard-sdk/src/types.ts
@@ -21,6 +21,7 @@ export interface BuiltMercurConfig extends MercurConfig {
base?: string;
root: string
srcDir: string
+ pluginDirs: string[]
}
export type RouteConfig = {
diff --git a/packages/dashboard-shared/package.json b/packages/dashboard-shared/package.json
index b72b81392..7fcba3594 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.67",
+ "version": "2.0.0-canary.68",
"repository": {
"type": "git",
"url": "https://github.com/mercurjs/mercur",
diff --git a/packages/types/package.json b/packages/types/package.json
index 24a7a9c33..f8f71d03a 100644
--- a/packages/types/package.json
+++ b/packages/types/package.json
@@ -1,6 +1,6 @@
{
"name": "@mercurjs/types",
- "version": "2.0.0-canary.67",
+ "version": "2.0.0-canary.68",
"repository": {
"type": "git",
"url": "https://github.com/mercurjs/mercur",
diff --git a/packages/vendor/package.json b/packages/vendor/package.json
index 158c54335..f2958e961 100644
--- a/packages/vendor/package.json
+++ b/packages/vendor/package.json
@@ -1,6 +1,6 @@
{
"name": "@mercurjs/vendor",
- "version": "2.0.0-canary.67",
+ "version": "2.0.0-canary.68",
"repository": {
"type": "git",
"url": "https://github.com/mercurjs/mercur",
diff --git a/templates/basic/apps/vendor/README.md b/templates/basic/apps/vendor/README.md
deleted file mode 100644
index d2e77611f..000000000
--- a/templates/basic/apps/vendor/README.md
+++ /dev/null
@@ -1,73 +0,0 @@
-# React + TypeScript + Vite
-
-This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
-
-Currently, two official plugins are available:
-
-- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
-- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
-
-## React Compiler
-
-The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
-
-## Expanding the ESLint configuration
-
-If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
-
-```js
-export default defineConfig([
- globalIgnores(['dist']),
- {
- files: ['**/*.{ts,tsx}'],
- extends: [
- // Other configs...
-
- // Remove tseslint.configs.recommended and replace with this
- tseslint.configs.recommendedTypeChecked,
- // Alternatively, use this for stricter rules
- tseslint.configs.strictTypeChecked,
- // Optionally, add this for stylistic rules
- tseslint.configs.stylisticTypeChecked,
-
- // Other configs...
- ],
- languageOptions: {
- parserOptions: {
- project: ['./tsconfig.node.json', './tsconfig.app.json'],
- tsconfigRootDir: import.meta.dirname,
- },
- // other options...
- },
- },
-])
-```
-
-You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
-
-```js
-// eslint.config.js
-import reactX from 'eslint-plugin-react-x'
-import reactDom from 'eslint-plugin-react-dom'
-
-export default defineConfig([
- globalIgnores(['dist']),
- {
- files: ['**/*.{ts,tsx}'],
- extends: [
- // Other configs...
- // Enable lint rules for React
- reactX.configs['recommended-typescript'],
- // Enable lint rules for React DOM
- reactDom.configs.recommended,
- ],
- languageOptions: {
- parserOptions: {
- project: ['./tsconfig.node.json', './tsconfig.app.json'],
- tsconfigRootDir: import.meta.dirname,
- },
- // other options...
- },
- },
-])
-```