From 99ab2fa2b87d90b741ad7c34e032b1c3acb3213f Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Fri, 10 Jan 2025 15:06:26 +0530 Subject: [PATCH] refactor: remove import of admin-bundler and accept it as an argument --- .../core/framework/src/build-tools/compiler.ts | 16 ++++++++++------ packages/medusa/src/commands/build.ts | 3 ++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/core/framework/src/build-tools/compiler.ts b/packages/core/framework/src/build-tools/compiler.ts index 2f9d283869bfd..7247c326b91a6 100644 --- a/packages/core/framework/src/build-tools/compiler.ts +++ b/packages/core/framework/src/build-tools/compiler.ts @@ -1,8 +1,8 @@ import path from "path" import type tsStatic from "typescript" import { getConfigFile } from "@medusajs/utils" -import type { ConfigModule, Logger } from "@medusajs/types" import { access, constants, copyFile, rm } from "fs/promises" +import type { AdminOptions, ConfigModule, Logger } from "@medusajs/types" /** * The compiler exposes the opinionated APIs for compiling Medusa @@ -299,7 +299,14 @@ export class Compiler { */ async buildAppFrontend( adminOnly: boolean, - tsConfig: tsStatic.ParsedCommandLine + adminBundler: { + build: ( + options: AdminOptions & { + sources: string[] + outDir: string + } + ) => Promise + } ): Promise { const tracker = this.#trackDuration() @@ -335,10 +342,7 @@ export class Compiler { try { this.#logger.info("Compiling frontend source...") - const { build: buildProductionBuild } = await import( - "@medusajs/admin-bundler" - ) - await buildProductionBuild({ + await adminBundler.build({ disable: false, sources: [this.#adminSourceFolder], ...configFile.configModule.admin, diff --git a/packages/medusa/src/commands/build.ts b/packages/medusa/src/commands/build.ts index 13fd38fba5233..7348d6ef01e48 100644 --- a/packages/medusa/src/commands/build.ts +++ b/packages/medusa/src/commands/build.ts @@ -22,7 +22,8 @@ export default async function build({ promises.push(compiler.buildAppBackend(tsConfig)) } - promises.push(compiler.buildAppFrontend(adminOnly, tsConfig)) + const bundler = await import("@medusajs/admin-bundler") + promises.push(compiler.buildAppFrontend(adminOnly, bundler)) await Promise.all(promises) return true }