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

[Question] How to see installed package source? #1183

Closed
fabis94 opened this issue Apr 10, 2020 · 3 comments
Closed

[Question] How to see installed package source? #1183

fabis94 opened this issue Apr 10, 2020 · 3 comments

Comments

@fabis94
Copy link

fabis94 commented Apr 10, 2020

It's a very common practice to look at package source code inside node_modules to see how something works, to see TypeScript type definitions etc. To me it looks like it is impossible to do so with Yarn 2.0. Since all packages are stored as .zip files, the IDE isn't able to open and show any files located inside the packages.

I tried Googling about this, but couldn't find anything. So is this true? Or is there a way to make Yarn 2.0 store the packages as unzipped folders so that they can be explored? If not, why? Surely this is an important feature

@paul-soporan
Copy link
Member

Follow #1157 for VSCode Zip support. Once VSCode has Zip support, Go to definition will work correctly. For now, you can do yarn unplug <package> to unplug a specific package (to view its source code inside the .yarn/unplugged folder), but the drawback is that the package will remain unplugged until you manually remove its entry from dependenciesMeta.<package>.unplugged in package.json.

@DaneTheory
Copy link

I disagree. Including this particular workflow as a feature enhancement defeats the entire point of Plug'N'Play. Doing so would require an additional step be added to the .pnp.js generation lifecycle; where resolved worktree deps would need an entirely new (internal) protocol to reference the mirrored contents of a modules .zip file. Further complicating the issue, zipped module archives have a completely unique file naming convention than that of a standard directory located in node_modules. This, again, is due to the pnpapi lifecycle and is an optimization perk in fetching remote modules during installation. Why add additional load to the workflow when the developer could simply look up the module's repository directly. I am not opposed to repo maintainers moving in a direction that favors more verbose documentation, rather than hack a workaround that allows for developers a fall back to old habits we are actively moving away from with what Yarn Berry is looking to accomplish. That said, Yarn v2 does offer core/generic plugins that allow for relatively easy hooks into the pnpapi lifecycle. pnpapi does allow for Locator/Resolver methods that theoretically could provide paths to cached module archives, as well as creating said archives themselves. I see no reason why we couldn't add an enhancement which streams the contents of any module archive via the @yarnPkg/cli as an additional command. If something like this was added, preferably it would be done as an optional plugin for devs to import on their own. Asking package maintainers to provide better documentation versus digging through 100000MB of node_modules seems like an option that better reflects best practices.

@arcanis
Copy link
Member

arcanis commented Apr 12, 2020

Package sources can be accessed as long as the surrounding "shell" provides support for that:

  • Most native shells now have built-in support for zip archives
  • Both Emacs and Vim have first-class support for zip archives
  • VSCode doesn't support it yet, but there's ongoing work to make it work - especially the "Go to definition" workflow that you mentioned in your original post

I think this should answer the question, so I'm going to close the thread 🙂

@arcanis arcanis closed this as completed Apr 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants