Raw
1 import { InputFileConfig } from "@medusajs/types"
2 import { getCallerFilePath } from "./get-caller-file-path"
3
4 export const MEDUSA_SKIP_FILE = Symbol.for("__MEDUSA_SKIP_FILE__")
5 /**
6 * The "defineFileConfig" helper can be used to define the configuration
7 * of any file auto-loaded by Medusa.
8 *
9 * It is used to avoid loading files that are not required. Like a feature flag
10 * that is disabled.
11 */
12 const FILE_CONFIGS = new Map()
13 export function defineFileConfig(config?: InputFileConfig) {
14 const filePath = config?.path ?? getCallerFilePath()
15 FILE_CONFIGS.set(filePath, config)
16 }
17
18 export function getDefinedFileConfig(path?: string) {
19 return FILE_CONFIGS.get(path)
20 }
21
22 export function isFileDisabled(path?: string) {
23 return !!getDefinedFileConfig(path)?.isDisabled?.()
24 }
25
26 export function isFileSkipped(exported: unknown) {
27 return !!exported?.[MEDUSA_SKIP_FILE]
28 }