From ef26a3243b60e31093b39318112ddcdc5ea092c4 Mon Sep 17 00:00:00 2001 From: Kasper Fabricius Kristensen <45367945+kasperkristensen@users.noreply.github.com> Date: Thu, 9 Jan 2025 14:43:07 +0100 Subject: [PATCH] fix tests and build --- .../admin/admin-bundler/src/lib/config.ts | 20 ++++++++++++++++- .../admin/admin-bundler/src/lib/plugin.ts | 22 +++++++++++++------ .../src/routes/generate-menu-items.ts | 4 ++-- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/packages/admin/admin-bundler/src/lib/config.ts b/packages/admin/admin-bundler/src/lib/config.ts index 26cea424fad74..9f9122d67d4db 100644 --- a/packages/admin/admin-bundler/src/lib/config.ts +++ b/packages/admin/admin-bundler/src/lib/config.ts @@ -1,8 +1,8 @@ import { VIRTUAL_MODULES } from "@medusajs/admin-shared" +import fs from "fs" import path from "path" import { Config } from "tailwindcss" import type { InlineConfig } from "vite" - import { BundlerOptions } from "../types" export async function getViteConfig( @@ -104,6 +104,24 @@ function createTailwindConfig(entry: string, sources: string[] = []) { const extensions = sources.map((s) => path.join(s, "**/*.{js,ts,jsx,tsx}")) + const presets: string[] = [require("@medusajs/ui-preset")] + + /** + * Look for a preset.{ts,js} file in each of the sources. If it exists, we should push it to the presets array. + */ + for (const source of sources) { + const tsPreset = path.join(source, `preset.ts`) + if (fs.existsSync(tsPreset)) { + presets.push(tsPreset) + continue + } + + const jsPreset = path.join(source, `preset.js`) + if (fs.existsSync(jsPreset)) { + presets.push(jsPreset) + } + } + const config: Config = { presets: [require("@medusajs/ui-preset")], content: [html, root, dashboard, ui, ...extensions], diff --git a/packages/admin/admin-bundler/src/lib/plugin.ts b/packages/admin/admin-bundler/src/lib/plugin.ts index 35b5977e37787..44c0261faf750 100644 --- a/packages/admin/admin-bundler/src/lib/plugin.ts +++ b/packages/admin/admin-bundler/src/lib/plugin.ts @@ -1,3 +1,4 @@ +import { readFileSync } from "fs" import { glob } from "glob" import path from "path" import { UserConfig } from "vite" @@ -16,6 +17,19 @@ export async function plugin() { return acc }, {} as Record) + const pkg = JSON.parse( + readFileSync(path.resolve(process.cwd(), "package.json"), "utf-8") + ) + const external = new Set([ + ...Object.keys(pkg.dependencies || {}), + ...Object.keys(pkg.peerDependencies || {}), + "react", + "react-dom", + "react/jsx-runtime", + "react-router-dom", + "@medusajs/admin-sdk", + ]) + const pluginConfig: UserConfig = { build: { lib: { @@ -25,13 +39,7 @@ export async function plugin() { minify: false, outDir: path.resolve(process.cwd(), "dist"), rollupOptions: { - external: [ - "react", - "react-dom", - "react/jsx-runtime", - "react-router-dom", - "@medusajs/admin-sdk", - ], + external: [...external], output: { globals: { react: "React", diff --git a/packages/admin/admin-vite-plugin/src/routes/generate-menu-items.ts b/packages/admin/admin-vite-plugin/src/routes/generate-menu-items.ts index 54db4a87f0d5a..f6195b6dd5140 100644 --- a/packages/admin/admin-vite-plugin/src/routes/generate-menu-items.ts +++ b/packages/admin/admin-vite-plugin/src/routes/generate-menu-items.ts @@ -219,11 +219,11 @@ function processConfigProperties( const nested = properties.find( (prop) => isObjectProperty(prop) && isIdentifier(prop.key, { name: "nested" }) - ) as ObjectProperty + ) as ObjectProperty | undefined let nestedValue: string | undefined = undefined - if (isStringLiteral(nested.value)) { + if (isStringLiteral(nested?.value)) { nestedValue = nested.value.value }