Skip to content

fix genexample appending keys to the last line of .env.example - #1051

Open
RaphaelFakhri wants to merge 1 commit into
dotenvx:mainfrom
RaphaelFakhri:fix-genexample-trailing-newline
Open

RaphaelFakhri wants to merge 1 commit into
dotenvx:mainfrom
RaphaelFakhri:fix-genexample-trailing-newline

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

What

dotenvx ext genexample now adds a newline before it appends missing keys to an existing .env.example that does not end with a newline.

Why

If .env.example has no trailing newline, the first new key goes onto the last existing line. For example, HELLO='' becomes HELLO=''HELLO2=''. The new key is lost and the existing value is changed.

Fixes #1050

How to test

npx tap run --test-env=DOTENVX_NO_ARMOR=true --allow-empty-coverage --allow-incomplete-coverage --disable-coverage tests/lib/services/genexample.test.js

The new test #run (.env.example already exists without trailing newline) fails without the change and passes with it. The preceding test now restores its readFileXSync stub so the new test can stub the same method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dotenvx ext genexample merges new keys into the last line of .env.example when the file has no trailing newline

1 participant