From f48e7219f8beb9ec26b30e245bad1d5b5535a2a1 Mon Sep 17 00:00:00 2001 From: Christoph Ladurner Date: Tue, 21 Jan 2025 14:06:24 +0100 Subject: [PATCH] assets: update to pnpm, rspack configuration * since rspack configuration is not more in webpack.config.js this is necessary --- invenio_cli/commands/assets.py | 37 ++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/invenio_cli/commands/assets.py b/invenio_cli/commands/assets.py index 674f84b..c49304c 100644 --- a/invenio_cli/commands/assets.py +++ b/invenio_cli/commands/assets.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # # Copyright (C) 2020 CERN. +# Copyright (C) 2025 Graz University of Technology. # # Invenio-Cli is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. @@ -9,9 +10,11 @@ import subprocess +import sys from pathlib import Path import click +from flask_webpackext.project import PNPMPackage from pynpm import NPMPackage from ..helpers import env @@ -27,10 +30,15 @@ def __init__(self, cli_config): """Constructor.""" super().__init__(cli_config) - @staticmethod - def _module_pkg(path): + def _module_pkg(self, path): """NPM package for the given path.""" - return NPMPackage(Path(path) / "package.json") + if self.cli_config.javascript_packages_manager == "npm": + return NPMPackage(Path(path) / "package.json") + elif self.cli_config.javascript_packages_manager == "pnpm": + return PNPMPackage(Path(path) / "package.json") + else: + print("please configure javascript package manager.") + sys.exit() def _assets_pkg(self): """NPM package for the instance's webpack project.""" @@ -73,8 +81,7 @@ def _npm_install_command(path): ) else: return ProcessResponse( - error=f"Unable to install dependent packages. " - "Got error code {status_code}", + error=f"Unable to install dependent packages. Got error code {status_code}", status_code=status_code, ) @@ -104,7 +111,8 @@ def _assets_link(assets_pkg, module_pkg): status_code = assets_pkg.link(module_name) if status_code == 0: return ProcessResponse( - output="Global module linked correctly to local folder", status_code=0 + output="Global module linked correctly to local folder", + status_code=0, ) else: return ProcessResponse( @@ -115,8 +123,21 @@ def _assets_link(assets_pkg, module_pkg): def watch_assets(self): """High-level command to watch assets for changes.""" # Commands - prefix = ["pipenv", "run"] - watch_cmd = prefix + ["invenio", "webpack", "run", "start"] + if self.cli_config.python_packages_manager == "uv": + prefix = ["uv", "run"] + elif self.cli_config.python_packages_manager == "pip": + prefix = ["pipenv", "run"] + else: + print("please configure python package manager.") + sys.exit() + + if self.cli_config.assets_builder == "webpack": + watch_cmd = prefix + ["invenio", "webpack", "run", "start"] + elif self.cli_config.assets_builder == "rspack": + watch_cmd = prefix + ["invenio", "webpack", "run", "start-rspack"] + else: + print("please configure assets builder.") + sys.exit() with env(FLASK_ENV="development"): # Collect into statics/ and assets/ folder