@guihakka2/envdiff 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Guihakka
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,61 @@
1
- # Temporary Holding Version
1
+ # envdiff
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Compare `.env` files across environments (dev, staging, prod, `.env.example`) — **without ever printing secret values**.
4
+
5
+ Safe to run in CI logs, screenshots and pull requests: values are compared in memory, only key names are shown.
6
+
7
+ ```bash
8
+ npx @guihakka2/envdiff .env .env.example --keys-only
9
+ npx @guihakka2/envdiff .env.staging .env.production
10
+ ```
11
+
12
+ ```
13
+ envdiff .env.staging vs .env.production
14
+
15
+ Missing in .env.production:
16
+ - REDIS_URL
17
+
18
+ Different values (hidden):
19
+ ~ DATABASE_URL
20
+
21
+ Possible real secrets in template files:
22
+ ! .env.example: AWS_ACCESS_KEY_ID (line 3)
23
+
24
+ ✗ Not in sync
25
+ ```
26
+
27
+ ## Features
28
+
29
+ - Missing / extra keys across **2 or more** files
30
+ - Changed values, shown only as key names
31
+ - Detects real-looking secrets (AWS, GitHub, OpenAI, Stripe, Slack, Google, private keys) committed in `.example` / `.sample` / `.template` files
32
+ - Duplicate keys, empty values, malformed lines
33
+ - `--json` output and exit codes for CI: `0` in sync, `1` differences, `2` usage error
34
+ - Zero dependencies, runs offline, nothing is sent anywhere
35
+
36
+ ## Use in CI (GitHub Actions)
37
+
38
+ ```yaml
39
+ - run: npx @guihakka2/envdiff .env.example .env.ci --keys-only
40
+ ```
41
+
42
+ ## Options
43
+
44
+ | Flag | What it does |
45
+ |---|---|
46
+ | `--keys-only` | Compare key names only (use with `.env.example`) |
47
+ | `--json` | Machine-readable report (never contains values) |
48
+ | `-h`, `--help` | Help |
49
+ | `-v`, `--version` | Version |
50
+
51
+ ## Limitations
52
+
53
+ Single-line values only (no multiline values or escaped quotes yet). Open an issue if you need them.
54
+
55
+ ## Security
56
+
57
+ See [SECURITY.md](SECURITY.md). Releases are published from GitHub Actions with [npm provenance](https://docs.npmjs.com/generating-provenance-statements), so you can verify every version was built from this repo.
58
+
59
+ ## License
60
+
61
+ MIT — part of [Guihakka Tools](https://github.com/Guihakka2/guihakka-tools).
package/bin/envdiff.js ADDED
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync } from 'node:fs';
3
+ import { parseArgs } from 'node:util';
4
+ import { compare } from '../src/index.js';
5
+
6
+ const HELP = `Usage: envdiff <file> <file> [more files...] [options]
7
+
8
+ Compares keys across .env files. Values are compared but NEVER printed.
9
+
10
+ Options:
11
+ --keys-only Only compare keys (useful against .env.example)
12
+ --json Machine-readable output
13
+ -h, --help Show help
14
+ -v, --version Show version
15
+
16
+ Exit codes: 0 = in sync, 1 = differences or leaked secret, 2 = usage error`;
17
+
18
+ let args;
19
+ try {
20
+ args = parseArgs({ allowPositionals: true, options: {
21
+ 'keys-only': { type: 'boolean' }, json: { type: 'boolean' },
22
+ help: { type: 'boolean', short: 'h' }, version: { type: 'boolean', short: 'v' } } });
23
+ } catch (e) { console.error(e.message + '\n\n' + HELP); process.exit(2); }
24
+ const { values: o, positionals } = args;
25
+ if (o.help) { console.log(HELP); process.exit(0); }
26
+ if (o.version) { console.log(JSON.parse(readFileSync(new URL('../package.json', import.meta.url))).version); process.exit(0); }
27
+ if (positionals.length < 2) { console.error(HELP); process.exit(2); }
28
+
29
+ let files;
30
+ try { files = positionals.map((name) => ({ name, text: readFileSync(name, 'utf8') })); }
31
+ catch (e) { console.error(`envdiff: cannot read ${e.path}: ${e.code}`); process.exit(2); }
32
+
33
+ const r = compare(files, { keysOnly: o['keys-only'] });
34
+ if (o.json) { console.log(JSON.stringify(r, null, 2)); process.exit(r.ok ? 0 : 1); }
35
+
36
+ const color = process.stdout.isTTY && !process.env.NO_COLOR;
37
+ const c = (code, s) => (color ? `\x1b[${code}m${s}\x1b[0m` : s);
38
+ const at = (w) => (w.lines ? ` (line ${w.lines.join(', ')})` : '');
39
+ const out = [c(1, `envdiff ${r.files.join(' vs ')}`), ''];
40
+ for (const m of r.missing) if (m.keys.length) out.push(c(31, `Missing in ${m.file}:`), ...m.keys.map((k) => ` - ${k}`), '');
41
+ if (r.different.length) out.push(c(33, 'Different values (hidden):'), ...r.different.map((k) => ` ~ ${k}`), '');
42
+ if (r.leaks.length) out.push(c(31, 'Possible real secrets in template files:'), ...r.leaks.map((w) => ` ! ${w.file}: ${w.key}${at(w)}`), '');
43
+ if (r.warnings.length) out.push(c(36, 'Warnings:'), ...r.warnings.map((w) => ` ! ${w.file}: ${w.type}${w.key ? ' ' + w.key : ''}${at(w)}`), '');
44
+ out.push(r.ok ? c(32, '✓ In sync') : c(31, '✗ Not in sync'));
45
+ console.log(out.join('\n'));
46
+ process.exit(r.ok ? 0 : 1);
package/package.json CHANGED
@@ -1,6 +1,14 @@
1
1
  {
2
2
  "name": "@guihakka2/envdiff",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Compare .env files across environments without ever printing secret values.",
5
+ "type": "module",
6
+ "bin": { "envdiff": "bin/envdiff.js" },
7
+ "exports": "./src/index.js",
8
+ "files": ["bin", "src"],
9
+ "engines": { "node": ">=20" },
10
+ "scripts": { "test": "node --test" },
11
+ "keywords": ["dotenv", "env", "diff", "config", "devops", "cli", "secrets"],
12
+ "repository": { "type": "git", "url": "git+https://github.com/Guihakka2/envdiff.git" },
13
+ "license": "MIT"
14
+ }
package/src/index.js ADDED
@@ -0,0 +1,50 @@
1
+ // shortcut: single-line values only (no multiline or escaped quotes); upgrade if users report it.
2
+ const LINE = /^(?:export\s+)?([A-Za-z_][A-Za-z0-9_.-]*)\s*=\s*(.*)$/;
3
+
4
+ export function parse(text) {
5
+ const vars = new Map(), duplicates = [], invalid = [];
6
+ text.split(/\r?\n/).forEach((raw, i) => {
7
+ const line = raw.trim();
8
+ if (!line || line.startsWith('#')) return;
9
+ const m = line.match(LINE);
10
+ if (!m) return invalid.push(i + 1);
11
+ let [, key, val] = m;
12
+ const q = val[0];
13
+ if (q === '"' || q === "'" || q === '`') {
14
+ const end = val.indexOf(q, 1);
15
+ val = end > 0 ? val.slice(1, end) : val.slice(1);
16
+ } else val = val.replace(/\s+#.*$/, '').trim();
17
+ if (vars.has(key)) duplicates.push({ key, lines: [vars.get(key).line, i + 1] });
18
+ vars.set(key, { value: val, line: i + 1 });
19
+ });
20
+ return { vars, duplicates, invalid };
21
+ }
22
+
23
+ const SECRET_PATTERNS = [
24
+ /AKIA[0-9A-Z]{16}/, /\bgh[pousr]_[A-Za-z0-9]{30,}/, /github_pat_\w{20,}/, /\bsk-[A-Za-z0-9_-]{20,}/,
25
+ /\b[sr]k_live_\w{10,}/, /\bxox[abprs]-[\w-]{10,}/, /-----BEGIN [A-Z ]*PRIVATE KEY/, /\bAIza[\w-]{35}/,
26
+ ];
27
+ export const looksSecret = (v) => SECRET_PATTERNS.some((re) => re.test(v));
28
+ const isTemplate = (name) => /example|sample|template|dist/i.test(name);
29
+
30
+ // files: [{ name, text }] -> report with keys only; values never leave this function.
31
+ export function compare(files, { keysOnly = false } = {}) {
32
+ const parsed = files.map((f) => ({ name: f.name, ...parse(f.text) }));
33
+ const all = [...new Set(parsed.flatMap((p) => [...p.vars.keys()]))].sort();
34
+ const missing = parsed.map((p) => ({ file: p.name, keys: all.filter((k) => !p.vars.has(k)) }));
35
+ const different = keysOnly ? [] : all.filter((k) => {
36
+ const vals = parsed.filter((p) => p.vars.has(k)).map((p) => p.vars.get(k).value);
37
+ return vals.length > 1 && new Set(vals).size > 1;
38
+ });
39
+ const warnings = [], leaks = [];
40
+ for (const p of parsed) {
41
+ for (const d of p.duplicates) warnings.push({ file: p.name, key: d.key, type: 'duplicate', lines: d.lines });
42
+ for (const line of p.invalid) warnings.push({ file: p.name, type: 'invalid-line', lines: [line] });
43
+ for (const [key, { value, line }] of p.vars) {
44
+ if (value === '') warnings.push({ file: p.name, key, type: 'empty', lines: [line] });
45
+ if (isTemplate(p.name) && looksSecret(value)) leaks.push({ file: p.name, key, type: 'secret-in-template', lines: [line] });
46
+ }
47
+ }
48
+ const ok = missing.every((m) => !m.keys.length) && !different.length && !leaks.length;
49
+ return { files: parsed.map((p) => p.name), missing, different, warnings, leaks, ok };
50
+ }