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

Update plugin tutorial on how to use commands #318

Merged
merged 4 commits into from
Jul 31, 2019

Conversation

lirantal
Copy link
Contributor

WIP
Current code snippet for the hello world command is incorrect in syntax, and probably with how it works so needs to update it.

This is currently WIP as we need to make another change to the 2nd example and also update guidelines on how to use deps in plugins.

@arcanis
Copy link
Member

arcanis commented Jul 31, 2019

Wait no, I think the original code is correct 😃 although it should be better explained.

The problem is: if every plugin has to bundle its own copy of clipanion, or @berry/core, it will add multiple MBs to the repo. Worse, if the version of @berry/core that a plugin uses is different from the one used by the local Yarn, an install won't have the same behavior depending on whether the plugin triggers it or Yarn does. So we need a mechanism - kinda like peerDependencies - to share some packages between Yarn and its plugins: both to ensure that the size stays minimal, and to prevent split brain issues.

In order to do that, Yarn implements what I called dynamic linking under the form of the require function that the plugin factory takes into parameter. This function allows the plugin to access a specific set of packages without them having to be dependencies of the plugin (or just for the type definitions). That's what happens in the code sample you've seen: we require clipanion from the dynamically linked packages.

The exact set of packages that can be required this way is stored here, plus all Berry plugins (meaning that a plugin can extend another plugin, which is what the plugin-npm-cli tool does by extending plugin-npm).

Does that make sense?

@lirantal
Copy link
Contributor Author

Makes more sense, thanks! 😌
So that's why the factory function passes the require argument there.

Regardless though, there is still an issue with the code here. I'll push a commit for it.

@arcanis arcanis merged commit 20e662f into yarnpkg:master Jul 31, 2019
@arcanis
Copy link
Member

arcanis commented Jul 31, 2019

👍

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

Successfully merging this pull request may close these issues.

None yet

2 participants