chore: remove internal module resources option (#9582)

What:
* removes resouces type "shared" or "isolated" from internal modules.
* modules can have an isolated database connection by providing a database config as part of their options on `medusa-config`

CLOSES: FRMW-2593
This commit is contained in:
Carlos R. L. Rodrigues
2024-10-17 18:31:46 -03:00
committed by GitHub
parent b07dd33a57
commit 902ac12f73
36 changed files with 75 additions and 258 deletions

View File

@@ -9,7 +9,6 @@ export const InventoryModule = {
dependencies: [],
defaultModuleDeclaration: {
scope: "internal",
resources: "shared",
},
},
__joinerConfig: {

View File

@@ -8,7 +8,6 @@ export const InventoryStockLocationLink = {
isQueryable: true,
defaultModuleDeclaration: {
scope: "internal",
resources: "shared",
},
},
__joinerConfig: {

View File

@@ -8,7 +8,6 @@ export const ProductInventoryLinkModule = {
isQueryable: true,
defaultModuleDeclaration: {
scope: "internal",
resources: "shared",
},
},
__joinerConfig: {

View File

@@ -9,7 +9,6 @@ export const ProductModule = {
dependencies: ["eventBusModuleService"],
defaultModuleDeclaration: {
scope: "internal",
resources: "shared",
},
},
__joinerConfig: {

View File

@@ -9,7 +9,6 @@ export const StockLocationModule = {
dependencies: ["eventBusModuleService"],
defaultModuleDeclaration: {
scope: "internal",
resources: "shared",
},
},
__joinerConfig: {

View File

@@ -5,7 +5,7 @@ import {
Modules,
upperCaseFirst,
} from "@medusajs/utils"
import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "./types"
import { MODULE_SCOPE } from "./types"
export const ModulesDefinition: {
[key: string]: ModuleDefinition
@@ -19,7 +19,6 @@ export const ModulesDefinition: {
dependencies: [ContainerRegistrationKeys.LOGGER],
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
[Modules.STOCK_LOCATION]: {
@@ -31,7 +30,6 @@ export const ModulesDefinition: {
dependencies: [Modules.EVENT_BUS],
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
[Modules.INVENTORY]: {
@@ -43,7 +41,6 @@ export const ModulesDefinition: {
dependencies: [Modules.EVENT_BUS],
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
[Modules.CACHE]: {
@@ -54,7 +51,6 @@ export const ModulesDefinition: {
isQueryable: false,
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
[Modules.PRODUCT]: {
@@ -66,7 +62,6 @@ export const ModulesDefinition: {
dependencies: [Modules.EVENT_BUS, ContainerRegistrationKeys.LOGGER],
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
[Modules.PRICING]: {
@@ -78,7 +73,6 @@ export const ModulesDefinition: {
dependencies: [Modules.EVENT_BUS, ContainerRegistrationKeys.LOGGER],
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
[Modules.PROMOTION]: {
@@ -90,7 +84,6 @@ export const ModulesDefinition: {
dependencies: [ContainerRegistrationKeys.LOGGER],
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
[Modules.AUTH]: {
@@ -102,7 +95,6 @@ export const ModulesDefinition: {
dependencies: [ContainerRegistrationKeys.LOGGER],
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
[Modules.WORKFLOW_ENGINE]: {
@@ -115,7 +107,6 @@ export const ModulesDefinition: {
__passSharedContainer: true,
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
[Modules.SALES_CHANNEL]: {
@@ -127,7 +118,6 @@ export const ModulesDefinition: {
dependencies: [ContainerRegistrationKeys.LOGGER],
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
[Modules.FULFILLMENT]: {
@@ -139,7 +129,6 @@ export const ModulesDefinition: {
dependencies: [ContainerRegistrationKeys.LOGGER, Modules.EVENT_BUS],
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
[Modules.CART]: {
@@ -151,7 +140,6 @@ export const ModulesDefinition: {
dependencies: [ContainerRegistrationKeys.LOGGER],
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
[Modules.CUSTOMER]: {
@@ -163,7 +151,6 @@ export const ModulesDefinition: {
dependencies: [ContainerRegistrationKeys.LOGGER],
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
[Modules.PAYMENT]: {
@@ -175,7 +162,6 @@ export const ModulesDefinition: {
dependencies: [ContainerRegistrationKeys.LOGGER],
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
[Modules.USER]: {
@@ -187,7 +173,6 @@ export const ModulesDefinition: {
dependencies: [Modules.EVENT_BUS, ContainerRegistrationKeys.LOGGER],
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
[Modules.REGION]: {
@@ -199,7 +184,6 @@ export const ModulesDefinition: {
dependencies: [ContainerRegistrationKeys.LOGGER],
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
[Modules.ORDER]: {
@@ -211,7 +195,6 @@ export const ModulesDefinition: {
dependencies: [ContainerRegistrationKeys.LOGGER, Modules.EVENT_BUS],
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
[Modules.TAX]: {
@@ -223,7 +206,6 @@ export const ModulesDefinition: {
dependencies: [ContainerRegistrationKeys.LOGGER, Modules.EVENT_BUS],
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
[Modules.API_KEY]: {
@@ -235,7 +217,6 @@ export const ModulesDefinition: {
dependencies: [ContainerRegistrationKeys.LOGGER],
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
[Modules.STORE]: {
@@ -247,7 +228,6 @@ export const ModulesDefinition: {
dependencies: [ContainerRegistrationKeys.LOGGER],
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
[Modules.CURRENCY]: {
@@ -259,7 +239,6 @@ export const ModulesDefinition: {
dependencies: [ContainerRegistrationKeys.LOGGER],
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
[Modules.FILE]: {
@@ -271,7 +250,6 @@ export const ModulesDefinition: {
dependencies: [ContainerRegistrationKeys.LOGGER],
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
[Modules.NOTIFICATION]: {
@@ -283,7 +261,6 @@ export const ModulesDefinition: {
dependencies: [Modules.EVENT_BUS, ContainerRegistrationKeys.LOGGER],
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
[Modules.INDEX]: {
@@ -300,7 +277,6 @@ export const ModulesDefinition: {
],
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
[Modules.LOCKING]: {
@@ -312,7 +288,6 @@ export const ModulesDefinition: {
dependencies: [ContainerRegistrationKeys.LOGGER],
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
}

View File

@@ -1,5 +1,5 @@
import { InternalModuleDeclaration } from "@medusajs/types"
import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "../../types"
import { MODULE_SCOPE } from "../../types"
import { asValue } from "awilix"
import { MedusaModule } from "../../medusa-module"
@@ -12,7 +12,6 @@ const mockRegisterMedusaModule = jest.fn().mockImplementation(() => {
},
moduleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
}
@@ -47,7 +46,6 @@ describe("Medusa Modules", () => {
defaultPath: "@path",
declaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.ISOLATED,
resolve: "@path",
options: {
abc: 123,
@@ -63,7 +61,6 @@ describe("Medusa Modules", () => {
defaultPath: "@path",
declaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.ISOLATED,
resolve: "@path",
options: {
abc: 123,
@@ -76,7 +73,6 @@ describe("Medusa Modules", () => {
defaultPath: "@path",
declaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.ISOLATED,
resolve: "@path",
options: {
different_options: "abc",
@@ -98,7 +94,6 @@ describe("Medusa Modules", () => {
defaultPath: "@path",
declaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.ISOLATED,
resolve: "@path",
options: {
abc: 123,
@@ -121,7 +116,6 @@ describe("Medusa Modules", () => {
defaultPath: "@path",
declaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.ISOLATED,
resolve: "@path",
options: {
abc: 123,
@@ -134,7 +128,6 @@ describe("Medusa Modules", () => {
defaultPath: "@path",
declaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.ISOLATED,
resolve: "@path",
options: {
different_options: "abc",
@@ -151,7 +144,6 @@ describe("Medusa Modules", () => {
defaultPath: "@path",
declaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.ISOLATED,
resolve: "@path",
options: {
abc: 123,
@@ -164,7 +156,6 @@ describe("Medusa Modules", () => {
defaultPath: "@path",
declaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.ISOLATED,
resolve: "@path",
main: true,
options: {
@@ -182,7 +173,6 @@ describe("Medusa Modules", () => {
defaultPath: "@path",
declaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.ISOLATED,
resolve: "@path",
alias: "mod_A",
options: {
@@ -196,7 +186,6 @@ describe("Medusa Modules", () => {
defaultPath: "@path",
declaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.ISOLATED,
resolve: "@path",
main: true,
alias: "mod_B",
@@ -211,7 +200,6 @@ describe("Medusa Modules", () => {
defaultPath: "@path",
declaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.ISOLATED,
resolve: "@path",
alias: "mod_C",
options: {
@@ -240,7 +228,6 @@ describe("Medusa Modules", () => {
defaultPath: "@path",
declaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.ISOLATED,
resolve: "@path",
alias: "mod_A",
options: {
@@ -254,7 +241,6 @@ describe("Medusa Modules", () => {
defaultPath: "@path",
declaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.ISOLATED,
resolve: "@path",
main: true,
alias: "mod_B",
@@ -269,7 +255,6 @@ describe("Medusa Modules", () => {
defaultPath: "@path",
declaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.ISOLATED,
resolve: "@path",
main: true,
alias: "mod_C",
@@ -290,7 +275,6 @@ describe("Medusa Modules", () => {
defaultPath: "@path",
declaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.ISOLATED,
resolve: "@path",
alias: "module_alias",
options: {
@@ -304,7 +288,6 @@ describe("Medusa Modules", () => {
defaultPath: "@path",
declaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.ISOLATED,
resolve: "@path",
alias: "module_alias",
options: {

View File

@@ -1,6 +1,6 @@
import { ModuleResolution } from "@medusajs/types"
import { createMedusaContainer } from "@medusajs/utils"
import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "../../types"
import { MODULE_SCOPE } from "../../types"
import { moduleLoader } from "../module-loader"
const logger = {
@@ -29,12 +29,10 @@ describe("modules loader", () => {
label: "TestService",
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
moduleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
}
@@ -57,12 +55,10 @@ describe("modules loader", () => {
label: "TestService",
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
moduleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
}
@@ -97,12 +93,10 @@ describe("modules loader", () => {
label: "TestService",
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
moduleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
}
@@ -122,12 +116,10 @@ describe("modules loader", () => {
label: "TestService",
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
moduleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
}
@@ -150,12 +142,10 @@ describe("modules loader", () => {
isRequired: true,
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
moduleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
}
@@ -179,12 +169,10 @@ describe("modules loader", () => {
isRequired: true,
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
moduleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
}
@@ -210,13 +198,10 @@ describe("modules loader", () => {
isRequired: true,
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
// @ts-ignore
moduleDeclaration: {
resources: MODULE_RESOURCE_TYPE.SHARED,
},
moduleDeclaration: {},
},
}
@@ -228,35 +213,4 @@ describe("modules loader", () => {
)
}
})
it("should throw an error if the resources is not set when scope is defined as internal", async () => {
expect.assertions(1)
const moduleResolutions: Record<string, ModuleResolution> = {
testService: {
resolutionPath: "@modules/no-service",
definition: {
key: "testService",
defaultPackage: "testService",
label: "TestService",
isRequired: true,
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
},
// @ts-ignore
moduleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
},
} as any,
}
try {
await moduleLoader({ container, moduleResolutions, logger })
} catch (err) {
expect(err.message).toEqual(
"The module TestService is missing its resources config"
)
}
})
})

View File

@@ -1,6 +1,6 @@
import { InternalModuleDeclaration, ModuleDefinition } from "@medusajs/types"
import { ModulesDefinition } from "../../definitions"
import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "../../types"
import { MODULE_SCOPE } from "../../types"
import { registerMedusaModule } from "../register-modules"
const testServiceResolved = require.resolve(
@@ -16,7 +16,6 @@ describe("module definitions loader", () => {
isRequired: false,
defaultModuleDeclaration: {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.SHARED,
},
}
@@ -45,7 +44,6 @@ describe("module definitions loader", () => {
options: {},
moduleDeclaration: {
scope: "internal",
resources: "shared",
},
})
)
@@ -67,7 +65,6 @@ describe("module definitions loader", () => {
label: "Custom: customModulesABC",
}),
moduleDeclaration: {
resources: "shared",
scope: "internal",
},
options: {
@@ -130,7 +127,6 @@ describe("module definitions loader", () => {
options: {},
moduleDeclaration: {
scope: "internal",
resources: "shared",
},
})
)
@@ -154,7 +150,6 @@ describe("module definitions loader", () => {
options: {},
moduleDeclaration: {
scope: "internal",
resources: "shared",
},
})
)
@@ -170,7 +165,6 @@ describe("module definitions loader", () => {
const res = registerMedusaModule(defaultDefinition.key, {
scope: MODULE_SCOPE.INTERNAL,
resolve: defaultDefinition.defaultPackage,
resources: MODULE_RESOURCE_TYPE.ISOLATED,
} as InternalModuleDeclaration)
expect(res[defaultDefinition.key]).toEqual(
@@ -180,7 +174,7 @@ describe("module definitions loader", () => {
options: {},
moduleDeclaration: {
scope: "internal",
resources: "isolated",
resolve: defaultDefinition.defaultPackage,
},
})
@@ -203,7 +197,7 @@ describe("module definitions loader", () => {
options: { test: 123 },
moduleDeclaration: {
scope: "internal",
resources: "shared",
options: { test: 123 },
},
})
@@ -219,7 +213,6 @@ describe("module definitions loader", () => {
resolve: defaultDefinition.defaultPackage,
options: { test: 123 },
scope: "internal",
resources: "isolated",
} as any)
expect(res[defaultDefinition.key]).toEqual(
@@ -229,7 +222,7 @@ describe("module definitions loader", () => {
options: { test: 123 },
moduleDeclaration: {
scope: "internal",
resources: "isolated",
resolve: defaultDefinition.defaultPackage,
options: { test: 123 },
},

View File

@@ -50,7 +50,7 @@ async function loadModule(
}
const keyName = modDefinition.key
const { scope, resources } = resolution.moduleDeclaration ?? ({} as any)
const { scope } = resolution.moduleDeclaration ?? ({} as any)
const canSkip =
!resolution.resolutionPath &&
@@ -63,11 +63,8 @@ async function loadModule(
throw new Error("External Modules are not supported yet.")
}
if (!scope || (scope === MODULE_SCOPE.INTERNAL && !resources)) {
if (!scope) {
let message = `The module ${resolution.definition.label} has to define its scope (internal | external)`
if (scope === MODULE_SCOPE.INTERNAL && !resources) {
message = `The module ${resolution.definition.label} is missing its resources config`
}
container.register(keyName, asValue(undefined))

View File

@@ -12,7 +12,7 @@ import {
normalizeImportPathWithSource,
} from "@medusajs/utils"
import { ModulesDefinition } from "../definitions"
import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "../types"
import { MODULE_SCOPE } from "../types"
export const registerMedusaModule = (
moduleKey: string,
@@ -86,12 +86,10 @@ function getCustomModuleResolution(
defaultPackage: "",
dependencies,
defaultModuleDeclaration: {
resources: MODULE_RESOURCE_TYPE.SHARED,
scope: MODULE_SCOPE.INTERNAL,
},
},
moduleDeclaration: {
resources: conf?.resources ?? MODULE_RESOURCE_TYPE.SHARED,
scope: MODULE_SCOPE.INTERNAL,
},
dependencies,

View File

@@ -7,14 +7,14 @@ import {
ModuleWithJoinerConfigFixtures,
ModuleWithoutJoinerConfigFixtures,
} from "../__fixtures__"
import { ModuleService as ModuleServiceWithProvider } from "../__fixtures__/module-with-providers"
import { ModuleProviderService as ModuleServiceWithProviderProvider1 } from "../__fixtures__/module-with-providers/provider-1"
import { ModuleProvider2Service as ModuleServiceWithProviderProvider2 } from "../__fixtures__/module-with-providers/provider-2"
import {
getProviderRegistrationKey,
loadInternalModule,
loadResources,
} from "../load-internal"
import { ModuleProviderService as ModuleServiceWithProviderProvider1 } from "../__fixtures__/module-with-providers/provider-1"
import { ModuleProvider2Service as ModuleServiceWithProviderProvider2 } from "../__fixtures__/module-with-providers/provider-2"
import { ModuleService as ModuleServiceWithProvider } from "../__fixtures__/module-with-providers"
describe("load internal", () => {
describe("loadResources", () => {
@@ -34,7 +34,6 @@ describe("load internal", () => {
defaultPackage: false,
defaultModuleDeclaration: {
scope: "internal",
resources: "shared",
},
},
}
@@ -117,7 +116,6 @@ describe("load internal", () => {
defaultPackage: false,
defaultModuleDeclaration: {
scope: "internal",
resources: "shared",
},
},
}
@@ -200,7 +198,6 @@ describe("load internal", () => {
defaultPackage: false,
defaultModuleDeclaration: {
scope: "internal",
resources: "shared",
},
},
}
@@ -282,7 +279,6 @@ describe("load internal", () => {
defaultPackage: false,
defaultModuleDeclaration: {
scope: "internal",
resources: "shared",
},
},
}
@@ -346,7 +342,6 @@ describe("load internal", () => {
),
moduleDeclaration: {
scope: "internal",
resources: "shared",
},
definition: {
key: "module-with-providers",
@@ -354,7 +349,6 @@ describe("load internal", () => {
defaultPackage: false,
defaultModuleDeclaration: {
scope: "internal",
resources: "shared",
},
},
options: {
@@ -399,7 +393,6 @@ describe("load internal", () => {
),
moduleDeclaration: {
scope: "internal",
resources: "shared",
},
definition: {
key: "module-with-providers",
@@ -407,7 +400,6 @@ describe("load internal", () => {
defaultPackage: false,
defaultModuleDeclaration: {
scope: "internal",
resources: "shared",
},
},
options: {

View File

@@ -28,7 +28,6 @@ import { asFunction, asValue } from "awilix"
import { statSync } from "fs"
import { readdir } from "fs/promises"
import { dirname, join, resolve } from "path"
import { MODULE_RESOURCE_TYPE } from "../../types"
type ModuleResource = {
services: Function[]
@@ -192,9 +191,6 @@ export async function loadInternalModule(args: {
? resolution.definition.key
: resolution.definition.key + "__loaderOnly"
const { resources } =
resolution.moduleDeclaration as InternalModuleDeclaration
const loadedModule = await resolveModuleExports({ resolution })
if ("error" in loadedModule) {
@@ -232,14 +228,13 @@ export async function loadInternalModule(args: {
const localContainer = createMedusaContainer()
const dependencies = resolution?.dependencies ?? []
if (resources === MODULE_RESOURCE_TYPE.SHARED) {
dependencies.push(
ContainerRegistrationKeys.MANAGER,
ContainerRegistrationKeys.CONFIG_MODULE,
ContainerRegistrationKeys.LOGGER,
ContainerRegistrationKeys.PG_CONNECTION
)
}
dependencies.push(
ContainerRegistrationKeys.MANAGER,
ContainerRegistrationKeys.CONFIG_MODULE,
ContainerRegistrationKeys.LOGGER,
ContainerRegistrationKeys.PG_CONNECTION
)
for (const dependency of dependencies) {
localContainer.register(

View File

@@ -18,6 +18,7 @@ import {
dynamicImport,
GraphQLUtils,
isObject,
isSharedConnectionSymbol,
isString,
MedusaError,
MODULE_PACKAGE_NAMES,
@@ -34,7 +35,7 @@ import {
} from "./medusa-module"
import { RemoteLink } from "./remote-link"
import { createQuery, RemoteQuery } from "./remote-query"
import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "./types"
import { MODULE_SCOPE } from "./types"
const LinkModulePackage = MODULE_PACKAGE_NAMES[Modules.LINK]
@@ -123,15 +124,14 @@ export async function loadModules(args: {
}
declaration.scope ??= MODULE_SCOPE.INTERNAL
if (declaration.scope === MODULE_SCOPE.INTERNAL && !declaration.resources) {
declaration.resources = MODULE_RESOURCE_TYPE.SHARED
}
if (
declaration.scope === MODULE_SCOPE.INTERNAL &&
declaration.resources === MODULE_RESOURCE_TYPE.SHARED
) {
if (declaration.scope === MODULE_SCOPE.INTERNAL) {
declaration.options ??= {}
if (!declaration.options.database) {
declaration.options[isSharedConnectionSymbol] = true
}
declaration.options.database ??= {
...sharedResourcesConfig?.database,
}
@@ -493,9 +493,7 @@ async function MedusaApp_({
for (const { resolution: moduleResolution } of moduleResolutions) {
if (
!moduleResolution.options?.database &&
moduleResolution.moduleDeclaration?.scope === MODULE_SCOPE.INTERNAL &&
moduleResolution.moduleDeclaration?.resources ===
MODULE_RESOURCE_TYPE.SHARED
moduleResolution.moduleDeclaration?.scope === MODULE_SCOPE.INTERNAL
) {
moduleResolution.options ??= {}
moduleResolution.options.database = {

View File

@@ -26,7 +26,7 @@ import {
registerMedusaModule,
} from "./loaders"
import { loadModuleMigrations } from "./loaders/utils"
import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "./types"
import { MODULE_SCOPE } from "./types"
const logger: any = {
log: (a) => console.log(a),
@@ -439,9 +439,6 @@ class MedusaModule {
if (declaration?.scope !== MODULE_SCOPE.EXTERNAL) {
modDeclaration = {
scope: declaration?.scope || MODULE_SCOPE.INTERNAL,
resources:
(declaration as InternalModuleDeclaration)?.resources ||
MODULE_RESOURCE_TYPE.ISOLATED,
resolve: defaultPath,
options: declaration?.options ?? declaration,
dependencies:
@@ -449,15 +446,10 @@ class MedusaModule {
alias: declaration?.alias,
main: declaration?.main,
worker_mode: workerMode,
} as any
} as InternalModuleDeclaration
}
// TODO: Only do that while legacy modules sharing the manager exists then remove the ternary in favor of createMedusaContainer({}, globalContainer)
const container =
modDeclaration.scope === MODULE_SCOPE.INTERNAL &&
modDeclaration.resources === MODULE_RESOURCE_TYPE.SHARED
? sharedContainer ?? createMedusaContainer()
: createMedusaContainer({}, sharedContainer)
const container = sharedContainer ?? createMedusaContainer()
if (injectedDependencies) {
for (const service in injectedDependencies) {
@@ -750,7 +742,6 @@ class MedusaModule {
}: MigrationOptions): Promise<void> {
const moduleResolutions = registerMedusaModule(moduleKey, {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.ISOLATED,
resolve: modulePath,
options,
})
@@ -787,7 +778,6 @@ class MedusaModule {
}: MigrationOptions): Promise<void> {
const moduleResolutions = registerMedusaModule(moduleKey, {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.ISOLATED,
resolve: modulePath,
options,
})
@@ -824,7 +814,6 @@ class MedusaModule {
}: MigrationOptions): Promise<void> {
const moduleResolutions = registerMedusaModule(moduleKey, {
scope: MODULE_SCOPE.INTERNAL,
resources: MODULE_RESOURCE_TYPE.ISOLATED,
resolve: modulePath,
options,
})

View File

@@ -2,8 +2,3 @@ export enum MODULE_SCOPE {
INTERNAL = "internal",
EXTERNAL = "external",
}
export enum MODULE_RESOURCE_TYPE {
SHARED = "shared",
ISOLATED = "isolated",
}