-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] fix: add script to install node_modules in mounted mfes #232
base: release
Are you sure you want to change the base?
[WIP] fix: add script to install node_modules in mounted mfes #232
Conversation
def _run_jobs_in_mounted_mfes(config: Config) -> None: | ||
mounts = get_typed(config, "MOUNTS", list, []) | ||
|
||
pattern = re.compile(r'frontend-app-(\w+)') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use the REPO_PREFIX variable defined above here instead of a hardcoded string.
@tutor_hooks.Actions.CONFIG_LOADED.add() | ||
def _run_jobs_in_mounted_mfes(config: Config) -> None: | ||
mounts = get_typed(config, "MOUNTS", list, []) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can return here if no mounts exist in the config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
@@ -0,0 +1,11 @@ | |||
{%- for app_name, app in iter_mfes() %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this patch needed?
pattern = re.compile(r'frontend-app-(\w+)') | ||
mounted_mfes = [match.group(1) for mount in mounts if (match := pattern.search(mount))] | ||
|
||
mfe_task_file = os.path.join( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mfe_npm_install could be a better name as this action is related only to npm install.
sha1sum "$PACKAGE_LOCK" | awk '{print $1}' | ||
} | ||
|
||
# Check if node_modules exists and fingerprint is valid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment can be broken down and mentioned against the appropriate if-elif-else block.
|
||
|
||
@tutor_hooks.Actions.CONFIG_LOADED.add() | ||
def _run_jobs_in_mounted_mfes(config: Config) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a big fan of adding callbacks to the CONFIG_LOADED action. It means we have to manually parse MOUNTS
and this is bound to fail in many edge cases. Also, we have to start using Context objects, which is VERY dirty.
Instead, I suggest the following:
@tutor_hooks.Filters.CLI_DO_INIT_TASKS.add()
def _mfe_npm_install(tasks):
for mfe in get_mfes():
if hooks.Filters.COMPOSE_MOUNTS.apply([], f"frontend-app-{mfe}"):
tasks.append((mfe, "... contents of npm-install.sh..."))
What do you think?
WIP -> The jobs run on tutor dev only
Description
These code changes introduce improvements to the Tutor MFE (Micro-Frontend) plugin by adding automation and efficiency for managing and running tasks in environments where MFEs are mounted. When MFEs are mounted, it will run
npm clean-install
as part of the runtutor dev launch
. The "mfe" init tasknpm-install.sh
is taking care of installing the node_modules, as it is done in the LMSTest Cases:
npm-install
script when MFEs are implicitly and expicitly mounted using the Tutor format:tutor mounts add $(pwd)/frontend-app-*
&tutor mounts add [mfe-name]:$(pwd)/frontend-app-*:/openedx/app
.tutor dev
, nottutor local
, as MFEs mount only intutor dev
environment.node_modules
are present, it should installnode_modules
.node_modules
directory exists but is empty or outdated, it should installnode_modules
.package-lock.json
file changes slightly, it should trigger reinstallation ofnode_modules
.node_modules
are installed and then reinstallation is attempted without changes topackage-lock.json
, it should not reinstallnode_modules
.Closes #218
Special thanks to @Danyal-Faheem for collaborating with me on this and helping to reach a solution. 🙌