@subramanyaks/env-drift 1.1.0 → 1.2.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 CHANGED
@@ -5,6 +5,19 @@ All notable changes to `@subramanyaks/env-drift` are documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.2.0] - 2026-12-02
9
+
10
+ ### Added
11
+ - **Multi-environment drift diffing (`--diff`):** Compare keys across two env files (e.g. `env-drift --diff .env.staging .env.production`) to surface keys only in one file and empty values without ever printing secret values. Supports `--ci`, `--strict`, and `--json`.
12
+ - **Zod runtime validation schema generator (`--schema` / `--schema-out`):** Generates a starter `env.schema.ts` with inferred Zod validators (`z.string().url()` for `*_URL`, `z.coerce.number()` for `PORT`/`*_PORT`/`*_TIMEOUT`, `z.coerce.boolean()` for boolean flags, and `z.string().min(1)` by default).
13
+ - **Monorepo / workspace auditing (`--workspaces`):** Automatically discovers workspaces from root `package.json` (`workspaces`) or `pnpm-workspace.yaml` and audits each package with a unified summary and combined `--ci` exit code.
14
+ - **Strict CI mode (`--strict`):** Extends `--ci` (and `"strict": true` in `.envdriftrc.json`) to also fail on empty `.env` values, unused keys, and duplicate keys.
15
+ - **New public API exports:** Exported `diffEnvFiles`, `hasDiffIssues`, `formatDiffReport`, `generateZodSchema`, `inferZodRule`, `writeZodSchema`, `discoverWorkspaces`, `auditWorkspaces`, `formatWorkspaceReport`, `EnvDiffResult`, `WorkspaceAuditItem`, and `WorkspaceAuditResult`.
16
+
17
+ ### Fixed
18
+ - **Multiline quoted `.env` values:** `parseEnvContent()` now properly parses multiline double-quoted values such as PEM private keys while preserving accurate starting line numbers.
19
+ - **Regex literal safety in scanner:** Replaced regex-based comment stripping with a single-pass lexer in `stripCommentsPreservingLines()` so regex literals containing `//` (e.g. `/https?:\/\//`) are never misread as line comments.
20
+
8
21
  ## [1.1.0] - 2026-11-26
9
22
 
10
23
  ### Added
package/README.md CHANGED
@@ -17,8 +17,9 @@ Runtime validators are great, but they require adding code and only fail *after*
17
17
  - **Unused / Dead vars** — Spot stale keys left behind in `.env` and `.env.example`.
18
18
  - **Public Secret Exposure** — Flags dangerous client-exposed names like `NEXT_PUBLIC_DB_PASSWORD` or `VITE_JWT_SECRET`.
19
19
  - **Real Secrets in `.env.example`** — Detects real API keys, tokens, JWTs, PEM private keys, and DB passwords accidentally committed to `.env.example`.
20
- - **Type Generation** — Auto-generate `env.d.ts` (`NodeJS.ProcessEnv` + `ImportMetaEnv`) with `--types`.
21
- - **CI & GitHub PR Annotations** — Drop `npx @subramanyaks/env-drift --ci --format github` into GitHub Actions to annotate PR diffs directly.
20
+ - **Type & Zod Schema Generation** — Auto-generate `env.d.ts` (`--types`) and a starter Zod runtime validation schema `env.schema.ts` (`--schema`).
21
+ - **Multi-Env Diff & Monorepos** — Compare `.env.staging` vs `.env.production` with `--diff` (without printing secret values) and audit all monorepo packages with `--workspaces`.
22
+ - **CI & GitHub PR Annotations** — Drop `npx @subramanyaks/env-drift --ci --format github` into GitHub Actions (with optional `--strict`) to annotate PR diffs directly.
22
23
 
23
24
  ## Quick Start
24
25
 
@@ -61,7 +62,12 @@ Tip: Run with --sync to safely append missing keys to .env.example.
61
62
  | `--sync` | Safely append missing keys to `.env.example` as `KEY=` | `false` |
62
63
  | `--types` | Generate `env.d.ts` for detected env variables | `false` |
63
64
  | `--types-out <path>` | Custom output path for `--types` | `env.d.ts` |
65
+ | `--schema` | Generate starter Zod runtime validation schema (`env.schema.ts`) | `false` |
66
+ | `--schema-out <path>` | Custom output path for `--schema` | `env.schema.ts` |
67
+ | `--diff <fileA> <fileB>` | Compare keys across two env files without printing secret values | `false` |
68
+ | `--workspaces` | Audit all monorepo workspaces (`package.json` / `pnpm-workspace.yaml`) | `false` |
64
69
  | `--ci` | Exit with code `1` if missing vars or secret leaks are found (skips local `.env` check when `.env` is absent) | `false` |
70
+ | `--strict` | In `--ci` mode, also fail on empty values, unused keys, and duplicate keys | `false` |
65
71
  | `--format <type>` | Output format: `text`, `json`, or `github` (GitHub Actions annotations) | `text` |
66
72
  | `--json` | Output structured JSON (`AuditResult`) — alias for `--format json` | `false` |
67
73
  | `-v, --version` | Print version | — |
@@ -76,8 +82,17 @@ npx @subramanyaks/env-drift --sync
76
82
  # Generate env.d.ts for TypeScript autocomplete
77
83
  npx @subramanyaks/env-drift --types
78
84
 
79
- # Run in CI (fails build on missing vars or public secret leaks)
80
- npx @subramanyaks/env-drift --ci
85
+ # Generate a starter Zod runtime validation schema (env.schema.ts)
86
+ npx @subramanyaks/env-drift --schema
87
+
88
+ # Compare staging and production env files (keys only, never prints secrets)
89
+ npx @subramanyaks/env-drift --diff .env.staging .env.production
90
+
91
+ # Audit all packages in a monorepo
92
+ npx @subramanyaks/env-drift --workspaces --ci
93
+
94
+ # Run in CI (fails build on missing vars or secret leaks; add --strict to fail on warnings too)
95
+ npx @subramanyaks/env-drift --ci --strict
81
96
 
82
97
  # Ignore specific platform variables
83
98
  npx @subramanyaks/env-drift --ignore VERCEL_URL,RAILWAY_ENVIRONMENT
@@ -103,7 +118,8 @@ You can persist options in `.envdriftrc.json` (or under an `"env-drift"` key in
103
118
  "ignore": ["VERCEL_URL", "RAILWAY_ENVIRONMENT"],
104
119
  "ignoreDirs": ["generated"],
105
120
  "publicPrefixes": ["CUSTOM_PUBLIC_"],
106
- "sensitiveKeywords": ["MASTER_KEY"]
121
+ "sensitiveKeywords": ["MASTER_KEY"],
122
+ "strict": false
107
123
  }
108
124
  ```
109
125