fix: make v2 with modules run (#6636)
This commit is contained in:
1 parent
c2d56ca12b
commit
a838ebae1b
10 files changed
+39
-35
No files matched your search
@@ -55,7 +55,7 @@
|
|||||||
"@mikro-orm/migrations": "5.9.7",
|
"@mikro-orm/migrations": "5.9.7",
|
||||||
"@mikro-orm/postgresql": "5.9.7",
|
"@mikro-orm/postgresql": "5.9.7",
|
||||||
"awilix": "^8.0.0",
|
"awilix": "^8.0.0",
|
||||||
"dotenv": "16.3.1",
|
"dotenv": "^16.4.5",
|
||||||
"knex": "2.4.2"
|
"knex": "2.4.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@
|
|||||||
"core-js": "^3.6.5",
|
"core-js": "^3.6.5",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"cross-spawn": "^7.0.3",
|
"cross-spawn": "^7.0.3",
|
||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.4.5",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"express-session": "^1.17.3",
|
"express-session": "^1.17.3",
|
||||||
"fs-exists-cached": "^1.0.0",
|
"fs-exists-cached": "^1.0.0",
|
||||||
|
|||||||
@@ -61,12 +61,10 @@ export const DELETE = async (
|
|||||||
res: MedusaResponse
|
res: MedusaResponse
|
||||||
) => {
|
) => {
|
||||||
const id = req.params.id
|
const id = req.params.id
|
||||||
const manager = req.scope.resolve("manager")
|
|
||||||
const deleteCampaigns = deleteCampaignsWorkflow(req.scope)
|
const deleteCampaigns = deleteCampaignsWorkflow(req.scope)
|
||||||
|
|
||||||
const { errors } = await deleteCampaigns.run({
|
const { errors } = await deleteCampaigns.run({
|
||||||
input: { ids: [id] },
|
input: { ids: [id] },
|
||||||
context: { manager },
|
|
||||||
throwOnError: false,
|
throwOnError: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import {
|
|||||||
import { AdminPostPromotionsPromotionReq } from "../validators"
|
import { AdminPostPromotionsPromotionReq } from "../validators"
|
||||||
import { IPromotionModuleService } from "@medusajs/types"
|
import { IPromotionModuleService } from "@medusajs/types"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { UpdateApplicationMethodDTO } from "@medusajs/types"
|
|
||||||
import { UpdatePromotionDTO } from "@medusajs/types"
|
import { UpdatePromotionDTO } from "@medusajs/types"
|
||||||
|
|
||||||
export const GET = async (
|
export const GET = async (
|
||||||
@@ -58,12 +57,10 @@ export const DELETE = async (
|
|||||||
res: MedusaResponse
|
res: MedusaResponse
|
||||||
) => {
|
) => {
|
||||||
const id = req.params.id
|
const id = req.params.id
|
||||||
const manager = req.scope.resolve("manager")
|
|
||||||
const deletePromotions = deletePromotionsWorkflow(req.scope)
|
const deletePromotions = deletePromotionsWorkflow(req.scope)
|
||||||
|
|
||||||
const { errors } = await deletePromotions.run({
|
const { errors } = await deletePromotions.run({
|
||||||
input: { ids: [id] },
|
input: { ids: [id] },
|
||||||
context: { manager },
|
|
||||||
throwOnError: false,
|
throwOnError: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -8,12 +8,14 @@ import getMigrations, {
|
|||||||
import {
|
import {
|
||||||
ContainerRegistrationKeys,
|
ContainerRegistrationKeys,
|
||||||
createMedusaContainer,
|
createMedusaContainer,
|
||||||
|
MedusaV2Flag,
|
||||||
|
promiseAll,
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import configModuleLoader from "../loaders/config"
|
import configModuleLoader from "../loaders/config"
|
||||||
import databaseLoader from "../loaders/database"
|
import databaseLoader from "../loaders/database"
|
||||||
import featureFlagLoader from "../loaders/feature-flags"
|
import featureFlagLoader from "../loaders/feature-flags"
|
||||||
import Logger from "../loaders/logger"
|
import Logger from "../loaders/logger"
|
||||||
import { loadMedusaApp } from "../loaders/medusa-app"
|
import { migrateMedusaApp, loadMedusaApp } from "../loaders/medusa-app"
|
||||||
import pgConnectionLoader from "../loaders/pg-connection"
|
import pgConnectionLoader from "../loaders/pg-connection"
|
||||||
|
|
||||||
const getDataSource = async (directory) => {
|
const getDataSource = async (directory) => {
|
||||||
@@ -70,15 +72,31 @@ const main = async function ({ directory }) {
|
|||||||
args.shift()
|
args.shift()
|
||||||
args.shift()
|
args.shift()
|
||||||
|
|
||||||
|
const featureFlagRouter = featureFlagLoader(configModule)
|
||||||
const configModule = configModuleLoader(directory)
|
const configModule = configModuleLoader(directory)
|
||||||
const dataSource = await getDataSource(directory)
|
const dataSource = await getDataSource(directory)
|
||||||
|
|
||||||
if (args[0] === "run") {
|
if (args[0] === "run") {
|
||||||
|
if (featureFlagRouter.isFeatureEnabled(MedusaV2Flag.key)) {
|
||||||
|
const container = createMedusaContainer()
|
||||||
|
const pgConnection = await pgConnectionLoader({ configModule, container })
|
||||||
|
container.register({
|
||||||
|
[ContainerRegistrationKeys.CONFIG_MODULE]: asValue(configModule),
|
||||||
|
[ContainerRegistrationKeys.LOGGER]: asValue(Logger),
|
||||||
|
[ContainerRegistrationKeys.PG_CONNECTION]: asValue(pgConnection),
|
||||||
|
featureFlagRouter: asValue(featureFlagRouter),
|
||||||
|
})
|
||||||
|
await migrateMedusaApp(
|
||||||
|
{ configModule, container },
|
||||||
|
{ registerInContainer: false }
|
||||||
|
)
|
||||||
|
} else {
|
||||||
await dataSource.runMigrations()
|
await dataSource.runMigrations()
|
||||||
await dataSource.destroy()
|
await dataSource.destroy()
|
||||||
await runIsolatedModulesMigration(configModule)
|
await runIsolatedModulesMigration(configModule)
|
||||||
|
|
||||||
await runLinkMigrations(directory)
|
await runLinkMigrations(directory)
|
||||||
|
}
|
||||||
process.exit()
|
process.exit()
|
||||||
|
|
||||||
Logger.info("Migrations completed.")
|
Logger.info("Migrations completed.")
|
||||||
|
|||||||
@@ -3,7 +3,11 @@ import {
|
|||||||
ModulesDefinition,
|
ModulesDefinition,
|
||||||
} from "@medusajs/modules-sdk"
|
} from "@medusajs/modules-sdk"
|
||||||
import { MODULE_RESOURCE_TYPE } from "@medusajs/types"
|
import { MODULE_RESOURCE_TYPE } from "@medusajs/types"
|
||||||
import { ContainerRegistrationKeys, isString } from "@medusajs/utils"
|
import {
|
||||||
|
ContainerRegistrationKeys,
|
||||||
|
isString,
|
||||||
|
MedusaV2Flag,
|
||||||
|
} from "@medusajs/utils"
|
||||||
import { asValue } from "awilix"
|
import { asValue } from "awilix"
|
||||||
import { Express, NextFunction, Request, Response } from "express"
|
import { Express, NextFunction, Request, Response } from "express"
|
||||||
import { createMedusaContainer } from "medusa-core-utils"
|
import { createMedusaContainer } from "medusa-core-utils"
|
||||||
@@ -77,9 +81,7 @@ async function loadLegacyModulesEntities(configModules, container) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadMedusaV2({ directory, expressApp }) {
|
async function loadMedusaV2({ configModule, featureFlagRouter, expressApp }) {
|
||||||
const configModule = loadConfig(directory)
|
|
||||||
|
|
||||||
const container = createMedusaContainer()
|
const container = createMedusaContainer()
|
||||||
|
|
||||||
// Add additional information to context of request
|
// Add additional information to context of request
|
||||||
@@ -91,12 +93,9 @@ async function loadMedusaV2({ directory, expressApp }) {
|
|||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
|
|
||||||
const featureFlagRouter = featureFlagsLoader(configModule, Logger)
|
|
||||||
|
|
||||||
const pgConnection = await pgConnectionLoader({ container, configModule })
|
const pgConnection = await pgConnectionLoader({ container, configModule })
|
||||||
|
|
||||||
container.register({
|
container.register({
|
||||||
[ContainerRegistrationKeys.MANAGER]: asValue(dataSource.manager),
|
|
||||||
[ContainerRegistrationKeys.LOGGER]: asValue(Logger),
|
[ContainerRegistrationKeys.LOGGER]: asValue(Logger),
|
||||||
featureFlagRouter: asValue(featureFlagRouter),
|
featureFlagRouter: asValue(featureFlagRouter),
|
||||||
[ContainerRegistrationKeys.CONFIG_MODULE]: asValue(configModule),
|
[ContainerRegistrationKeys.CONFIG_MODULE]: asValue(configModule),
|
||||||
@@ -142,11 +141,13 @@ export default async ({
|
|||||||
app: Express
|
app: Express
|
||||||
pgConnection: unknown
|
pgConnection: unknown
|
||||||
}> => {
|
}> => {
|
||||||
if (process.env.MEDUSA_FF_MEDUSA_V2 == "true") {
|
|
||||||
return await loadMedusaV2({ directory: rootDirectory, expressApp })
|
|
||||||
}
|
|
||||||
|
|
||||||
const configModule = loadConfig(rootDirectory)
|
const configModule = loadConfig(rootDirectory)
|
||||||
|
const featureFlagRouter = featureFlagsLoader(configModule, Logger)
|
||||||
|
track("FEATURE_FLAGS_LOADED")
|
||||||
|
|
||||||
|
if (featureFlagRouter.isFeatureEnabled(MedusaV2Flag.key)) {
|
||||||
|
return await loadMedusaV2({ configModule, featureFlagRouter, expressApp })
|
||||||
|
}
|
||||||
|
|
||||||
const container = createMedusaContainer()
|
const container = createMedusaContainer()
|
||||||
container.register(
|
container.register(
|
||||||
@@ -163,9 +164,6 @@ export default async ({
|
|||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
|
|
||||||
const featureFlagRouter = featureFlagsLoader(configModule, Logger)
|
|
||||||
track("FEATURE_FLAGS_LOADED")
|
|
||||||
|
|
||||||
container.register({
|
container.register({
|
||||||
[ContainerRegistrationKeys.LOGGER]: asValue(Logger),
|
[ContainerRegistrationKeys.LOGGER]: asValue(Logger),
|
||||||
featureFlagRouter: asValue(featureFlagRouter),
|
featureFlagRouter: asValue(featureFlagRouter),
|
||||||
|
|||||||
@@ -51,7 +51,6 @@
|
|||||||
"@medusajs/modules-sdk": "^1.12.5",
|
"@medusajs/modules-sdk": "^1.12.5",
|
||||||
"@medusajs/types": "^1.11.9",
|
"@medusajs/types": "^1.11.9",
|
||||||
"@medusajs/utils": "^1.11.2",
|
"@medusajs/utils": "^1.11.2",
|
||||||
"@medusajs/workflows-sdk": "workspace:^",
|
|
||||||
"@mikro-orm/core": "5.9.7",
|
"@mikro-orm/core": "5.9.7",
|
||||||
"@mikro-orm/migrations": "5.9.7",
|
"@mikro-orm/migrations": "5.9.7",
|
||||||
"@mikro-orm/postgresql": "5.9.7",
|
"@mikro-orm/postgresql": "5.9.7",
|
||||||
|
|||||||
@@ -55,7 +55,7 @@
|
|||||||
"@mikro-orm/migrations": "5.9.7",
|
"@mikro-orm/migrations": "5.9.7",
|
||||||
"@mikro-orm/postgresql": "5.9.7",
|
"@mikro-orm/postgresql": "5.9.7",
|
||||||
"awilix": "^8.0.0",
|
"awilix": "^8.0.0",
|
||||||
"dotenv": "16.3.1",
|
"dotenv": "^16.4.5",
|
||||||
"knex": "2.4.2"
|
"knex": "2.4.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,17 +3,12 @@ import { isObject } from "./is-object"
|
|||||||
/**
|
/**
|
||||||
* In most casees, JSON.parse(JSON.stringify(obj)) is enough to deep copy an object.
|
* In most casees, JSON.parse(JSON.stringify(obj)) is enough to deep copy an object.
|
||||||
* But in some cases, it's not enough. For example, if the object contains a function or a proxy, it will be lost after JSON.parse(JSON.stringify(obj)).
|
* But in some cases, it's not enough. For example, if the object contains a function or a proxy, it will be lost after JSON.parse(JSON.stringify(obj)).
|
||||||
* Furthermore, structuredClone is not present in all environments, such as with jest so we need to use a custom deepCopy function.
|
|
||||||
*
|
*
|
||||||
* @param obj
|
* @param obj
|
||||||
*/
|
*/
|
||||||
export function deepCopy<T extends Record<any, any> = Record<any, any>>(
|
export function deepCopy<T extends Record<any, any> = Record<any, any>>(
|
||||||
obj: T | T[]
|
obj: T | T[]
|
||||||
): T | T[] {
|
): T | T[] {
|
||||||
if (typeof structuredClone != "undefined") {
|
|
||||||
return structuredClone(obj)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (obj === null || typeof obj !== "object") {
|
if (obj === null || typeof obj !== "object") {
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8122,7 +8122,7 @@ __metadata:
|
|||||||
"@mikro-orm/postgresql": 5.9.7
|
"@mikro-orm/postgresql": 5.9.7
|
||||||
awilix: ^8.0.0
|
awilix: ^8.0.0
|
||||||
cross-env: ^5.2.1
|
cross-env: ^5.2.1
|
||||||
dotenv: 16.3.1
|
dotenv: ^16.4.5
|
||||||
jest: ^29.6.3
|
jest: ^29.6.3
|
||||||
knex: 2.4.2
|
knex: 2.4.2
|
||||||
medusa-test-utils: ^1.1.40
|
medusa-test-utils: ^1.1.40
|
||||||
@@ -8499,7 +8499,7 @@ __metadata:
|
|||||||
cors: ^2.8.5
|
cors: ^2.8.5
|
||||||
cross-env: ^5.2.1
|
cross-env: ^5.2.1
|
||||||
cross-spawn: ^7.0.3
|
cross-spawn: ^7.0.3
|
||||||
dotenv: ^16.0.3
|
dotenv: ^16.4.5
|
||||||
express: ^4.18.2
|
express: ^4.18.2
|
||||||
express-session: ^1.17.3
|
express-session: ^1.17.3
|
||||||
fs-exists-cached: ^1.0.0
|
fs-exists-cached: ^1.0.0
|
||||||
@@ -8683,7 +8683,6 @@ __metadata:
|
|||||||
"@medusajs/modules-sdk": ^1.12.5
|
"@medusajs/modules-sdk": ^1.12.5
|
||||||
"@medusajs/types": ^1.11.9
|
"@medusajs/types": ^1.11.9
|
||||||
"@medusajs/utils": ^1.11.2
|
"@medusajs/utils": ^1.11.2
|
||||||
"@medusajs/workflows-sdk": "workspace:^"
|
|
||||||
"@mikro-orm/cli": 5.9.7
|
"@mikro-orm/cli": 5.9.7
|
||||||
"@mikro-orm/core": 5.9.7
|
"@mikro-orm/core": 5.9.7
|
||||||
"@mikro-orm/migrations": 5.9.7
|
"@mikro-orm/migrations": 5.9.7
|
||||||
@@ -8775,7 +8774,7 @@ __metadata:
|
|||||||
"@mikro-orm/postgresql": 5.9.7
|
"@mikro-orm/postgresql": 5.9.7
|
||||||
awilix: ^8.0.0
|
awilix: ^8.0.0
|
||||||
cross-env: ^5.2.1
|
cross-env: ^5.2.1
|
||||||
dotenv: 16.3.1
|
dotenv: ^16.4.5
|
||||||
jest: ^29.6.3
|
jest: ^29.6.3
|
||||||
knex: 2.4.2
|
knex: 2.4.2
|
||||||
medusa-test-utils: ^1.1.40
|
medusa-test-utils: ^1.1.40
|
||||||
@@ -9194,7 +9193,7 @@ __metadata:
|
|||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
|
|
||||||
"@medusajs/workflows-sdk@^0.1.2, @medusajs/workflows-sdk@^0.1.3, @medusajs/workflows-sdk@workspace:^, @medusajs/workflows-sdk@workspace:packages/workflows-sdk":
|
"@medusajs/workflows-sdk@^0.1.2, @medusajs/workflows-sdk@^0.1.3, @medusajs/workflows-sdk@workspace:packages/workflows-sdk":
|
||||||
version: 0.0.0-use.local
|
version: 0.0.0-use.local
|
||||||
resolution: "@medusajs/workflows-sdk@workspace:packages/workflows-sdk"
|
resolution: "@medusajs/workflows-sdk@workspace:packages/workflows-sdk"
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -25870,7 +25869,7 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"dotenv@npm:16.4.5":
|
"dotenv@npm:16.4.5, dotenv@npm:^16.4.5":
|
||||||
version: 16.4.5
|
version: 16.4.5
|
||||||
resolution: "dotenv@npm:16.4.5"
|
resolution: "dotenv@npm:16.4.5"
|
||||||
checksum: 48d92870076832af0418b13acd6e5a5a3e83bb00df690d9812e94b24aff62b88ade955ac99a05501305b8dc8f1b0ee7638b18493deb6fe93d680e5220936292f
|
checksum: 48d92870076832af0418b13acd6e5a5a3e83bb00df690d9812e94b24aff62b88ade955ac99a05501305b8dc8f1b0ee7638b18493deb6fe93d680e5220936292f
|
||||||
|
|||||||
Reference in new issue
Block a user