Describe the user story
I've read pros&cons of pnp, but really, I don't suffer from any of them. I don't run add every 5 seconds and even on CI it takes 1-2 minutes to install everything without to cache anything.
But my biggest problem with it, that it's used instead of node_modules. I really like to look at real code or real TS type definitions, which are used in my projects and therefore I look into node_modules.
It there any way to achieve that?
Yes and no. There are two questions:
Is it possible to read files like we did before with the node_modules?
Yes. You can use yarn unplug to eject a specific package. Such packages will be put inside the .yarn/unplugged/<package name> directory, and you'll be able to see their sources and edit them as you did before.
Additionally, various editors (such as Emacs and Vim) have builtin integrations with zip archives, to various degrees. For example, I often open zip archives with emacs, which allows me to edit their content in-place as with any other file.
Is it possible to opt-out from PnP?
Yes, but. Berry is extremely extensible. One new capability is that we can add plugin that change the package manager behavior. One type of plugin are linkers. Linkers can affect how the packages are written on the disk. In this way, the PnP installer is just a plugin that specifies that JS packages should generate a .pnp.js file.
It is totally possible to register a plugin that would generate a node_modules folder instead of the .pnp.js. It would be a bit difficult to get right such a plugin because node_modules have a lot of edge cases (mainly because some packages must be put at multiple places on the filesystem, which doesn't interact well with how they are built, etc), but it's possible.
The reason I said "Yes, but" is that while it's conceivable to have such a plugin, it hasn't been written yet. It's also not on my personal shortlist (I focus my efforts on PnP exclusively), meaning that we will need someone to champion this feature.
So yes, but not at the time of this writing.
I'm using both flow and react-native, which apparently don't work with yarn v2. In the documentation, it says to install a node-modules plugin, but when I try the command given, I get:
yarn plugin import node-modules
➤ YN0051: Couldn't find a plugin named "@yarnpkg/plugin-node-modules" on the remote registry. Note that only the plugins referenced on our website (https://github.com/yarnpkg/berry/blob/master/plugins.yml) can be referenced by their name; any other plugin will have to be referenced through its public url (for example https://github.com/yarnpkg/berry/raw/master/packages/plugin-typescript/bin/%40yarnpkg/plugin-typescript.js).
➤ YN0000: Failed with errors in 0.47s
Is the documentation a little overly optimistic about there being such a plugin? :)
No, it exists, but we literally merged it two days ago so it hasn't been released yet 🙂
Fixed 🙂
Most helpful comment
Yes and no. There are two questions:
Is it possible to read files like we did before with the
node_modules?Yes. You can use
yarn unplugto eject a specific package. Such packages will be put inside the.yarn/unplugged/<package name>directory, and you'll be able to see their sources and edit them as you did before.Additionally, various editors (such as Emacs and Vim) have builtin integrations with zip archives, to various degrees. For example, I often open zip archives with emacs, which allows me to edit their content in-place as with any other file.
Is it possible to opt-out from PnP?
Yes, but. Berry is extremely extensible. One new capability is that we can add plugin that change the package manager behavior. One type of plugin are linkers. Linkers can affect how the packages are written on the disk. In this way, the PnP installer is just a plugin that specifies that JS packages should generate a
.pnp.jsfile.It is totally possible to register a plugin that would generate a
node_modulesfolder instead of the.pnp.js. It would be a bit difficult to get right such a plugin becausenode_moduleshave a lot of edge cases (mainly because some packages must be put at multiple places on the filesystem, which doesn't interact well with how they are built, etc), but it's possible.The reason I said "Yes, but" is that while it's conceivable to have such a plugin, it hasn't been written yet. It's also not on my personal shortlist (I focus my efforts on PnP exclusively), meaning that we will need someone to champion this feature.
So yes, but not at the time of this writing.