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
parent 8424236799
commit e143a86976
2 changed files with 14 additions and 11 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
fix(medusa): Plugin repository loader to work with Typeorm update

View File

@@ -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<unknown>
const loaded = require(fn)
Object.entries(loaded).map(
([, val]: [string, ClassConstructor<unknown>]) => {
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),
})
}
)
})
})
}