feat: generate modules mappings at runtime (#10791)

This commit is contained in:
Harminder Virk
2025-01-03 15:49:47 +05:30
committed by GitHub
parent 5e9d86d75d
commit ecc09fd77d
9 changed files with 220 additions and 12 deletions

View File

@@ -12,6 +12,7 @@ import {
gqlSchemaToTypes,
GracefulShutdownServer,
isPresent,
generateContainerTypes,
} from "@medusajs/framework/utils"
import { logger } from "@medusajs/framework/logger"
@@ -120,21 +121,29 @@ async function start(args: {
})
try {
const { shutdown, gqlSchema, container } = await loaders({
const { shutdown, gqlSchema, container, modules } = await loaders({
directory,
expressApp: app,
})
if (gqlSchema && generateTypes) {
const outputDirGeneratedTypes = path.join(directory, ".medusa/types")
await gqlSchemaToTypes({
outputDir: outputDirGeneratedTypes,
filename: "remote-query-entry-points",
interfaceName: "RemoteQueryEntryPoints",
schema: gqlSchema,
joinerConfigs: MedusaModule.getAllJoinerConfigs(),
if (generateTypes) {
await generateContainerTypes(modules, {
outputDir: path.join(directory, ".medusa/types"),
interfaceName: "ModuleImplementations",
})
logger.info("Generated modules types")
logger.debug("Generated container types")
if (gqlSchema) {
const outputDirGeneratedTypes = path.join(directory, ".medusa/types")
await gqlSchemaToTypes({
outputDir: outputDirGeneratedTypes,
filename: "remote-query-entry-points",
interfaceName: "RemoteQueryEntryPoints",
schema: gqlSchema,
joinerConfigs: MedusaModule.getAllJoinerConfigs(),
})
logger.debug("Generated modules types")
}
}
const serverActivity = logger.activity(`Creating server`)

View File

@@ -1,5 +1,6 @@
import {
ConfigModule,
LoadedModule,
MedusaContainer,
PluginDetails,
} from "@medusajs/framework/types"
@@ -136,6 +137,7 @@ export default async ({
}: Options): Promise<{
container: MedusaContainer
app: Express
modules: Record<string, LoadedModule | LoadedModule[]>
shutdown: () => Promise<void>
gqlSchema?: GraphQLSchema
}> => {
@@ -154,6 +156,7 @@ export default async ({
onApplicationStart,
onApplicationShutdown,
onApplicationPrepareShutdown,
modules,
gqlSchema,
} = await new MedusaAppLoader().load()
@@ -192,6 +195,7 @@ export default async ({
container,
app: expressApp,
shutdown,
modules,
gqlSchema,
}
}