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.

fix(deploy): pin @mercurjs deps to source version and load vite plugin via createRequire

vholik9c0d2902abff
diff --git a/scripts/deploy.sh b/scripts/deploy.sh
index 768532769..a017d55fa 100755
--- a/scripts/deploy.sh
+++ b/scripts/deploy.sh
@@ -9,7 +9,7 @@
set -euo pipefail
HOST="${MERCUR_HOST:[email protected]}"
-BRANCH="${MERCUR_BRANCH:-canary}"
+BRANCH="${MERCUR_BRANCH:-main}"
BACKEND_URL="${MERCUR_BACKEND_URL:-https://new.mercur.dev}"
echo "→ Deploying $BRANCH to $HOST (backend: $BACKEND_URL)"
@@ -79,15 +79,23 @@ mkdir -p "$DEPLOY_DIR/packages/api/apps"
ln -sfn "$DEPLOY_DIR/apps/admin" "$DEPLOY_DIR/packages/api/apps/admin"
ln -sfn "$DEPLOY_DIR/apps/vendor" "$DEPLOY_DIR/packages/api/apps/vendor"
-# Patch the dashboard Vite configs. @mercurjs/dashboard-sdk defaults
-# backendUrl to http://localhost:9000 — that gets baked into the SPA
-# bundle and breaks every non-local deployment. We pass an empty string
-# so API calls go to the same origin the dashboard is served from.
+# Patch the dashboard Vite configs. Two things baked in here:
+# 1. backendUrl: @mercurjs/dashboard-sdk defaults it to http://localhost:9000,
+# which gets baked into the SPA bundle and breaks every non-local deploy.
+# We pass an empty string so API calls go to the same origin the dashboard
+# is served from.
+# 2. Plugin loaded via createRequire, not a static import: the plugin's ESM
+# build can't dynamic-require medusa-config.ts, so base detection silently
+# falls back to "/" and every panel asset 404s under its sub-path.
+# createRequire resolves its CJS build, where dynamic require works.
for app in admin vendor; do
cat > "$DEPLOY_DIR/apps/$app/vite.config.ts" <<VITE
import { defineConfig } from "vite"
import react from "@vitejs/plugin-react"
-import { mercurDashboardPlugin } from "@mercurjs/dashboard-sdk"
+import { createRequire } from "node:module"
+
+const require = createRequire(import.meta.url)
+const { mercurDashboardPlugin } = require("@mercurjs/dashboard-sdk/vite")
export default defineConfig({
plugins: [
@@ -197,6 +205,12 @@ VERSION=$(python3 -c "import json; print(json.load(open('$SOURCE_DIR/packages/co
# compiled prod dir — the latter's package.json is regenerated by
# `medusa build` and never inherits the workspace rewrite, so its transitive
# @mercurjs/* edges would otherwise re-hit the quarantine.
+#
+# VERSION comes from the synced source tree (packages/core/package.json), i.e.
+# the latest canary on $BRANCH. We deliberately IGNORE whatever @mercurjs/*
+# version templates/basic pins (e.g. an older 2.2.0-rc.0) and force every
+# @mercurjs/* dep — direct and transitive — to VERSION. Otherwise the deploy
+# ships a stale panel bundle that lags behind main.
rewrite_mercur_deps() {
( cd "$1" && VERSION="$VERSION" SOURCE_DIR="$SOURCE_DIR" python3 - <<'PY'
import json, glob, os
@@ -236,17 +250,24 @@ for path in ["package.json"] + glob.glob("packages/*/package.json") + glob.glob(
for key in ("dependencies", "devDependencies", "peerDependencies", "optionalDependencies"):
deps = data.get(key) or {}
for name, spec in list(deps.items()):
- if name.startswith(SCOPE) and spec == VERSION:
- deps[name] = tarball(name, VERSION)
- changed = True
- # Force transitive @mercurjs/* edges to tarballs via root resolutions.
+ # Force any published @mercurjs/* dep to the source-tree VERSION,
+ # regardless of the version templates/basic pins. `workspace:*`
+ # edges are left alone — those are resolved locally, not fetched.
+ if name in mercur_names and not str(spec).startswith("workspace:"):
+ url = tarball(name, VERSION)
+ if deps[name] != url:
+ deps[name] = url
+ changed = True
+ # Force every @mercurjs/* edge (direct + transitive, any requested range)
+ # to the VERSION tarball via root resolutions. An unversioned resolution
+ # key overrides all specifiers, so a manifest pinning an older tag
+ # (e.g. 2.2.0-rc.0) still resolves to VERSION.
if path == "package.json":
resolutions = data.get("resolutions") or {}
for name in sorted(mercur_names):
- key = f"{name}@{VERSION}"
url = tarball(name, VERSION)
- if resolutions.get(key) != url:
- resolutions[key] = url
+ if resolutions.get(name) != url:
+ resolutions[name] = url
changed = True
if zod_pin and resolutions.get("zod") != zod_pin:
resolutions["zod"] = zod_pin