-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes: FRMW-2858 This PR merge the modules exported by the plugins with the modules defined within the user config. As a result, all modules get loaded without changing the internals of the loader. However, you cannot disable the module of a plugin by re-adding it to the `modules` array. That is something we should handle separately. We've added the breaking change label because of the following fix: We did broke the ability to completely disable modules in the past pr's, in this pr we re add the ability to disable a module and that this modules does not get loaded at all. ([here](6dd164f)) Co-authored-by: Adrien de Peretti <[email protected]>
- Loading branch information
1 parent
a607b8e
commit c1930bd
Showing
15 changed files
with
244 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@medusajs/medusa": patch | ||
"@medusajs/types": patch | ||
"@medusajs/utils": patch | ||
--- | ||
|
||
Feat/merge plugin modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
packages/core/utils/src/common/__tests__/transform-modules.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { MODULE_PACKAGE_NAMES, Modules } from "../../modules-sdk" | ||
import { transformModules } from "../define-config" | ||
|
||
describe("transformModules", () => { | ||
test("convert array of modules to an object", () => { | ||
const modules = transformModules([ | ||
{ | ||
resolve: require.resolve("../__fixtures__/define-config/github"), | ||
options: { | ||
apiKey: "test", | ||
}, | ||
}, | ||
]) | ||
|
||
expect(modules).toEqual({ | ||
GithubModuleService: { | ||
options: { | ||
apiKey: "test", | ||
}, | ||
resolve: require.resolve("../__fixtures__/define-config/github"), | ||
}, | ||
}) | ||
}) | ||
|
||
test("transform default module", () => { | ||
const modules = transformModules([ | ||
{ | ||
resolve: MODULE_PACKAGE_NAMES[Modules.CACHE], | ||
}, | ||
]) | ||
|
||
expect(modules).toEqual({ | ||
cache: { | ||
resolve: "@medusajs/medusa/cache-inmemory", | ||
}, | ||
}) | ||
}) | ||
|
||
test("should manage loading priority of modules when its disabled at a later stage in the array", () => { | ||
const modules = transformModules([ | ||
{ | ||
resolve: MODULE_PACKAGE_NAMES[Modules.CACHE], | ||
}, | ||
{ | ||
resolve: MODULE_PACKAGE_NAMES[Modules.CACHE], | ||
disable: true, | ||
}, | ||
]) | ||
|
||
expect(modules).toEqual({ | ||
cache: { | ||
resolve: MODULE_PACKAGE_NAMES[Modules.CACHE], | ||
disable: true, | ||
}, | ||
}) | ||
}) | ||
|
||
test("should manage loading priority of modules when its not disabled at a later stage in the array", () => { | ||
const modules = transformModules([ | ||
{ | ||
resolve: MODULE_PACKAGE_NAMES[Modules.CACHE], | ||
disable: true, | ||
}, | ||
{ | ||
resolve: MODULE_PACKAGE_NAMES[Modules.CACHE], | ||
}, | ||
]) | ||
|
||
expect(modules).toEqual({ | ||
cache: { | ||
resolve: MODULE_PACKAGE_NAMES[Modules.CACHE], | ||
}, | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { | ||
PluginDetails, | ||
ConfigModule, | ||
InputConfigModules, | ||
} from "@medusajs/types" | ||
import { transformModules } from "./define-config" | ||
|
||
/** | ||
* Mutates the configModules object and merges the plugin modules with | ||
* the modules defined inside the user-config file | ||
*/ | ||
export function mergePluginModules( | ||
configModule: ConfigModule, | ||
plugins: PluginDetails[] | ||
) { | ||
/** | ||
* Create a flat array of all the modules exposed by the registered | ||
* plugins | ||
*/ | ||
const pluginsModules = plugins.reduce((result, plugin) => { | ||
if (plugin.modules) { | ||
result = result.concat(plugin.modules) | ||
} | ||
return result | ||
}, [] as InputConfigModules) | ||
|
||
/** | ||
* Merge plugin modules with the modules defined within the | ||
* config file. | ||
*/ | ||
configModule.modules = { | ||
...transformModules(pluginsModules), | ||
...configModule.modules, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.