Skip to content

Commit b2f315f

Browse files
jkowalleckarcanis
andauthored
feat(builder): transform node: imports as needed (#6356)
## What's the problem this PR addresses? <!-- Describe the rationale of your PR. --> <!-- Link all issues that it closes. (Closes/Resolves #xxxx.) --> 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? <!-- A detailed description of your implementation. --> 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 <!--- Don't worry if you miss something, chores are automatically tested. --> <!--- This checklist exists to help you remember doing the chores when you submit a PR. --> <!--- Put an `x` in all the boxes that apply. --> - [x] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). <!-- See https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released for more details. --> <!-- Check with `yarn version check` and fix with `yarn version check -i` --> - [x] I have set the packages that need to be released for my changes to be effective. <!-- The "Testing chores" workflow validates that your PR follows our guidelines. --> <!-- If it doesn't pass, click on it to see details as to what your PR might be missing. --> - [x] I will check that all automated PR checks pass before the PR gets reviewed. --------- Signed-off-by: Jan Kowalleck <[email protected]> Co-authored-by: Maël Nison <[email protected]>
1 parent d12fd9b commit b2f315f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

.yarn/versions/c8b9b062.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
releases:
2+
"@yarnpkg/builder": minor
3+
4+
declined:
5+
- "@yarnpkg/plugin-constraints"
6+
- "@yarnpkg/plugin-exec"
7+
- "@yarnpkg/plugin-interactive-tools"
8+
- "@yarnpkg/plugin-stage"
9+
- "@yarnpkg/plugin-typescript"
10+
- "@yarnpkg/plugin-version"
11+
- "@yarnpkg/plugin-workspace-tools"
12+
- "@yarnpkg/cli"

packages/yarnpkg-builder/sources/commands/build/plugin.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ export default class BuildPluginCommand extends Command {
128128
minify: !this.noMinify,
129129
sourcemap: this.sourceMap ? `inline` : false,
130130
target: `node${semver.minVersion(pkg.engines.node)!.version}`,
131+
supported: {
132+
/*
133+
Yarn plugin-runtime did not support builtin modules prefixed with "node:".
134+
See https://github.com/yarnpkg/berry/pull/5997
135+
As a solution, and for backwards compatibility, esbuild should strip these prefixes.
136+
*/
137+
'node-colon-prefix-import': false,
138+
'node-colon-prefix-require': false,
139+
},
131140
});
132141

133142
for (const warning of res.warnings) {

0 commit comments

Comments
 (0)