@xlameiro/env-typegen 0.1.1 → 0.1.3
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 +46 -2
- package/README.md +118 -20
- package/dist/cli.js +1352 -89
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +1563 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +560 -6
- package/dist/index.d.ts +560 -6
- package/dist/index.js +1551 -53
- package/dist/index.js.map +1 -1
- package/package.json +19 -23
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Refresh package and site documentation for the validation suite (`check`, `diff`, `doctor`), cloud snapshot sources, and plugin-based extension points. Expand public API examples to include `runValidationCommand`, `loadCloudSource`, and plugin loading helpers.
|
|
8
|
+
|
|
9
|
+
## 0.1.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Refresh the published npm package metadata and README to match the current repository documentation.
|
|
14
|
+
|
|
3
15
|
All notable changes to this project will be documented in this file.
|
|
4
16
|
|
|
5
17
|
This project adheres to [Semantic Versioning](https://semver.org/) and uses
|
|
@@ -7,7 +19,39 @@ This project adheres to [Semantic Versioning](https://semver.org/) and uses
|
|
|
7
19
|
|
|
8
20
|
<!-- Releases are added automatically by `changeset version` -->
|
|
9
21
|
|
|
10
|
-
## [0.1.
|
|
22
|
+
## [0.1.1] — 2026-03-17
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- **A1** — VERSION was hardcoded as `"0.1.0"` in `cli.ts`; now read dynamically from `package.json` via `createRequire` so it stays in sync without manual edits.
|
|
27
|
+
- **A2** — Double-quotes in `@description` annotations were not escaped in the t3-generator output, corrupting the generated `createEnv(...)` call. Fixed with `.replace(/"/g, '\\"')`.
|
|
28
|
+
- **A3** — Prettier parse errors in `formatOutput` were silently swallowed; a `console.warn` is now emitted before the raw-content fallback.
|
|
29
|
+
- **A4** — Watch mode only listened for `"change"` events; it now also handles `"add"` and `"unlink"` so editor save-with-delete patterns are covered.
|
|
30
|
+
- **A5** — Config file changes during `--watch` were silently ignored; a second chokidar watcher now monitors the config file and reloads it on change.
|
|
31
|
+
- **C1** — `formatOutput` (Prettier) was called unnecessarily in dry-run mode; formatting now runs only when actually writing to disk.
|
|
32
|
+
- **C3** — Removed duplicate alias exports (`generateTypeScript`, `generateZod`); the canonical names `generateTypeScriptTypes` and `generateZodSchema` are the only public exports.
|
|
33
|
+
- **E1–E3** — README badge URLs had `YOUR_USERNAME` placeholders; replaced with the real GitHub/npm identifiers. Package name aligned to `@xlameiro/env-typegen` throughout all docs.
|
|
34
|
+
- **E4** — README `--format` example was misleading; corrected to use `--generator`/`-f` for generator selection and document `--no-format` for disabling Prettier.
|
|
35
|
+
- **E5** — `parseEnvFile` was documented as `async`/awaitable but is synchronous; removed erroneous `await` from all examples.
|
|
36
|
+
- **DRY** — `CONFIG_FILE_NAMES` was duplicated between `config.ts` and `watch.ts`; exported from `config.ts` and imported in `watch.ts`.
|
|
37
|
+
|
|
38
|
+
### Added
|
|
39
|
+
|
|
40
|
+
- **B1** — `EnvTypegenConfig.input` now accepts `string | string[]`; CLI `--input`/`-i` can be repeated to process multiple `.env` files in one run.
|
|
41
|
+
- **B2** — `inferenceRules?: InferenceRule[]` added to `EnvTypegenConfig` and `RunGenerateOptions`; custom rules are prepended before the built-in ruleset.
|
|
42
|
+
- **B3** — Default generators changed from `["typescript"]` to all four: `["typescript", "zod", "t3", "declaration"]`, matching the spec.
|
|
43
|
+
- **B4** — Dry-run mode now prints each generated output block to stdout so users can preview content without touching the filesystem.
|
|
44
|
+
- **B5** — Watch mode debounces rapid file-change events (200 ms) to prevent multiple simultaneous pipeline runs on editor autosave.
|
|
45
|
+
|
|
46
|
+
### Tests
|
|
47
|
+
|
|
48
|
+
- Regression test for double-quotes in t3-generator descriptions (A2).
|
|
49
|
+
- CLI version tests read expected version from `package.json` (A1).
|
|
50
|
+
- Four `loadConfig()` unit tests with temp-dir fixtures (no stale state).
|
|
51
|
+
- Dry-run stdout spy test verifying preview content appears (B4).
|
|
52
|
+
- Integration tests expanded to five end-to-end scenarios via `execSync` against the built `dist/cli.js`.
|
|
53
|
+
|
|
54
|
+
[0.1.1]: https://github.com/xlameiro/env-typegen/compare/packages/env-typegen@0.1.0...packages/env-typegen@0.1.1
|
|
11
55
|
|
|
12
56
|
### Added
|
|
13
57
|
|
|
@@ -54,4 +98,4 @@ This project adheres to [Semantic Versioning](https://semver.org/) and uses
|
|
|
54
98
|
- Full TSDoc on every public export in `src/index.ts`
|
|
55
99
|
- README with Quick Start (CLI examples), Programmatic API, and Configuration sections
|
|
56
100
|
|
|
57
|
-
[0.1.0]: https://github.com/
|
|
101
|
+
[0.1.0]: https://github.com/xlameiro/env-typegen/releases/tag/v0.1.0
|
package/README.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
> From `.env.example` to TypeScript in one command.
|
|
4
4
|
|
|
5
|
-
[](https://npmjs.com/package/@xlameiro/env-typegen)
|
|
6
|
+
[](https://github.com/xlameiro/env-typegen/actions/workflows/ci.yml)
|
|
7
7
|
[](LICENSE)
|
|
8
8
|
[](https://www.typescriptlang.org/)
|
|
9
9
|
|
|
@@ -11,31 +11,115 @@
|
|
|
11
11
|
|
|
12
12
|
`env-typegen` reads `.env.example` files and automatically generates:
|
|
13
13
|
|
|
14
|
-
- TypeScript types (`type
|
|
14
|
+
- TypeScript types (`type EnvVars = { PORT: number; DATABASE_URL: string }`)
|
|
15
15
|
- Zod v4 schemas (`z.object({ PORT: z.coerce.number() })`)
|
|
16
16
|
- `@t3-oss/env-nextjs` `createEnv` configuration
|
|
17
17
|
- `.d.ts` declaration files that augment `NodeJS.ProcessEnv`
|
|
18
18
|
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pnpm add -D @xlameiro/env-typegen
|
|
23
|
+
# or
|
|
24
|
+
npm install --save-dev @xlameiro/env-typegen
|
|
25
|
+
```
|
|
26
|
+
|
|
19
27
|
## Quick Start
|
|
20
28
|
|
|
21
29
|
```bash
|
|
22
|
-
# Generate
|
|
30
|
+
# Generate all outputs (default: typescript + zod + t3 + declaration)
|
|
23
31
|
npx env-typegen --input .env.example --output src/env.generated.ts
|
|
24
32
|
|
|
25
|
-
# Generate a Zod schema
|
|
33
|
+
# Generate only a Zod schema
|
|
26
34
|
npx env-typegen -i .env.example -o src/env.schema.ts -g zod
|
|
27
35
|
|
|
28
|
-
# Generate multiple outputs
|
|
29
|
-
npx env-typegen -i .env.example -o src/env.ts -
|
|
36
|
+
# Generate multiple outputs explicitly
|
|
37
|
+
npx env-typegen -i .env.example -o src/env.ts -f typescript -f zod
|
|
38
|
+
|
|
39
|
+
# Generate without running Prettier
|
|
40
|
+
npx env-typegen -i .env.example -o src/env.ts --no-format
|
|
30
41
|
|
|
31
42
|
# Watch mode — regenerate on every change
|
|
32
43
|
npx env-typegen -i .env.example -o src/env.ts --watch
|
|
44
|
+
|
|
45
|
+
# Validate one env source against a contract (strict by default)
|
|
46
|
+
npx env-typegen check --env .env --contract env.contract.ts
|
|
47
|
+
|
|
48
|
+
# Compare drift across multiple env files
|
|
49
|
+
npx env-typegen diff --targets .env,.env.example,.env.production --contract env.contract.ts
|
|
50
|
+
|
|
51
|
+
# Full diagnostics (check + diff + recommendations)
|
|
52
|
+
npx env-typegen doctor --env .env --targets .env,.env.example,.env.production --contract env.contract.ts
|
|
53
|
+
|
|
54
|
+
# Machine-readable report for CI pipelines
|
|
55
|
+
npx env-typegen check --env .env --json --output-file reports/env-check.json
|
|
33
56
|
```
|
|
34
57
|
|
|
58
|
+
All paths (`--env`, `--contract`, `--targets`, and `--output-file`) are resolved from your current working directory.
|
|
59
|
+
|
|
60
|
+
## Generator formats
|
|
61
|
+
|
|
62
|
+
Use `-f` / `--format` (or `-g` / `--generator` alias):
|
|
63
|
+
|
|
64
|
+
| Value | Meaning |
|
|
65
|
+
| -------------------- | ------------------------------------ |
|
|
66
|
+
| `ts` or `typescript` | Generate TypeScript types |
|
|
67
|
+
| `zod` | Generate Zod schema |
|
|
68
|
+
| `t3` | Generate `@t3-oss/env-nextjs` config |
|
|
69
|
+
| `declaration` | Generate `.d.ts` declaration |
|
|
70
|
+
|
|
71
|
+
## Validation commands
|
|
72
|
+
|
|
73
|
+
`env-typegen` also includes governance-focused commands:
|
|
74
|
+
|
|
75
|
+
- `check` — validates one env source against the contract
|
|
76
|
+
- `diff` — compares env sources and detects configuration drift
|
|
77
|
+
- `doctor` — aggregates findings and prints remediation suggestions
|
|
78
|
+
|
|
79
|
+
### Strict mode
|
|
80
|
+
|
|
81
|
+
- Strict mode is enabled by default for validation commands.
|
|
82
|
+
- Use `--no-strict` to downgrade undeclared variables to warnings.
|
|
83
|
+
|
|
84
|
+
### JSON output
|
|
85
|
+
|
|
86
|
+
- `--json` outputs compact JSON
|
|
87
|
+
- `--json=pretty` outputs formatted JSON
|
|
88
|
+
- `--output-file <path>` writes the JSON report to disk
|
|
89
|
+
|
|
90
|
+
### Cloud snapshots
|
|
91
|
+
|
|
92
|
+
Validation commands can include cloud snapshot files as additional sources:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
npx env-typegen check --cloud-provider vercel --cloud-file vercel-env.json --contract env.contract.ts
|
|
96
|
+
npx env-typegen diff --cloud-provider cloudflare --cloud-file cloudflare-env.json --contract env.contract.ts
|
|
97
|
+
npx env-typegen doctor --cloud-provider aws --cloud-file aws-env.json --contract env.contract.ts
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Supported providers: `vercel`, `cloudflare`, `aws`.
|
|
101
|
+
|
|
102
|
+
### Plugins
|
|
103
|
+
|
|
104
|
+
Use plugins to extend validation behavior:
|
|
105
|
+
|
|
106
|
+
- `transformContract` — mutate the loaded contract before validation
|
|
107
|
+
- `transformSource` — mutate environment values per source
|
|
108
|
+
- `transformReport` — enrich final validation reports
|
|
109
|
+
|
|
110
|
+
Load plugins with repeated `--plugin` flags or from `env-typegen.config.ts` (`plugins` field).
|
|
111
|
+
|
|
35
112
|
## Programmatic API
|
|
36
113
|
|
|
37
114
|
```ts
|
|
38
|
-
import {
|
|
115
|
+
import {
|
|
116
|
+
runGenerate,
|
|
117
|
+
runValidationCommand,
|
|
118
|
+
parseEnvFile,
|
|
119
|
+
generateTypeScriptTypes,
|
|
120
|
+
loadCloudSource,
|
|
121
|
+
loadPlugins,
|
|
122
|
+
} from "@xlameiro/env-typegen";
|
|
39
123
|
|
|
40
124
|
// High-level: full pipeline
|
|
41
125
|
await runGenerate({
|
|
@@ -46,8 +130,18 @@ await runGenerate({
|
|
|
46
130
|
});
|
|
47
131
|
|
|
48
132
|
// Low-level: parse then generate individually
|
|
49
|
-
const parsed =
|
|
133
|
+
const parsed = parseEnvFile(".env.example");
|
|
50
134
|
const ts = generateTypeScriptTypes(parsed);
|
|
135
|
+
|
|
136
|
+
// Run validation commands programmatically
|
|
137
|
+
const exitCode = await runValidationCommand({
|
|
138
|
+
command: "check",
|
|
139
|
+
argv: ["--env", ".env", "--contract", "env.contract.ts", "--json"],
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// Load cloud snapshots and plugins in custom integrations
|
|
143
|
+
const cloudValues = await loadCloudSource({ provider: "vercel", filePath: "vercel-env.json" });
|
|
144
|
+
const plugins = await loadPlugins({ pluginPaths: ["./plugins/custom.mjs"] });
|
|
51
145
|
```
|
|
52
146
|
|
|
53
147
|
## Configuration
|
|
@@ -55,28 +149,32 @@ const ts = generateTypeScriptTypes(parsed);
|
|
|
55
149
|
Create `env-typegen.config.ts` at your project root:
|
|
56
150
|
|
|
57
151
|
```ts
|
|
58
|
-
import { defineConfig } from "env-typegen";
|
|
152
|
+
import { defineConfig } from "@xlameiro/env-typegen";
|
|
59
153
|
|
|
60
154
|
export default defineConfig({
|
|
61
155
|
input: ".env.example",
|
|
62
156
|
output: "src/env.generated.ts",
|
|
63
157
|
generators: ["typescript", "zod"],
|
|
64
158
|
format: true,
|
|
159
|
+
schemaFile: "env.contract.ts",
|
|
160
|
+
strict: true,
|
|
161
|
+
diffTargets: [".env", ".env.example", ".env.production"],
|
|
162
|
+
plugins: ["./plugins/custom-validator.mjs"],
|
|
65
163
|
});
|
|
66
164
|
```
|
|
67
165
|
|
|
166
|
+
## Documentation
|
|
167
|
+
|
|
168
|
+
- Fumadocs source in repo: [`/content/docs`](../../content/docs)
|
|
169
|
+
- Package markdown docs: [`/packages/env-typegen/docs`](./docs)
|
|
170
|
+
|
|
68
171
|
## Status
|
|
69
172
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
| 4 | Generators | ✅ |
|
|
76
|
-
| 5 | Config & Utils | ✅ |
|
|
77
|
-
| 6 | CLI | ✅ |
|
|
78
|
-
| 7 | Quality & Docs | ✅ |
|
|
79
|
-
| 8 | Publishing | 🔜 |
|
|
173
|
+
`env-typegen` is actively maintained and published on npm.
|
|
174
|
+
|
|
175
|
+
## Changelog
|
|
176
|
+
|
|
177
|
+
See [`CHANGELOG.md`](./CHANGELOG.md) for release notes.
|
|
80
178
|
|
|
81
179
|
## License
|
|
82
180
|
|