fix(medusa): Plugin loader must also check for TransactionBaseService (#1601)
This commit is contained in:
@@ -13,6 +13,12 @@ const buildServiceTemplate = (name: string) => {
|
|||||||
export default class ${name}Service extends BaseService {}
|
export default class ${name}Service extends BaseService {}
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
const buildTransactionBaseServiceServiceTemplate = (name: string) => {
|
||||||
|
return `
|
||||||
|
import { TransactionBaseService } from "${resolve(__dirname, "../../interfaces")}"
|
||||||
|
export default class ${name}Service extends TransactionBaseService {}
|
||||||
|
`
|
||||||
|
}
|
||||||
|
|
||||||
describe('plugins loader', () => {
|
describe('plugins loader', () => {
|
||||||
const container = createContainer() as MedusaContainer
|
const container = createContainer() as MedusaContainer
|
||||||
@@ -30,6 +36,7 @@ describe('plugins loader', () => {
|
|||||||
mkdirSync(servicesTestTargetDirectoryPath, { mode: "777", recursive: true })
|
mkdirSync(servicesTestTargetDirectoryPath, { mode: "777", recursive: true })
|
||||||
writeFileSync(resolve(servicesTestTargetDirectoryPath, "test.js"), buildServiceTemplate("test"))
|
writeFileSync(resolve(servicesTestTargetDirectoryPath, "test.js"), buildServiceTemplate("test"))
|
||||||
writeFileSync(resolve(servicesTestTargetDirectoryPath, "test2.js"), buildServiceTemplate("test2"))
|
writeFileSync(resolve(servicesTestTargetDirectoryPath, "test2.js"), buildServiceTemplate("test2"))
|
||||||
|
writeFileSync(resolve(servicesTestTargetDirectoryPath, "test3.js"), buildTransactionBaseServiceServiceTemplate("test3"))
|
||||||
writeFileSync(resolve(servicesTestTargetDirectoryPath, "test2.js.map"), "map:file")
|
writeFileSync(resolve(servicesTestTargetDirectoryPath, "test2.js.map"), "map:file")
|
||||||
writeFileSync(resolve(servicesTestTargetDirectoryPath, "test2.d.ts"), "export interface Test {}")
|
writeFileSync(resolve(servicesTestTargetDirectoryPath, "test2.d.ts"), "export interface Test {}")
|
||||||
})
|
})
|
||||||
@@ -51,11 +58,14 @@ describe('plugins loader', () => {
|
|||||||
|
|
||||||
const testService: (...args: unknown[]) => any = container.resolve("testService")
|
const testService: (...args: unknown[]) => any = container.resolve("testService")
|
||||||
const test2Service: (...args: unknown[]) => any = container.resolve("test2Service")
|
const test2Service: (...args: unknown[]) => any = container.resolve("test2Service")
|
||||||
|
const test3Service: (...args: unknown[]) => any = container.resolve("test3Service")
|
||||||
|
|
||||||
expect(testService).toBeTruthy()
|
expect(testService).toBeTruthy()
|
||||||
expect(testService.constructor.name).toBe("testService")
|
expect(testService.constructor.name).toBe("testService")
|
||||||
expect(test2Service).toBeTruthy()
|
expect(test2Service).toBeTruthy()
|
||||||
expect(test2Service.constructor.name).toBe("test2Service")
|
expect(test2Service.constructor.name).toBe("test2Service")
|
||||||
|
expect(test3Service).toBeTruthy()
|
||||||
|
expect(test3Service.constructor.name).toBe("test3Service")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -2,7 +2,7 @@ import glob from "glob"
|
|||||||
import { Express } from "express"
|
import { Express } from "express"
|
||||||
import { EntitySchema } from "typeorm"
|
import { EntitySchema } from "typeorm"
|
||||||
import {
|
import {
|
||||||
BaseService,
|
BaseService as LegacyBaseService,
|
||||||
PaymentService,
|
PaymentService,
|
||||||
FulfillmentService,
|
FulfillmentService,
|
||||||
NotificationService,
|
NotificationService,
|
||||||
@@ -10,18 +10,17 @@ import {
|
|||||||
OauthService,
|
OauthService,
|
||||||
SearchService,
|
SearchService,
|
||||||
} from "medusa-interfaces"
|
} from "medusa-interfaces"
|
||||||
import { getConfigFile, createRequireFromPath } from "medusa-core-utils"
|
import { createRequireFromPath } from "medusa-core-utils"
|
||||||
import _ from "lodash"
|
import _ from "lodash"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import fs from "fs"
|
import fs from "fs"
|
||||||
import { asValue, asClass, asFunction, aliasTo } from "awilix"
|
import { asValue, asClass, asFunction, aliasTo } from "awilix"
|
||||||
import { sync as existsSync } from "fs-exists-cached"
|
import { sync as existsSync } from "fs-exists-cached"
|
||||||
import {
|
import {
|
||||||
AbstractFileService,
|
|
||||||
AbstractTaxService,
|
AbstractTaxService,
|
||||||
isFileService,
|
isFileService,
|
||||||
isTaxCalculationStrategy,
|
isTaxCalculationStrategy,
|
||||||
TransactionBaseService,
|
TransactionBaseService as BaseService,
|
||||||
} from "../interfaces"
|
} from "../interfaces"
|
||||||
import formatRegistrationName from "../utils/format-registration-name"
|
import formatRegistrationName from "../utils/format-registration-name"
|
||||||
import {
|
import {
|
||||||
@@ -297,11 +296,11 @@ export async function registerServices(
|
|||||||
const name = formatRegistrationName(fn)
|
const name = formatRegistrationName(fn)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!(loaded.prototype instanceof BaseService) &&
|
!(loaded.prototype instanceof LegacyBaseService) &&
|
||||||
!(loaded.prototype instanceof TransactionBaseService)
|
!(loaded.prototype instanceof BaseService)
|
||||||
) {
|
) {
|
||||||
const logger = container.resolve<Logger>("logger")
|
const logger = container.resolve<Logger>("logger")
|
||||||
const message = `File must be a valid service implementation, please check ${fn}`
|
const message = `The class must be a valid service implementation, please check ${fn}`
|
||||||
logger.error(message)
|
logger.error(message)
|
||||||
throw new Error(message)
|
throw new Error(message)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user