Migrate from Yarn to pnpm - #34
Conversation
a5b8ffa to
92e178e
Compare
anarchivist
left a comment
There was a problem hiding this comment.
in general, so far i think it looks pretty good. per your comments do we need separate tickets to replace webpack, etc. for this app?
|
Webpack itself is still maintained, it's the Ruby Gem connecting it to the asset pipeline that is deprecated and EOL. So I think we can actually keep using it just fine. (They even have plans for a new major release next year.) |
|
Thanks! (I suppose what I meant is do we want to bother with switching to Propshaft, etc.?) |
|
Oh, yes, replacing Sprockets with Propshaft is probably its own ticket. I don't mind looking into that after this is merged, but I also don't see a huge emergency in it, either. We are already using Edit: I do realise that the original intent of the ticket was that change, but the more I dug in, the more I realised that our actual friction point is Yarn. I feel like switching to pnpm solves the issues we were having, and also provides us a clear pathway towards Propshaft if we want that later. |
|
@awilfox OK, I've created AP-868 for that work. |
ee90446 to
80cfe2c
Compare
80cfe2c to
d432cd1
Compare
PNPM_HOMEis where the global binaries are installed - it is not where any of the modules are installed. Therefore it does not need to be, and absolutely should not be, writable by the app user's account.The suggested installation method was curl|bash, which felt quite unauditable. I read the entire 400 line script, and besides signature validation (which was only possible on NPM-uploaded versions, i.e. 11.x) it's just a thick wrapper around figuring out how to download a tarball and extract it. The
RUNI wrote pretty much does the same thing.The
pnpmVersionvariable in thatRUNshould be set to the desired tag in the upstream pnpm repository. They have immutable tags and releases set, so once we have verified a version is not malicious, we can be confident in deploying it whenever we want - the binaries will not change.--forceis documented as only allowing PNPM_HOME to be overridden (which we want it to be), but also allows installation to continue without modifying the shell login file. By default, it wants to add bin-stub paths to the user's PATH by writing to .profile/.bash_profile/.zshrc - we don't want this in a Docker container, and it can't do it anyway because the shell detection heuristic fails due to empty$SHELLenvironment variable.To upgrade Node, run
pnpm runtime set node [version], i.e.pnpm runtime set node 24is what I ran in the UCBEARS repo. The runtime version itself is saved to the lock file, so upon first fetch it will download the runtime as well. Since signatures are verified, that means we never have to worry about dealing with Node's repositories nor GPG keys again!The
-Pflag topnpm installensures that only runtime dependencies are installed. This is all that is needed for theproductiontarget;devDependenciesare unused. This keeps the container size smaller.A
node_modulesvolume is added to the Compose file. This is to keep the container's modules separate from your local development environment. Otherwise, when using pnpm from your local environment after runningcompose uporcompose build, you will see something like:Or
If you see either of those messages, stop and ensure
node_modulesis a separate volume.This change was solely from manually installing Node and using Yarn as a package manager to using PNPM as both a package manager and Node manager. This did not remove Webpack nor did it update any of the (in some cases, very stale) JS dependencies of the repo. It is hoped that this will be significantly easier with modern tooling, but was out of the scope of the ticket.