-
-
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.
Merge branch 'develop' into chore/compiler-utility
- Loading branch information
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.