|
1
|
import type { |
|
2
|
PluginDetails, |
|
3
|
ConfigModule, |
|
4
|
InputConfigModules, |
|
5
|
} from "@medusajs/types" |
|
6
|
import { transformModules } from "./define-config" |
|
7
|
|
|
8
|
/** |
|
9
|
* Mutates the configModules object and merges the plugin modules with |
|
10
|
* the modules defined inside the user-config file |
|
11
|
*/ |
|
12
|
export function mergePluginModules( |
|
13
|
configModule: ConfigModule, |
|
14
|
plugins: PluginDetails[], |
|
15
|
/** |
|
16
|
* Root directory of the Medusa application. The modules exposed by a plugin |
|
17
|
* are referenced by a bare specifier, so they have to be resolved from the |
|
18
|
* application and not from wherever `@medusajs/utils` was hoisted to. |
|
19
|
*/ |
|
20
|
rootDirectory: string = process.cwd() |
|
21
|
) { |
|
22
|
/** |
|
23
|
* Create a flat array of all the modules exposed by the registered |
|
24
|
* plugins |
|
25
|
*/ |
|
26
|
const pluginsModules = plugins.reduce((result, plugin) => { |
|
27
|
if (plugin.modules) { |
|
28
|
result = result.concat(plugin.modules) |
|
29
|
} |
|
30
|
return result |
|
31
|
}, [] as InputConfigModules) |
|
32
|
|
|
33
|
/** |
|
34
|
* Merge plugin modules with the modules defined within the |
|
35
|
* config file. |
|
36
|
*/ |
|
37
|
configModule.modules = { |
|
38
|
...transformModules(pluginsModules, rootDirectory), |
|
39
|
...configModule.modules, |
|
40
|
} |
|
41
|
} |