dotenv-diff 1.1.1 → 1.1.3

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 CHANGED
@@ -1 +1,49 @@
1
- # dotenv diff cli to compare .env with .env.example
1
+ # dotenv-diff
2
+
3
+ Easily compare your `.env` and `.env.example` files in Node.js projects to detect missing, extra, empty, or mismatched environment variables.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/dotenv-diff.svg)](https://www.npmjs.com/package/dotenv-diff)
6
+ [![npm downloads](https://img.shields.io/npm/dt/dotenv-diff.svg)](https://www.npmjs.com/package/dotenv-diff)
7
+
8
+ ---
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ # npm
14
+ npm install -g dotenv-diff
15
+
16
+ # yarn
17
+ yarn global add dotenv-diff
18
+
19
+ # pnpm
20
+ pnpm add -g dotenv-diff
21
+ ```
22
+ ## Usage
23
+
24
+ ```bash
25
+ dotenv-diff
26
+ ```
27
+ ## Compares .env and .env.example in the current working directory and checks for:
28
+ - Missing variables in `.env.example`
29
+ - Extra variables in `.env`
30
+ - Empty variables in `.env`
31
+ - Mismatched values between `.env` and `.env.example`
32
+
33
+ ## Optional: Check values too
34
+
35
+ ```bash
36
+ dotenv-diff --check-values
37
+ ```
38
+
39
+ When using the `--check-values` option, the tool will also compare the actual values of the variables in `.env` and `.env.example`. It will report any mismatches found and it also compares values if .env.example defines a non-empty expected value.
40
+
41
+ ## 🤝 Contributing
42
+
43
+ Contributions are welcome! Feel free to open an issue or a pull request.
44
+
45
+ ## License
46
+
47
+ MIT
48
+
49
+ ### Created by [chrilleweb](https://github.com/chrilleweb)
package/dist/cli.js CHANGED
@@ -1,9 +1,19 @@
1
1
  #!/usr/bin/env node
2
+ import { Command } from 'commander';
2
3
  import path from "path";
3
4
  import fs from "fs";
4
5
  import chalk from "chalk";
5
6
  import { parseEnvFile } from "./lib/parseEnv.js";
6
7
  import { diffEnv } from "./lib/diffEnv.js";
8
+ const program = new Command();
9
+ program
10
+ .name('dotenv-diff')
11
+ .description('Compare .env and .env.example files')
12
+ .option('--check-values', 'Compare actual values if example has values')
13
+ .parse(process.argv);
14
+ const options = program.opts();
15
+ const checkValues = options.checkValues ?? false;
16
+ // Her kører din eksisterende diff-logik videre:
7
17
  const envPath = path.resolve(process.cwd(), ".env");
8
18
  const examplePath = path.resolve(process.cwd(), ".env.example");
9
19
  if (!fs.existsSync(envPath)) {
@@ -17,7 +27,7 @@ if (!fs.existsSync(examplePath)) {
17
27
  console.log(chalk.bold("🔍 Comparing .env and .env.example..."));
18
28
  const current = parseEnvFile(envPath);
19
29
  const example = parseEnvFile(examplePath);
20
- const diff = diffEnv(current, example);
30
+ const diff = diffEnv(current, example, checkValues);
21
31
  // Find tomme variabler i .env
22
32
  const emptyKeys = Object.entries(current)
23
33
  .filter(([key, value]) => value.trim() === "")
@@ -25,7 +35,8 @@ const emptyKeys = Object.entries(current)
25
35
  let hasWarnings = false;
26
36
  if (diff.missing.length === 0 &&
27
37
  diff.extra.length === 0 &&
28
- emptyKeys.length === 0) {
38
+ emptyKeys.length === 0 &&
39
+ diff.valueMismatches.length === 0) {
29
40
  console.log(chalk.green("✅ All keys match! Your .env file is valid."));
30
41
  process.exit(0);
31
42
  }
@@ -42,7 +53,7 @@ if (emptyKeys.length > 0) {
42
53
  console.log(chalk.yellow("\n⚠️ The following keys in .env have no value (empty):"));
43
54
  emptyKeys.forEach((key) => console.log(chalk.yellow(` - ${key}`)));
44
55
  }
45
- if (diff.valueMismatches.length > 0) {
56
+ if (checkValues && diff.valueMismatches.length > 0) {
46
57
  hasWarnings = true;
47
58
  console.log(chalk.yellow("\n⚠️ The following keys have different values:"));
48
59
  diff.valueMismatches.forEach(({ key, expected, actual }) => {
@@ -1,18 +1,21 @@
1
- export function diffEnv(current, example) {
1
+ export function diffEnv(current, example, checkValues = false) {
2
2
  const currentKeys = Object.keys(current);
3
3
  const exampleKeys = Object.keys(example);
4
4
  const missing = exampleKeys.filter((key) => !currentKeys.includes(key));
5
5
  const extra = currentKeys.filter((key) => !exampleKeys.includes(key));
6
- const valueMismatches = exampleKeys
7
- .filter((key) => {
8
- return (currentKeys.includes(key) &&
9
- example[key].trim() !== "" &&
10
- current[key] !== example[key]);
11
- })
12
- .map((key) => ({
13
- key,
14
- expected: example[key],
15
- actual: current[key],
16
- }));
6
+ let valueMismatches = [];
7
+ if (checkValues) {
8
+ valueMismatches = exampleKeys
9
+ .filter((key) => {
10
+ return (currentKeys.includes(key) &&
11
+ example[key].trim() !== "" &&
12
+ current[key] !== example[key]);
13
+ })
14
+ .map((key) => ({
15
+ key,
16
+ expected: example[key],
17
+ actual: current[key],
18
+ }));
19
+ }
17
20
  return { missing, extra, valueMismatches };
18
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dotenv-diff",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "type": "module",
5
5
  "description": "A small CLI and library to find differences between .env and .env.example files.",
6
6
  "bin": {
@@ -9,13 +9,13 @@
9
9
  "main": "dist/index.js",
10
10
  "types": "dist/index.d.ts",
11
11
  "files": [
12
- "dist/cli.js",
13
- "dist/lib/diffEnv.js",
14
- "dist/lib/parseEnv.js",
15
- "dist/index.js",
16
- "dist/index.d.ts",
17
- "README.md"
18
- ],
12
+ "dist/cli.js",
13
+ "dist/lib/diffEnv.js",
14
+ "dist/lib/parseEnv.js",
15
+ "dist/index.js",
16
+ "dist/index.d.ts",
17
+ "README.md"
18
+ ],
19
19
  "scripts": {
20
20
  "build": "tsc",
21
21
  "dev": "vitest --watch",
@@ -41,7 +41,8 @@
41
41
  "node": ">=14.0.0"
42
42
  },
43
43
  "dependencies": {
44
- "chalk": "^5.4.1"
44
+ "chalk": "^5.4.1",
45
+ "commander": "^14.0.0"
45
46
  },
46
47
  "devDependencies": {
47
48
  "@types/node": "^20.0.0",