[Bug]: Cannot use literal `${x}` in environment variable files
Self-service
- [ ] I'd be willing to implement a fix
Describe the bug
If your env variable needs to have a value with ${} in it, yarn will error:
Usage Error: Environment variable not found (endpoint)
To reproduce
create a env file with:
CYPRESS_DOWNLOAD_PATH_TEMPLATE="${endpoint}/${platform}-${arch}/cypress.zip"
Environment
windows
Additional context
the problem is here:
https://github.com/yarnpkg/berry/blob/10d16c36653713dae4c4347394cd80b7c2015412/packages/yarnpkg-core/sources/miscUtils.ts#L470
I think it just needs a negative look behind for an escaping \ - which would match the behaviour of npm and setting variables in npmrc.
Can you expand your reproduction? It is unclear where you put that line and what command(s) you are running when the bug occurs.
FWIW, I tried and failed to reproduce:
PS> yarn init -2
PS> echo 'CYPRESS_DOWNLOAD_PATH_TEMPLATE="${endpoint}/${platform}-${arch}/cypress.zip"' > .env.yarn
PS> $env:endpoint = "http://localhost"; $env:platform="win32"; $env:arch="x64";
PS> yarn node -p 'process.env.CYPRESS_DOWNLOAD_PATH_TEMPLATE'
http://localhost/win32-x64/cypress.zip
@clemyan thanks for your response, I can see I am not clear.
Cypress actually expands those variables itself - so I don't want yarn to expand them, I want to be able to escape it so yarn leaves it alone.
repro:
yarn init -2
echo 'CYPRESS_DOWNLOAD_PATH_TEMPLATE="${endpoint}/${platform}-${arch}/cypress.zip"' > .env.yarn
yarn node -p 'process.env.CYPRESS_DOWNLOAD_PATH_TEMPLATE'
and I guess you could change the repro to this:
yarn init -2
echo 'CYPRESS_DOWNLOAD_PATH_TEMPLATE="\${endpoint}/\${platform}-\${arch}/cypress.zip"' > .env.yarn
yarn node -p 'process.env.CYPRESS_DOWNLOAD_PATH_TEMPLATE'
where the $ is escaped, but yarn still tries to expand the variables.
https://docs.cypress.io/guides/references/advanced-installation#Download-path-template
I see, you want a literal ${x} in your variable
Maybe we should follow dotenv-expand's expansion logic.