Skip to content

Commit

Permalink
discover extensions from plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperkristensen committed Jan 9, 2025
1 parent 2ed208b commit cebeaba
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
19 changes: 14 additions & 5 deletions packages/medusa/src/loaders/admin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { logger } from "@medusajs/framework/logger"
import { AdminOptions, ConfigModule } from "@medusajs/framework/types"
import {
AdminOptions,
ConfigModule,
PluginDetails,
} from "@medusajs/framework/types"
import { Express } from "express"
import fs from "fs"
import path from "path"
Expand All @@ -9,6 +13,7 @@ type Options = {
app: Express
configModule: ConfigModule
rootDirectory: string
plugins: PluginDetails[]
}

type IntializedOptions = Required<Pick<AdminOptions, "path" | "disable">> &
Expand All @@ -23,16 +28,20 @@ export default async function adminLoader({
app,
configModule,
rootDirectory,
plugins,
}: Options) {
const { admin } = configModule

const sources: string[] = []

const projectSource = path.join(rootDirectory, "src", "admin")
for (const plugin of plugins) {
const pluginSource = plugin.resolve.endsWith("/src")
? path.join(plugin.resolve, "admin")
: path.join(plugin.resolve, "src", "admin")

// check if the projectSource exists
if (fs.existsSync(projectSource)) {
sources.push(projectSource)
if (fs.existsSync(pluginSource)) {
sources.push(pluginSource)
}
}

const adminOptions: IntializedOptions = {
Expand Down
22 changes: 11 additions & 11 deletions packages/medusa/src/loaders/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import { container, MedusaAppLoader } from "@medusajs/framework"
import { configLoader } from "@medusajs/framework/config"
import { pgConnectionLoader } from "@medusajs/framework/database"
import { featureFlagsLoader } from "@medusajs/framework/feature-flags"
import { expressLoader } from "@medusajs/framework/http"
import { JobLoader } from "@medusajs/framework/jobs"
import { LinkLoader } from "@medusajs/framework/links"
import { logger } from "@medusajs/framework/logger"
import { SubscriberLoader } from "@medusajs/framework/subscribers"
import {
ConfigModule,
LoadedModule,
Expand All @@ -9,23 +18,14 @@ import {
GraphQLSchema,
promiseAll,
} from "@medusajs/framework/utils"
import { WorkflowLoader } from "@medusajs/framework/workflows"
import { asValue } from "awilix"
import { Express, NextFunction, Request, Response } from "express"
import { join } from "path"
import requestIp from "request-ip"
import { v4 } from "uuid"
import adminLoader from "./admin"
import apiLoader from "./api"
import { configLoader } from "@medusajs/framework/config"
import { expressLoader } from "@medusajs/framework/http"
import { JobLoader } from "@medusajs/framework/jobs"
import { LinkLoader } from "@medusajs/framework/links"
import { logger } from "@medusajs/framework/logger"
import { container, MedusaAppLoader } from "@medusajs/framework"
import { pgConnectionLoader } from "@medusajs/framework/database"
import { SubscriberLoader } from "@medusajs/framework/subscribers"
import { WorkflowLoader } from "@medusajs/framework/workflows"
import { featureFlagsLoader } from "@medusajs/framework/feature-flags"
import { getResolvedPlugins } from "./helpers/resolve-plugins"

type Options = {
Expand Down Expand Up @@ -106,7 +106,7 @@ async function loadEntrypoints(
next()
})

await adminLoader({ app: expressApp, configModule, rootDirectory })
await adminLoader({ app: expressApp, configModule, rootDirectory, plugins })
await apiLoader({
container,
plugins,
Expand Down

0 comments on commit cebeaba

Please sign in to comment.