Skip to content

Commit

Permalink
fix tests and build
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperkristensen committed Jan 9, 2025
1 parent f3881bf commit ef26a32
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
20 changes: 19 additions & 1 deletion packages/admin/admin-bundler/src/lib/config.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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],
Expand Down
22 changes: 15 additions & 7 deletions packages/admin/admin-bundler/src/lib/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { readFileSync } from "fs"
import { glob } from "glob"
import path from "path"
import { UserConfig } from "vite"
Expand All @@ -16,6 +17,19 @@ export async function plugin() {
return acc
}, {} as Record<string, string>)

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: {
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit ef26a32

Please sign in to comment.