feat: remove dead code and refactor the logic of resolving plugins (#10874)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import {
|
||||
ConfigModule,
|
||||
ExternalModuleDeclaration,
|
||||
InputConfig,
|
||||
InternalModuleDeclaration,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
@@ -29,42 +29,6 @@ export const DEFAULT_STORE_RESTRICTED_FIELDS = [
|
||||
"payment_collections"*/
|
||||
]
|
||||
|
||||
type InternalModuleDeclarationOverride = InternalModuleDeclaration & {
|
||||
/**
|
||||
* Optional key to be used to identify the module, if not provided, it will be inferred from the module joiner config service name.
|
||||
*/
|
||||
key?: string
|
||||
/**
|
||||
* By default, modules are enabled, if provided as true, this will disable the module entirely.
|
||||
*/
|
||||
disable?: boolean
|
||||
}
|
||||
|
||||
type ExternalModuleDeclarationOverride = ExternalModuleDeclaration & {
|
||||
/**
|
||||
* key to be used to identify the module, if not provided, it will be inferred from the module joiner config service name.
|
||||
*/
|
||||
key: string
|
||||
/**
|
||||
* By default, modules are enabled, if provided as true, this will disable the module entirely.
|
||||
*/
|
||||
disable?: boolean
|
||||
}
|
||||
|
||||
type Config = Partial<
|
||||
Omit<ConfigModule, "admin" | "modules"> & {
|
||||
admin: Partial<ConfigModule["admin"]>
|
||||
modules:
|
||||
| Partial<
|
||||
InternalModuleDeclarationOverride | ExternalModuleDeclarationOverride
|
||||
>[]
|
||||
/**
|
||||
* @deprecated use the array instead
|
||||
*/
|
||||
| ConfigModule["modules"]
|
||||
}
|
||||
>
|
||||
|
||||
/**
|
||||
* The "defineConfig" helper can be used to define the configuration
|
||||
* of a medusa application.
|
||||
@@ -73,7 +37,7 @@ type Config = Partial<
|
||||
* make an application work seamlessly, but still provide you the ability
|
||||
* to override configuration as needed.
|
||||
*/
|
||||
export function defineConfig(config: Config = {}): ConfigModule {
|
||||
export function defineConfig(config: InputConfig = {}): ConfigModule {
|
||||
const { http, redisOptions, ...restOfProjectConfig } =
|
||||
config.projectConfig || {}
|
||||
|
||||
@@ -150,14 +114,14 @@ export function defineConfig(config: Config = {}): ConfigModule {
|
||||
* @param configModules
|
||||
*/
|
||||
function resolveModules(
|
||||
configModules: Config["modules"]
|
||||
configModules: InputConfig["modules"]
|
||||
): ConfigModule["modules"] {
|
||||
/**
|
||||
* The default set of modules to always use. The end user can swap
|
||||
* the modules by providing an alternate implementation via their
|
||||
* config. But they can never remove a module from this list.
|
||||
*/
|
||||
const modules: Config["modules"] = [
|
||||
const modules: InputConfig["modules"] = [
|
||||
{ resolve: MODULE_PACKAGE_NAMES[Modules.CACHE] },
|
||||
{ resolve: MODULE_PACKAGE_NAMES[Modules.EVENT_BUS] },
|
||||
{ resolve: MODULE_PACKAGE_NAMES[Modules.WORKFLOW_ENGINE] },
|
||||
|
||||
@@ -2,21 +2,51 @@ import { Dirent } from "fs"
|
||||
import { readdir } from "fs/promises"
|
||||
import { join } from "path"
|
||||
|
||||
export async function readDirRecursive(dir: string): Promise<Dirent[]> {
|
||||
let allEntries: Dirent[] = []
|
||||
const readRecursive = async (dir) => {
|
||||
const MISSING_NODE_ERRORS = ["ENOTDIR", "ENOENT"]
|
||||
|
||||
export async function readDir(
|
||||
dir: string,
|
||||
options?: {
|
||||
ignoreMissing?: boolean
|
||||
}
|
||||
) {
|
||||
try {
|
||||
const entries = await readdir(dir, { withFileTypes: true })
|
||||
return entries
|
||||
} catch (error) {
|
||||
if (options?.ignoreMissing && MISSING_NODE_ERRORS.includes(error.code)) {
|
||||
return []
|
||||
}
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
for (const entry of entries) {
|
||||
const fullPath = join(dir, entry.name)
|
||||
Object.defineProperty(entry, "path", {
|
||||
value: dir,
|
||||
})
|
||||
allEntries.push(entry)
|
||||
export async function readDirRecursive(
|
||||
dir: string,
|
||||
options?: {
|
||||
ignoreMissing?: boolean
|
||||
}
|
||||
): Promise<Dirent[]> {
|
||||
let allEntries: Dirent[] = []
|
||||
const readRecursive = async (dir: string) => {
|
||||
try {
|
||||
const entries = await readdir(dir, { withFileTypes: true })
|
||||
for (const entry of entries) {
|
||||
const fullPath = join(dir, entry.name)
|
||||
Object.defineProperty(entry, "path", {
|
||||
value: dir,
|
||||
})
|
||||
allEntries.push(entry)
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
await readRecursive(fullPath)
|
||||
if (entry.isDirectory()) {
|
||||
await readRecursive(fullPath)
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
if (options?.ignoreMissing && error.code === "ENOENT") {
|
||||
return
|
||||
}
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user