Skip to content

Commit 49bb54f

Browse files
fix: skip npm install in local
1 parent 7b1f7e9 commit 49bb54f

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{%- for app_name, app in iter_mfes() %}
2+
{%- set mounts = iter_mounts(MOUNTS, app_name)|list %}
3+
{%- if mounts %}
4+
{{ app_name }}-job:
5+
image: "{{ MFE_DOCKER_IMAGE }}"
6+
{%- endif %}
7+
{%- endfor %}

tutormfe/plugin.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,13 @@ def _check_mfe_host(config: Config) -> None:
311311
def _run_jobs_in_mounted_mfes(config: Config) -> None:
312312
mounts = get_typed(config, "MOUNTS", list, [])
313313

314-
pattern = re.compile(r'frontend-app-(\w+)')
314+
if not mounts:
315+
return None
316+
317+
pattern = re.compile(rf'{re.escape(REPO_PREFIX)}(\w+)')
315318
mounted_mfes = [match.group(1) for mount in mounts if (match := pattern.search(mount))]
316319

317-
mfe_task_file = os.path.join(
320+
mfe_npm_install_file = os.path.join(
318321
str(
319322
importlib_resources.files("tutormfe")
320323
/ "templates"
@@ -327,5 +330,5 @@ def _run_jobs_in_mounted_mfes(config: Config) -> None:
327330

328331
for mounted_mfe in mounted_mfes:
329332
with tutor_hooks.Contexts.app("mfe").enter():
330-
with open(mfe_task_file, encoding='utf-8') as fi:
333+
with open(mfe_npm_install_file, encoding='utf-8') as fi:
331334
tutor_hooks.Filters.CLI_DO_INIT_TASKS.add_item((mounted_mfe , fi.read()))

tutormfe/templates/mfe/tasks/mfe/npm-install.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/bin/bash
22

3+
if [ "$NODE_ENV" != "development" ]; then
4+
echo "This script is intended to run only in the development environment."
5+
exit
6+
fi
7+
38
# Paths for the fingerprint and package-lock.json
49
FINGERPRINT_FILE="node_modules/.fingerprint"
510
PACKAGE_LOCK="package-lock.json"
@@ -9,28 +14,33 @@ generate_fingerprint() {
914
sha1sum "$PACKAGE_LOCK" | awk '{print $1}'
1015
}
1116

12-
# Check if node_modules exists and fingerprint is valid
17+
# If node_modules directory is missing, install dependencies
1318
if [ ! -d "node_modules" ]; then
1419
echo "⚠️ node_modules not found! Installing dependencies..."
1520
npm clean-install
1621

22+
# If fingerprint file is missing, assume packages may be out of sync and reinstall
1723
elif [ ! -f "$FINGERPRINT_FILE" ]; then
1824
echo "⚠️ Fingerprint file not found! Re-installing dependencies..."
1925
npm clean-install
2026

27+
# If both node_modules and fingerprint file exist, compare fingerprints
2128
else
2229
CURRENT_FINGERPRINT=$(generate_fingerprint)
2330
STORED_FINGERPRINT=$(cat "$FINGERPRINT_FILE")
2431

32+
# Reinstall if package-lock.json has changed
2533
if [ "$CURRENT_FINGERPRINT" != "$STORED_FINGERPRINT" ]; then
2634
echo "⚠️ package-lock.json changed! Re-installing dependencies..."
2735
npm clean-install
2836
else
37+
# Everything is up to date
2938
echo "✅ Dependencies are up to date."
3039
exit 0
3140
fi
3241
fi
3342

43+
3444
# Store the new fingerprint after installation
3545
generate_fingerprint > "$FINGERPRINT_FILE"
3646
echo "✅ Dependencies installed and fingerprint updated."

0 commit comments

Comments
 (0)