@guihakka2/envdiff 0.0.0-stage → 0.1.1

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,62 @@
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 # compares .env.example with .env in this folder
9
+ npx @guihakka2/envdiff .env .env.example --keys-only
10
+ npx @guihakka2/envdiff .env.staging .env.production
11
+ ```
12
+
13
+ ```
14
+ envdiff .env.staging vs .env.production
15
+
16
+ Missing in .env.production:
17
+ - REDIS_URL
18
+
19
+ Different values (hidden):
20
+ ~ DATABASE_URL
21
+
22
+ Possible real secrets in template files:
23
+ ! .env.example: AWS_ACCESS_KEY_ID (line 3)
24
+
25
+ ✗ Not in sync
26
+ ```
27
+
28
+ ## Features
29
+
30
+ - Missing / extra keys across **2 or more** files
31
+ - Changed values, shown only as key names
32
+ - Detects real-looking secrets (AWS, GitHub, OpenAI, Stripe, Slack, Google, private keys) committed in `.example` / `.sample` / `.template` files
33
+ - Duplicate keys, empty values, malformed lines
34
+ - `--json` output and exit codes for CI: `0` in sync, `1` differences, `2` usage error
35
+ - Zero dependencies, runs offline, nothing is sent anywhere
36
+
37
+ ## Use in CI (GitHub Actions)
38
+
39
+ ```yaml
40
+ - run: npx @guihakka2/envdiff .env.example .env.ci --keys-only
41
+ ```
42
+
43
+ ## Options
44
+
45
+ | Flag | What it does |
46
+ |---|---|
47
+ | `--keys-only` | Compare key names only (use with `.env.example`) |
48
+ | `--json` | Machine-readable report (never contains values) |
49
+ | `-h`, `--help` | Help |
50
+ | `-v`, `--version` | Version |
51
+
52
+ ## Limitations
53
+
54
+ Single-line values only (no multiline values or escaped quotes yet). Open an issue if you need them.
55
+
56
+ ## Security
57
+
58
+ 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.
59
+
60
+ ## License
61
+
62
+ MIT — part of [Guihakka Tools](https://github.com/Guihakka2/guihakka-tools).
package/bin/envdiff.js ADDED
@@ -0,0 +1,53 @@
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
+ With no files, compares .env.example and .env in the current folder (keys only).
10
+
11
+ Options:
12
+ --keys-only Only compare keys (useful against .env.example)
13
+ --json Machine-readable output
14
+ -h, --help Show help
15
+ -v, --version Show version
16
+
17
+ Exit codes: 0 = in sync, 1 = differences or leaked secret, 2 = usage error`;
18
+
19
+ let args;
20
+ try {
21
+ args = parseArgs({ allowPositionals: true, options: {
22
+ 'keys-only': { type: 'boolean' }, json: { type: 'boolean' },
23
+ help: { type: 'boolean', short: 'h' }, version: { type: 'boolean', short: 'v' } } });
24
+ } catch (e) { console.error(e.message + '\n\n' + HELP); process.exit(2); }
25
+ const { values: o, positionals } = args;
26
+ if (o.help) { console.log(HELP); process.exit(0); }
27
+ if (o.version) { console.log(JSON.parse(readFileSync(new URL('../package.json', import.meta.url))).version); process.exit(0); }
28
+ const zeroArg = positionals.length === 0;
29
+ const names = zeroArg ? ['.env.example', '.env'] : positionals;
30
+ if (names.length < 2) { console.error(HELP); process.exit(2); }
31
+
32
+ let files;
33
+ try { files = names.map((name) => ({ name, text: readFileSync(name, 'utf8') })); }
34
+ catch (e) {
35
+ console.error(`envdiff: cannot read ${e.path}: ${e.code}`);
36
+ if (zeroArg) console.error('With no arguments envdiff compares .env.example and .env in the current folder.\nRun envdiff --help for usage.');
37
+ process.exit(2);
38
+ }
39
+
40
+ const r = compare(files, { keysOnly: o['keys-only'] || zeroArg });
41
+ if (o.json) { console.log(JSON.stringify(r, null, 2)); process.exit(r.ok ? 0 : 1); }
42
+
43
+ const color = process.stdout.isTTY && !process.env.NO_COLOR;
44
+ const c = (code, s) => (color ? `\x1b[${code}m${s}\x1b[0m` : s);
45
+ const at = (w) => (w.lines ? ` (line ${w.lines.join(', ')})` : '');
46
+ const out = [c(1, `envdiff ${r.files.join(' vs ')}`), ''];
47
+ for (const m of r.missing) if (m.keys.length) out.push(c(31, `Missing in ${m.file}:`), ...m.keys.map((k) => ` - ${k}`), '');
48
+ if (r.different.length) out.push(c(33, 'Different values (hidden):'), ...r.different.map((k) => ` ~ ${k}`), '');
49
+ if (r.leaks.length) out.push(c(31, 'Possible real secrets in template files:'), ...r.leaks.map((w) => ` ! ${w.file}: ${w.key}${at(w)}`), '');
50
+ if (r.warnings.length) out.push(c(36, 'Warnings:'), ...r.warnings.map((w) => ` ! ${w.file}: ${w.type}${w.key ? ' ' + w.key : ''}${at(w)}`), '');
51
+ out.push(r.ok ? c(32, '✓ In sync') : c(31, '✗ Not in sync'));
52
+ console.log(out.join('\n'));
53
+ process.exit(r.ok ? 0 : 1);
package/package.json CHANGED
@@ -1,6 +1,34 @@
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.1",
4
+ "description": "Compare .env files across environments without ever printing secret values.",
5
+ "type": "module",
6
+ "bin": {
7
+ "envdiff": "bin/envdiff.js"
8
+ },
9
+ "exports": "./src/index.js",
10
+ "files": [
11
+ "bin",
12
+ "src"
13
+ ],
14
+ "engines": {
15
+ "node": ">=20"
16
+ },
17
+ "scripts": {
18
+ "test": "node --test"
19
+ },
20
+ "keywords": [
21
+ "dotenv",
22
+ "env",
23
+ "diff",
24
+ "config",
25
+ "devops",
26
+ "cli",
27
+ "secrets"
28
+ ],
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/Guihakka2/envdiff.git"
32
+ },
33
+ "license": "MIT"
34
+ }
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
+ }