Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Polish the Vite plugin: overlay per connection, correct file: handling
Damian Legawiec4098e9395fa0
diff --git a/packages/dashboard-core/src/vite/discover.ts b/packages/dashboard-core/src/vite/discover.tsindex 81c1c20b7c..740c0b00eb 100644--- a/packages/dashboard-core/src/vite/discover.ts+++ b/packages/dashboard-core/src/vite/discover.ts@@ -1,16 +1,18 @@import fs from 'node:fs'import { createRequire } from 'node:module'import path from 'node:path'+import { fileURLToPath } from 'node:url'/*** Walk a host project's `package.json` dependencies and return the names of* packages that opt-in as dashboard plugins by declaring* `"spree": { "dashboard": { "plugin": true } }` in their own `package.json`.*- * Auto-discovery is what makes `pnpm add @acme/foo-plugin` a one-step install- * for host-app developers — no manual edit of `vite.config.ts` to register- * the plugin name. Plugin authors opt-in by adding the marker field; hosts- * never have to know it exists.+ * Auto-discovery removes the `vite.config.ts` half of a plugin install —+ * Tailwind scanning is wired up the moment the dependency lands. (The host+ * still activates the plugin's code with a side-effect import in `main.tsx`.)+ * Plugin authors opt-in by adding the marker field; hosts never have to know+ * it exists.** Order is deterministic — the order packages appear in the host's combined* `dependencies` + `devDependencies` maps. Tailwind class scanning is@@ -108,7 +110,7 @@ function resolveManifest(pkg: string, require: NodeJS.Require): string | null {return null}- let current = path.dirname(entry.startsWith('file:') ? entry.slice(7) : entry)+ let current = path.dirname(entry.startsWith('file:') ? fileURLToPath(entry) : entry)const { root } = path.parse(current)while (current !== root) {const candidate = path.join(current, 'package.json')diff --git a/packages/dashboard-core/src/vite/index.ts b/packages/dashboard-core/src/vite/index.tsindex 8dc976c979..da35540e9a 100644--- a/packages/dashboard-core/src/vite/index.ts+++ b/packages/dashboard-core/src/vite/index.ts@@ -144,10 +144,11 @@ function dashboardTailwindSourcePlugin(options: SpreeDashboardPluginOptions): PlconfigureServer(server) {// Surface unresolved plugins as a Vite error overlay in dev so the// failure mode is loud. Without this, a missing plugin silently emits- // unstyled HTML when the host imports it.+ // unstyled HTML when the host imports it. Sent once per client+ // connection rather than per HTTP request.if (pluginErrors.length === 0) returnconst message = formatPluginErrorOverlay(pluginErrors)- server.middlewares.use((_req, _res, next) => {+ server.ws.on('connection', () => {server.ws.send({type: 'error',err: {@@ -156,7 +157,6 @@ function dashboardTailwindSourcePlugin(options: SpreeDashboardPluginOptions): Plplugin: 'spree:dashboard-tailwind-source',},})- next()})},}