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>
This commit is contained in:
Adrien de Peretti
2023-03-01 18:14:36 +01:00
committed by GitHub
co-authored by Oliver Windall Juhl
parent 8424236799
commit e143a86976
2 changed files with 14 additions and 11 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
fix(medusa): Plugin repository loader to work with Typeorm update
+9 -11
View File
@@ -1,4 +1,4 @@
import { aliasTo, asClass, asFunction, asValue } from "awilix" import { aliasTo, asFunction, asValue } from "awilix"
import { Express } from "express" import { Express } from "express"
import fs from "fs" import fs from "fs"
import { sync as existsSync } from "fs-exists-cached" import { sync as existsSync } from "fs-exists-cached"
@@ -495,18 +495,16 @@ function registerRepositories(
): void { ): void {
const files = glob.sync(`${pluginDetails.resolve}/repositories/*.js`, {}) const files = glob.sync(`${pluginDetails.resolve}/repositories/*.js`, {})
files.forEach((fn) => { files.forEach((fn) => {
const loaded = require(fn) as ClassConstructor<unknown> const loaded = require(fn)
Object.entries(loaded).map( Object.entries(loaded).map(([, val]: [string, any]) => {
([, val]: [string, ClassConstructor<unknown>]) => { if (typeof loaded === "object") {
if (typeof val === "function") { const name = formatRegistrationName(fn)
const name = formatRegistrationName(fn) container.register({
container.register({ [name]: asValue(val),
[name]: asClass(val), })
})
}
} }
) })
}) })
} }