dotenv-diff 2.1.5 → 2.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -2
- package/dist/src/cli/run.js +25 -5
- package/dist/src/index.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# dotenv-diff
|
|
2
2
|
|
|
3
|
+

|
|
4
|
+
|
|
3
5
|
Easily compare your .env, .env.example, and other environment files (like .env.local, .env.production) to detect missing, extra, empty, or mismatched variables — and ensure they’re properly ignored by Git.
|
|
4
6
|
|
|
5
7
|
Or scan your codebase to find out which environment variables are actually used in your code, and which ones are not.
|
|
@@ -35,6 +37,14 @@ dotenv-diff will automatically compare all matching .env* files in your project
|
|
|
35
37
|
- `.env.production`
|
|
36
38
|
- Any other .env.* file
|
|
37
39
|
|
|
40
|
+
## Why dotenv-diff?
|
|
41
|
+
|
|
42
|
+
- **Prevent production issues**: Ensure all required environment variables are defined before deploying.
|
|
43
|
+
- **Avoid runtime errors**: Catch missing or misconfigured variables early in development.
|
|
44
|
+
- **Improve collaboration**: Keep your team aligned on necessary environment variables.
|
|
45
|
+
- **Enhance security**: Ensure sensitive variables are not accidentally committed to version control.
|
|
46
|
+
- **Scale confidently**: Perfect for turbo monorepos and multi-environment setups.
|
|
47
|
+
|
|
38
48
|
## Scan your codebase for environment variable usage
|
|
39
49
|
|
|
40
50
|
```bash
|
|
@@ -50,11 +60,11 @@ Use the `--ci` flag for automated environments. This enables strict mode where t
|
|
|
50
60
|
|
|
51
61
|
And the `--example` option allows you to specify which `.env.example` file to compare against.
|
|
52
62
|
|
|
53
|
-
### Use it in Github Actions
|
|
63
|
+
### Use it in Github Actions Example:
|
|
54
64
|
|
|
55
65
|
```yaml
|
|
56
66
|
- name: Check environment variables
|
|
57
|
-
run: dotenv-diff --ci --scan-usage --
|
|
67
|
+
run: dotenv-diff --ci --scan-usage --example .env.example --ignore VITE_MODE,NODE_ENV
|
|
58
68
|
```
|
|
59
69
|
|
|
60
70
|
You can also change the comparison file by using the `--example` flag to point to a different `.env.example` file.
|
package/dist/src/cli/run.js
CHANGED
|
@@ -37,14 +37,34 @@ export async function run(program) {
|
|
|
37
37
|
if (opts.envFlag && opts.exampleFlag) {
|
|
38
38
|
const envExists = fs.existsSync(opts.envFlag);
|
|
39
39
|
const exExists = fs.existsSync(opts.exampleFlag);
|
|
40
|
+
// Handle missing files with prompting (unless in CI mode)
|
|
40
41
|
if (!envExists || !exExists) {
|
|
41
|
-
if
|
|
42
|
-
|
|
42
|
+
// Check if we should prompt for file creation
|
|
43
|
+
if (!opts.isCiMode) {
|
|
44
|
+
const res = await ensureFilesOrPrompt({
|
|
45
|
+
cwd: opts.cwd,
|
|
46
|
+
primaryEnv: opts.envFlag,
|
|
47
|
+
primaryExample: opts.exampleFlag,
|
|
48
|
+
alreadyWarnedMissingEnv: false,
|
|
49
|
+
isYesMode: opts.isYesMode,
|
|
50
|
+
isCiMode: opts.isCiMode,
|
|
51
|
+
});
|
|
52
|
+
if (res.shouldExit) {
|
|
53
|
+
if (opts.json)
|
|
54
|
+
console.log(JSON.stringify([], null, 2));
|
|
55
|
+
process.exit(res.exitCode);
|
|
56
|
+
}
|
|
43
57
|
}
|
|
44
|
-
|
|
45
|
-
|
|
58
|
+
else {
|
|
59
|
+
// In CI mode, we just show errors and exit
|
|
60
|
+
if (!envExists) {
|
|
61
|
+
console.error(chalk.red(`❌ Error: --env file not found: ${path.basename(opts.envFlag)}`));
|
|
62
|
+
}
|
|
63
|
+
if (!exExists) {
|
|
64
|
+
console.error(chalk.red(`❌ Error: --example file not found: ${path.basename(opts.exampleFlag)}`));
|
|
65
|
+
}
|
|
66
|
+
process.exit(1);
|
|
46
67
|
}
|
|
47
|
-
process.exit(1);
|
|
48
68
|
}
|
|
49
69
|
const report = [];
|
|
50
70
|
const { exitWithError } = await compareMany([
|
package/dist/src/index.js
CHANGED
package/package.json
CHANGED