Say I have a repository with packages/foo/package.json and packages/foo/pnpm-lock.yaml. I want to add packages/foo to a pnpm workspace at the repository root.
As far as I can tell, when I add packages/foo to pnpm-workspace.yaml and run pnpm install, pnpm ignores the existing packages/foo/pnpm-lock.yaml file and re-resolves the entire transitive dependency tree of packages/foo/package.json from scratch. It's important for the stability of this package that this not happen; many things break if this package's transitive dependencies receive an unlocked upgrade.
How can I get pnpm to preserve the versions from packages/foo/pnpm-lock.yaml when building the workspace's pnpm-lock.yaml?
Add Your Package to the Workspace: Just manually add your package to the
pnpm-workspace.yamlfile. Something like this will do:Run
pnpm install: Do this from your workspace root.pnpmis pretty smart about workspaces and should respect your existingpnpm-lock.yamlin most cases.Check After Installation: Once you run
pnpm install, take a peek at your workspace'spnpm-lock.yaml. It should now include your package's dependencies, ideally matching what you had in your package's lock file.Handle Any Conflicts: If things look off (like some versions didn't match), you might have to deal with version conflicts manually. This can happen if other packages in the workspace have conflicting dependency requirements. Remember,
pnpmdoesn't have a magic command to do this directly, but it usually handles workspace dependencies well.Happy coding!