luqmanoop / sync-dotenv Goto Github PK
View Code? Open in Web Editor NEWKeep your .env in sync with .env.example
Home Page: https://www.npmjs.com/package/sync-dotenv
License: MIT License
Keep your .env in sync with .env.example
Home Page: https://www.npmjs.com/package/sync-dotenv
License: MIT License
I have a use-case to sync .env and .env.example (or .env.dist in my case) in the opposite direction - pushing updates on the .env file whenever .env.dist additions are made. Not the immediate use-case you cover, but it feels possible and equivalent.
Currently this fails, due to some check on the .env file name. Is this check necessary?
> sync-dotenv --env .env.dist --sample .env
Cannot sync .env with .env
Take this .env
file:
MY_URL=https://my.website.com?this=that
With a .env.example
equivalent of:
MY_URL=
After processing with sync-dotenv
this is changed to:
MY_URL=https://my.website.com?this
Whatever is parsing the =
for delimiting Key and Value appears to be doing something else for any subsequent =
occurrences.
Hi @codeshifu , I have this problem.
Sometimes I keep some keys in .env.example
for documentation but not in .env
because I use defaults or something.
So, if you have keys in .env.example
but not in .env
, when you sync they are deleted from .env.example
.
Example
.env
:
BOTH=1
ENV=0
.env.example
:
BOTH=2
EXAMPLE=42
ANOTHER=24
ENV=3
run sync-dotenv
then
.env.example
:
BOTH=2
ENV=3
The keys EXAMPLE
and ANOTHER
were deleted.
Thanks
Hello
It's not clear from the README but what does this do...
"sync-dotenv": {
"preserve": ["CHANNEL"]
}
Is "CHANNEL" a variable name that is to be preserved ?
Thanks,
Nick
I have to store an env variable with a slack channel starting with #
character.
Scenario 1:
.env
:
# Default channel
CHANNEL=#general
.env.example
:
# Default channel
CHANNEL=#random
run sync-dotenv
then
.env.example
:
CHANNEL= #general
Comment was deleted and value was overwritten with .env
value and a spaces was added.
Scenario 2:
If I use quotes (singles or doubles)
.env
:
# Default channel
CHANNEL='#general'
.env.example
:
# Default channel
CHANNEL='#random'
run sync-dotenv
then
.env.example
:
CHANNEL=
It deletes both, comment and value from key.
So I can't keep my .env.example
with a useful example.
It would be great if you could consider this case.
Thanks
Thanks for this great library. It solves an issue we've had with keeping .env
files in sync and we're super glad we've found it.
We are wondering if it would be of interest for the library to support "fan-out" to multiple .env
files from one .env.template
.
Our setup often looks like:
.env.template
.env.local
.env.staging
.env.production
this helps us simulating and configuring interaction with different parts of the system. We would love to sync from the .env.template
to all other env files. This would require, to my understanding, some globbing (in the root) by the library instead of relying on one file.
Thanks.
Improve the functionality of our CLI tool that synchronises .env
files to .example.env
files by providing an escape mechanism to preserve specific values for public variables.
Currently, all variables in the .example.env
file exist as empty strings after the syncing process. It would be helpful for public variables to retain their values.
I thought of two way to achive this:
Public Prefix Preservation: Allow users to specify a custom or default prefix for variable names that they want to remain public. Any variable with this prefix will retain its value during the sync process.
CLI Example:
sync-dotenv --preserve-public-prefix=NEXT_PUBLIC
In this example, any variable starting with NEXT_PUBLIC
will keep its original value in the .example.env
file.
Default behavior (when flag is used without a value): An error will be thrown requesting for a prefix input.
Keyword Comment Preservation: Allow users to mark variables for preservation using a default or custom keyword comment at the end of the line.
.env
file Example:
SENTRY_URL='https://example.ingest.sentry.io/example' #SYNC_VALUE
CLI Example:
sync-dotenv --preserve-keyword-comment=SYNC_VALUE
In this example, any variable line ending with #SYNC_VALUE
will keep its original value in the .example.env
file.
Default behavior (when flag is used without a value): An error will be thrown requesting for a keyword input.
Need to ensure these changes are well documented in the CLI help text.
Need to provide examples in the readme for the new flag and potential use cases.
Error handling needs to be designed carefully to provide meaningful error messages, especially when the new flags are used without necessary inputs.
No matter how I order the .env file always it always gets screwed up after the tenth extra new line. The following gets inserted instead of new lines: __EMPTYLINE_10__=
__EMPTYLINE_11__=
etc instead of a blank line.
As a convoluted example:
APP_NAME=
APP_ENV=
APP_KEY=
APP_DEBUG=
APP_URL=
LOG_CHANNEL=
DB_CONNECTION=
DB_HOST=
DB_PORT=
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
OTHER_ENV=
Gets synced as:
APP_NAME=
APP_ENV=
APP_KEY=
APP_DEBUG=
APP_URL=
LOG_CHANNEL=
DB_CONNECTION=
DB_HOST=
DB_PORT=
DB_DATABASE=
__EMPTYLINE_10__=
DB_USERNAME=
__EMPTYLINE_11__=
DB_PASSWORD=
__EMPTYLINE_12__=
Not sure if its on my end or the scripts end but was hoping you might have some answers
If no .env.example file is already created, the script just says undefined not found. I expected it to create the file automatically if it didn't already exist.
Please update globby to at least 10.0.
So ever since those packages were deprecated 2 months ago, when I run npm install
with sync-dotenv 2.7.0 as a dependency, I get these deprecation warnings:
$ npm install
npm WARN deprecated [email protected]: See https://github.com/lydell/source-map-url#deprecated
npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated [email protected]: See https://github.com/lydell/source-map-resolve#deprecated
sync-dotenv is using globby.sync which has the same input and output from 9.2.0 up until 12.0.0, at which point globby.sync
became globbySync
.
globby 9.2 could be updated to 10 or 11 without API breaking changes. It could be updated to 13.1 with 1 breaking change, which would simply require import
ing { globbySync }
instead of globby
, and calling globbySync
directly instead of calling globby.sync
.
I will open a pull request to update globby to 11.1 without the breaking change.
Not a big deal, of course, but it's a tiny issue nonetheless -
Currently, any sample filename provided via the CLI that ends with .env
throws an error.
While I understand the reasoning - can't sync .env
itself with .env
- my team uses example.env
as the filename for the example file (as if to say, "here's an example .env file").
Would it be OK to change the check for exclusively .env
files - not all files that end with .env
, or is this a matter of policy (or a best practice I'm unaware of)?
Thanks for your help!
As the communities still have a lots node v12 & v14, should set minimum support from v12/v14 instead of v16
Dear @codeshifu ,
thanks for this wonderful package - i really like it.
I recently stumbled upon the issue, that i have comments in my .env
file. I would like to synchronize these comments with my .env.example
file.
Would you consider adding this feature to your library?
Thanks a lot!
Hi ,
In symfony 4.3 they changed the way to use .env files , now .env file are the example & are commited into repo & we have to overwrite them with .env.local.
So to use sync-dotenv
we should be able to indicate source / destination .
I will do a PR if got some time
Take this .env
file:
MY_URL=https://my.website.com?this=that
With a .env.example
equivalent of:
MY_URL=
After processing with sync-dotenv
this is changed to:
MY_URL=https://my.website.com?this
Whatever is parsing the =
for delimiting Key and Value appears to be doing something else for any subsequent =
occurrences.
I am using macOS with a .env
file with LF (\n) line endings. Running sync-dotenv
produced a .env.example
file with CRLF line endings (\r\n).
First things first: Great work, thanks for this tool π
I encounter the following error when I try to run sync-dotenv
in version 2.5.0
:
TypeError: Cannot read property 'inherits' of undefined β
at Object.<anonymous> (/home/x3ro/.local/opt/n/lib/node_modules/sync-dotenv/dist/index.js:2:16669) βfound 0 vulnerabilities
at Module._compile (internal/modules/cjs/loader.js:1147:30) β
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10) βx3ro@K1STE:~/Projects/x3ro/hacker-news-bot$ ^C
at Module.load (internal/modules/cjs/loader.js:996:32) βx3ro@K1STE:~/Projects/x3ro/hacker-news-bot$ tail -f .env.example
at Function.Module._load (internal/modules/cjs/loader.js:896:14) β # Copy this file to `.env` and change values as needed.
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) β
at internal/main/run_main_module.js:17:47
I tried installing it globally, in a project and even in an empty project.
Installing [email protected]
works flawlessly.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.