@pradip1995/framework-compiler 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -26,6 +26,27 @@ function formatValue(value, indent = 4) {
|
|
|
26
26
|
return "undefined"
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
function deepMerge(base, override) {
|
|
30
|
+
if (!override) return base ?? {}
|
|
31
|
+
if (Array.isArray(override)) return override
|
|
32
|
+
const result = { ...(base ?? {}) }
|
|
33
|
+
for (const [key, val] of Object.entries(override)) {
|
|
34
|
+
if (
|
|
35
|
+
val &&
|
|
36
|
+
typeof val === "object" &&
|
|
37
|
+
!Array.isArray(val) &&
|
|
38
|
+
result[key] &&
|
|
39
|
+
typeof result[key] === "object" &&
|
|
40
|
+
!Array.isArray(result[key])
|
|
41
|
+
) {
|
|
42
|
+
result[key] = deepMerge(result[key], val)
|
|
43
|
+
} else {
|
|
44
|
+
result[key] = val
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return result
|
|
48
|
+
}
|
|
49
|
+
|
|
29
50
|
function formatPluginEntry(key, definition) {
|
|
30
51
|
const lines = [" {"]
|
|
31
52
|
if (definition.resolveSpecial === "medusa-analytics") {
|
|
@@ -41,14 +62,20 @@ function formatPluginEntry(key, definition) {
|
|
|
41
62
|
return lines.join("\n")
|
|
42
63
|
}
|
|
43
64
|
|
|
44
|
-
function buildPluginsBlock(enabledPlugins) {
|
|
65
|
+
function buildPluginsBlock(enabledPlugins, moduleOnlyPlugins = [], pluginOptions = {}) {
|
|
66
|
+
const skip = new Set(moduleOnlyPlugins)
|
|
45
67
|
const entries = []
|
|
46
68
|
for (const key of enabledPlugins) {
|
|
69
|
+
if (skip.has(key)) continue
|
|
47
70
|
const definition = pluginDefinitions[key]
|
|
48
71
|
if (!definition) {
|
|
49
72
|
throw new Error(`Unknown plugin "${key}" — add it to plugin-definitions.cjs or remove from plugins.config.json`)
|
|
50
73
|
}
|
|
51
|
-
|
|
74
|
+
const merged = {
|
|
75
|
+
...definition,
|
|
76
|
+
options: deepMerge(definition.options, pluginOptions[key]),
|
|
77
|
+
}
|
|
78
|
+
entries.push(formatPluginEntry(key, merged))
|
|
52
79
|
}
|
|
53
80
|
return entries.join(",\n")
|
|
54
81
|
}
|
|
@@ -57,7 +84,12 @@ function hasPlugin(enabledPlugins, name) {
|
|
|
57
84
|
return enabledPlugins.includes(name)
|
|
58
85
|
}
|
|
59
86
|
|
|
60
|
-
function generateMedusaConfig({
|
|
87
|
+
function generateMedusaConfig({
|
|
88
|
+
enabledPlugins,
|
|
89
|
+
preset = "full",
|
|
90
|
+
moduleOnlyPlugins = [],
|
|
91
|
+
pluginOptions = {},
|
|
92
|
+
}) {
|
|
61
93
|
const useShiprocket =
|
|
62
94
|
preset === "full" && hasPlugin(enabledPlugins, "medusa-shiprocket-fulfillment-sbl")
|
|
63
95
|
const usePaymentProvider =
|
|
@@ -244,7 +276,7 @@ module.exports = defineConfig({
|
|
|
244
276
|
},
|
|
245
277
|
},
|
|
246
278
|
plugins: [
|
|
247
|
-
${buildPluginsBlock(enabledPlugins)}
|
|
279
|
+
${buildPluginsBlock(enabledPlugins, moduleOnlyPlugins, pluginOptions)}
|
|
248
280
|
],
|
|
249
281
|
modules: {
|
|
250
282
|
[Modules.AUTH]: {
|
package/bin/backend-build.js
CHANGED
|
@@ -122,6 +122,7 @@ function main() {
|
|
|
122
122
|
const pluginsConfig = loadJson(pluginsConfigPath)
|
|
123
123
|
const backendConfig = loadJson(backendConfigPath)
|
|
124
124
|
const defaults = loadJson(join(TEMPLATE_ROOT, "medusa-plugin-versions.json"))
|
|
125
|
+
const pluginOptions = pluginsConfig.pluginOptions || {}
|
|
125
126
|
|
|
126
127
|
const enabledPlugins = resolveEnabledPlugins(pluginsConfig, backendConfig, defaults)
|
|
127
128
|
const { medusa, plugins } = resolveDependencies(pluginsConfig, enabledPlugins, defaults)
|
|
@@ -160,7 +161,12 @@ function main() {
|
|
|
160
161
|
|
|
161
162
|
writeFileSync(
|
|
162
163
|
join(outDir, "medusa-config.ts"),
|
|
163
|
-
generateMedusaConfig({
|
|
164
|
+
generateMedusaConfig({
|
|
165
|
+
enabledPlugins,
|
|
166
|
+
preset,
|
|
167
|
+
moduleOnlyPlugins: defaults.moduleOnlyPlugins || [],
|
|
168
|
+
pluginOptions,
|
|
169
|
+
})
|
|
164
170
|
)
|
|
165
171
|
|
|
166
172
|
writeFileSync(
|