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:
@@ -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", () => {
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -18,6 +18,7 @@ export default ({ modules }: ConfigModule) => {
|
||||
}
|
||||
if (!moduleConfiguration) {
|
||||
moduleResolutions[definition.key] = {
|
||||
resolutionPath: false,
|
||||
definition,
|
||||
options: {},
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export type ModulesResponse = {
|
||||
module: string
|
||||
resolution?: string
|
||||
resolution: string | false
|
||||
}[]
|
||||
|
||||
Reference in New Issue
Block a user