fix: load custom modules by path (#6312)
What:
medusa-config.js loading custom modules by their path.
```typescript
{
modules: {
internalModule: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
resolve: "./internal_module",
definition: {
key: "internalModule",
registrationName: "internalModule",
},
},
}
}
```
This commit is contained in:
@@ -18,7 +18,6 @@ describe("module definitions loader", () => {
|
||||
label: "TestService",
|
||||
isLegacy: true,
|
||||
isRequired: false,
|
||||
canOverride: true,
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
|
||||
@@ -94,7 +94,7 @@ function getInternalModuleResolution(
|
||||
|
||||
// If user added a module and it's overridable, we resolve that instead
|
||||
const isString = typeof moduleConfig === "string"
|
||||
if (definition.canOverride && (isString || (isObj && moduleConfig.resolve))) {
|
||||
if (isString || (isObj && moduleConfig.resolve)) {
|
||||
resolutionPath = !moduleExports
|
||||
? resolveCwd(isString ? moduleConfig : (moduleConfig.resolve as string))
|
||||
: // Explicitly assign an empty string, later, we will check if the value is exactly false.
|
||||
|
||||
@@ -29,12 +29,12 @@ export async function loadInternalModule(
|
||||
// the exports. This is useful when a package export an initialize function which will bootstrap itself and therefore
|
||||
// does not need to import the package that is currently being loaded as it would create a
|
||||
// circular reference.
|
||||
const path = resolution.resolutionPath as string
|
||||
const modulePath = resolution.resolutionPath as string
|
||||
|
||||
if (resolution.moduleExports) {
|
||||
loadedModule = resolution.moduleExports
|
||||
} else {
|
||||
loadedModule = await import(path)
|
||||
loadedModule = await import(modulePath)
|
||||
loadedModule = (loadedModule as any).default
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user