dotenv-diff 2.4.4 → 2.4.6
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 +14 -0
- package/README.md +26 -129
- package/dist/src/cli/run.d.ts.map +1 -1
- package/dist/src/cli/run.js +49 -36
- package/dist/src/cli/run.js.map +1 -1
- package/dist/src/commands/compare.d.ts.map +1 -1
- package/dist/src/commands/compare.js +49 -49
- package/dist/src/commands/compare.js.map +1 -1
- package/dist/src/commands/scanUsage.d.ts.map +1 -1
- package/dist/src/commands/scanUsage.js +1 -3
- package/dist/src/commands/scanUsage.js.map +1 -1
- package/dist/src/config/loadConfig.d.ts.map +1 -1
- package/dist/src/config/loadConfig.js +6 -2
- package/dist/src/config/loadConfig.js.map +1 -1
- package/dist/src/config/options.d.ts +20 -3
- package/dist/src/config/options.d.ts.map +1 -1
- package/dist/src/config/options.js +71 -54
- package/dist/src/config/options.js.map +1 -1
- package/dist/src/config/types.d.ts +25 -4
- package/dist/src/config/types.d.ts.map +1 -1
- package/dist/src/config/types.js +0 -1
- package/dist/src/config/types.js.map +1 -1
- package/dist/src/core/envPairing.d.ts +1 -2
- package/dist/src/core/envPairing.d.ts.map +1 -1
- package/dist/src/core/envPairing.js.map +1 -1
- package/dist/src/core/fixEnv.d.ts.map +1 -1
- package/dist/src/core/fixEnv.js +2 -1
- package/dist/src/core/fixEnv.js.map +1 -1
- package/dist/src/core/frameworkDetector.d.ts +3 -2
- package/dist/src/core/frameworkDetector.d.ts.map +1 -1
- package/dist/src/core/frameworkDetector.js +2 -1
- package/dist/src/core/frameworkDetector.js.map +1 -1
- package/dist/src/core/frameworkValidator.d.ts +1 -9
- package/dist/src/core/frameworkValidator.d.ts.map +1 -1
- package/dist/src/core/frameworkValidator.js +2 -1
- package/dist/src/core/frameworkValidator.js.map +1 -1
- package/dist/src/core/frameworks/nextJsRules.d.ts +1 -2
- package/dist/src/core/frameworks/nextJsRules.d.ts.map +1 -1
- package/dist/src/core/frameworks/nextJsRules.js +8 -7
- package/dist/src/core/frameworks/nextJsRules.js.map +1 -1
- package/dist/src/core/frameworks/sveltekitRules.d.ts +1 -2
- package/dist/src/core/frameworks/sveltekitRules.d.ts.map +1 -1
- package/dist/src/core/frameworks/sveltekitRules.js +3 -12
- package/dist/src/core/frameworks/sveltekitRules.js.map +1 -1
- package/dist/src/core/patterns.d.ts +0 -15
- package/dist/src/core/patterns.d.ts.map +1 -1
- package/dist/src/core/patterns.js +0 -18
- package/dist/src/core/patterns.js.map +1 -1
- package/dist/src/core/scanFile.d.ts +1 -1
- package/dist/src/core/scanFile.d.ts.map +1 -1
- package/dist/src/core/scanFile.js +7 -5
- package/dist/src/core/scanFile.js.map +1 -1
- package/dist/src/core/scanJsonOutput.d.ts +2 -4
- package/dist/src/core/scanJsonOutput.d.ts.map +1 -1
- package/dist/src/core/scanJsonOutput.js +35 -29
- package/dist/src/core/scanJsonOutput.js.map +1 -1
- package/dist/src/services/codeBaseScanner.js +2 -2
- package/dist/src/services/codeBaseScanner.js.map +1 -1
- package/dist/src/services/duplicates.js +2 -2
- package/dist/src/services/duplicates.js.map +1 -1
- package/dist/src/services/envDiscovery.d.ts +1 -14
- package/dist/src/services/envDiscovery.d.ts.map +1 -1
- package/dist/src/services/envDiscovery.js.map +1 -1
- package/dist/src/ui/scan/printFrameworkWarnings.d.ts +1 -1
- package/dist/src/ui/scan/printFrameworkWarnings.d.ts.map +1 -1
- package/dist/src/ui/scan/printFrameworkWarnings.js +7 -1
- package/dist/src/ui/scan/printFrameworkWarnings.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -17,6 +17,20 @@ This project follows [Keep a Changelog](https://keepachangelog.com/) and [Semant
|
|
|
17
17
|
|
|
18
18
|
-
|
|
19
19
|
|
|
20
|
+
## [2.4.6] - 2026-01-06
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
- Modified JSON output for scan usage.
|
|
25
|
+
|
|
26
|
+
## [2.4.5] - 2025-12-29
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
|
|
30
|
+
- Changed UI for framework warnings to include framework name + better formatting.
|
|
31
|
+
- Updated nextjs framework rules.
|
|
32
|
+
- Updated sveltekit framework rules.
|
|
33
|
+
|
|
20
34
|
## [2.4.4] - 2025-12-27
|
|
21
35
|
|
|
22
36
|
### Fixed
|
package/README.md
CHANGED
|
@@ -2,13 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
and compares them against your `.env` or `.env.example` files.
|
|
5
|
+
Scan your entire codebase to detect every environment variable reference. It helps you catch missing, unused, duplicated, and misused variables early, before they cause runtime errors.
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Optimized for **SvelteKit** and **Next.js**, but works well with modern
|
|
11
|
-
JavaScript and TypeScript projects such as **Node.js, Nuxt, and Vue**.
|
|
7
|
+
Optimized for SvelteKit and Next.js. Also works well in modern JavaScript/TypeScript projects and frameworks like Node.js, Nuxt, and Vue — or any other setup where you want reliable .env file comparison.
|
|
12
8
|
|
|
13
9
|

|
|
14
10
|
[](https://www.npmjs.com/package/dotenv-diff)
|
|
@@ -26,50 +22,6 @@ JavaScript and TypeScript projects such as **Node.js, Nuxt, and Vue**.
|
|
|
26
22
|
|
|
27
23
|
---
|
|
28
24
|
|
|
29
|
-
## GitHub Actions Example
|
|
30
|
-
|
|
31
|
-
Run `dotenv-diff` in CI to validate environment variables automatically:
|
|
32
|
-
|
|
33
|
-
```yaml
|
|
34
|
-
- name: Check environment variables
|
|
35
|
-
run: dotenv-diff --example .env.example
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
To compare against a different example file:
|
|
39
|
-
|
|
40
|
-
```bash
|
|
41
|
-
dotenv-diff --example .env.example.staging
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
If no `.env.example` file exists, run:
|
|
45
|
-
|
|
46
|
-
```bash
|
|
47
|
-
dotenv-diff
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
This scans the codebase but skips comparison.
|
|
51
|
-
|
|
52
|
-
---
|
|
53
|
-
|
|
54
|
-
## Monorepo (Turborepo) Usage
|
|
55
|
-
|
|
56
|
-
In monorepos with multiple apps and packages, you can include shared folders:
|
|
57
|
-
|
|
58
|
-
```json
|
|
59
|
-
{
|
|
60
|
-
"scripts": {
|
|
61
|
-
"dotenv-diff": "dotenv-diff --example .env.example --include-files '../../packages/**/*' --ignore VITE_MODE"
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
This will:
|
|
67
|
-
- Scan the current app
|
|
68
|
-
- Include shared packages
|
|
69
|
-
- Ignore variables used only in specific environments
|
|
70
|
-
|
|
71
|
-
---
|
|
72
|
-
|
|
73
25
|
## Automatic Fixes (`--fix`)
|
|
74
26
|
|
|
75
27
|
Automatically add missing variables to your `.env` file:
|
|
@@ -82,7 +34,7 @@ dotenv-diff --fix
|
|
|
82
34
|
|
|
83
35
|
1. Code uses `process.env.NEW_API_KEY`
|
|
84
36
|
2. Run `dotenv-diff --fix`
|
|
85
|
-
3. Tool adds `NEW_API_KEY=` to `.env`
|
|
37
|
+
3. Tool adds `NEW_API_KEY=` to `.env` or `.env.example`
|
|
86
38
|
|
|
87
39
|
---
|
|
88
40
|
|
|
@@ -98,63 +50,19 @@ dotenv-diff --strict
|
|
|
98
50
|
|
|
99
51
|
## Framework-Specific Warnings
|
|
100
52
|
|
|
101
|
-
|
|
53
|
+
In SvelteKit and Next.js projects, dotenv-diff detects framework-specific
|
|
54
|
+
environment variable misuses.
|
|
102
55
|
|
|
103
56
|
Example warning:
|
|
104
57
|
|
|
105
58
|
```bash
|
|
106
|
-
|
|
59
|
+
Framework issues (Sveltekit):
|
|
107
60
|
- PUBLIC_URL (src/routes/+page.ts:1)
|
|
108
61
|
→ Variables accessed through import.meta.env must start with "VITE_"
|
|
109
62
|
```
|
|
110
63
|
|
|
111
64
|
---
|
|
112
65
|
|
|
113
|
-
## Detect Secrets in `.env.example`
|
|
114
|
-
|
|
115
|
-
`dotenv-diff` scans example files for potential secrets:
|
|
116
|
-
|
|
117
|
-
```bash
|
|
118
|
-
Potential real secrets found in .env.example:
|
|
119
|
-
- API_KEY = "sk_test_..." → Matches known provider pattern [high]
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
---
|
|
123
|
-
|
|
124
|
-
## Logging Environment Variables
|
|
125
|
-
|
|
126
|
-
Detect accidental logging of sensitive values:
|
|
127
|
-
|
|
128
|
-
```js
|
|
129
|
-
console.log(process.env.API_KEY);
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
This triggers a warning.
|
|
133
|
-
|
|
134
|
-
---
|
|
135
|
-
|
|
136
|
-
## Ignore Specific Warnings
|
|
137
|
-
|
|
138
|
-
Ignore specific lines using comments:
|
|
139
|
-
|
|
140
|
-
```js
|
|
141
|
-
const secret = "https://example.com"; // dotenv-diff-ignore
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
---
|
|
145
|
-
|
|
146
|
-
## Health Score
|
|
147
|
-
|
|
148
|
-
Provides an overall score based on:
|
|
149
|
-
- Missing variables
|
|
150
|
-
- Potential secrets
|
|
151
|
-
- Naming conventions
|
|
152
|
-
- Logged variables
|
|
153
|
-
- Unused variables
|
|
154
|
-
- Framework-specific rules
|
|
155
|
-
|
|
156
|
-
---
|
|
157
|
-
|
|
158
66
|
## Expiration Warnings
|
|
159
67
|
|
|
160
68
|
Add expiration metadata to variables:
|
|
@@ -166,34 +74,6 @@ API_TOKEN=
|
|
|
166
74
|
|
|
167
75
|
---
|
|
168
76
|
|
|
169
|
-
## Inconsistent Naming Warnings
|
|
170
|
-
|
|
171
|
-
Warns about inconsistent keys like `APIKEY` vs `API_KEY`.
|
|
172
|
-
|
|
173
|
-
Disable via config:
|
|
174
|
-
|
|
175
|
-
```json
|
|
176
|
-
"inconsistentNamingWarnings": false
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
---
|
|
180
|
-
|
|
181
|
-
## Show / Hide Output Options
|
|
182
|
-
|
|
183
|
-
Disable unused variables list:
|
|
184
|
-
|
|
185
|
-
```bash
|
|
186
|
-
dotenv-diff --no-show-unused
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
Disable statistics:
|
|
190
|
-
|
|
191
|
-
```bash
|
|
192
|
-
dotenv-diff --no-show-stats
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
---
|
|
196
|
-
|
|
197
77
|
## File Scanning Options
|
|
198
78
|
|
|
199
79
|
Include or exclude files:
|
|
@@ -224,12 +104,23 @@ dotenv-diff --compare --env .env.local --example .env.example.local
|
|
|
224
104
|
|
|
225
105
|
---
|
|
226
106
|
|
|
227
|
-
##
|
|
107
|
+
## Monorepo (Turborepo) Usage
|
|
108
|
+
|
|
109
|
+
In monorepos with multiple apps and packages, you can include shared folders:
|
|
228
110
|
|
|
229
|
-
```
|
|
230
|
-
|
|
111
|
+
```json
|
|
112
|
+
{
|
|
113
|
+
"scripts": {
|
|
114
|
+
"dotenv-diff": "dotenv-diff --example .env.example --include-files '../../packages/**/*' --ignore VITE_MODE"
|
|
115
|
+
}
|
|
116
|
+
}
|
|
231
117
|
```
|
|
232
118
|
|
|
119
|
+
This will:
|
|
120
|
+
- Scan the current app
|
|
121
|
+
- Include shared packages
|
|
122
|
+
- Ignore variables used only in specific environments
|
|
123
|
+
|
|
233
124
|
---
|
|
234
125
|
|
|
235
126
|
## Exit Codes
|
|
@@ -239,6 +130,12 @@ dotenv-diff --compare --yes
|
|
|
239
130
|
|
|
240
131
|
---
|
|
241
132
|
|
|
133
|
+
## Documentation
|
|
134
|
+
|
|
135
|
+
Full documentation: https://dotenv-diff-docs.vercel.app
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
242
139
|
## 🤝 Contributing
|
|
243
140
|
|
|
244
141
|
Issues and pull requests are welcome.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/cli/run.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/cli/run.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAqBzC;;;;GAIG;AACH,wBAAsB,GAAG,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAuBzD"}
|
package/dist/src/cli/run.js
CHANGED
|
@@ -10,6 +10,7 @@ import { scanUsage } from '../commands/scanUsage.js';
|
|
|
10
10
|
import { printErrorNotFound } from '../ui/compare/printErrorNotFound.js';
|
|
11
11
|
import { setupGlobalConfig } from '../ui/shared/setupGlobalConfig.js';
|
|
12
12
|
import { loadConfig } from '../config/loadConfig.js';
|
|
13
|
+
const DEFAULT_ENV_FILE = '.env';
|
|
13
14
|
/**
|
|
14
15
|
* Run the CLI program
|
|
15
16
|
* @param program The commander program instance
|
|
@@ -27,25 +28,19 @@ export async function run(program) {
|
|
|
27
28
|
// Normalize merged options
|
|
28
29
|
const opts = normalizeOptions(mergedRawOptions);
|
|
29
30
|
setupGlobalConfig(opts);
|
|
30
|
-
// Route to appropriate command
|
|
31
|
-
|
|
32
|
-
await runCompareMode(opts)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
await runScanMode(opts);
|
|
36
|
-
}
|
|
31
|
+
// Route to appropriate command and handle exit
|
|
32
|
+
const exitWithError = opts.compare
|
|
33
|
+
? await runCompareMode(opts)
|
|
34
|
+
: await runScanMode(opts);
|
|
35
|
+
process.exit(exitWithError ? 1 : 0);
|
|
37
36
|
}
|
|
38
37
|
/**
|
|
39
38
|
* Run scan-usage mode (default behavior)
|
|
40
39
|
* @param opts - Normalized options
|
|
41
|
-
* @returns
|
|
40
|
+
* @returns Whether to exit with an error code
|
|
42
41
|
*/
|
|
43
42
|
async function runScanMode(opts) {
|
|
44
|
-
const envPath =
|
|
45
|
-
? opts.envFlag
|
|
46
|
-
: fs.existsSync('.env')
|
|
47
|
-
? '.env'
|
|
48
|
-
: undefined;
|
|
43
|
+
const envPath = resolveEnvPath(opts.envFlag);
|
|
49
44
|
const { exitWithError } = await scanUsage({
|
|
50
45
|
cwd: opts.cwd,
|
|
51
46
|
include: opts.includeFiles,
|
|
@@ -67,35 +62,40 @@ async function runScanMode(opts) {
|
|
|
67
62
|
inconsistentNamingWarnings: opts.inconsistentNamingWarnings,
|
|
68
63
|
...(opts.files ? { files: opts.files } : {}),
|
|
69
64
|
});
|
|
70
|
-
|
|
65
|
+
return exitWithError;
|
|
71
66
|
}
|
|
72
67
|
/**
|
|
73
68
|
* Run compare mode
|
|
74
69
|
* @param opts - Normalized options
|
|
75
|
-
* @returns
|
|
70
|
+
* @returns Whether to exit with an error code
|
|
76
71
|
*/
|
|
77
72
|
async function runCompareMode(opts) {
|
|
78
73
|
// Handle direct file comparison (both --env and --example specified)
|
|
79
74
|
if (opts.envFlag && opts.exampleFlag) {
|
|
80
|
-
await runDirectFileComparison(opts);
|
|
81
|
-
return;
|
|
75
|
+
return await runDirectFileComparison(opts);
|
|
82
76
|
}
|
|
83
77
|
// Handle auto-discovery comparison
|
|
84
|
-
await runAutoDiscoveryComparison(opts);
|
|
78
|
+
return await runAutoDiscoveryComparison(opts);
|
|
85
79
|
}
|
|
86
80
|
/**
|
|
87
81
|
* Compare two specific files directly
|
|
88
82
|
* @param opts - Normalized options
|
|
89
|
-
* @returns
|
|
83
|
+
* @returns Whether to exit with an error code
|
|
90
84
|
*/
|
|
91
85
|
async function runDirectFileComparison(opts) {
|
|
86
|
+
// Type guard ensures both flags are defined
|
|
87
|
+
if (!opts.envFlag || !opts.exampleFlag) {
|
|
88
|
+
throw new Error('Both envFlag and exampleFlag must be defined for direct file comparison');
|
|
89
|
+
}
|
|
92
90
|
const envExists = fs.existsSync(opts.envFlag);
|
|
93
91
|
const exExists = fs.existsSync(opts.exampleFlag);
|
|
94
92
|
// Handle missing files
|
|
95
93
|
if (!envExists || !exExists) {
|
|
96
|
-
const
|
|
97
|
-
if (shouldExit)
|
|
98
|
-
|
|
94
|
+
const result = await handleMissingFiles(opts, opts.envFlag, opts.exampleFlag);
|
|
95
|
+
if (result.shouldExit) {
|
|
96
|
+
outputResults([], opts);
|
|
97
|
+
return result.exitWithError;
|
|
98
|
+
}
|
|
99
99
|
}
|
|
100
100
|
// Perform comparison
|
|
101
101
|
const report = [];
|
|
@@ -106,12 +106,13 @@ async function runDirectFileComparison(opts) {
|
|
|
106
106
|
examplePath: opts.exampleFlag,
|
|
107
107
|
},
|
|
108
108
|
], buildCompareOptions(opts, report));
|
|
109
|
-
outputResults(report, opts
|
|
109
|
+
outputResults(report, opts);
|
|
110
|
+
return exitWithError;
|
|
110
111
|
}
|
|
111
112
|
/**
|
|
112
113
|
* Compare using auto-discovery
|
|
113
114
|
* @param opts - Normalized options
|
|
114
|
-
* @returns
|
|
115
|
+
* @returns Whether to exit with an error code
|
|
115
116
|
*/
|
|
116
117
|
async function runAutoDiscoveryComparison(opts) {
|
|
117
118
|
// Discover available env files
|
|
@@ -130,21 +131,22 @@ async function runAutoDiscoveryComparison(opts) {
|
|
|
130
131
|
isCiMode: opts.isCiMode,
|
|
131
132
|
});
|
|
132
133
|
if (initResult.shouldExit) {
|
|
133
|
-
outputResults([], opts
|
|
134
|
-
return;
|
|
134
|
+
outputResults([], opts);
|
|
135
|
+
return initResult.exitCode !== 0;
|
|
135
136
|
}
|
|
136
137
|
// Compare all discovered pairs
|
|
137
138
|
const pairs = pairWithExample(discovery);
|
|
138
139
|
const report = [];
|
|
139
140
|
const { exitWithError } = await compareMany(pairs, buildCompareOptions(opts, report));
|
|
140
|
-
outputResults(report, opts
|
|
141
|
+
outputResults(report, opts);
|
|
142
|
+
return exitWithError;
|
|
141
143
|
}
|
|
142
144
|
/**
|
|
143
145
|
* Handle missing files in CI vs interactive mode
|
|
144
146
|
* @param opts - Normalized options
|
|
145
147
|
* @param envFlag - Path to the .env file
|
|
146
148
|
* @param exampleFlag - Path to the example file
|
|
147
|
-
* @returns
|
|
149
|
+
* @returns Result indicating if process should exit and with what error code
|
|
148
150
|
*/
|
|
149
151
|
async function handleMissingFiles(opts, envFlag, exampleFlag) {
|
|
150
152
|
const envExists = fs.existsSync(envFlag);
|
|
@@ -152,7 +154,7 @@ async function handleMissingFiles(opts, envFlag, exampleFlag) {
|
|
|
152
154
|
if (opts.isCiMode) {
|
|
153
155
|
// In CI mode, just show errors and exit
|
|
154
156
|
printErrorNotFound(envExists, exExists, envFlag, exampleFlag);
|
|
155
|
-
|
|
157
|
+
return { shouldExit: true, exitWithError: true };
|
|
156
158
|
}
|
|
157
159
|
else {
|
|
158
160
|
// Interactive mode - try to prompt for file creation
|
|
@@ -165,11 +167,10 @@ async function handleMissingFiles(opts, envFlag, exampleFlag) {
|
|
|
165
167
|
isCiMode: opts.isCiMode,
|
|
166
168
|
});
|
|
167
169
|
if (result.shouldExit) {
|
|
168
|
-
|
|
169
|
-
return true;
|
|
170
|
+
return { shouldExit: true, exitWithError: result.exitCode !== 0 };
|
|
170
171
|
}
|
|
171
172
|
}
|
|
172
|
-
return false;
|
|
173
|
+
return { shouldExit: false, exitWithError: false };
|
|
173
174
|
}
|
|
174
175
|
/**
|
|
175
176
|
* Build options object for compareMany function
|
|
@@ -206,15 +207,27 @@ async function handleInitFlag(cliOptions) {
|
|
|
206
207
|
return false;
|
|
207
208
|
}
|
|
208
209
|
/**
|
|
209
|
-
*
|
|
210
|
+
* Resolve the environment file path based on the flag or default
|
|
211
|
+
* @param envFlag - Optional environment file path from CLI flag
|
|
212
|
+
* @returns The resolved env file path or undefined
|
|
213
|
+
*/
|
|
214
|
+
function resolveEnvPath(envFlag) {
|
|
215
|
+
if (typeof envFlag === 'string') {
|
|
216
|
+
return envFlag;
|
|
217
|
+
}
|
|
218
|
+
if (fs.existsSync(DEFAULT_ENV_FILE)) {
|
|
219
|
+
return DEFAULT_ENV_FILE;
|
|
220
|
+
}
|
|
221
|
+
return undefined;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Output results to console if in JSON mode
|
|
210
225
|
* @param report - The comparison report entries
|
|
211
226
|
* @param opts - Normalized options
|
|
212
|
-
* @param exitWithError - Whether to exit with an error code
|
|
213
227
|
*/
|
|
214
|
-
function outputResults(report, opts
|
|
228
|
+
function outputResults(report, opts) {
|
|
215
229
|
if (opts.json) {
|
|
216
230
|
console.log(JSON.stringify(report, null, 2));
|
|
217
231
|
}
|
|
218
|
-
process.exit(exitWithError ? 1 : 0);
|
|
219
232
|
}
|
|
220
233
|
//# sourceMappingURL=run.js.map
|
package/dist/src/cli/run.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../../src/cli/run.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAKN,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,GAAG,CAAC,OAAgB;IACxC,OAAO,CA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IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;QACd,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/C,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../../../src/commands/compare.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAGV,iBAAiB,EACjB,QAAQ,EACR,gBAAgB,EAGjB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../../../src/commands/compare.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAGV,iBAAiB,EACjB,QAAQ,EACR,gBAAgB,EAGjB,MAAM,oBAAoB,CAAC;AAa5B;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,KAAK,EAAE,QAAQ,EAAE,EACjB,IAAI,EAAE,QAAQ,CAAC,iBAAiB,CAAC,GAChC,OAAO,CAAC,gBAAgB,CAAC,CAqK3B"}
|
|
@@ -16,55 +16,6 @@ import { printAutoFix } from '../ui/shared/printAutoFix.js';
|
|
|
16
16
|
import { printIssues } from '../ui/compare/printIssues.js';
|
|
17
17
|
import { printSuccess } from '../ui/shared/printSuccess.js';
|
|
18
18
|
import { printGitignoreWarning } from '../ui/shared/printGitignore.js';
|
|
19
|
-
/**
|
|
20
|
-
* Creates a category filter function based on options.
|
|
21
|
-
* fx: onlyFiltering({ only: ['missing', 'extra'] })
|
|
22
|
-
* @param opts Comparison options
|
|
23
|
-
* @returns A function that filters categories
|
|
24
|
-
*/
|
|
25
|
-
function createCategoryFilter(opts) {
|
|
26
|
-
const onlySet = opts.only?.length
|
|
27
|
-
? new Set(opts.only)
|
|
28
|
-
: undefined;
|
|
29
|
-
return (category) => !onlySet || onlySet.has(category);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Parses and filters the environment and example files.
|
|
33
|
-
* @param envPath The path to the .env file
|
|
34
|
-
* @param examplePath The path to the .env.example file
|
|
35
|
-
* @param opts Comparison options
|
|
36
|
-
* @returns An object containing the parsed and filtered environment variables
|
|
37
|
-
*/
|
|
38
|
-
function parseAndFilter(envPath, examplePath, opts) {
|
|
39
|
-
const currentFull = parseEnvFile(envPath);
|
|
40
|
-
const exampleFull = parseEnvFile(examplePath);
|
|
41
|
-
const currentKeys = filterIgnoredKeys(Object.keys(currentFull), opts.ignore, opts.ignoreRegex);
|
|
42
|
-
const exampleKeys = filterIgnoredKeys(Object.keys(exampleFull), opts.ignore, opts.ignoreRegex);
|
|
43
|
-
return {
|
|
44
|
-
current: Object.fromEntries(currentKeys.map((k) => [k, currentFull[k] ?? ''])),
|
|
45
|
-
example: Object.fromEntries(exampleKeys.map((k) => [k, exampleFull[k] ?? ''])),
|
|
46
|
-
currentKeys,
|
|
47
|
-
exampleKeys,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Finds duplicate keys in the environment and example files.
|
|
52
|
-
* @param envPath The path to the .env file
|
|
53
|
-
* @param examplePath The path to the .env.example file
|
|
54
|
-
* @param opts Comparison options
|
|
55
|
-
* @param run A function that determines if a category should be included
|
|
56
|
-
* @returns An object containing arrays of duplicate keys for both files
|
|
57
|
-
*/
|
|
58
|
-
function findDuplicates(envPath, examplePath, opts, run) {
|
|
59
|
-
if (opts.allowDuplicates || !run('duplicate'))
|
|
60
|
-
return { dupsEnv: [], dupsEx: [] };
|
|
61
|
-
const ignoreSet = new Set(opts.ignore);
|
|
62
|
-
const regexList = opts.ignoreRegex;
|
|
63
|
-
const filterKey = (key) => !ignoreSet.has(key) && !regexList.some((rx) => rx.test(key));
|
|
64
|
-
const dupsEnv = findDuplicateKeys(envPath).filter(({ key }) => filterKey(key));
|
|
65
|
-
const dupsEx = findDuplicateKeys(examplePath).filter(({ key }) => filterKey(key));
|
|
66
|
-
return { dupsEnv, dupsEx };
|
|
67
|
-
}
|
|
68
19
|
/**
|
|
69
20
|
* Compares multiple pairs of .env and .env.example files.
|
|
70
21
|
* @param pairs - The pairs of environment files to compare.
|
|
@@ -178,4 +129,53 @@ export async function compareMany(pairs, opts) {
|
|
|
178
129
|
}
|
|
179
130
|
return { exitWithError };
|
|
180
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Creates a category filter function based on options.
|
|
134
|
+
* fx: onlyFiltering({ only: ['missing', 'extra'] })
|
|
135
|
+
* @param opts Comparison options
|
|
136
|
+
* @returns A function that filters categories
|
|
137
|
+
*/
|
|
138
|
+
function createCategoryFilter(opts) {
|
|
139
|
+
const onlySet = opts.only?.length
|
|
140
|
+
? new Set(opts.only)
|
|
141
|
+
: undefined;
|
|
142
|
+
return (category) => !onlySet || onlySet.has(category);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Parses and filters the environment and example files.
|
|
146
|
+
* @param envPath The path to the .env file
|
|
147
|
+
* @param examplePath The path to the .env.example file
|
|
148
|
+
* @param opts Comparison options
|
|
149
|
+
* @returns An object containing the parsed and filtered environment variables
|
|
150
|
+
*/
|
|
151
|
+
function parseAndFilter(envPath, examplePath, opts) {
|
|
152
|
+
const currentFull = parseEnvFile(envPath);
|
|
153
|
+
const exampleFull = parseEnvFile(examplePath);
|
|
154
|
+
const currentKeys = filterIgnoredKeys(Object.keys(currentFull), opts.ignore, opts.ignoreRegex);
|
|
155
|
+
const exampleKeys = filterIgnoredKeys(Object.keys(exampleFull), opts.ignore, opts.ignoreRegex);
|
|
156
|
+
return {
|
|
157
|
+
current: Object.fromEntries(currentKeys.map((k) => [k, currentFull[k] ?? ''])),
|
|
158
|
+
example: Object.fromEntries(exampleKeys.map((k) => [k, exampleFull[k] ?? ''])),
|
|
159
|
+
currentKeys,
|
|
160
|
+
exampleKeys,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Finds duplicate keys in the environment and example files.
|
|
165
|
+
* @param envPath The path to the .env file
|
|
166
|
+
* @param examplePath The path to the .env.example file
|
|
167
|
+
* @param opts Comparison options
|
|
168
|
+
* @param run A function that determines if a category should be included
|
|
169
|
+
* @returns An object containing arrays of duplicate keys for both files
|
|
170
|
+
*/
|
|
171
|
+
function findDuplicates(envPath, examplePath, opts, run) {
|
|
172
|
+
if (opts.allowDuplicates || !run('duplicate'))
|
|
173
|
+
return { dupsEnv: [], dupsEx: [] };
|
|
174
|
+
const ignoreSet = new Set(opts.ignore);
|
|
175
|
+
const regexList = opts.ignoreRegex;
|
|
176
|
+
const filterKey = (key) => !ignoreSet.has(key) && !regexList.some((rx) => rx.test(key));
|
|
177
|
+
const dupsEnv = findDuplicateKeys(envPath).filter(({ key }) => filterKey(key));
|
|
178
|
+
const dupsEx = findDuplicateKeys(examplePath).filter(({ key }) => filterKey(key));
|
|
179
|
+
return { dupsEnv, dupsEx };
|
|
180
|
+
}
|
|
181
181
|
//# sourceMappingURL=compare.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compare.js","sourceRoot":"","sources":["../../../src/commands/compare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAUjE,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;A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CACf,CAAC;IAEF,OAAO,EAAE,OAAO,EAAE,MAAM,EAA4B,CAAC;AACvD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanUsage.d.ts","sourceRoot":"","sources":["../../../src/commands/scanUsage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAGjB,MAAM,oBAAoB,CAAC;AAW5B;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,SAAS,CAC7B,IAAI,EAAE,gBAAgB,GACrB,OAAO,CAAC;IAAE,aAAa,EAAE,OAAO,CAAA;CAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"scanUsage.d.ts","sourceRoot":"","sources":["../../../src/commands/scanUsage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAGjB,MAAM,oBAAoB,CAAC;AAW5B;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,SAAS,CAC7B,IAAI,EAAE,gBAAgB,GACrB,OAAO,CAAC;IAAE,aAAa,EAAE,OAAO,CAAA;CAAE,CAAC,CA4HrC"}
|
|
@@ -45,7 +45,6 @@ export async function scanUsage(opts) {
|
|
|
45
45
|
}
|
|
46
46
|
// Determine which file to compare against
|
|
47
47
|
const compareFile = determineComparisonFile(opts);
|
|
48
|
-
let envVariables = {};
|
|
49
48
|
let comparedAgainst = '';
|
|
50
49
|
let duplicatesFound = false;
|
|
51
50
|
// Store fix information for consolidated display
|
|
@@ -64,7 +63,6 @@ export async function scanUsage(opts) {
|
|
|
64
63
|
}
|
|
65
64
|
else {
|
|
66
65
|
scanResult = result.scanResult;
|
|
67
|
-
envVariables = result.envVariables;
|
|
68
66
|
comparedAgainst = result.comparedAgainst;
|
|
69
67
|
duplicatesFound = result.duplicatesFound;
|
|
70
68
|
fixApplied = result.fixApplied;
|
|
@@ -90,7 +88,7 @@ export async function scanUsage(opts) {
|
|
|
90
88
|
calculateStats(scanResult);
|
|
91
89
|
// JSON output
|
|
92
90
|
if (opts.json) {
|
|
93
|
-
const jsonOutput = createJsonOutput(scanResult,
|
|
91
|
+
const jsonOutput = createJsonOutput(scanResult, comparedAgainst);
|
|
94
92
|
console.log(JSON.stringify(jsonOutput, null, 2));
|
|
95
93
|
// Check for high severity secrets
|
|
96
94
|
const hasHighSeveritySecrets = (scanResult.secrets ?? []).some((s) => s.severity === 'high');
|