pnpm / pnpm

Fast, disk space efficient package manager
https://pnpm.io
MIT License
29.19k stars 978 forks source link

`pnpm unlink` should revert changes made by `pnpm link` #4219

Open GenrikhFetischev opened 2 years ago

GenrikhFetischev commented 2 years ago

pnpm version: 6.25.1

Code to reproduce the issue:

# I invoke that command in a pnpm workspace
$ pnpm link .../apps/library

devDependencies:
- @package/library 0.2.0-alpha.349
+ @package/library 0.0.1 <- ../../../another-repo/apps/library

# There are changes made by pnpm link command below
$ git diff
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 88427b78..dbc3df84 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -77,7 +77,7 @@ importers:
     devDependencies:
-      '@package/library': 0.2.0-alpha.349
+      '@package/library': link:../../../another-repo/apps/library

@@ -4016,10 +4016,6 @@ packages:
       - utf-8-validate
     dev: false

-  /@package/library/0.2.0-alpha.349:
-    resolution: {integrity: sha1-9olGuM=, tarball: '@package/library/-/@package/library-0.2.0-alpha.349.tgz'}
-    dev: true

$ pnpm unlink # According to docs: If called without arguments, all linked dependencies will be unlinked.

# Shows the same result as above
$ git diff  
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 88427b78..dbc3df84 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -77,7 +77,7 @@ importers:
     devDependencies:
-      '@package/library': 0.2.0-alpha.349
+      '@package/library': link:../../../another-repo/apps/library

@@ -4016,10 +4016,6 @@ packages:
       - utf-8-validate
     dev: false

-  /@package/library/0.2.0-alpha.349:
-    resolution: {integrity: sha1-9olGuM=, tarball: '@package/library/-/@package/library-0.2.0-alpha.349.tgz'}
-    dev: true

Expected behavior:

pnpm unlink reverts changes made by pnpm link

Actual behavior:

Symlink in node_modules directory and changes in pnpm-lock.yaml remain after pnpm unlink

Additional information:

I tried to use pnpm link/unlink commands in two monorepos organized as pnpm workspaces. pnpm link works as expected and patches pnpm-lock.yaml, but it looks like unlink command does nothing, so I have to run pnpm install or reset changes in pnpm-lock.yaml; whereas I was expecting pnpm unlink to do that for me. I expect unlink to revert changes back and according to docs there should be an automatic execution of pnpm install command.

geekdada commented 2 years ago

I don't understand why pnpm changes the lock file after pnpm link. The package targets a local directory in the lock file, which doesn't make sense to anyone else but me.

geekdada commented 2 years ago

It's also quite strange that this ticket didn't get any response for months. Isn't it an obvious problem, or am I missing something? I'm still a rookie to pnpm.

zkochan commented 2 years ago

I don't understand why pnpm changes the lock file after pnpm link

So, don't commit the change, what is the problem?

pnpm uses information from the lockfile to understand what the structure of node_modules is. We can't make changes to the node_modules without making changes to the lockfile. I mean, we can, but on next install pnpm would return the node_modules to the state described by the lockfile.

geekdada commented 2 years ago

Thanks, @zkochan for answering 👍

What about the issue, is it a bug or expected behavior?

callmeaponte commented 1 year ago

+1 to get this answered, as I'm experiencing this same issue as well.

transitive-bullshit commented 1 year ago

This is really confusing coming from how yarn and npm both work.

Local linking during package development should imho be a completely separate feature from hard-linking a path to a local dependency.

rudimusmaximus commented 1 year ago

I use a private repo and our org's package repository on github not npmjs BUT I think it would be similar...Given you're .npmrc is set up and you are logged in correctly with a PAT with the correct OAuth scopes:

Does that help you at all?

My only complaint is I still have to publish "npm publish myOrg/myPackage". Suggestions welcome.

rsodre commented 1 year ago

I also find that unlink mostly does not work. I'm using pnpm install again to unlink.

artemis-prime commented 6 months ago

How is this still not addressed? It's a serious bug

KaelWD commented 2 months ago

So, don't commit the change, what is the problem?

It adds an extra step, we have to either roll back the lockfile or make sure to never use git add . if we have something linked. If retaining links after reinstall is a goal then put that information in a separate file we can gitignore.

jcelaya775 commented 2 months ago

I just started experimenting with this. I haven't found that pnpm link ../project changes my lockfile, but pnpm unlink doesn't remove any symlinks in my project's node_modules. Weirdly though, passing in anything after pnpm unlink does (e.g., pnpm unlink random args).