allow module definitions to have no default package (#2878)

* allow module definitions to have no default package

* remove duplicated test

* update modulesresponse type
This commit is contained in:
Philip Korsholm
2022-12-22 14:51:24 +01:00
committed by GitHub
parent 37aaca0da4
commit 3f097b7987
7 changed files with 49 additions and 7 deletions

View File

@@ -45,7 +45,7 @@ describe("module definitions loader", () => {
} as ConfigModule)
expect(res[defaultDefinition.key]).toEqual({
resolutionPath: undefined,
resolutionPath: false,
definition: defaultDefinition,
options: {},
})
@@ -65,6 +65,25 @@ describe("module definitions loader", () => {
)
}
})
it("Resolves module with no resolution path when not given custom resolution path as false as default package", () => {
const definition = {
...defaultDefinition,
defaultPackage: false as false,
}
MODULE_DEFINITIONS.push(definition)
const res = ModuleDefinitionLoader({
modules: {},
} as ConfigModule)
expect(res[defaultDefinition.key]).toEqual({
resolutionPath: false,
definition: definition,
options: {},
})
})
})
describe("string config", () => {

View File

@@ -84,7 +84,7 @@ describe("modules loader", () => {
it("registers service as false in container when no resolution path is given", async () => {
const moduleResolutions: Record<string, ModuleResolution> = {
testService: {
resolutionPath: undefined,
resolutionPath: false,
definition: {
registrationName: "testService",
key: "testService",

View File

@@ -1,5 +1,22 @@
import { ModuleDefinition } from "../../types/global"
export const MODULE_DEFINITIONS: ModuleDefinition[] = []
export const MODULE_DEFINITIONS: ModuleDefinition[] = [
{
key: "stockLocationService",
registrationName: "stockLocationService",
defaultPackage: false,
label: "StockLocationService",
isRequired: false,
canOverride: true,
},
{
key: "inventoryService",
registrationName: "inventoryService",
defaultPackage: false,
label: "InventoryService",
isRequired: false,
canOverride: true,
},
]
export default MODULE_DEFINITIONS

View File

@@ -18,6 +18,7 @@ export default ({ modules }: ConfigModule) => {
}
if (!moduleConfiguration) {
moduleResolutions[definition.key] = {
resolutionPath: false,
definition,
options: {},
}

View File

@@ -45,7 +45,12 @@ const registerModule = async (
const moduleLoaders = loadedModule?.loaders || []
try {
for (const loader of moduleLoaders) {
await loader({ container, configModule, logger })
await loader({
container,
configModule,
logger,
options: resolution.options,
})
}
} catch (err) {
return {

View File

@@ -38,7 +38,7 @@ export type Logger = _Logger & {
}
export type ModuleResolution = {
resolutionPath?: string
resolutionPath: string | false
definition: ModuleDefinition
options?: Record<string, unknown>
}
@@ -46,7 +46,7 @@ export type ModuleResolution = {
export type ModuleDefinition = {
key: string
registrationName: string
defaultPackage: string
defaultPackage: string | false
label: string
canOverride?: boolean
isRequired?: boolean

View File

@@ -1,4 +1,4 @@
export type ModulesResponse = {
module: string
resolution?: string
resolution: string | false
}[]