fix(medusa): Use default logger in plugin:develop (#13375)
**What** Use default logger for plugin command, since there is no `medusa-config.ts` to load the container with (the container that holds the custom logger)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(medusa): Use default logger in plugin:develop
|
||||||
@@ -1,18 +1,16 @@
|
|||||||
|
import { logger } from "@medusajs/framework"
|
||||||
import type { Logger } from "@medusajs/framework/types"
|
import type { Logger } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
ContainerRegistrationKeys,
|
|
||||||
defineMikroOrmCliConfig,
|
defineMikroOrmCliConfig,
|
||||||
DmlEntity,
|
DmlEntity,
|
||||||
dynamicImport,
|
dynamicImport,
|
||||||
isFileSkipped,
|
isFileSkipped,
|
||||||
toUnixSlash,
|
toUnixSlash,
|
||||||
} from "@medusajs/framework/utils"
|
} from "@medusajs/framework/utils"
|
||||||
import { glob } from "glob"
|
|
||||||
import { dirname, join } from "path"
|
|
||||||
|
|
||||||
import { MetadataStorage } from "@mikro-orm/core"
|
import { MetadataStorage } from "@mikro-orm/core"
|
||||||
import { MikroORM } from "@mikro-orm/postgresql"
|
import { MikroORM } from "@mikro-orm/postgresql"
|
||||||
import { initializeContainer } from "../../../loaders"
|
import { glob } from "glob"
|
||||||
|
import { dirname, join } from "path"
|
||||||
|
|
||||||
const TERMINAL_SIZE = process.stdout.columns
|
const TERMINAL_SIZE = process.stdout.columns
|
||||||
|
|
||||||
@@ -20,11 +18,6 @@ const TERMINAL_SIZE = process.stdout.columns
|
|||||||
* Generate migrations for all scanned modules in a plugin
|
* Generate migrations for all scanned modules in a plugin
|
||||||
*/
|
*/
|
||||||
const main = async function ({ directory }) {
|
const main = async function ({ directory }) {
|
||||||
const container = await initializeContainer(directory, {
|
|
||||||
skipDbConnection: true,
|
|
||||||
})
|
|
||||||
const logger = container.resolve(ContainerRegistrationKeys.LOGGER)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const moduleDescriptors = [] as {
|
const moduleDescriptors = [] as {
|
||||||
serviceName: string
|
serviceName: string
|
||||||
|
|||||||
+1
-18
@@ -1,24 +1,9 @@
|
|||||||
|
import { logger } from "@medusajs/framework"
|
||||||
import { FileSystem } from "@medusajs/framework/utils"
|
import { FileSystem } from "@medusajs/framework/utils"
|
||||||
import { join } from "path"
|
import { join } from "path"
|
||||||
import main from "../../generate"
|
import main from "../../generate"
|
||||||
|
|
||||||
const logger = {
|
|
||||||
log: jest.fn(),
|
|
||||||
info: jest.fn(),
|
|
||||||
error: jest.fn(),
|
|
||||||
warn: jest.fn(),
|
|
||||||
}
|
|
||||||
|
|
||||||
jest.mock("@medusajs/framework/logger")
|
jest.mock("@medusajs/framework/logger")
|
||||||
jest.mock("../../../../../loaders", () => {
|
|
||||||
return {
|
|
||||||
initializeContainer: jest.fn().mockImplementation(() => {
|
|
||||||
return {
|
|
||||||
resolve: jest.fn(() => logger),
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("plugin-generate", () => {
|
describe("plugin-generate", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@@ -28,8 +13,6 @@ describe("plugin-generate", () => {
|
|||||||
.mockImplementation((code?: string | number | null) => {
|
.mockImplementation((code?: string | number | null) => {
|
||||||
return code as never
|
return code as never
|
||||||
})
|
})
|
||||||
|
|
||||||
jest.mock("@medusajs/framework/logger")
|
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
|
|||||||
@@ -1,18 +1,14 @@
|
|||||||
import { Compiler } from "@medusajs/framework/build-tools"
|
import { Compiler } from "@medusajs/framework/build-tools"
|
||||||
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
|
import { logger } from "@medusajs/framework/logger"
|
||||||
import * as swcCore from "@swc/core"
|
import * as swcCore from "@swc/core"
|
||||||
import { execFile } from "child_process"
|
import { execFile } from "child_process"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { initializeContainer } from "../../loaders"
|
|
||||||
|
|
||||||
export default async function developPlugin({
|
export default async function developPlugin({
|
||||||
directory,
|
directory,
|
||||||
}: {
|
}: {
|
||||||
directory: string
|
directory: string
|
||||||
}) {
|
}) {
|
||||||
const container = await initializeContainer(directory)
|
|
||||||
const logger = container.resolve(ContainerRegistrationKeys.LOGGER)
|
|
||||||
|
|
||||||
let isBusy = false
|
let isBusy = false
|
||||||
const compiler = new Compiler(directory, logger)
|
const compiler = new Compiler(directory, logger)
|
||||||
const parsedConfig = await compiler.loadTSConfigFile()
|
const parsedConfig = await compiler.loadTSConfigFile()
|
||||||
|
|||||||
Reference in New Issue
Block a user