From e143a86976a5cc6a53b7a795e8486df4db1d1c09 Mon Sep 17 00:00:00 2001 From: Adrien de Peretti Date: Wed, 1 Mar 2023 18:14:36 +0100 Subject: [PATCH] fix(medusa): Plugin repository loader (#3345) * fix(medusa): Plugin repository loader * Create brave-goats-pay.md --------- Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com> --- .changeset/brave-goats-pay.md | 5 +++++ packages/medusa/src/loaders/plugins.ts | 20 +++++++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 .changeset/brave-goats-pay.md diff --git a/.changeset/brave-goats-pay.md b/.changeset/brave-goats-pay.md new file mode 100644 index 0000000000..8b63b1e7f0 --- /dev/null +++ b/.changeset/brave-goats-pay.md @@ -0,0 +1,5 @@ +--- +"@medusajs/medusa": patch +--- + +fix(medusa): Plugin repository loader to work with Typeorm update diff --git a/packages/medusa/src/loaders/plugins.ts b/packages/medusa/src/loaders/plugins.ts index ac3d27ac99..28ac45cf77 100644 --- a/packages/medusa/src/loaders/plugins.ts +++ b/packages/medusa/src/loaders/plugins.ts @@ -1,4 +1,4 @@ -import { aliasTo, asClass, asFunction, asValue } from "awilix" +import { aliasTo, asFunction, asValue } from "awilix" import { Express } from "express" import fs from "fs" import { sync as existsSync } from "fs-exists-cached" @@ -495,18 +495,16 @@ function registerRepositories( ): void { const files = glob.sync(`${pluginDetails.resolve}/repositories/*.js`, {}) files.forEach((fn) => { - const loaded = require(fn) as ClassConstructor + const loaded = require(fn) - Object.entries(loaded).map( - ([, val]: [string, ClassConstructor]) => { - if (typeof val === "function") { - const name = formatRegistrationName(fn) - container.register({ - [name]: asClass(val), - }) - } + Object.entries(loaded).map(([, val]: [string, any]) => { + if (typeof loaded === "object") { + const name = formatRegistrationName(fn) + container.register({ + [name]: asValue(val), + }) } - ) + }) }) }