chore: remove container registration name (#9137)
This commit is contained in:
@@ -9,7 +9,6 @@ const mockRegisterMedusaModule = jest.fn().mockImplementation(() => {
|
||||
moduleKey: {
|
||||
definition: {
|
||||
key: "moduleKey",
|
||||
registrationName: "moduleKey",
|
||||
},
|
||||
moduleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
|
||||
@@ -24,7 +24,6 @@ describe("modules loader", () => {
|
||||
testService: {
|
||||
resolutionPath: false,
|
||||
definition: {
|
||||
registrationName: "testService",
|
||||
key: "testService",
|
||||
defaultPackage: "testService",
|
||||
label: "TestService",
|
||||
@@ -53,7 +52,6 @@ describe("modules loader", () => {
|
||||
testService: {
|
||||
resolutionPath: "@modules/default",
|
||||
definition: {
|
||||
registrationName: "testService",
|
||||
key: "testService",
|
||||
defaultPackage: "testService",
|
||||
label: "TestService",
|
||||
@@ -94,7 +92,6 @@ describe("modules loader", () => {
|
||||
testService: {
|
||||
resolutionPath: "@modules/brokenloader",
|
||||
definition: {
|
||||
registrationName: "testService",
|
||||
key: "testService",
|
||||
defaultPackage: "testService",
|
||||
label: "TestService",
|
||||
@@ -120,7 +117,6 @@ describe("modules loader", () => {
|
||||
testService: {
|
||||
resolutionPath: "@modules/no-service",
|
||||
definition: {
|
||||
registrationName: "testService",
|
||||
key: "testService",
|
||||
defaultPackage: "testService",
|
||||
label: "TestService",
|
||||
@@ -148,7 +144,6 @@ describe("modules loader", () => {
|
||||
testService: {
|
||||
resolutionPath: "@modules/no-service",
|
||||
definition: {
|
||||
registrationName: "testService",
|
||||
key: "testService",
|
||||
defaultPackage: "testService",
|
||||
label: "TestService",
|
||||
@@ -178,7 +173,6 @@ describe("modules loader", () => {
|
||||
testService: {
|
||||
resolutionPath: "@medusajs/testService",
|
||||
definition: {
|
||||
registrationName: "testService",
|
||||
key: "testService",
|
||||
defaultPackage: "@medusajs/testService",
|
||||
label: "TestService",
|
||||
@@ -210,7 +204,6 @@ describe("modules loader", () => {
|
||||
testService: {
|
||||
resolutionPath: "@modules/no-service",
|
||||
definition: {
|
||||
registrationName: "testService",
|
||||
key: "testService",
|
||||
defaultPackage: "testService",
|
||||
label: "TestService",
|
||||
@@ -242,7 +235,6 @@ describe("modules loader", () => {
|
||||
testService: {
|
||||
resolutionPath: "@modules/no-service",
|
||||
definition: {
|
||||
registrationName: "testService",
|
||||
key: "testService",
|
||||
defaultPackage: "testService",
|
||||
label: "TestService",
|
||||
|
||||
@@ -9,7 +9,6 @@ jest.mock("resolve-cwd", () => jest.fn(() => RESOLVED_PACKAGE))
|
||||
describe("module definitions loader", () => {
|
||||
const defaultDefinition: ModuleDefinition = {
|
||||
key: "testService",
|
||||
registrationName: "testService",
|
||||
defaultPackage: "@medusajs/test-service",
|
||||
label: "TestService",
|
||||
isRequired: false,
|
||||
@@ -63,7 +62,6 @@ describe("module definitions loader", () => {
|
||||
definition: expect.objectContaining({
|
||||
key: "customModulesABC",
|
||||
label: "Custom: customModulesABC",
|
||||
registrationName: "customModulesABC",
|
||||
}),
|
||||
moduleDeclaration: {
|
||||
resources: "shared",
|
||||
|
||||
@@ -49,10 +49,7 @@ async function loadModule(
|
||||
throw new Error(`Module definition is missing property "key"`)
|
||||
}
|
||||
|
||||
modDefinition.registrationName ??= modDefinition.key
|
||||
|
||||
const registrationName = modDefinition.registrationName
|
||||
|
||||
const keyName = modDefinition.key
|
||||
const { scope, resources } = resolution.moduleDeclaration ?? ({} as any)
|
||||
|
||||
const canSkip =
|
||||
@@ -72,7 +69,7 @@ async function loadModule(
|
||||
message = `The module ${resolution.definition.label} is missing its resources config`
|
||||
}
|
||||
|
||||
container.register(registrationName, asValue(undefined))
|
||||
container.register(keyName, asValue(undefined))
|
||||
|
||||
return {
|
||||
error: new Error(message),
|
||||
@@ -80,7 +77,7 @@ async function loadModule(
|
||||
}
|
||||
|
||||
if (resolution.resolutionPath === false) {
|
||||
container.register(registrationName, asValue(undefined))
|
||||
container.register(keyName, asValue(undefined))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -84,7 +84,6 @@ function getCustomModuleResolution(
|
||||
isRequired: false,
|
||||
defaultPackage: "",
|
||||
dependencies,
|
||||
registrationName: key,
|
||||
defaultModuleDeclaration: {
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
|
||||
@@ -22,7 +22,6 @@ describe("load internal - load resources", () => {
|
||||
),
|
||||
definition: {
|
||||
key: "module-with-dml-mixed-without-joiner-config",
|
||||
registrationName: "service",
|
||||
label: "Module with DML mixed without joiner config",
|
||||
defaultPackage: false,
|
||||
defaultModuleDeclaration: {
|
||||
@@ -103,7 +102,6 @@ describe("load internal - load resources", () => {
|
||||
),
|
||||
definition: {
|
||||
key: "module-with-dml-without-joiner-config",
|
||||
registrationName: "service",
|
||||
label: "Module with DML without joiner config",
|
||||
defaultPackage: false,
|
||||
defaultModuleDeclaration: {
|
||||
@@ -184,7 +182,6 @@ describe("load internal - load resources", () => {
|
||||
),
|
||||
definition: {
|
||||
key: "module-without-joiner-config",
|
||||
registrationName: "service",
|
||||
label: "Module without joiner config",
|
||||
defaultPackage: false,
|
||||
defaultModuleDeclaration: {
|
||||
@@ -264,7 +261,6 @@ describe("load internal - load resources", () => {
|
||||
),
|
||||
definition: {
|
||||
key: "module-without-joiner-config",
|
||||
registrationName: "service",
|
||||
label: "Module without joiner config",
|
||||
defaultPackage: false,
|
||||
defaultModuleDeclaration: {
|
||||
|
||||
@@ -11,11 +11,11 @@ import {
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
createMedusaContainer,
|
||||
defineJoinerConfig,
|
||||
DmlEntity,
|
||||
MedusaModuleType,
|
||||
ModulesSdkUtils,
|
||||
createMedusaContainer,
|
||||
defineJoinerConfig,
|
||||
toMikroOrmEntities,
|
||||
} from "@medusajs/utils"
|
||||
import { asFunction, asValue } from "awilix"
|
||||
@@ -45,9 +45,9 @@ export async function loadInternalModule(
|
||||
migrationOnly?: boolean,
|
||||
loaderOnly?: boolean
|
||||
): Promise<{ error?: Error } | void> {
|
||||
const registrationName = !loaderOnly
|
||||
? resolution.definition.registrationName
|
||||
: resolution.definition.registrationName + "__loaderOnly"
|
||||
const keyName = !loaderOnly
|
||||
? resolution.definition.key
|
||||
: resolution.definition.key + "__loaderOnly"
|
||||
|
||||
const { resources } =
|
||||
resolution.moduleDeclaration as InternalModuleDeclaration
|
||||
@@ -95,7 +95,7 @@ export async function loadInternalModule(
|
||||
|
||||
if (!loadedModule?.service && !moduleResources.moduleService) {
|
||||
container.register({
|
||||
[registrationName]: asValue(undefined),
|
||||
[keyName]: asValue(undefined),
|
||||
})
|
||||
|
||||
return {
|
||||
@@ -112,8 +112,9 @@ export async function loadInternalModule(
|
||||
const moduleService = {
|
||||
__joinerConfig: moduleService_.prototype.__joinerConfig,
|
||||
}
|
||||
|
||||
container.register({
|
||||
[registrationName]: asValue(moduleService),
|
||||
[keyName]: asValue(moduleService),
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -155,7 +156,7 @@ export async function loadInternalModule(
|
||||
logger,
|
||||
resolution,
|
||||
loaderOnly,
|
||||
registrationName,
|
||||
keyName,
|
||||
})
|
||||
|
||||
if (error) {
|
||||
@@ -165,7 +166,7 @@ export async function loadInternalModule(
|
||||
const moduleService = moduleResources.moduleService ?? loadedModule.service
|
||||
|
||||
container.register({
|
||||
[registrationName]: asFunction((cradle) => {
|
||||
[keyName]: asFunction((cradle) => {
|
||||
;(moduleService as any).__type = MedusaModuleType
|
||||
return new moduleService(
|
||||
localContainer.cradle,
|
||||
@@ -177,7 +178,7 @@ export async function loadInternalModule(
|
||||
|
||||
if (loaderOnly) {
|
||||
// The expectation is only to run the loader as standalone, so we do not need to register the service and we need to cleanup all services
|
||||
const service = container.resolve<IModuleService>(registrationName)
|
||||
const service = container.resolve<IModuleService>(keyName)
|
||||
await service.__hooks?.onApplicationPrepareShutdown?.()
|
||||
await service.__hooks?.onApplicationShutdown?.()
|
||||
}
|
||||
@@ -348,14 +349,7 @@ export async function loadResources(
|
||||
|
||||
async function runLoaders(
|
||||
loaders: Function[] = [],
|
||||
{
|
||||
localContainer,
|
||||
container,
|
||||
logger,
|
||||
resolution,
|
||||
loaderOnly,
|
||||
registrationName,
|
||||
}
|
||||
{ localContainer, container, logger, resolution, loaderOnly, keyName }
|
||||
): Promise<void | { error: Error }> {
|
||||
try {
|
||||
for (const loader of loaders) {
|
||||
@@ -371,7 +365,7 @@ async function runLoaders(
|
||||
}
|
||||
} catch (err) {
|
||||
container.register({
|
||||
[registrationName]: asValue(undefined),
|
||||
[keyName]: asValue(undefined),
|
||||
})
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user