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

Feature request: pnpm link -r #3026

Open
nategreen opened this issue Dec 16, 2020 · 10 comments
Open

Feature request: pnpm link -r #3026

nategreen opened this issue Dec 16, 2020 · 10 comments
Labels
area: monorepo Everything related to the pnpm workspace feature type: feature

Comments

@nategreen
Copy link

When running pnpm link -r <dir>, I expected pnpm to link the local package at <dir> (outside the workspace) to all the packages in my workspace. I found out that wasn't possible:

 ERROR  Unknown option: 'recursive'

It would be great if pnpm link (and unlink) could be recursive. A flag like the one suggested in #1228 would be good too—only link if the target package name is found in the workspace packages' dependencies.

@zkochan zkochan added type: feature area: monorepo Everything related to the pnpm workspace feature labels Dec 19, 2020
@zkochan
Copy link
Member

zkochan commented Jan 2, 2021

You can use a workaround. In the root package.json of your workspace, use pnpm.overrides. Let's say you want to link foo from a local directory, put this in the pnpm.overrides:

{
  "pnpm": {
    "overrides": {
      "foo": "<dir>"
    }
}

then just run pnpm install.

related: #3054

@benallfree
Copy link

@zkochan This is not working as expected for me:

{
  "dependencies": {
     "foo": "0.0.1",
  },
  "pnpm": {
    "overrides": {
      "foo": "../foo"
    }
}

Still links to

foo -> .pnpm/foo@0.0.1/node_modules/foo

@zkochan
Copy link
Member

zkochan commented Feb 7, 2021

what about this:

{
  "dependencies": {
     "foo": "0.0.1",
  },
  "pnpm": {
    "overrides": {
      "foo": "link:../foo"
    }
}

@benallfree
Copy link

benallfree commented Feb 7, 2021

@zkochan Nope, same result. Is pnpm.overrides only active inside workspaces?

Further background... I ran into this because my I found relative paths in my pnpm-lock.yaml which was making CI fail. So I started looking for a way to support local package links without affecting the lockfile and that led me here. But actually, it would be best to have maybe a .pnpm-local or some kind of file that didn't get committed so I could maintain local package links during development but update the lockfile after I had finalized changes to my forked deps under development concurrently. If you think that's a worthwhile discussion I'll make a new ticket for it :)

@zkochan
Copy link
Member

zkochan commented Feb 8, 2021

pnpm.overrides will result in relative paths in pnpm-lock.yaml as well. Why are modifications to pnpm-lock.yaml an issue? Because you accidentally committed them?

@benallfree
Copy link

benallfree commented Feb 8, 2021

@zkochan Well that's a good point, packages intended to be used as a dependency generally shouldn't have a lockfile committed. But top level packages like a monorepo may have a lockfile so a dev team can all work against the same deps and have repeatable builds. In those cases, CI would fail if the lockfile contained paths only present in a local dev environment. I assume this is why npm link doesn't modify the lockfile.

I have a complex case where I'm trying to fork transient dependencies as well as direct dependencies. For example, my main monorepo depends upon a package I authored named georedis-promised. That package, in turn, depends upon a forked version of node-georedis. So my file structure looks like:

./monorepo
   {
      "dependencies": {
         "georedis-promised": "0.0.1", # link:../georedis-promised
      }
   }
./georedis-promised (benallfree/georedis-promised#master)
   {
      "dependencies": {
         "georedis": "0.0.1",  # link:../node-georedis
      }
   }
./node-georedis (from fork benallfree/node-georedis#typescript)

@zkochan
Copy link
Member

zkochan commented Feb 8, 2021

@zkochan Nope, same result. Is pnpm.overrides only active inside workspaces?

no, it works in non-workspaces as well. What pnpm version do you use? This feature was added in 5.10.1: https://pnpm.js.org/en/package_json#pnpmoverrides

@igortas
Copy link

igortas commented Dec 30, 2021

@zkochan
Is there other way to do this?
I've started using turborepo with pnpm and the structure is like this

  • apps
  • packages (here i have subfolders like shared, and in shared i've installed shared deps, like rimraf)

Problem is, in apps I see the symlink from shared folder, but runninig inside apps/*, command like:
"dev": "rimraf node_modules" does not working, command is not found.
Is there a way with pnpm to know upstreams in monorepo about subfolders dependencies, like from packages/shared, or everything needs to be hoisted in the root folder?

@zkochan
Copy link
Member

zkochan commented Dec 30, 2021

@igortas this is not really related to this issue but if you need rimraf to be accessible in each package of the monorepo, then you need to install it as a dependencies in the root of the monorepo.

Like in case of the repository, these packages are available in all subpackages:

pnpm/package.json

Lines 27 to 59 in 6e4becd

"devDependencies": {
"@babel/core": "^7.16.0",
"@babel/plugin-proposal-dynamic-import": "^7.16.0",
"@babel/plugin-transform-modules-commonjs": "^7.16.0",
"@babel/preset-typescript": "^7.16.0",
"@babel/types": "^7.16.0",
"@changesets/cli": "^2.17.0",
"@commitlint/cli": "^15.0.0",
"@commitlint/config-conventional": "^15.0.0",
"@commitlint/prompt-cli": "^15.0.0",
"@pnpm/eslint-config": "workspace:*",
"@pnpm/meta-updater": "0.0.6",
"@pnpm/registry-mock": "^2.12.1",
"@pnpm/tsconfig": "workspace:*",
"@types/jest": "^27.0.0",
"@types/node": "^14.17.32",
"c8": "^7.10.0",
"cross-env": "^7.0.3",
"eslint": "^8.2.0",
"husky": "^7.0.4",
"jest": "^27.3.1",
"lcov-result-merger": "^3.1.0",
"npm-run-all": "^4.1.5",
"publish-packed": "^4.0.2",
"rimraf": "^3.0.2",
"shx": "^0.3.3",
"syncpack": "^5.8.15",
"ts-jest": "27.1.2",
"ts-node": "^10.4.0",
"typescript": "4.5.4",
"verdaccio": "5.4.0",
"yarn": "^1.22.17"
},

@EvHaus
Copy link

EvHaus commented Nov 11, 2022

I'm also looking for this feature. In Yarn they call it --all (https://yarnpkg.com/cli/link#options-A%2C-all).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: monorepo Everything related to the pnpm workspace feature type: feature
Projects
None yet
Development

No branches or pull requests

5 participants