fix: normalize path before consuming it while loading models (#8194)

* fix: normalize path before consuming it while loading models

* Make it so that models derived from the service if present

* fix linkable tests that now match what has been passed to the medusa service if there is no custom joiner config

* fix linkable tests that now match what has been passed to the medusa service if there is no custom joiner config

* fix linkable tests that now match what has been passed to the medusa service if there is no custom joiner config
This commit is contained in:
Adrien de Peretti
2024-07-21 21:21:05 +02:00
committed by GitHub
parent 2f56030101
commit 566300d54b
7 changed files with 203 additions and 248 deletions

View File

@@ -5,7 +5,7 @@ import {
PropertyType,
} from "@medusajs/types"
import * as path from "path"
import { dirname, join } from "path"
import { dirname, join, normalize } from "path"
import {
camelToSnakeCase,
deduplicate,
@@ -77,11 +77,16 @@ export function defineJoinerConfig(
break
}
fullPath = normalize(fullPath)
const integrationTestPotentialPath = normalize(
"integration-tests/__tests__"
)
/**
* Handle integration-tests/__tests__ path based on conventional naming
*/
if (fullPath.includes("integration-tests/__tests__")) {
const sourcePath = fullPath.split("integration-tests/__tests__")[0]
if (fullPath.includes(integrationTestPotentialPath)) {
const sourcePath = fullPath.split(integrationTestPotentialPath)[0]
fullPath = path.join(sourcePath, "src")
}
@@ -90,7 +95,8 @@ export function defineJoinerConfig(
let basePath = splitPath[0] + srcDir
const isMedusaProject = fullPath.includes(`${srcDir}/modules/`)
const potentialModulesDirPathSegment = normalize(`${srcDir}/modules/`)
const isMedusaProject = fullPath.includes(potentialModulesDirPathSegment)
if (isMedusaProject) {
basePath = dirname(fullPath)
}

View File

@@ -33,11 +33,15 @@ export function Module<
): ModuleExports<Service> & {
linkable: Linkable
} {
const defaultJoinerConfig = defineJoinerConfig(serviceName)
service.prototype.__joinerConfig ??= () => defaultJoinerConfig
const modelObjects = service[MedusaServiceModelObjectsSymbol] ?? {}
const defaultJoinerConfig = defineJoinerConfig(serviceName, {
models: Object.keys(modelObjects).length
? Object.values(modelObjects)
: undefined,
})
service.prototype.__joinerConfig ??= () => defaultJoinerConfig
let linkable = {} as Linkable
if (Object.keys(modelObjects)?.length) {