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

feat(builder): transform node: imports as needed #6356

Merged
merged 5 commits into from
Aug 25, 2024
Merged

feat(builder): transform node: imports as needed #6356

merged 5 commits into from
Aug 25, 2024

Conversation

jkowalleck
Copy link
Contributor

@jkowalleck jkowalleck commented Jun 26, 2024

What's the problem this PR addresses?

Yarn plugins used to be forbidden to import/require built-in modules prefixed with node:.
see #6135
see #5417
Fixes #5637

The yarn plugin builder should be aware of this fact and produce bundled code, that does not contain any node: prefixed import/require.

This is especially important when building plugins with 3rd party dependencies, where the plugin author cannot "fix" the imports to yarn's needs.

How did you fix it?

I enabled the plugin-compiler to generate the plugin-code as needed:

I utilized the capability of esbuild to strip these node: prefixes from import/require instructions.
Therefore, I added config options to the plugin build process to instruct esbuild to do so.

This is a fix of the plugin builder, which enables plugin authors to compile their work in a backwards-compatible way, so that the build result is runnable in old/unpatched versions of yarn. Unpatched regarding #5997

Related

The #5997 tries to address the issue from the plugin-runtime side.
This would enable "broken" plugins to be runnable in all future/patched versions of yarn-core.

Additionally

This very PR aims to enable plugin authors to create plugins that are runnable with unpatched versions of yarn-core.
It is considered a friction-free backwards-compatible solution on all ends. Yet it does not replace #5997.

Checklist

  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

@jkowalleck jkowalleck marked this pull request as draft June 26, 2024 10:50
@jkowalleck jkowalleck marked this pull request as ready for review June 26, 2024 10:58
@jkowalleck jkowalleck changed the title Feat/yarnpkg builder trasform node imports Feat: yarnpkg builder for plugins trasform node: imports as needed Jun 26, 2024
@jkowalleck jkowalleck changed the title Feat: yarnpkg builder for plugins trasform node: imports as needed feat: yarnpkg/builder for plugins transform node: imports as needed Jun 26, 2024
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
@jkowalleck
Copy link
Contributor Author

rebased on master.

@jkowalleck jkowalleck requested a review from arcanis July 7, 2024 08:43
@adrian-gierakowski
Copy link

any hope to get this merged soon?

@jkowalleck
Copy link
Contributor Author

@arcanis @merceyz could you see what is necessary to get this merged?

@jkowalleck
Copy link
Contributor Author

@arcanis @merceyz could you see what is necessary to get this merged?

This small change is a huge improvement, enabling a lot of modern libraries being bundled.

@merceyz merceyz changed the title feat: yarnpkg/builder for plugins transform node: imports as needed feat(builder): transform node: imports as needed Aug 25, 2024
@merceyz merceyz added this pull request to the merge queue Aug 25, 2024
Merged via the queue into yarnpkg:master with commit b2f315f Aug 25, 2024
26 checks passed
@merceyz
Copy link
Member

merceyz commented Aug 25, 2024

Thanks for the PR, sorry it took so long to get it landed.

@jkowalleck
Copy link
Contributor Author

Thanks for the PR, sorry it took so long to get it landed.

I am happy seeing this merged, and looking forward to having this available with the next release badge.
This will hopefully enable my own yarn plugins to use some modern versions of 3rd party libraries, and help others doing so, too :D

@adrian-gierakowski
Copy link

Yay 🎉

@merceyz
Copy link
Member

merceyz commented Aug 25, 2024

and looking forward to having this available with the next release badge

I've created a new release so it should be available now.

@jkowalleck
Copy link
Contributor Author

and looking forward to having this available with the next release badge

I've created a new release so it should be available now.

yes, the changes are included in v4.2.0 🚀

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.

[Bug?]: @yarnpkg/builder@4.0.0-rc.48 produces bundles which yarn cannot consume
4 participants