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

Create pnpm webpack resolver plugin #12054

Open
bjester opened this issue Apr 5, 2024 · 0 comments
Open

Create pnpm webpack resolver plugin #12054

bjester opened this issue Apr 5, 2024 · 0 comments
Assignees
Labels
DEV: dev-ops Continuous integration & deployment DEV: tools Internal tooling for development TAG: dependencies Pull requests that update a dependency file

Comments

@bjester
Copy link
Member

bjester commented Apr 5, 2024

Overview

In transitioning to pnpm from yarn, it has become apparent that a webpack plugin would be helpful to resolve the differences between the two package managers, and how webpack resolves dependencies. In essence, the hoisted nature of yarn v1 can cause dependency conflicts, but it can also create 'ghost dependencies' that are not explicitly defined in the project but end up being resolved anyway.

The benefits of this webpack plugin will be:

  • easier transition to pnpm
  • clearer indication of missing dependencies (raise warnings or errors)
  • avoidance of global workarounds that can lead to ghost dependencies
  • allows us to be more explicit with dependencies overall

Description and outcomes

A webpack resolver plugin should be created in kolibri-tools which:

  • resolves first party dependencies (direct project dependencies) as normal: only if available in /node_modules/
  • resolves third party dependencies by:
    • first resolving with that first party's dependencies: /node_modules/.pnpm/kolibri-design-system@XXX/node_modules/
    • if the module being resolved is a peer dependency of the first party dependency, allows: /node_modules/*
    • otherwise throws a warning / error about missing dependency

Once this plugin is created, we can use the plugin in Studio:

  • add it to Studio's webpack config for resolving both modules and loaders
  • remove the manual inclusion of /node_modules/.pnpm/node_modules/ in the config for resolving both modules and loaders

Resources

Workarounds

The simplest workaround that maintains somewhat similar behavior to yarn is to add node_modules/.pnpm/node_modules to webpack's modules resolver configs. Although, this does not help to clarify 'ghost dependencies'.

I was not able to find something like this that exists. There is this plugin but it doesn't work because I believe it's using the wrong webpack API. pnpm does have support for Yarn's plug'n'play, but it requires a custom resolver to be injected into node commands (as far as I can tell) which is unappealing. yarn's PnP also gets rid of node_modules which feels weird and gives less visibility IMO.

Ghost dependencies

Kolibri Studio uses workbox, and there were some workbox dependencies missing. This wasn't apparent until transitioning to pnpm, likely because some other dependency had included it and that was hoisted. For workbox in particular, this wasn't a major issue because there hasn't been much change in the libraries, but it illustrates the ghost dependency problem.

@bjester bjester added DEV: dev-ops Continuous integration & deployment TAG: dependencies Pull requests that update a dependency file DEV: tools Internal tooling for development labels Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DEV: dev-ops Continuous integration & deployment DEV: tools Internal tooling for development TAG: dependencies Pull requests that update a dependency file
Projects
None yet
Development

No branches or pull requests

2 participants