-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support frontend plugins via env.config.jsx
This provides a mechanism to configure frontend plugins using a new PLUGIN_SLOTS filter and a series of patches that modify a base `env.config.jsx`, in such a way that multiple plugins can take advantage of the file (including for purposes beyond frontend plugins) without clobbering each other.
- Loading branch information
Showing
6 changed files
with
248 additions
and
7 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
1 change: 1 addition & 0 deletions
1
changelog.d/20241111_172451_arbrandes_frontend_plugin_support.md
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 @@ | ||
- [Improvement] Adds support for frontend plugin slot configuration via env.config.jsx. (by @arbrandes) |
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
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,51 @@ | ||
{{- patch("mfe-env-config-buildtime-imports") }} | ||
|
||
function addPlugins(config, slot_name, plugins) { | ||
if (slot_name in config.pluginSlots === false) { | ||
config.pluginSlots[slot_name] = { | ||
keepDefault: true, | ||
plugins: [] | ||
}; | ||
} | ||
|
||
config.pluginSlots[slot_name].plugins.push(...plugins); | ||
} | ||
|
||
{{- patch("mfe-env-config-buildtime-definitions") }} | ||
|
||
async function setConfig () { | ||
let config = { | ||
pluginSlots: {} | ||
}; | ||
|
||
try { | ||
/* We can't assume FPF exists, as it's not declared as a dependency in all | ||
* MFEs, so we import it dynamically. In addition, for dynamic imports to | ||
* work with Webpack all of the code that actually uses the imported module | ||
* needs to be inside the `try{}` block. | ||
*/ | ||
const { DIRECT_PLUGIN, PLUGIN_OPERATIONS } = await import('@openedx/frontend-plugin-framework'); | ||
|
||
{{- patch("mfe-env-config-runtime-definitions") }} | ||
|
||
{%- for slot_name, plugin_config in iter_plugin_slots("all") %} | ||
addPlugins(config, '{{ slot_name }}', [{{ plugin_config }}]); | ||
{%- endfor %} | ||
|
||
{%- for app_name, _ in iter_mfes() %} | ||
if (process.env.APP_ID == '{{ app_name }}') { | ||
{{- patch("mfe-env-config-runtime-definitions-{}".format(app_name)) }} | ||
|
||
{%- for slot_name, plugin_config in iter_plugin_slots(app_name) %} | ||
addPlugins(config, '{{ slot_name }}', [{{ plugin_config }}]); | ||
{%- endfor %} | ||
} | ||
{%- endfor %} | ||
|
||
{{- patch("mfe-env-config-runtime-final") }} | ||
} catch { } | ||
|
||
return config; | ||
} | ||
|
||
export default setConfig; |