Skip to content

Commit dad4f9b

Browse files
authored
Fixes settings interpolation with dotenv variables (#5544)
**What's the problem this PR addresses?** I forgot in #4718 to add a test making sure that the yarnrc settings could use the variable set in the dotenv files (the existing tests were mainly around the values set during script execution), and of course I forgot a change 🥲 **How did you fix it?** We now pass the updated environment when interpolating values. **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.
1 parent d83c886 commit dad4f9b

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

.yarn/versions/a1769d6c.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declined:
2+
- "@yarnpkg/core"

.yarnrc.yml

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ enableGlobalCache: false
1313
immutablePatterns:
1414
- .pnp.*
1515

16-
initScope: yarnpkg
17-
1816
npmPublishAccess: public
1917

2018
packageExtensions:

packages/acceptance-tests/pkg-tests-specs/sources/features/dotEnvFiles.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,20 @@ describe(`DotEnv files`, () => {
110110

111111
await run(`install`);
112112
}));
113+
114+
it(`should allow values from environment files to be reused in other configuration settings`, makeTemporaryEnv({}, async ({path, run, source}) => {
115+
await run(`install`);
116+
117+
await xfs.writeFilePromise(ppath.join(path, `.env`), [
118+
`INJECTED_FROM_ENV_FILE=hello\n`,
119+
].join(``));
120+
121+
await xfs.writeJsonPromise(ppath.join(path, Filename.rc), {
122+
initScope: `\${INJECTED_FROM_ENV_FILE}`,
123+
});
124+
125+
await expect(run(`config`, `get`, `initScope`)).resolves.toMatchObject({
126+
stdout: `hello\n`,
127+
});
128+
}));
113129
});

packages/yarnpkg-core/sources/Configuration.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ function parseSingleValue(configuration: Configuration, path: string, valueBase:
749749
throw new Error(`Expected configuration setting "${path}" to be a string, got ${typeof value}`);
750750

751751
const valueWithReplacedVariables = miscUtils.replaceEnvVariables(value, {
752-
env: process.env,
752+
env: configuration.env,
753753
});
754754

755755
switch (definition.type) {

0 commit comments

Comments
 (0)