@subramanyaks/env-drift 1.0.1 → 1.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/CHANGELOG.md +35 -0
- package/README.md +29 -8
- package/dist/cli.js +394 -52
- package/dist/index.cjs +349 -32
- package/dist/index.d.cts +47 -7
- package/dist/index.d.ts +47 -7
- package/dist/index.js +343 -29
- package/package.json +2 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@subramanyaks/env-drift` are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.1.0] - 2026-11-26
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- **Real secret leak detection in `.env.example`:** Detects committed credentials (Stripe keys, GitHub tokens, AWS Access Key IDs, AI provider keys, Slack tokens, Google API keys, JWTs, PEM private keys, and connection URLs with real passwords) while ignoring empty values and common placeholders. Treated as a blocking issue in `--ci` mode.
|
|
12
|
+
- **Empty value detection in `.env`:** Flags keys referenced in code that exist in `.env` with blank values (`emptyInEnv`), respecting `.env.local` overrides.
|
|
13
|
+
- **Project configuration file support:** Automatically loads optional settings from `.envdriftrc.json` or the `"env-drift"` field in `package.json` (`envFile`, `exampleFile`, `ignore`, `ignoreDirs`, `publicPrefixes`, `sensitiveKeywords`). CLI flags override config values.
|
|
14
|
+
- **GitHub Actions inline PR annotations (`--format github`):** Emits `::error` and `::warning` workflow commands with file and line metadata so findings appear inline on PR diffs. Also added `--format <text|json|github>` (with `--json` kept as an alias).
|
|
15
|
+
- **Broader runtime support & inline ignore comments:** Added detection for `Bun.env` (dot, bracket, destructuring) and `Deno.env.get(...)`, plus `// env-drift-ignore` and `// env-drift-ignore-next-line` comments.
|
|
16
|
+
- **New public API exports:** Exported `loadConfig`, `detectExampleSecretLeak`, `formatGitHubAnnotations`, `EnvDriftConfig`, and `ExampleSecretLeak`.
|
|
17
|
+
|
|
18
|
+
## [1.0.1] - 2026-11-26
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
- **CI mode with gitignored `.env`:** `--ci` and `hasBlockingIssues()` no longer fail on `missingInEnv` when no local `.env` / `.env.local` file exists on disk, while still blocking on `missingInExample` and `secretExposures`. Added `envFileExists` and `exampleFileExists` to `AuditResult`.
|
|
22
|
+
- **Stale report after `--sync`:** Keys newly written to `.env.example` by `--sync` are now cleared from `result.missingInExample` before rendering the report/JSON or evaluating `--ci`.
|
|
23
|
+
- **Dynamic CLI version:** CLI `--version` now reads directly from `package.json` instead of a hardcoded string.
|
|
24
|
+
- **Cross-platform direct execution guard:** Replaced suffix-matching with `realpathSync` + `fileURLToPath(import.meta.url)` so CLI execution works reliably across Windows, macOS, and Linux shims.
|
|
25
|
+
- **Parser & scanner edge cases:** Properly unescapes `\"`, `\n`, `\r`, and `\t` inside double-quoted `.env` values, and detects optional-chained bracket access (`process.env?.["KEY"]`, `import.meta.env?.["KEY"]`).
|
|
26
|
+
|
|
27
|
+
## [1.0.0] - 2026-11-25
|
|
28
|
+
|
|
29
|
+
### Added
|
|
30
|
+
- Initial release of `@subramanyaks/env-drift` CLI and programmatic TypeScript/ESM/CJS library.
|
|
31
|
+
- Static codebase scanning for `process.env` and `import.meta.env` (dot, optional-chain, bracket, and destructuring access) while ignoring comments.
|
|
32
|
+
- Drift analysis detecting missing keys in `.env` and `.env.example`, unused/dead keys, duplicate keys, and client-exposed sensitive variable names (`NEXT_PUBLIC_*`, `VITE_*`, `REACT_APP_*`, etc.).
|
|
33
|
+
- Safe `--sync` to append missing keys as empty `KEY=` placeholders to `.env.example`.
|
|
34
|
+
- TypeScript `env.d.ts` declaration generator (`--types` / `--types-out`).
|
|
35
|
+
- CI exit code gating (`--ci`) and structured JSON output (`--json`).
|
package/README.md
CHANGED
|
@@ -11,12 +11,14 @@ Zero-config CLI and TypeScript library that detects **environment variable drift
|
|
|
11
11
|
|
|
12
12
|
Runtime validators are great, but they require adding code and only fail *after* your app boots. `env-drift` statically audits your repo in milliseconds with **zero setup**:
|
|
13
13
|
|
|
14
|
-
- **Missing in `.env`** — Catch `process.env.STRIPE_KEY
|
|
14
|
+
- **Missing in `.env`** — Catch `process.env.STRIPE_KEY`, `import.meta.env.VITE_API_URL`, `Bun.env.API_KEY`, or `Deno.env.get("TOKEN")` before runtime crashes.
|
|
15
15
|
- **Missing in `.env.example`** — Keep teammate onboarding in sync (with `--sync` to safely append `KEY=` placeholders without ever copying secret values).
|
|
16
|
+
- **Empty Values in `.env`** — Catch keys that exist in `.env` as `STRIPE_KEY=` with no value set.
|
|
16
17
|
- **Unused / Dead vars** — Spot stale keys left behind in `.env` and `.env.example`.
|
|
17
18
|
- **Public Secret Exposure** — Flags dangerous client-exposed names like `NEXT_PUBLIC_DB_PASSWORD` or `VITE_JWT_SECRET`.
|
|
19
|
+
- **Real Secrets in `.env.example`** — Detects real API keys, tokens, JWTs, PEM private keys, and DB passwords accidentally committed to `.env.example`.
|
|
18
20
|
- **Type Generation** — Auto-generate `env.d.ts` (`NodeJS.ProcessEnv` + `ImportMetaEnv`) with `--types`.
|
|
19
|
-
- **CI
|
|
21
|
+
- **CI & GitHub PR Annotations** — Drop `npx @subramanyaks/env-drift --ci --format github` into GitHub Actions to annotate PR diffs directly.
|
|
20
22
|
|
|
21
23
|
## Quick Start
|
|
22
24
|
|
|
@@ -59,8 +61,9 @@ Tip: Run with --sync to safely append missing keys to .env.example.
|
|
|
59
61
|
| `--sync` | Safely append missing keys to `.env.example` as `KEY=` | `false` |
|
|
60
62
|
| `--types` | Generate `env.d.ts` for detected env variables | `false` |
|
|
61
63
|
| `--types-out <path>` | Custom output path for `--types` | `env.d.ts` |
|
|
62
|
-
| `--ci` | Exit with code `1` if missing vars or
|
|
63
|
-
| `--
|
|
64
|
+
| `--ci` | Exit with code `1` if missing vars or secret leaks are found (skips local `.env` check when `.env` is absent) | `false` |
|
|
65
|
+
| `--format <type>` | Output format: `text`, `json`, or `github` (GitHub Actions annotations) | `text` |
|
|
66
|
+
| `--json` | Output structured JSON (`AuditResult`) — alias for `--format json` | `false` |
|
|
64
67
|
| `-v, --version` | Print version | — |
|
|
65
68
|
| `-h, --help` | Print help message | — |
|
|
66
69
|
|
|
@@ -82,13 +85,30 @@ npx @subramanyaks/env-drift --ignore VERCEL_URL,RAILWAY_ENVIRONMENT
|
|
|
82
85
|
|
|
83
86
|
## GitHub Actions CI Recipe
|
|
84
87
|
|
|
85
|
-
Add this step to your `.github/workflows/ci.yml` to block PRs with undocumented env vars or leaked
|
|
88
|
+
Add this step to your `.github/workflows/ci.yml` to block PRs with undocumented env vars or leaked secrets and render inline PR annotations:
|
|
86
89
|
|
|
87
90
|
```yaml
|
|
88
91
|
- name: Check environment drift
|
|
89
|
-
run: npx @subramanyaks/env-drift --ci
|
|
92
|
+
run: npx @subramanyaks/env-drift --ci --format github
|
|
90
93
|
```
|
|
91
94
|
|
|
95
|
+
## Configuration File (Optional)
|
|
96
|
+
|
|
97
|
+
You can persist options in `.envdriftrc.json` (or under an `"env-drift"` key in `package.json`):
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"envFile": ".env",
|
|
102
|
+
"exampleFile": ".env.example",
|
|
103
|
+
"ignore": ["VERCEL_URL", "RAILWAY_ENVIRONMENT"],
|
|
104
|
+
"ignoreDirs": ["generated"],
|
|
105
|
+
"publicPrefixes": ["CUSTOM_PUBLIC_"],
|
|
106
|
+
"sensitiveKeywords": ["MASTER_KEY"]
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
CLI flags always override config file values.
|
|
111
|
+
|
|
92
112
|
## Programmatic API
|
|
93
113
|
|
|
94
114
|
Install as a dev dependency to use in custom scripts:
|
|
@@ -113,10 +133,11 @@ if (hasBlockingIssues(result)) {
|
|
|
113
133
|
|
|
114
134
|
## What Patterns Are Detected?
|
|
115
135
|
|
|
116
|
-
- `process.env.API_KEY` and `process.env?.API_KEY`
|
|
117
|
-
- `process.env["API_KEY"]` and `process.env['API_KEY']`
|
|
136
|
+
- `process.env.API_KEY`, `process.env?.API_KEY`, `process.env["API_KEY"]`, and `process.env?.["API_KEY"]`
|
|
118
137
|
- `const { API_KEY, PORT: port = "3000" } = process.env`
|
|
119
138
|
- `import.meta.env.VITE_API_URL` and destructuring from `import.meta.env`
|
|
139
|
+
- `Bun.env.API_KEY`, `Bun.env["API_KEY"]`, and `Deno.env.get("API_KEY")`
|
|
140
|
+
- Inline ignore comments: `// env-drift-ignore` and `// env-drift-ignore-next-line`
|
|
120
141
|
- Commented-out code (`//` and `/* ... */`) is automatically ignored.
|
|
121
142
|
- Standard built-ins (`NODE_ENV`, `CI`, `MODE`, `DEV`, `PROD`, `SSR`, `BASE_URL`) are ignored by default.
|
|
122
143
|
|