chore: upgrade moduleResolution to Node16 (#9269)

This commit is contained in:
Harminder Virk
2024-09-24 17:19:20 +05:30
committed by GitHub
parent d721282600
commit 9e711720dd
216 changed files with 981 additions and 2439 deletions
@@ -1,5 +1,6 @@
import { MedusaContainer, ModuleProvider } from "@medusajs/types"
import {
dynamicImport,
isString,
lowerCaseFirst,
normalizeImportPathWithSource,
@@ -44,7 +45,7 @@ export async function loadModuleProvider(
if (isString(provider.resolve)) {
const normalizedPath = normalizeImportPathWithSource(provider.resolve)
loadedProvider = await import(normalizedPath)
loadedProvider = await dynamicImport(normalizedPath)
}
} catch (error) {
throw new Error(
@@ -11,11 +11,13 @@ import {
} from "@medusajs/types"
import {
ContainerRegistrationKeys,
DmlEntity,
MedusaModuleType,
ModulesSdkUtils,
createMedusaContainer,
defineJoinerConfig,
DmlEntity,
dynamicImport,
MedusaModuleType,
ModulesSdkUtils,
resolveExports,
toMikroOrmEntities,
} from "@medusajs/utils"
import { asFunction, asValue } from "awilix"
@@ -65,7 +67,7 @@ export async function loadInternalModule(
// If we want to benefit from the auto load mechanism, even if the module exports is provided, we need to ask for the module path
loadedModule = resolution.moduleExports
} else {
loadedModule = await import(modulePath)
loadedModule = await dynamicImport(modulePath)
loadedModule = (loadedModule as any).default
}
} catch (error) {
@@ -195,7 +197,8 @@ export async function loadModuleMigrations(
let loadedModule: ModuleExports
try {
loadedModule =
moduleExports ?? (await import(resolution.resolutionPath as string))
moduleExports ??
(await dynamicImport(resolution.resolutionPath as string))
let runMigrations = loadedModule.runMigrations
let revertMigration = loadedModule.revertMigration
@@ -263,7 +266,7 @@ async function importAllFromDir(path: string) {
return (
await Promise.all(filesToLoad.map((filePath) => import(filePath)))
).flatMap((value) => {
return Object.values(value)
return Object.values(resolveExports(value))
})
}
@@ -284,7 +287,9 @@ export async function loadResources(
}
const [moduleService, services, models, repositories] = await Promise.all([
import(modulePath).then((moduleExports) => moduleExports.default.service),
import(modulePath).then((moduleExports) => {
return resolveExports(moduleExports).default.service
}),
importAllFromDir(resolve(normalizedPath, "services")).catch(
defaultOnFail
),
+9 -8
View File
@@ -18,12 +18,13 @@ import {
} from "@medusajs/types"
import {
ContainerRegistrationKeys,
createMedusaContainer,
dynamicImport,
isObject,
isString,
MedusaError,
Modules,
ModulesSdkUtils,
createMedusaContainer,
isObject,
isString,
promiseAll,
} from "@medusajs/utils"
import type { Knex } from "@mikro-orm/knex"
@@ -36,7 +37,7 @@ import {
RegisterModuleJoinerConfig,
} from "./medusa-module"
import { RemoteLink } from "./remote-link"
import { RemoteQuery, createQuery } from "./remote-query"
import { createQuery, RemoteQuery } from "./remote-query"
import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "./types"
import { cleanGraphQLSchema } from "./utils"
@@ -171,7 +172,7 @@ async function initializeLinks({
}) {
try {
const { initialize, getMigrationPlanner } =
moduleExports ?? (await import(LinkModulePackage))
moduleExports ?? (await dynamicImport(LinkModulePackage))
const linkResolution = await initialize(
config,
@@ -298,9 +299,9 @@ async function MedusaApp_({
const modules: MedusaModuleConfig =
modulesConfig ??
(
await import(
modulesConfigPath ??
process.cwd() + (modulesConfigFileName ?? "/modules-config")
await dynamicImport(
await (modulesConfigPath ??
process.cwd() + (modulesConfigFileName ?? "/modules-config"))
)
).default