fix(utils): support omitting modules in config (#7563)
* fix: skip module loading if mod: false * fix: don't include disabled modules in config * add test * fix: revert changes to module loading in medusaapp
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { Modules } from "../../modules-sdk"
|
||||
import { defineConfig } from "../define-config"
|
||||
|
||||
describe("defineConfig", function () {
|
||||
@@ -256,4 +257,93 @@ describe("defineConfig", function () {
|
||||
}
|
||||
`)
|
||||
})
|
||||
|
||||
it("should not include disabled modules", function () {
|
||||
expect(
|
||||
defineConfig({
|
||||
projectConfig: {
|
||||
http: {
|
||||
adminCors: "http://localhost:3000",
|
||||
} as any,
|
||||
},
|
||||
modules: {
|
||||
[Modules.CART]: false,
|
||||
},
|
||||
})
|
||||
).toMatchInlineSnapshot(`
|
||||
{
|
||||
"admin": {
|
||||
"backendUrl": "http://localhost:9000",
|
||||
},
|
||||
"featureFlags": {},
|
||||
"modules": {
|
||||
"apiKey": true,
|
||||
"auth": true,
|
||||
"cacheService": true,
|
||||
"currency": true,
|
||||
"customer": true,
|
||||
"eventBus": true,
|
||||
"file": {
|
||||
"options": {
|
||||
"providers": [
|
||||
{
|
||||
"options": {
|
||||
"config": {
|
||||
"local": {},
|
||||
},
|
||||
},
|
||||
"resolve": "@medusajs/file-local-next",
|
||||
},
|
||||
],
|
||||
},
|
||||
"resolve": "@medusajs/file",
|
||||
},
|
||||
"fulfillment": {
|
||||
"options": {
|
||||
"providers": [
|
||||
{
|
||||
"options": {
|
||||
"config": {
|
||||
"manual": {},
|
||||
},
|
||||
},
|
||||
"resolve": "@medusajs/fulfillment-manual",
|
||||
},
|
||||
],
|
||||
},
|
||||
"resolve": "@medusajs/fulfillment",
|
||||
},
|
||||
"inventoryService": true,
|
||||
"order": true,
|
||||
"payment": true,
|
||||
"pricingService": true,
|
||||
"productService": true,
|
||||
"promotion": true,
|
||||
"region": true,
|
||||
"salesChannel": true,
|
||||
"stockLocationService": true,
|
||||
"store": true,
|
||||
"tax": true,
|
||||
"user": {
|
||||
"options": {
|
||||
"jwt_secret": "supersecret",
|
||||
},
|
||||
"resolve": "@medusajs/user",
|
||||
},
|
||||
"workflows": true,
|
||||
},
|
||||
"plugins": [],
|
||||
"projectConfig": {
|
||||
"databaseUrl": "postgres://localhost/medusa-starter-default",
|
||||
"http": {
|
||||
"adminCors": "http://localhost:3000",
|
||||
"authCors": "http://localhost:7000,http://localhost:7001,http://localhost:5173",
|
||||
"cookieSecret": "supersecret",
|
||||
"jwtSecret": "supersecret",
|
||||
"storeCors": "http://localhost:8000",
|
||||
},
|
||||
},
|
||||
}
|
||||
`)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -117,6 +117,13 @@ export function defineConfig(config: Partial<ConfigModule> = {}): ConfigModule {
|
||||
...config.modules,
|
||||
}
|
||||
|
||||
// Remove any modules set to false
|
||||
Object.keys(modules).forEach((key) => {
|
||||
if (modules[key] === false) {
|
||||
delete modules[key]
|
||||
}
|
||||
})
|
||||
|
||||
return {
|
||||
projectConfig,
|
||||
featureFlags,
|
||||
|
||||
Reference in New Issue
Block a user