fix: custom link resolution in medusa app (#7950)
* fix custom link resolution in medusa app * improve * fix duplicate
This commit is contained in:
1 parent
5544303b91
commit
f49139b20f
3 files changed
+16
-12
No files matched your search
@@ -435,12 +435,6 @@ async function MedusaApp_({
|
|||||||
...(sharedResourcesConfig?.database ?? {}),
|
...(sharedResourcesConfig?.database ?? {}),
|
||||||
}
|
}
|
||||||
|
|
||||||
const customLinks = MedusaModule.getCustomLinks().map((link) => {
|
|
||||||
return typeof link === "function"
|
|
||||||
? link(MedusaModule.getAllJoinerConfigs())
|
|
||||||
: link
|
|
||||||
})
|
|
||||||
|
|
||||||
if (revert) {
|
if (revert) {
|
||||||
revertLinkModuleMigration &&
|
revertLinkModuleMigration &&
|
||||||
(await revertLinkModuleMigration(
|
(await revertLinkModuleMigration(
|
||||||
@@ -448,7 +442,7 @@ async function MedusaApp_({
|
|||||||
options: linkModuleOpt,
|
options: linkModuleOpt,
|
||||||
injectedDependencies,
|
injectedDependencies,
|
||||||
},
|
},
|
||||||
customLinks
|
linkModules
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
linkModuleMigration &&
|
linkModuleMigration &&
|
||||||
@@ -457,7 +451,7 @@ async function MedusaApp_({
|
|||||||
options: linkModuleOpt,
|
options: linkModuleOpt,
|
||||||
injectedDependencies,
|
injectedDependencies,
|
||||||
},
|
},
|
||||||
customLinks
|
linkModules
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import { LinkModulesExtraFields, ModuleJoinerConfig } from "@medusajs/types"
|
|||||||
import { isObject, pluralize, toPascalCase } from "../common"
|
import { isObject, pluralize, toPascalCase } from "../common"
|
||||||
import { composeLinkName } from "../link"
|
import { composeLinkName } from "../link"
|
||||||
|
|
||||||
|
export const DefineLinkSymbol = Symbol.for("DefineLink")
|
||||||
|
|
||||||
type InputSource = {
|
type InputSource = {
|
||||||
serviceName: string
|
serviceName: string
|
||||||
field: string
|
field: string
|
||||||
@@ -116,7 +118,7 @@ export function defineLink(
|
|||||||
throw new Error(`Invalid linkable passed for the second argument`)
|
throw new Error(`Invalid linkable passed for the second argument`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const output = { serviceName: "" }
|
const output = { [DefineLinkSymbol]: true, serviceName: "" }
|
||||||
|
|
||||||
const register = function (
|
const register = function (
|
||||||
modules: ModuleJoinerConfig[]
|
modules: ModuleJoinerConfig[]
|
||||||
|
|||||||
@@ -4,7 +4,11 @@ import {
|
|||||||
ModuleJoinerConfig,
|
ModuleJoinerConfig,
|
||||||
PluginDetails,
|
PluginDetails,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import { ContainerRegistrationKeys, isObject } from "@medusajs/utils"
|
import {
|
||||||
|
ContainerRegistrationKeys,
|
||||||
|
DefineLinkSymbol,
|
||||||
|
isObject,
|
||||||
|
} from "@medusajs/utils"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* import files from the links directory to retrieve the links to be loaded
|
* import files from the links directory to retrieve the links to be loaded
|
||||||
@@ -42,8 +46,12 @@ export async function resolvePluginsLinks(
|
|||||||
return import_.default
|
return import_.default
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
).filter(Boolean)
|
).filter((value) => {
|
||||||
|
return isObject(value) && !value[DefineLinkSymbol]
|
||||||
|
})
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
).flat(Infinity)
|
)
|
||||||
|
.flat(Infinity)
|
||||||
|
.filter(Boolean)
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user