@subramanyaks/env-drift 0.0.0-stage → 1.0.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 +21 -0
- package/README.md +137 -2
- package/dist/cli.js +720 -0
- package/dist/index.cjs +589 -0
- package/dist/index.d.cts +126 -0
- package/dist/index.d.ts +126 -0
- package/dist/index.js +537 -0
- package/package.json +67 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Subramanya KS
|
|
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,138 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @subramanyaks/env-drift
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@subramanyaks/env-drift)
|
|
4
|
+
[](https://www.npmjs.com/package/@subramanyaks/env-drift)
|
|
5
|
+
[](https://github.com/SubramanyaKS/env-drift/actions/workflows/ci.yml)
|
|
6
|
+
[](./LICENSE)
|
|
7
|
+
|
|
8
|
+
Zero-config CLI and TypeScript library that detects **environment variable drift**, **missing keys**, **dead vars**, and **accidental public secret exposure** across JS, TS, React, Next.js, Vite, and Node.js projects.
|
|
9
|
+
|
|
10
|
+
## Why `@subramanyaks/env-drift`?
|
|
11
|
+
|
|
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
|
+
|
|
14
|
+
- **Missing in `.env`** — Catch `process.env.STRIPE_KEY` or `import.meta.env.VITE_API_URL` before runtime crashes.
|
|
15
|
+
- **Missing in `.env.example`** — Keep teammate onboarding in sync (with `--sync` to safely append `KEY=` placeholders without ever copying secret values).
|
|
16
|
+
- **Unused / Dead vars** — Spot stale keys left behind in `.env` and `.env.example`.
|
|
17
|
+
- **Public Secret Exposure** — Flags dangerous client-exposed names like `NEXT_PUBLIC_DB_PASSWORD` or `VITE_JWT_SECRET`.
|
|
18
|
+
- **Type Generation** — Auto-generate `env.d.ts` (`NodeJS.ProcessEnv` + `ImportMetaEnv`) with `--types`.
|
|
19
|
+
- **CI Ready** — Drop `npx @subramanyaks/env-drift --ci` into GitHub Actions to fail PRs on drift or leaked public secrets.
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
Run directly in any project with `npx`:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npx @subramanyaks/env-drift
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Example Output
|
|
30
|
+
|
|
31
|
+
```text
|
|
32
|
+
env-drift — scanned 24 files
|
|
33
|
+
|
|
34
|
+
✖ Possible Public Secret Exposure (1)
|
|
35
|
+
• NEXT_PUBLIC_DB_PASSWORD (public prefix "NEXT_PUBLIC_" + sensitive "PASSWORD") ← src/db.ts:14
|
|
36
|
+
|
|
37
|
+
✖ Missing in .env (2)
|
|
38
|
+
• NEXT_PUBLIC_DB_PASSWORD ← src/db.ts:14
|
|
39
|
+
• STRIPE_WEBHOOK_SECRET ← src/api/webhook.ts:8
|
|
40
|
+
|
|
41
|
+
⚠ Missing in .env.example (2)
|
|
42
|
+
• NEXT_PUBLIC_DB_PASSWORD ← src/db.ts:14
|
|
43
|
+
• STRIPE_WEBHOOK_SECRET ← src/api/webhook.ts:8
|
|
44
|
+
|
|
45
|
+
○ Unused in .env (1)
|
|
46
|
+
• LEGACY_API_KEY
|
|
47
|
+
|
|
48
|
+
Tip: Run with --sync to safely append missing keys to .env.example.
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## CLI Options
|
|
52
|
+
|
|
53
|
+
| Flag | Description | Default |
|
|
54
|
+
| :--- | :--- | :--- |
|
|
55
|
+
| `-d, --dir <path>` | Project directory to scan | `.` |
|
|
56
|
+
| `--env <file>` | Local env file name (also reads `.env.local` by default) | `.env` |
|
|
57
|
+
| `--example <file>` | Example env file name | `.env.example` |
|
|
58
|
+
| `--ignore <vars>` | Comma-separated env variable names to ignore | — |
|
|
59
|
+
| `--sync` | Safely append missing keys to `.env.example` as `KEY=` | `false` |
|
|
60
|
+
| `--types` | Generate `env.d.ts` for detected env variables | `false` |
|
|
61
|
+
| `--types-out <path>` | Custom output path for `--types` | `env.d.ts` |
|
|
62
|
+
| `--ci` | Exit with code `1` if missing vars or public secret leaks are found | `false` |
|
|
63
|
+
| `--json` | Output structured JSON (`AuditResult`) | `false` |
|
|
64
|
+
| `-v, --version` | Print version | — |
|
|
65
|
+
| `-h, --help` | Print help message | — |
|
|
66
|
+
|
|
67
|
+
### Common Commands
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
# Sync missing keys into .env.example (empty placeholders only)
|
|
71
|
+
npx @subramanyaks/env-drift --sync
|
|
72
|
+
|
|
73
|
+
# Generate env.d.ts for TypeScript autocomplete
|
|
74
|
+
npx @subramanyaks/env-drift --types
|
|
75
|
+
|
|
76
|
+
# Run in CI (fails build on missing vars or public secret leaks)
|
|
77
|
+
npx @subramanyaks/env-drift --ci
|
|
78
|
+
|
|
79
|
+
# Ignore specific platform variables
|
|
80
|
+
npx @subramanyaks/env-drift --ignore VERCEL_URL,RAILWAY_ENVIRONMENT
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## GitHub Actions CI Recipe
|
|
84
|
+
|
|
85
|
+
Add this step to your `.github/workflows/ci.yml` to block PRs with undocumented env vars or leaked client secrets:
|
|
86
|
+
|
|
87
|
+
```yaml
|
|
88
|
+
- name: Check environment drift
|
|
89
|
+
run: npx @subramanyaks/env-drift --ci
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Programmatic API
|
|
93
|
+
|
|
94
|
+
Install as a dev dependency to use in custom scripts:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
npm install -D @subramanyaks/env-drift
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import { auditEnv, hasBlockingIssues } from "@subramanyaks/env-drift";
|
|
102
|
+
|
|
103
|
+
const result = auditEnv({
|
|
104
|
+
rootDir: process.cwd(),
|
|
105
|
+
ignore: ["VERCEL_URL"],
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
if (hasBlockingIssues(result)) {
|
|
109
|
+
console.error("Env drift detected:", result.missingInExample);
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## What Patterns Are Detected?
|
|
115
|
+
|
|
116
|
+
- `process.env.API_KEY` and `process.env?.API_KEY`
|
|
117
|
+
- `process.env["API_KEY"]` and `process.env['API_KEY']`
|
|
118
|
+
- `const { API_KEY, PORT: port = "3000" } = process.env`
|
|
119
|
+
- `import.meta.env.VITE_API_URL` and destructuring from `import.meta.env`
|
|
120
|
+
- Commented-out code (`//` and `/* ... */`) is automatically ignored.
|
|
121
|
+
- Standard built-ins (`NODE_ENV`, `CI`, `MODE`, `DEV`, `PROD`, `SSR`, `BASE_URL`) are ignored by default.
|
|
122
|
+
|
|
123
|
+
## Development
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
npm install
|
|
127
|
+
npm run typecheck
|
|
128
|
+
npm test
|
|
129
|
+
npm run build
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Author
|
|
133
|
+
|
|
134
|
+
[Subramanya KS](https://github.com/SubramanyaKS)
|
|
135
|
+
|
|
136
|
+
## License
|
|
137
|
+
|
|
138
|
+
MIT — see [LICENSE](./LICENSE) for details.
|