Skip to content

[Bug]: Cannot use literal ${x} in environment variable files #6491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task
lukpsaxo opened this issue Sep 11, 2024 · 3 comments
Open
1 task

[Bug]: Cannot use literal ${x} in environment variable files #6491

lukpsaxo opened this issue Sep 11, 2024 · 3 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@lukpsaxo
Copy link

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:

export function replaceEnvVariables(value: string, {env}: {env: {[key: string]: string | undefined}}) {

I think it just needs a negative look behind for an escaping \ - which would match the behaviour of npm and setting variables in npmrc.

@lukpsaxo lukpsaxo added the bug Something isn't working label Sep 11, 2024
@clemyan
Copy link
Member

clemyan commented Sep 11, 2024

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 clemyan added the waiting for feedback Will autoclose in a while unless more data are provided label Sep 11, 2024
@lukpsaxo
Copy link
Author

@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

image

@clemyan
Copy link
Member

clemyan commented Sep 13, 2024

I see, you want a literal ${x} in your variable

Maybe we should follow dotenv-expand's expansion logic.

@clemyan clemyan changed the title [Bug?]: You cannot use ${x} in environment variable files [Bug?]: Cannot use literal ${x} in environment variable files Sep 13, 2024
@clemyan clemyan changed the title [Bug?]: Cannot use literal ${x} in environment variable files [Bug]: Cannot use literal ${x} in environment variable files Sep 13, 2024
@clemyan clemyan added good first issue Good for newcomers and removed waiting for feedback Will autoclose in a while unless more data are provided labels Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants