Skip to content

Commit

Permalink
assets: update to pnpm, rspack configuration
Browse files Browse the repository at this point in the history
* since rspack configuration is not more in webpack.config.js this is
  necessary
  • Loading branch information
utnapischtim committed Jan 21, 2025
1 parent 45aba6a commit f48e721
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions invenio_cli/commands/assets.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand All @@ -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."""
Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand Down

0 comments on commit f48e721

Please sign in to comment.