Skip to content

Update plugin tutorial on how to use commands#318

Merged
arcanis merged 4 commits into
yarnpkg:masterfrom
lirantal:patch-1
Jul 31, 2019
Merged

Update plugin tutorial on how to use commands#318
arcanis merged 4 commits into
yarnpkg:masterfrom
lirantal:patch-1

Conversation

@lirantal
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

2 participants