@pradip1995/framework-compiler 0.3.3 → 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,7 +62,7 @@ function formatPluginEntry(key, definition) {
41
62
  return lines.join("\n")
42
63
  }
43
64
 
44
- function buildPluginsBlock(enabledPlugins, moduleOnlyPlugins = []) {
65
+ function buildPluginsBlock(enabledPlugins, moduleOnlyPlugins = [], pluginOptions = {}) {
45
66
  const skip = new Set(moduleOnlyPlugins)
46
67
  const entries = []
47
68
  for (const key of enabledPlugins) {
@@ -50,7 +71,11 @@ function buildPluginsBlock(enabledPlugins, moduleOnlyPlugins = []) {
50
71
  if (!definition) {
51
72
  throw new Error(`Unknown plugin "${key}" — add it to plugin-definitions.cjs or remove from plugins.config.json`)
52
73
  }
53
- entries.push(formatPluginEntry(key, definition))
74
+ const merged = {
75
+ ...definition,
76
+ options: deepMerge(definition.options, pluginOptions[key]),
77
+ }
78
+ entries.push(formatPluginEntry(key, merged))
54
79
  }
55
80
  return entries.join(",\n")
56
81
  }
@@ -59,7 +84,12 @@ function hasPlugin(enabledPlugins, name) {
59
84
  return enabledPlugins.includes(name)
60
85
  }
61
86
 
62
- function generateMedusaConfig({ enabledPlugins, preset = "full", moduleOnlyPlugins = [] }) {
87
+ function generateMedusaConfig({
88
+ enabledPlugins,
89
+ preset = "full",
90
+ moduleOnlyPlugins = [],
91
+ pluginOptions = {},
92
+ }) {
63
93
  const useShiprocket =
64
94
  preset === "full" && hasPlugin(enabledPlugins, "medusa-shiprocket-fulfillment-sbl")
65
95
  const usePaymentProvider =
@@ -246,7 +276,7 @@ module.exports = defineConfig({
246
276
  },
247
277
  },
248
278
  plugins: [
249
- ${buildPluginsBlock(enabledPlugins, moduleOnlyPlugins)}
279
+ ${buildPluginsBlock(enabledPlugins, moduleOnlyPlugins, pluginOptions)}
250
280
  ],
251
281
  modules: {
252
282
  [Modules.AUTH]: {
@@ -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)
@@ -164,6 +165,7 @@ function main() {
164
165
  enabledPlugins,
165
166
  preset,
166
167
  moduleOnlyPlugins: defaults.moduleOnlyPlugins || [],
168
+ pluginOptions,
167
169
  })
168
170
  )
169
171
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pradip1995/framework-compiler",
3
- "version": "0.3.3",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "publishConfig": {