Skip to content
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

Enable PNPM and rspack #385

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

max-moser
Copy link
Contributor

@max-moser max-moser commented Mar 1, 2025

Second part of #383 – support for pnpm and rspack

Current state

This PR won't work as standalone, it still requires changes to core Invenio packages.
Either inveniosoftware/invenio-assets#176
Or inveniosoftware/invenio-assets#172, inveniosoftware/flask-webpackext#26, inveniosoftware/pywebpack#47
Depending on the choice, some tweaks need to be performed in this PR here.

Also, npm is still hard-coded in React-Invenio-Forms which needs to be addressed.

@max-moser max-moser force-pushed the mm/pnpm-and-rspack branch from c6ff314 to 187dfa2 Compare March 1, 2025 00:22
@@ -108,7 +109,9 @@ def update_statics_and_assets(self, force, debug=False, log_file=None):
if op[-1] in messages:
click.secho(messages[op[-1]], fg="green")
response = run_interactive(
op, env={"PIPENV_VERBOSITY": "-1"}, log_file=log_file
op,
env={"PIPENV_VERBOSITY": "-1", **js_pkg_man.env_overrides()},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we tell invenio about the JS package manager that we want to use, via environment variables

Comment on lines +89 to +97
ops = [py_pkg_man.run_command("invenio", "collect", "--verbose")]

if force:
ops.append(pkg_man.run_command("invenio", "webpack", "clean", "create"))
ops.append(pkg_man.run_command("invenio", "webpack", "install"))
ops.append(py_pkg_man.run_command("invenio", "webpack", "clean", "create"))
ops.append(py_pkg_man.run_command("invenio", "webpack", "install"))
else:
ops.append(pkg_man.run_command("invenio", "webpack", "create"))
ops.append(py_pkg_man.run_command("invenio", "webpack", "create"))
ops.append(self._statics)
ops.append(pkg_man.run_command("invenio", "webpack", "build"))
ops.append(py_pkg_man.run_command("invenio", "webpack", "build"))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is still a good amount of optimization potential by calling the invenio command only once and thus saving all the redundant application initializations which eat up a lot of time.
one way to move forward is to implement a single larger command (e.g. in invenio-app-rdm) that performs all the steps currently implemented here, based on the provided CLI args.
@ntarocco has pointed out to me that something very much like that has already been done in Invenio-App-ILS

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an option would be to use a rpc-server implementation. a WIP would be here for invenio-cli combined with PR from invenio-app

@max-moser max-moser force-pushed the mm/pnpm-and-rspack branch 3 times, most recently from 8e073f3 to 62a7f3a Compare March 6, 2025 15:29
utnapischtim and others added 2 commits March 6, 2025 16:33
* bump pynpm dependency for the PNPMPackage
* tell invenio about which JS package manager is actually selected
  currently (npm or pnpm), via the new `ASSETS_NPM_PKG_CLS` config
* also, use the module_pkg to execute the install command in the target
  path (rather than the instance's path, which made a difference in the
  case of pnpm)
* as discussed, we implement the `pnpm link` to basically do the same
  thing as the current `npm link` procedure, to not require any changes
  in JS packages
@max-moser max-moser force-pushed the mm/pnpm-and-rspack branch from 62a7f3a to 0ee5d67 Compare March 6, 2025 15:33
Comment on lines +360 to +362
AssetsFunction(_prelink_dist, "Executing prelink-dist script..."),
AssetsFunction(_link_package_single_step, "Linking module to assets..."),
AssetsFunction(_postlink_dist, "Executing postlink-dist script..."),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 is better than 1!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed, we're basically executing the same scripts with pnpm as we did with npm, except for the part where the actual linking happens (which is more sane with pnpm.

since we don't have preprelink-dist, postprelink-dist, prepostlink-dist and postpostlink-dist scripts defined in our packages i think we should be executing the same set of scripts as before here.

# This is geared towards Invenio JS packages...
# But so are all the other steps
status_code = assets_pkg.link(
str(module_pkg.package_json_path.parent / "dist")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the fact that we're linking against the "dist" directory and not using the scripts requires some knowledge about the target package... but so does executing the link-dist script, which is not exactly a standard AFAIK 😅

class AssetsFunction:
"""Function to run an assets command with `assets_pkg` and `module_pkg`."""

function: Callable[[NPMPackage, NPMPackage], ProcessResponse]
Copy link
Contributor Author

@max-moser max-moser Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the dataclass wants to have some type annotation, but Callable should do the trick already.
i have no strong attachment to this type hint otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants