Skip to content

Commit 483215f

Browse files
committed
feat(yarn2): Enforce using the "node-modules" node linker
The Yarn 2 implementation requires that the "node-modules" node linker [1] is used to filter out optional dependencies that were not installed. Enforce that setting with the `YARN_NODE_LINKER` environment variable to avoid the issue that no dependencies are found for projects that do not set `nodeLinker=node-modules` in their `.yarnrc.yml`. It has also been verified that the environment variable overrides any different setting for `nodeLinker` in the `.yarnrc.yml`. Also adapt the `.yarnrc.yml` files for all functional test projects as they do not need to set `nodeLinker=node-modules` anymore. [1]: https://yarnpkg.com/features/linkers Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
1 parent 1bc5d1d commit 483215f

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

plugins/package-managers/node/src/funTest/assets/projects/synthetic/yarn2/dependency-with-patch/.yarnrc.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
nodeLinker: node-modules
2-
31
yarnPath: .yarn/releases/yarn-3.2.1.cjs
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
nodeLinker: node-modules
2-
31
yarnPath: .yarn/releases/yarn-3.2.1.cjs

plugins/package-managers/node/src/main/kotlin/yarn2/Yarn2.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,16 @@ class Yarn2(override val descriptor: PluginDescriptor = Yarn2Factory.descriptor,
182182
}
183183

184184
private fun installDependencies(workingDir: File) {
185-
yarn2Command.run("install", workingDir = workingDir).requireSuccess()
185+
yarn2Command.run(
186+
"install",
187+
workingDir = workingDir,
188+
environment = mapOf(
189+
// Set the node linker to "node-modules" as the "node_modules" directory is required by this class to
190+
// filter out optional dependencies that were not installed.
191+
// See: https://yarnpkg.com/features/linkers
192+
"YARN_NODE_LINKER" to "node-modules"
193+
)
194+
).requireSuccess()
186195
}
187196

188197
private fun getPackageInfos(workingDir: File): List<PackageInfo> {

0 commit comments

Comments
 (0)