Skip to content

Commit 12fd2a9

Browse files
Bee-Marclaude
andauthored
Fix/dev hints (#304)
* chore: remove unused axios dep; replace npm run with node --run axios was listed as a direct UI dependency but had no import sites. Switch MagicMirror start command and CI lint step from `npm run` to `node --run` (available in Node 22+, matches the current test matrix). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: replace git checkout . with git restore . for working tree reset git restore is the correct modern replacement for discarding working tree changes; git switch is for branch switching. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * build: update dependencies * chore: fix build with nix * chore: fix setup with bun.nix prevent modifications to file when not needed * chore: add pre-commit script to unify version location * docs: update changelog --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 1d45d12 commit 12fd2a9

16 files changed

Lines changed: 5698 additions & 6907 deletions

.github/workflows/workflow.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ jobs:
134134
135135
- name: Angular Lint
136136
run: |
137-
cd ui && npm run lint && cd ..
137+
cd ui && node --run lint && cd ..
138138
139139
- name: Angular Unit Tests
140140
run: |

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,3 +462,22 @@
462462

463463
- Bumping version to 4.6.2 to trigger a new build
464464
- Stale cache within CI/CD pipeline caused incorrect wheels to be built thus producing inconsistent builds
465+
466+
## Version 4.6.3
467+
468+
### Bug Fixes
469+
470+
- Fixed working tree reset in `MagicMirrorPackage.upgrade()` to use `git restore .` instead of the deprecated `git checkout .`; `git restore` is the correct modern command for discarding working tree changes
471+
472+
### Build
473+
474+
- Fixed `nix build` failure caused by Angular attempting to inline Google Fonts over the network during the production build; disabled `optimization.fonts.inline` in the production configuration so fonts continue to load at runtime via `<link>` as intended
475+
- Fixed `postinstall` script bash quoting bug where `[ -x $(command -v b2n) ]` evaluated truthy when `b2n` was absent, causing a spurious "command not found" error in the Nix sandbox
476+
- Updated Python and UI dependencies
477+
478+
### Tooling
479+
480+
- `bun.nix` no longer regenerates on every `direnv reload` / shell entry; the devshell now runs `bun install --ignore-scripts` to skip lifecycle scripts during shell initialization, and `lock` explicitly regenerates `bun.nix` after `bun update`
481+
- Added `sync:version` pre-commit hook that reads the version from `pyproject.toml` and keeps `mmpm/__version__.py` and `ui/package.json` in sync automatically on every commit
482+
- Removed unused `axios` dependency from the UI
483+
- Replaced `npm run` with `node --run` in the MagicMirror start command and CI lint step (requires Node 22+)

flake.lock

Lines changed: 31 additions & 59 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,31 @@
127127
};
128128

129129
nixfmt.enable = true;
130+
131+
sync-version = {
132+
enable = true;
133+
name = "sync:version";
134+
stages = [ "pre-commit" ];
135+
pass_filenames = false;
136+
entry = toString (
137+
pkgs.writeShellScript "sync-version" ''
138+
set -euo pipefail
139+
VERSION=$(${pkgs.python3}/bin/python3 -c "import tomllib; f=open('pyproject.toml','rb'); print(tomllib.load(f)['project']['version'])")
140+
IFS='.' read -r MAJOR MINOR PATCH <<< "''${VERSION}"
141+
printf '%s\n' \
142+
"major = ''${MAJOR}" \
143+
"minor = ''${MINOR}" \
144+
"patch = ''${PATCH}" \
145+
"" \
146+
'version = f"{major}.{minor}.{patch}"' \
147+
> mmpm/__version__.py
148+
${pkgs.gnused}/bin/sed -i \
149+
"s/\"version\": \"[^\"]*\"/\"version\": \"''${VERSION}\"/" \
150+
ui/package.json
151+
git add mmpm/__version__.py ui/package.json
152+
''
153+
);
154+
};
130155
};
131156
};
132157
}
@@ -219,16 +244,16 @@
219244
};
220245

221246
# ---- Utility Scripts
222-
start = pkgs.writeShellScriptBin "start" ''pm2 start dev/ecosystem.json'';
223-
stop = pkgs.writeShellScriptBin "stop" ''pm2 stop mmpm'';
224-
remove = pkgs.writeShellScriptBin "remove" ''pm2 delete mmpm'';
225-
logs = pkgs.writeShellScriptBin "logs" ''pm2 logs mmpm'';
247+
start = pkgs.writeShellScriptBin "start" "pm2 start dev/ecosystem.json";
248+
stop = pkgs.writeShellScriptBin "stop" "pm2 stop mmpm";
249+
remove = pkgs.writeShellScriptBin "remove" "pm2 delete mmpm";
250+
logs = pkgs.writeShellScriptBin "logs" "pm2 logs mmpm";
226251

227252
unit-tests = pkgs.writeShellScriptBin "unit-tests" ''
228253
uv run coverage run -m pytest
229254
CHROME_BIN=${pkgs.chromium}/bin/chromium bun --cwd=ui run test --watch=false --browsers=ChromeHeadlessNoSandbox
230255
'';
231-
static-analysis = pkgs.writeShellScriptBin "static-analysis" ''uv run mypy mmpm'';
256+
static-analysis = pkgs.writeShellScriptBin "static-analysis" "uv run mypy mmpm";
232257

233258
format = pkgs.writeShellScriptBin "format" ''
234259
uv run ruff format mmpm tests
@@ -249,6 +274,7 @@
249274
lock = pkgs.writeShellScriptBin "lock" ''
250275
uv lock --upgrade
251276
bun --cwd=ui update
277+
(cd ui && ${bun2nix.packages.${system}.default}/bin/bun2nix -o bun.nix)
252278
'';
253279

254280
deploy = pkgs.writeShellScriptBin "deploy" ''
@@ -336,7 +362,7 @@
336362
337363
source $VIRTUAL_ENV/bin/activate
338364
uv sync
339-
bun --cwd=ui install
365+
bun --cwd=ui install --ignore-scripts
340366
'';
341367
};
342368
}

mmpm/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
major = 4
22
minor = 6
3-
patch = 2
3+
patch = 3
44

55
version = f"{major}.{minor}.{patch}"

mmpm/magicmirror/controller.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def _detect_display_server_script() -> str:
188188

189189
def start(self) -> bool:
190190
"""
191-
Launches MagicMirror using pm2, if found, otherwise a 'npm start' is run as
191+
Launches MagicMirror using pm2, if found, otherwise a 'node --run' is run as
192192
a background process
193193
194194
Parameters:
@@ -199,7 +199,7 @@ def start(self) -> bool:
199199
"""
200200
script = self._detect_display_server_script()
201201
os.environ["ELECTRON_DISABLE_SANDBOX"] = "1"
202-
command = ["npm", "run", script]
202+
command = ["node", "--run", script]
203203

204204
pm2_process = str(self.env.MMPM_MAGICMIRROR_PM2_PROCESS_NAME.get())
205205
compose_file = str(self.env.MMPM_MAGICMIRROR_DOCKER_COMPOSE_FILE.get())
@@ -228,7 +228,7 @@ def start(self) -> bool:
228228
error_code, _, stderr = run_cmd(
229229
command,
230230
message="Starting MagicMirror",
231-
background=bool(command[0] == "npm"),
231+
background=bool(command[0] == "node"),
232232
)
233233

234234
if error_code:

mmpm/magicmirror/magicmirror.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ def upgrade(self):
121121

122122
os.chdir(root_dir)
123123

124-
error_code, _, stderr = run_cmd(["git", "checkout", "."], progress=False)
124+
error_code, _, stderr = run_cmd(["git", "restore", "."], progress=False)
125125

126126
if error_code:
127-
message = "Failed to checkout MagicMirror repo for clean upgrade"
127+
message = "Failed to restore MagicMirror repo for clean upgrade"
128128
logger.error(f"{message}. See `mmpm logs` for details")
129129
return stderr
130130

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "mmpm"
3-
version = "4.6.2"
3+
version = "4.6.3"
44
description = "MMPM, the MagicMirror Package Manager CLI simplifies the installation, removal, and general maintenance of MagicMirror packages"
55

66
authors = [

tests/magicmirror/test_controller.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ def test_start_with_npm(self, mock_env, mock_chdir, mock_which, mock_run_cmd, mo
4646
mock_env.return_value.MMPM_MAGICMIRROR_DOCKER_COMPOSE_FILE.get.return_value = None
4747
mock_env.return_value.MMPM_MAGICMIRROR_ROOT.get.return_value = "/path/to/magicmirror"
4848
mock_exists.return_value = True
49-
mock_which.side_effect = lambda x: "/usr/bin/" + x if x in ["npm"] else None
49+
mock_which.side_effect = lambda x: "/usr/bin/" + x if x in ["node"] else None
5050
mock_run_cmd.return_value = (0, "", "") # Simulate successful command execution
5151

5252
# Instantiate and start MagicMirror
5353
controller = MagicMirrorController()
5454
success = controller.start()
5555
self.assertTrue(success)
5656
args, kwargs = mock_run_cmd.call_args
57-
self.assertEqual(args[0][:2], ["npm", "run"])
57+
self.assertEqual(args[0][:2], ["node", "--run"])
5858
self.assertIn(args[0][2], ["start:x11", "start:wayland", "start:windows"])
5959
self.assertEqual(kwargs.get("message"), "Starting MagicMirror")
6060
self.assertTrue(kwargs.get("background"))
@@ -331,7 +331,7 @@ def test_returns_x11_as_fallback_with_no_env(self):
331331
self.assertEqual(MagicMirrorController._detect_display_server_script(), "start:x11")
332332

333333
def test_start_uses_detected_script(self):
334-
"""start() passes the detected script to npm run."""
334+
"""start() passes the detected script to node --run."""
335335
from mmpm.singleton import Singleton
336336

337337
Singleton._instances = {}
@@ -350,7 +350,7 @@ def test_start_uses_detected_script(self):
350350

351351
self.assertTrue(result)
352352
args, _ = mock_run_cmd.call_args
353-
self.assertEqual(args[0], ["npm", "run", "start:wayland"])
353+
self.assertEqual(args[0], ["node", "--run", "start:wayland"])
354354

355355

356356
class TestMagicMirrorControllerErrors(unittest.TestCase):

tests/magicmirror/test_magicmirror.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ def test_upgrade_root_not_exists(self):
215215
self.assertFalse(result)
216216

217217
@patch("mmpm.magicmirror.magicmirror.run_cmd")
218-
def test_upgrade_git_checkout_fails(self, mock_run_cmd):
219-
"""Lines 129-131: returns stderr string when git checkout fails."""
218+
def test_upgrade_git_restore_fails(self, mock_run_cmd):
219+
"""Lines 129-131: returns stderr string when git restore fails."""
220220
mm = MagicMirror()
221221
mm.env = MockedMMPMEnv()
222222
root = mm.env.MMPM_MAGICMIRROR_ROOT.get()

0 commit comments

Comments
 (0)