This PR is going to implement the first-class support for the pnpm package manager.
Thanks to @mikrostew for the well-written https://github.com/volta-cli/rfcs/pull/46, I've been able to implement this feature initially. Most of the critical functionalities have been implemented, except for the global package management. Due to a lack of further details on how to intercept pnpm to relocate its global package installs to fit Volta's current layout.
Implemented
- pnpm shim
- pnpm fetch / install / pin
- pnpm hooks
- per project pnpm manipulation
- volta run with
--pnpm
and --no-pnpm
Not Implemented
- global package manipulation/management via pnpm
In fact the argument parser for_pnpm()
has been introduced to try to intercept pnpm args, but I found that there is no proper way to make pnpm's global installs whose original location is <path to pnpm home>/global/5/node_modules
fit Volta's current global package image layout <path to volta home>/tools/image/packages
. Hence I intercepted all --global
pnpm commands and marked them as unimplemented.
Trackers
RFC: https://github.com/volta-cli/rfcs/pull/46
Tracking issue: https://github.com/volta-cli/volta/issues/737
This is currently a draft PR, please leave your review or comment if you have any ideas to improve the PR to push forward.
Demo
❯ .\target\debug\volta.exe list
⚡️ Currently active tools:
Node: v16.16.0 (default)
npm: v8.15.1 (default)
pnpm: v7.7.1 (default)
Yarn: v1.22.19 (default)
Tool binaries available:
cleancss (default)
yarn-deduplicate (default)
See options for more detailed reports by running `volta list --help`.
DESKTOP in volta on feature/pnpm [?] is 📦 v1.0.8 via 🦀 v1.62.0
❯ .\target\debug\pnpm.exe -h
Version 7.7.1
Usage: pnpm [command] [flags]
pnpm [ -h | --help | -v | --version ]
Manage your dependencies:
add Installs a package and any packages that it depends on. By default, any new package is installed as a prod dependency
import Generates a pnpm-lock.yaml from an npm package-lock.json (or npm-shrinkwrap.json) file
i, install Install all dependencies for a project
it, install-test Runs a pnpm install followed immediately by a pnpm test
ln, link Connect the local project to another one
prune Removes extraneous packages
rb, rebuild Rebuild a package
rm, remove Removes packages from node_modules and from the project's package.json
unlink Unlinks a package. Like yarn unlink but pnpm re-installs the dependency after removing the external link
up, update Updates packages to their latest version based on the specified range
Review your dependencies:
audit Checks for known security issues with the installed packages
ls, list Print all the versions of packages that are installed, as well as their dependencies, in a tree-structure
outdated Check for outdated packages
Run your scripts:
exec Executes a shell command in scope of a project
run Runs a defined package script
start Runs an arbitrary command specified in the package's "start" property of its "scripts" object
t, test Runs a package's "test" script, if one was provided
Other:
pack
publish Publishes a package to the registry
root
Manage your store:
store add Adds new packages to the pnpm store directly. Does not modify any projects or files outside the store
store prune Removes unreferenced (extraneous, orphan) packages from the store
store status Checks for modified packages in the store
Options:
-r, --recursive Run the command for each project in the workspace.
DESKTOP in volta on feature/pnpm [!] is 📦 v1.1.0-alpha.1 via 🦀 v1.62.0
❯ .\target\debug\pnpm.exe dlx create-vite vite-project --template vanilla
.../../../.pnpm-store/v3/tmp/dlx-31720 | +6 +
Packages are hard linked from the content-addressable store to the virtual store.
Content-addressable store is at: D:\.pnpm-store\v3
Virtual store is at: ../../../../../.pnpm-store/v3/tmp/dlx-31720/node_modules/.pnpm
.../../../.pnpm-store/v3/tmp/dlx-31720 | Progress: resolved 6, reused 6, downloaded 0, added 6, done
Scaffolding project in D:\workspace\repos\chawyehsu\volta\vite-project...
Done. Now run:
cd vite-project
pnpm install
pnpm run dev
DESKTOP in volta on feature/pnpm [!?] is 📦 v1.1.0-alpha.1 via 🦀 v1.62.0 took 5s
❯ cd vite-project
DESKTOP in volta\vite-project on feature/pnpm [!?] via ⬢ v16.16.0
❯ ..\target\debug\pnpm.exe i
Packages: +14
++++++++++++++
Packages are copied from the content-addressable store to the virtual store.
Content-addressable store is at: D:\.pnpm-store\v3
Virtual store is at: node_modules/.pnpm
node_modules/.pnpm/[email protected]/node_modules/esbuild: Running postinstall script, done in 318ms
Progress: resolved 34, reused 0, downloaded 14, added 14, done
devDependencies:
+ vite 3.0.4
DESKTOP in volta\vite-project on feature/pnpm [!?] via ⬢ v16.16.0
❯ ..\target\debug\volta.exe pin node pnpm
success: pinned [email protected] (with [email protected]) in package.json
success: pinned [email protected] in package.json
DESKTOP in volta\vite-project on feature/pnpm [!?] via ⬢ v16.16.0 took 3s
❯ cat .\package.json
{
"name": "vite-project",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"vite": "^3.0.0"
},
"volta": {
"node": "16.16.0",
"pnpm": "7.7.1"
}
}
DESKTOP in volta\vite-project on feature/pnpm [!?] via ⬢ v16.16.0
❯ ..\target\debug\pnpm.exe --version
7.7.1
DESKTOP in volta\vite-project on feature/pnpm [!?] via ⬢ v16.16.0
❯