From c1acbe2fb614ad9702b0feb95bd8f83764cc0b3c Mon Sep 17 00:00:00 2001 From: Clement Yan Date: Mon, 9 Mar 2026 00:31:53 +0800 Subject: [PATCH 1/3] fix(core): resolve `config.projectCwd` before `.env.yarn` path --- packages/yarnpkg-core/sources/Configuration.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/yarnpkg-core/sources/Configuration.ts b/packages/yarnpkg-core/sources/Configuration.ts index ed63eb4cd20d..a993ef516301 100644 --- a/packages/yarnpkg-core/sources/Configuration.ts +++ b/packages/yarnpkg-core/sources/Configuration.ts @@ -1176,6 +1176,8 @@ export class Configuration { delete environmentSettings.rcFilename; const configuration = new Configuration(startingCwd); + configuration.projectCwd = await Configuration.findProjectCwd(startingCwd); + const rcFiles = await Configuration.findRcFiles(startingCwd); const homeRcFile = await Configuration.findFolderRcFile(folderUtils.getHomeFolder()); @@ -1239,17 +1241,9 @@ export class Configuration { } } - // We need to know the project root before being able to truly instantiate - // our configuration. - - const projectCwd = await Configuration.findProjectCwd(startingCwd); - // Great! We now have enough information to really start to setup the // core configuration object. - configuration.startingCwd = startingCwd; - configuration.projectCwd = projectCwd; - const env = Object.assign(Object.create(null), process.env); configuration.env = env; From c4d8f351b08e7c5cf6ad7f1322dbb8716528bb0a Mon Sep 17 00:00:00 2001 From: Clement Yan Date: Mon, 9 Mar 2026 00:36:53 +0800 Subject: [PATCH 2/3] test: Add tests --- .../sources/features/dotEnvFiles.test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/acceptance-tests/pkg-tests-specs/sources/features/dotEnvFiles.test.ts b/packages/acceptance-tests/pkg-tests-specs/sources/features/dotEnvFiles.test.ts index 744e10f45b15..b6147da4ad17 100644 --- a/packages/acceptance-tests/pkg-tests-specs/sources/features/dotEnvFiles.test.ts +++ b/packages/acceptance-tests/pkg-tests-specs/sources/features/dotEnvFiles.test.ts @@ -126,4 +126,23 @@ describe(`DotEnv files`, () => { stdout: `hello\n`, }); })); + + it(`should correctly resolve .env.yarn files from project root`, makeTemporaryEnv({}, async ({path, run, source}) => { + const subdir = ppath.join(path, `subdir`); + await xfs.mkdirPromise(subdir); + + await xfs.writeFilePromise(ppath.join(subdir, `.env.yarn`), [ + `INJECTED_FROM_SUBDIR_ENV_FILE=hello\n`, + ].join(``)); + await xfs.writeFilePromise(ppath.join(path, `.env.yarn`), [ + `INJECTED_FROM_ENV_FILE=hello\n`, + ].join(``)); + + await run(`install`); + + const {stdout} = await run(`exec`, `env`, {cwd: subdir}); + + expect(stdout).toMatch(/^INJECTED_FROM_ENV_FILE=hello$/m); + expect(stdout).not.toMatch(/^INJECTED_FROM_SUBDIR_ENV_FILE=hello$/m); + })); }); From b2a38cb893340d6aeffb9a98161ffb86714e8312 Mon Sep 17 00:00:00 2001 From: Clement Yan Date: Mon, 9 Mar 2026 00:42:39 +0800 Subject: [PATCH 3/3] versions --- .yarn/versions/b32850f7.yml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .yarn/versions/b32850f7.yml diff --git a/.yarn/versions/b32850f7.yml b/.yarn/versions/b32850f7.yml new file mode 100644 index 000000000000..560a6144009a --- /dev/null +++ b/.yarn/versions/b32850f7.yml @@ -0,0 +1,36 @@ +releases: + "@yarnpkg/cli": patch + "@yarnpkg/core": patch + "@yarnpkg/doctor": patch + "@yarnpkg/plugin-constraints": patch + "@yarnpkg/plugin-dlx": patch + "@yarnpkg/plugin-essentials": patch + "@yarnpkg/plugin-init": patch + "@yarnpkg/plugin-interactive-tools": patch + "@yarnpkg/plugin-npm-cli": patch + "@yarnpkg/plugin-pack": patch + "@yarnpkg/plugin-patch": patch + "@yarnpkg/plugin-pnp": patch + "@yarnpkg/plugin-stage": patch + "@yarnpkg/plugin-version": patch + "@yarnpkg/plugin-workspace-tools": patch + +declined: + - "@yarnpkg/plugin-catalog" + - "@yarnpkg/plugin-compat" + - "@yarnpkg/plugin-exec" + - "@yarnpkg/plugin-file" + - "@yarnpkg/plugin-git" + - "@yarnpkg/plugin-github" + - "@yarnpkg/plugin-http" + - "@yarnpkg/plugin-jsr" + - "@yarnpkg/plugin-link" + - "@yarnpkg/plugin-nm" + - "@yarnpkg/plugin-npm" + - "@yarnpkg/plugin-pnpm" + - "@yarnpkg/plugin-typescript" + - "@yarnpkg/builder" + - "@yarnpkg/extensions" + - "@yarnpkg/nm" + - "@yarnpkg/pnpify" + - "@yarnpkg/sdks"