dotenv-diff 2.2.7 → 2.3.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/README.md +28 -0
- package/dist/src/cli/program.d.ts.map +1 -1
- package/dist/src/cli/program.js +4 -1
- package/dist/src/cli/program.js.map +1 -1
- package/dist/src/cli/run.d.ts.map +1 -1
- package/dist/src/cli/run.js +42 -31
- package/dist/src/cli/run.js.map +1 -1
- package/dist/src/commands/compare.d.ts +2 -20
- package/dist/src/commands/compare.d.ts.map +1 -1
- package/dist/src/commands/compare.js +107 -173
- package/dist/src/commands/compare.js.map +1 -1
- package/dist/src/commands/init.d.ts +3 -15
- package/dist/src/commands/init.d.ts.map +1 -1
- package/dist/src/commands/init.js +17 -66
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/scanUsage.d.ts.map +1 -1
- package/dist/src/commands/scanUsage.js +87 -173
- package/dist/src/commands/scanUsage.js.map +1 -1
- package/dist/src/config/loadConfig.d.ts +9 -1
- package/dist/src/config/loadConfig.d.ts.map +1 -1
- package/dist/src/config/loadConfig.js +31 -0
- package/dist/src/config/loadConfig.js.map +1 -0
- package/dist/src/config/options.d.ts.map +1 -1
- package/dist/src/config/options.js +46 -32
- package/dist/src/config/options.js.map +1 -1
- package/dist/src/config/types.d.ts +65 -0
- package/dist/src/config/types.d.ts.map +1 -1
- package/dist/src/core/determineComparisonFile.d.ts.map +1 -1
- package/dist/src/core/determineComparisonFile.js +3 -0
- package/dist/src/core/determineComparisonFile.js.map +1 -1
- package/dist/src/core/entropy.js +1 -1
- package/dist/src/core/entropy.js.map +1 -1
- package/dist/src/core/fixEnv.d.ts +24 -15
- package/dist/src/core/fixEnv.d.ts.map +1 -1
- package/dist/src/core/fixEnv.js +70 -11
- package/dist/src/core/fixEnv.js.map +1 -1
- package/dist/src/core/helpers/isAllOk.d.ts +8 -0
- package/dist/src/core/helpers/isAllOk.d.ts.map +1 -0
- package/dist/src/core/helpers/isAllOk.js +15 -0
- package/dist/src/core/helpers/isAllOk.js.map +1 -0
- package/dist/src/core/helpers/resolveFromCwd.d.ts.map +1 -1
- package/dist/src/core/helpers/resolveFromCwd.js.map +1 -1
- package/dist/src/core/helpers/updateTotals.d.ts +20 -0
- package/dist/src/core/helpers/updateTotals.d.ts.map +1 -0
- package/dist/src/core/helpers/updateTotals.js +37 -0
- package/dist/src/core/helpers/updateTotals.js.map +1 -0
- package/dist/src/core/processComparisonFile.d.ts +36 -0
- package/dist/src/core/processComparisonFile.d.ts.map +1 -0
- package/dist/src/core/processComparisonFile.js +124 -0
- package/dist/src/core/processComparisonFile.js.map +1 -0
- package/dist/src/core/secretDetectors.d.ts +10 -1
- package/dist/src/core/secretDetectors.d.ts.map +1 -1
- package/dist/src/core/secretDetectors.js +35 -4
- package/dist/src/core/secretDetectors.js.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/services/codeBaseScanner.js +1 -1
- package/dist/src/services/codeBaseScanner.js.map +1 -1
- package/dist/src/services/ensureFilesOrPrompt.d.ts.map +1 -1
- package/dist/src/services/ensureFilesOrPrompt.js +10 -11
- package/dist/src/services/ensureFilesOrPrompt.js.map +1 -1
- package/dist/src/services/git.d.ts +9 -0
- package/dist/src/services/git.d.ts.map +1 -1
- package/dist/src/services/git.js +46 -3
- package/dist/src/services/git.js.map +1 -1
- package/dist/src/services/scanOutputToConsole.d.ts +6 -1
- package/dist/src/services/scanOutputToConsole.d.ts.map +1 -1
- package/dist/src/services/scanOutputToConsole.js +67 -140
- package/dist/src/services/scanOutputToConsole.js.map +1 -1
- package/dist/src/ui/compare/printAutoFix.d.ts +16 -0
- package/dist/src/ui/compare/printAutoFix.d.ts.map +1 -0
- package/dist/src/ui/compare/printAutoFix.js +34 -0
- package/dist/src/ui/compare/printAutoFix.js.map +1 -0
- package/dist/src/ui/compare/printAutoFixApplied.d.ts +7 -0
- package/dist/src/ui/compare/printAutoFixApplied.d.ts.map +1 -0
- package/dist/src/ui/compare/printAutoFixApplied.js +22 -0
- package/dist/src/ui/compare/printAutoFixApplied.js.map +1 -0
- package/dist/src/ui/compare/printDuplicates.d.ts +17 -0
- package/dist/src/ui/compare/printDuplicates.d.ts.map +1 -0
- package/dist/src/ui/compare/printDuplicates.js +25 -0
- package/dist/src/ui/compare/printDuplicates.js.map +1 -0
- package/dist/src/ui/compare/printErrorNotFound.d.ts +9 -0
- package/dist/src/ui/compare/printErrorNotFound.d.ts.map +1 -0
- package/dist/src/ui/compare/printErrorNotFound.js +18 -0
- package/dist/src/ui/compare/printErrorNotFound.js.map +1 -0
- package/dist/src/ui/compare/printFixTips.d.ts +11 -0
- package/dist/src/ui/compare/printFixTips.d.ts.map +1 -0
- package/dist/src/ui/compare/printFixTips.js +46 -0
- package/dist/src/ui/compare/printFixTips.js.map +1 -0
- package/dist/src/ui/compare/printHeader.d.ts +10 -0
- package/dist/src/ui/compare/printHeader.d.ts.map +1 -0
- package/dist/src/ui/compare/printHeader.js +20 -0
- package/dist/src/ui/compare/printHeader.js.map +1 -0
- package/dist/src/ui/compare/printIssues.d.ts +9 -0
- package/dist/src/ui/compare/printIssues.d.ts.map +1 -0
- package/dist/src/ui/compare/printIssues.js +34 -0
- package/dist/src/ui/compare/printIssues.js.map +1 -0
- package/dist/src/ui/compare/printPrompt.d.ts +11 -0
- package/dist/src/ui/compare/printPrompt.d.ts.map +1 -0
- package/dist/src/ui/compare/printPrompt.js +24 -0
- package/dist/src/ui/compare/printPrompt.js.map +1 -0
- package/dist/src/ui/compare/printStats.d.ts +19 -0
- package/dist/src/ui/compare/printStats.d.ts.map +1 -0
- package/dist/src/ui/compare/printStats.js +30 -0
- package/dist/src/ui/compare/printStats.js.map +1 -0
- package/dist/src/ui/compare/printSuccess.d.ts +11 -0
- package/dist/src/ui/compare/printSuccess.d.ts.map +1 -0
- package/dist/src/ui/compare/printSuccess.js +27 -0
- package/dist/src/ui/compare/printSuccess.js.map +1 -0
- package/dist/src/ui/scan/printComparisonError.d.ts +11 -0
- package/dist/src/ui/scan/printComparisonError.d.ts.map +1 -0
- package/dist/src/ui/scan/printComparisonError.js +20 -0
- package/dist/src/ui/scan/printComparisonError.js.map +1 -0
- package/dist/src/ui/scan/printHeader.d.ts +7 -0
- package/dist/src/ui/scan/printHeader.d.ts.map +1 -0
- package/dist/src/ui/scan/printHeader.js +16 -0
- package/dist/src/ui/scan/printHeader.js.map +1 -0
- package/dist/src/ui/scan/printMissing.d.ts +13 -0
- package/dist/src/ui/scan/printMissing.d.ts.map +1 -0
- package/dist/src/ui/scan/printMissing.js +43 -0
- package/dist/src/ui/scan/printMissing.js.map +1 -0
- package/dist/src/ui/scan/printMissingExample.d.ts +9 -0
- package/dist/src/ui/scan/printMissingExample.d.ts.map +1 -0
- package/dist/src/ui/scan/printMissingExample.js +27 -0
- package/dist/src/ui/scan/printMissingExample.js.map +1 -0
- package/dist/src/ui/scan/printSecrets.d.ts +14 -0
- package/dist/src/ui/scan/printSecrets.d.ts.map +1 -0
- package/dist/src/ui/scan/printSecrets.js +29 -0
- package/dist/src/ui/scan/printSecrets.js.map +1 -0
- package/dist/src/ui/scan/printStats.d.ts +13 -0
- package/dist/src/ui/scan/printStats.d.ts.map +1 -0
- package/dist/src/ui/scan/printStats.js +17 -0
- package/dist/src/ui/scan/printStats.js.map +1 -0
- package/dist/src/ui/scan/printUniqueVariables.d.ts +7 -0
- package/dist/src/ui/scan/printUniqueVariables.d.ts.map +1 -0
- package/dist/src/ui/scan/printUniqueVariables.js +14 -0
- package/dist/src/ui/scan/printUniqueVariables.js.map +1 -0
- package/dist/src/ui/scan/printUnused.d.ts +10 -0
- package/dist/src/ui/scan/printUnused.d.ts.map +1 -0
- package/dist/src/ui/scan/printUnused.js +22 -0
- package/dist/src/ui/scan/printUnused.js.map +1 -0
- package/dist/src/ui/scan/printVariables.d.ts +10 -0
- package/dist/src/ui/scan/printVariables.d.ts.map +1 -0
- package/dist/src/ui/scan/printVariables.js +37 -0
- package/dist/src/ui/scan/printVariables.js.map +1 -0
- package/dist/src/ui/shared/printAutoFix.d.ts +16 -0
- package/dist/src/ui/shared/printAutoFix.d.ts.map +1 -0
- package/dist/src/ui/shared/printAutoFix.js +34 -0
- package/dist/src/ui/shared/printAutoFix.js.map +1 -0
- package/dist/src/ui/shared/printConfigStatus.d.ts +11 -0
- package/dist/src/ui/shared/printConfigStatus.d.ts.map +1 -0
- package/dist/src/ui/shared/printConfigStatus.js +23 -0
- package/dist/src/ui/shared/printConfigStatus.js.map +1 -0
- package/dist/src/ui/shared/printDuplicates.d.ts +17 -0
- package/dist/src/ui/shared/printDuplicates.d.ts.map +1 -0
- package/dist/src/ui/shared/printDuplicates.js +25 -0
- package/dist/src/ui/shared/printDuplicates.js.map +1 -0
- package/dist/src/ui/shared/printFixTips.d.ts +11 -0
- package/dist/src/ui/shared/printFixTips.d.ts.map +1 -0
- package/dist/src/ui/shared/printFixTips.js +46 -0
- package/dist/src/ui/shared/printFixTips.js.map +1 -0
- package/dist/src/ui/shared/printGitignore.d.ts +13 -0
- package/dist/src/ui/shared/printGitignore.d.ts.map +1 -0
- package/dist/src/ui/shared/printGitignore.js +20 -0
- package/dist/src/ui/shared/printGitignore.js.map +1 -0
- package/dist/src/ui/shared/printInitStatus.d.ts +9 -0
- package/dist/src/ui/shared/printInitStatus.d.ts.map +1 -0
- package/dist/src/ui/shared/printInitStatus.js +20 -0
- package/dist/src/ui/shared/printInitStatus.js.map +1 -0
- package/dist/src/ui/shared/printOptionErrors.d.ts +17 -0
- package/dist/src/ui/shared/printOptionErrors.d.ts.map +1 -0
- package/dist/src/ui/shared/printOptionErrors.js +27 -0
- package/dist/src/ui/shared/printOptionErrors.js.map +1 -0
- package/dist/src/ui/shared/printStrictModeError.d.ts +16 -0
- package/dist/src/ui/shared/printStrictModeError.d.ts.map +1 -0
- package/dist/src/ui/shared/printStrictModeError.js +29 -0
- package/dist/src/ui/shared/printStrictModeError.js.map +1 -0
- package/dist/src/ui/shared/printSuccess.d.ts +11 -0
- package/dist/src/ui/shared/printSuccess.d.ts.map +1 -0
- package/dist/src/ui/shared/printSuccess.js +27 -0
- package/dist/src/ui/shared/printSuccess.js.map +1 -0
- package/dist/src/ui/shared/setupGlobalConfig.d.ts +7 -0
- package/dist/src/ui/shared/setupGlobalConfig.d.ts.map +1 -0
- package/dist/src/ui/shared/setupGlobalConfig.js +12 -0
- package/dist/src/ui/shared/setupGlobalConfig.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
* @returns An object indicating whether a file was created or if the process should exit.
|
|
2
|
+
* Creates a default dotenv-diff.config.json in the current directory if it doesn't exist.
|
|
3
|
+
* If the file already exists, it notifies the user and does nothing.
|
|
5
4
|
*/
|
|
6
|
-
export declare function
|
|
7
|
-
cwd: string;
|
|
8
|
-
primaryEnv: string;
|
|
9
|
-
primaryExample: string;
|
|
10
|
-
alreadyWarnedMissingEnv: boolean;
|
|
11
|
-
isYesMode: boolean;
|
|
12
|
-
isCiMode: boolean;
|
|
13
|
-
}): Promise<{
|
|
14
|
-
didCreate: boolean;
|
|
15
|
-
shouldExit: boolean;
|
|
16
|
-
exitCode: number;
|
|
17
|
-
}>;
|
|
5
|
+
export declare function runInit(): Promise<void>;
|
|
18
6
|
//# sourceMappingURL=init.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/commands/init.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/commands/init.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wBAAsB,OAAO,kBAkB5B"}
|
|
@@ -1,73 +1,24 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
import
|
|
4
|
-
import { confirmYesNo } from '../ui/prompts.js';
|
|
5
|
-
import { warnIfEnvNotIgnored } from '../services/git.js';
|
|
3
|
+
import { printInitSuccess, printInitExists } from '../ui/shared/printInitStatus.js';
|
|
6
4
|
/**
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
* @returns An object indicating whether a file was created or if the process should exit.
|
|
5
|
+
* Creates a default dotenv-diff.config.json in the current directory if it doesn't exist.
|
|
6
|
+
* If the file already exists, it notifies the user and does nothing.
|
|
10
7
|
*/
|
|
11
|
-
export async function
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
// Case 1: no .env and no .env.example
|
|
18
|
-
if (!envExists && !exampleExists) {
|
|
19
|
-
const hasAnyEnv = fs.readdirSync(cwd).some((f) => f.startsWith('.env'));
|
|
20
|
-
if (!hasAnyEnv) {
|
|
21
|
-
console.log(chalk.yellow('⚠️ No .env* or .env.example file found. Skipping comparison.'));
|
|
22
|
-
return { didCreate: false, shouldExit: true, exitCode: 0 };
|
|
23
|
-
}
|
|
8
|
+
export async function runInit() {
|
|
9
|
+
const cwd = process.cwd();
|
|
10
|
+
const configPath = path.join(cwd, 'dotenv-diff.config.json');
|
|
11
|
+
if (fs.existsSync(configPath)) {
|
|
12
|
+
printInitExists(configPath);
|
|
13
|
+
return;
|
|
24
14
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
: isCiMode
|
|
34
|
-
? false
|
|
35
|
-
: await confirmYesNo(`❓ Do you want to create a new ${path.basename(envPath)} file from ${path.basename(examplePath)}?`, { isCiMode, isYesMode });
|
|
36
|
-
if (!createEnv) {
|
|
37
|
-
console.log(chalk.gray('🚫 Skipping .env creation.'));
|
|
38
|
-
return { didCreate: false, shouldExit: true, exitCode: 0 };
|
|
39
|
-
}
|
|
40
|
-
const exampleContent = fs.readFileSync(examplePath, 'utf-8');
|
|
41
|
-
fs.writeFileSync(envPath, exampleContent);
|
|
42
|
-
console.log(chalk.green(`✅ ${path.basename(envPath)} file created successfully from ${path.basename(examplePath)}.\n`));
|
|
43
|
-
warnIfEnvNotIgnored({ envFile: path.basename(envPath) });
|
|
44
|
-
}
|
|
45
|
-
// Case 3: has .env but is missing .env.example
|
|
46
|
-
if (envExists && !exampleExists) {
|
|
47
|
-
console.log(chalk.yellow(`📄 ${path.basename(examplePath)} file not found.`));
|
|
48
|
-
let createExample = isYesMode
|
|
49
|
-
? true
|
|
50
|
-
: isCiMode
|
|
51
|
-
? false
|
|
52
|
-
: await confirmYesNo(`❓ Do you want to create a new ${path.basename(examplePath)} file from ${path.basename(envPath)}?`, { isCiMode, isYesMode });
|
|
53
|
-
if (!createExample) {
|
|
54
|
-
console.log(chalk.gray('🚫 Skipping .env.example creation.'));
|
|
55
|
-
return { didCreate: false, shouldExit: true, exitCode: 0 };
|
|
56
|
-
}
|
|
57
|
-
const envContent = fs
|
|
58
|
-
.readFileSync(envPath, 'utf-8')
|
|
59
|
-
.split('\n')
|
|
60
|
-
.map((line) => {
|
|
61
|
-
const trimmed = line.trim();
|
|
62
|
-
if (!trimmed || trimmed.startsWith('#'))
|
|
63
|
-
return trimmed;
|
|
64
|
-
const [key] = trimmed.split('=');
|
|
65
|
-
return `${key}=`;
|
|
66
|
-
})
|
|
67
|
-
.join('\n');
|
|
68
|
-
fs.writeFileSync(examplePath, envContent);
|
|
69
|
-
console.log(chalk.green(`✅ ${path.basename(examplePath)} file created successfully from ${path.basename(envPath)}.\n`));
|
|
70
|
-
}
|
|
71
|
-
return { didCreate: true, shouldExit: false, exitCode: 0 };
|
|
15
|
+
const defaultConfig = {
|
|
16
|
+
strict: false,
|
|
17
|
+
example: '.env.example',
|
|
18
|
+
ignore: ['NODE_ENV', 'VITE_MODE'],
|
|
19
|
+
ignoreUrls: ['https://example.com'],
|
|
20
|
+
};
|
|
21
|
+
fs.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 2));
|
|
22
|
+
printInitSuccess(configPath);
|
|
72
23
|
}
|
|
73
24
|
//# sourceMappingURL=init.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAEpF;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO;IAC3B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC1B,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,yBAAyB,CAAC,CAAC;IAE7D,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9B,eAAe,CAAC,UAAU,CAAC,CAAC;QAC5B,OAAO;IACT,CAAC;IAED,MAAM,aAAa,GAAG;QACpB,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,cAAc;QACvB,MAAM,EAAE,CAAC,UAAU,EAAE,WAAW,CAAC;QACjC,UAAU,EAAE,CAAC,qBAAqB,CAAC;KACpC,CAAC;IAEF,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IACrE,gBAAgB,CAAC,UAAU,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanUsage.d.ts","sourceRoot":"","sources":["../../../src/commands/scanUsage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scanUsage.d.ts","sourceRoot":"","sources":["../../../src/commands/scanUsage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAGjB,MAAM,oBAAoB,CAAC;AA0E5B;;;;;;;;;;;GAWG;AACH,wBAAsB,SAAS,CAC7B,IAAI,EAAE,gBAAgB,GACrB,OAAO,CAAC;IAAE,aAAa,EAAE,OAAO,CAAA;CAAE,CAAC,CAmFrC"}
|
|
@@ -1,16 +1,64 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { parseEnvFile } from '../core/parseEnv.js';
|
|
5
1
|
import { scanCodebase } from '../services/codeBaseScanner.js';
|
|
6
|
-
import { filterIgnoredKeys } from '../core/filterIgnoredKeys.js';
|
|
7
|
-
import { resolveFromCwd } from '../core/helpers/resolveFromCwd.js';
|
|
8
2
|
import { determineComparisonFile } from '../core/determineComparisonFile.js';
|
|
9
3
|
import { outputToConsole } from '../services/scanOutputToConsole.js';
|
|
10
4
|
import { createJsonOutput } from '../core/scanJsonOutput.js';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
5
|
+
import { printMissingExample } from '../ui/scan/printMissingExample.js';
|
|
6
|
+
import { processComparisonFile } from '../core/processComparisonFile.js';
|
|
7
|
+
import { printComparisonError } from '../ui/scan/printComparisonError.js';
|
|
8
|
+
import { hasIgnoreComment } from '../core/secretDetectors.js';
|
|
9
|
+
/**
|
|
10
|
+
* Filters out commented usages from the list.
|
|
11
|
+
* Skipping comments:
|
|
12
|
+
* // process.env.API_URL
|
|
13
|
+
* # process.env.API_URL
|
|
14
|
+
* /* process.env.API_URL
|
|
15
|
+
* * process.env.API_URL
|
|
16
|
+
* <!-- process.env.API_URL -->
|
|
17
|
+
* @param usages - List of environment variable usages
|
|
18
|
+
* @returns Filtered list of environment variable usages
|
|
19
|
+
*/
|
|
20
|
+
function skipCommentedUsages(usages) {
|
|
21
|
+
let insideHtmlComment = false;
|
|
22
|
+
let insideIgnoreBlock = false;
|
|
23
|
+
return usages.filter((u) => {
|
|
24
|
+
if (!u.context)
|
|
25
|
+
return true;
|
|
26
|
+
const line = u.context.trim();
|
|
27
|
+
if (line.includes('<!--'))
|
|
28
|
+
insideHtmlComment = true;
|
|
29
|
+
if (line.includes('-->')) {
|
|
30
|
+
insideHtmlComment = false;
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
if (/<!--\s*dotenv[\s-]*diff[\s-]*ignore[\s-]*start\s*-->/i.test(line)) {
|
|
34
|
+
insideIgnoreBlock = true;
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
if (/<!--\s*dotenv[\s-]*diff[\s-]*ignore[\s-]*end\s*-->/i.test(line)) {
|
|
38
|
+
insideIgnoreBlock = false;
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
if (insideIgnoreBlock)
|
|
42
|
+
return false;
|
|
43
|
+
return (!insideHtmlComment &&
|
|
44
|
+
!/^\s*(\/\/|#|\/\*|\*|<!--|-->)/.test(line) &&
|
|
45
|
+
!hasIgnoreComment(line));
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Recalculates statistics for a scan result after filtering usages.
|
|
50
|
+
* @param scanResult The current scan result
|
|
51
|
+
* @returns Updated scanResult with recalculated stats
|
|
52
|
+
*/
|
|
53
|
+
function calculateStats(scanResult) {
|
|
54
|
+
const uniqueVariables = new Set(scanResult.used.map((u) => u.variable)).size;
|
|
55
|
+
scanResult.stats = {
|
|
56
|
+
filesScanned: scanResult.stats.filesScanned,
|
|
57
|
+
totalUsages: scanResult.used.length,
|
|
58
|
+
uniqueVariables,
|
|
59
|
+
};
|
|
60
|
+
return scanResult;
|
|
61
|
+
}
|
|
14
62
|
/**
|
|
15
63
|
* Scans codebase for environment variable usage and compares with .env file
|
|
16
64
|
* @param {ScanUsageOptions} opts - Scan configuration options
|
|
@@ -24,150 +72,47 @@ import { applyFixes } from '../core/fixEnv.js';
|
|
|
24
72
|
* @returns {Promise<{exitWithError: boolean}>} Returns true if missing variables found
|
|
25
73
|
*/
|
|
26
74
|
export async function scanUsage(opts) {
|
|
27
|
-
if (!opts.json) {
|
|
28
|
-
console.log();
|
|
29
|
-
console.log(chalk.blue('🔍 Scanning codebase for environment variable usage...'));
|
|
30
|
-
console.log();
|
|
31
|
-
}
|
|
32
75
|
// Scan the codebase
|
|
33
76
|
let scanResult = await scanCodebase(opts);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
scanResult
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
};
|
|
42
|
-
// If user explicitly passed --example but the file doesn't exist:
|
|
43
|
-
if (opts.examplePath) {
|
|
44
|
-
const exampleAbs = resolveFromCwd(opts.cwd, opts.examplePath);
|
|
45
|
-
const missing = !fs.existsSync(exampleAbs);
|
|
46
|
-
if (missing) {
|
|
47
|
-
const msg = `❌ Missing specified example file: ${opts.examplePath}`;
|
|
48
|
-
if (opts.isCiMode) {
|
|
49
|
-
// IMPORTANT: stdout (console.log), not stderr, to satisfy the test
|
|
50
|
-
console.log(chalk.red(msg));
|
|
51
|
-
return { exitWithError: true };
|
|
52
|
-
}
|
|
53
|
-
else if (!opts.json) {
|
|
54
|
-
console.log(chalk.yellow(msg.replace('❌', '⚠️')));
|
|
55
|
-
}
|
|
56
|
-
// Non-CI: continue without comparison
|
|
57
|
-
}
|
|
77
|
+
// Filter out commented usages
|
|
78
|
+
scanResult.used = skipCommentedUsages(scanResult.used);
|
|
79
|
+
// Recalculate stats after filtering
|
|
80
|
+
calculateStats(scanResult);
|
|
81
|
+
// If user explicitly passed --example flag, but the file doesn't exist:
|
|
82
|
+
if (printMissingExample(opts)) {
|
|
83
|
+
return { exitWithError: true };
|
|
58
84
|
}
|
|
59
85
|
// Determine which file to compare against
|
|
60
86
|
const compareFile = determineComparisonFile(opts);
|
|
61
87
|
let envVariables = {};
|
|
62
88
|
let comparedAgainst = '';
|
|
63
89
|
let duplicatesFound = false;
|
|
64
|
-
let dupsEnv = [];
|
|
65
|
-
let dupsExample = [];
|
|
66
90
|
// Store fix information for consolidated display
|
|
67
91
|
let fixApplied = false;
|
|
68
92
|
let fixedKeys = [];
|
|
69
93
|
let removedDuplicates = [];
|
|
94
|
+
let gitignoreUpdated = false;
|
|
95
|
+
// If comparing against a file, process it
|
|
96
|
+
// fx: if the scan is comparing against .env.example, it will check for missing keys there
|
|
70
97
|
if (compareFile) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
scanResult = compareWithEnvFiles(scanResult, envVariables);
|
|
76
|
-
comparedAgainst = compareFile.name;
|
|
77
|
-
// Check for duplicates in the env file
|
|
78
|
-
if (!opts.allowDuplicates) {
|
|
79
|
-
dupsEnv = findDuplicateKeys(compareFile.path).filter(({ key }) => !opts.ignore.includes(key) &&
|
|
80
|
-
!opts.ignoreRegex.some((rx) => rx.test(key)));
|
|
81
|
-
// Also check for duplicates in example file if it exists AND is different from compareFile
|
|
82
|
-
if (opts.examplePath) {
|
|
83
|
-
const examplePath = resolveFromCwd(opts.cwd, opts.examplePath);
|
|
84
|
-
// Only check example file if it exists and is NOT the same as the comparison file
|
|
85
|
-
if (fs.existsSync(examplePath) && examplePath !== compareFile.path) {
|
|
86
|
-
dupsExample = findDuplicateKeys(examplePath).filter(({ key }) => !opts.ignore.includes(key) &&
|
|
87
|
-
!opts.ignoreRegex.some((rx) => rx.test(key)));
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
duplicatesFound = dupsEnv.length > 0 || dupsExample.length > 0;
|
|
91
|
-
// Apply duplicate fixes if --fix is enabled (but don't show message yet)
|
|
92
|
-
if (opts.fix && (dupsEnv.length > 0 || dupsExample.length > 0)) {
|
|
93
|
-
const { changed, result } = applyFixes({
|
|
94
|
-
envPath: compareFile.path,
|
|
95
|
-
examplePath: opts.examplePath
|
|
96
|
-
? resolveFromCwd(opts.cwd, opts.examplePath)
|
|
97
|
-
: '',
|
|
98
|
-
missingKeys: [],
|
|
99
|
-
duplicateKeys: dupsEnv.map((d) => d.key),
|
|
100
|
-
});
|
|
101
|
-
if (changed) {
|
|
102
|
-
fixApplied = true;
|
|
103
|
-
removedDuplicates = result.removedDuplicates;
|
|
104
|
-
// Clear duplicates after fix
|
|
105
|
-
duplicatesFound = false;
|
|
106
|
-
dupsEnv = [];
|
|
107
|
-
dupsExample = [];
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
// Add to scan result for both JSON and console output (only if not fixed)
|
|
111
|
-
if ((dupsEnv.length > 0 || dupsExample.length > 0) &&
|
|
112
|
-
(!opts.fix || !fixApplied)) {
|
|
113
|
-
if (!scanResult.duplicates)
|
|
114
|
-
scanResult.duplicates = {};
|
|
115
|
-
if (dupsEnv.length > 0)
|
|
116
|
-
scanResult.duplicates.env = dupsEnv;
|
|
117
|
-
if (dupsExample.length > 0)
|
|
118
|
-
scanResult.duplicates.example = dupsExample;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
catch (error) {
|
|
123
|
-
const errorMessage = `⚠️ Could not read ${compareFile.name}: ${compareFile.path} - ${error}`;
|
|
124
|
-
if (opts.isCiMode) {
|
|
125
|
-
// In CI mode, exit with error if file doesn't exist
|
|
126
|
-
console.log(chalk.red(`❌ ${errorMessage}`));
|
|
98
|
+
const result = processComparisonFile(scanResult, compareFile, opts);
|
|
99
|
+
if (result.error) {
|
|
100
|
+
const { exit } = printComparisonError(result.error.message, result.error.shouldExit, opts.json ?? false);
|
|
101
|
+
if (exit)
|
|
127
102
|
return { exitWithError: true };
|
|
128
|
-
}
|
|
129
|
-
if (!opts.json) {
|
|
130
|
-
console.log(chalk.yellow(errorMessage));
|
|
131
|
-
}
|
|
132
103
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
// Append missing keys to .env
|
|
143
|
-
const content = fs.readFileSync(envFilePath, 'utf-8');
|
|
144
|
-
const newContent = content +
|
|
145
|
-
(content.endsWith('\n') ? '' : '\n') +
|
|
146
|
-
missingKeys.map((k) => `${k}=`).join('\n') +
|
|
147
|
-
'\n';
|
|
148
|
-
fs.writeFileSync(envFilePath, newContent);
|
|
149
|
-
// Append to .env.example if it exists
|
|
150
|
-
if (exampleFilePath && fs.existsSync(exampleFilePath)) {
|
|
151
|
-
const exContent = fs.readFileSync(exampleFilePath, 'utf-8');
|
|
152
|
-
const existingExKeys = new Set(exContent
|
|
153
|
-
.split('\n')
|
|
154
|
-
.map((l) => l.trim().split('=')[0])
|
|
155
|
-
.filter(Boolean));
|
|
156
|
-
const newKeys = missingKeys.filter((k) => !existingExKeys.has(k));
|
|
157
|
-
if (newKeys.length) {
|
|
158
|
-
const newExContent = exContent +
|
|
159
|
-
(exContent.endsWith('\n') ? '' : '\n') +
|
|
160
|
-
newKeys.join('\n') +
|
|
161
|
-
'\n';
|
|
162
|
-
fs.writeFileSync(exampleFilePath, newExContent);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
fixApplied = true;
|
|
166
|
-
fixedKeys = missingKeys;
|
|
167
|
-
scanResult.missing = [];
|
|
104
|
+
else {
|
|
105
|
+
scanResult = result.scanResult;
|
|
106
|
+
envVariables = result.envVariables;
|
|
107
|
+
comparedAgainst = result.comparedAgainst;
|
|
108
|
+
duplicatesFound = result.duplicatesFound;
|
|
109
|
+
fixApplied = result.fixApplied;
|
|
110
|
+
removedDuplicates = result.removedDuplicates;
|
|
111
|
+
fixedKeys = result.addedEnv;
|
|
112
|
+
gitignoreUpdated = result.gitignoreUpdated;
|
|
168
113
|
}
|
|
169
114
|
}
|
|
170
|
-
//
|
|
115
|
+
// JSON output
|
|
171
116
|
if (opts.json) {
|
|
172
117
|
const jsonOutput = createJsonOutput(scanResult, opts, comparedAgainst, Object.keys(envVariables).length);
|
|
173
118
|
console.log(JSON.stringify(jsonOutput, null, 2));
|
|
@@ -182,43 +127,12 @@ export async function scanUsage(opts) {
|
|
|
182
127
|
};
|
|
183
128
|
}
|
|
184
129
|
// Console output
|
|
185
|
-
const result = outputToConsole(scanResult, opts, comparedAgainst
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
if (removedDuplicates.length > 0) {
|
|
192
|
-
console.log(chalk.green(` - Removed ${removedDuplicates.length} duplicate keys from ${comparedAgainst}: ${removedDuplicates.join(', ')}`));
|
|
193
|
-
}
|
|
194
|
-
// Show added missing keys
|
|
195
|
-
if (fixedKeys.length > 0) {
|
|
196
|
-
console.log(chalk.green(` - Added ${fixedKeys.length} missing keys to ${comparedAgainst}: ${fixedKeys.join(', ')}`));
|
|
197
|
-
if (opts.examplePath) {
|
|
198
|
-
console.log(chalk.green(` - Synced ${fixedKeys.length} keys to ${path.basename(opts.examplePath)}`));
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
console.log();
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
console.log(chalk.green('✅ Auto-fix applied: no changes needed.'));
|
|
205
|
-
console.log();
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
if (!opts.json && !opts.fix) {
|
|
209
|
-
if (scanResult.missing.length > 0 && duplicatesFound) {
|
|
210
|
-
console.log(chalk.gray('💡 Tip: Run with `--fix` to add missing keys and remove duplicates'));
|
|
211
|
-
console.log();
|
|
212
|
-
}
|
|
213
|
-
else if (scanResult.missing.length > 0) {
|
|
214
|
-
console.log(chalk.gray('💡 Tip: Run with `--fix` to add missing keys'));
|
|
215
|
-
console.log();
|
|
216
|
-
}
|
|
217
|
-
else if (duplicatesFound) {
|
|
218
|
-
console.log(chalk.gray('💡 Tip: Run with `--fix` to remove duplicate keys'));
|
|
219
|
-
console.log();
|
|
220
|
-
}
|
|
221
|
-
}
|
|
130
|
+
const result = outputToConsole(scanResult, opts, comparedAgainst, {
|
|
131
|
+
fixApplied,
|
|
132
|
+
removedDuplicates,
|
|
133
|
+
addedEnv: fixedKeys,
|
|
134
|
+
gitignoreUpdated,
|
|
135
|
+
});
|
|
222
136
|
return { exitWithError: result.exitWithError || duplicatesFound };
|
|
223
137
|
}
|
|
224
138
|
//# sourceMappingURL=scanUsage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanUsage.js","sourceRoot":"","sources":["../../../src/commands/scanUsage.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"scanUsage.js","sourceRoot":"","sources":["../../../src/commands/scanUsage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAM9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D;;;;;;;;;;GAUG;AACH,SAAS,mBAAmB,CAAC,MAAkB;IAC7C,IAAI,iBAAiB,GAAG,KAAK,CAAC;IAC9B,IAAI,iBAAiB,GAAG,KAAK,CAAC;IAE9B,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE;QACzB,IAAI,CAAC,CAAC,CAAC,OAAO;YAAE,OAAO,IAAI,CAAC;QAC5B,MAAM,IAAI,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAE9B,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;YAAE,iBAAiB,GAAG,IAAI,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diff.config.json (if present)
|
|
4
|
+
* and merges it with CLI flags.
|
|
5
|
+
* CLI options always take precedence.
|
|
6
|
+
* @param cliOptions - Options provided via CLI
|
|
7
|
+
* @return Merged options
|
|
8
|
+
*/
|
|
9
|
+
export declare function loadConfig(cliOptions: Partial<RawOptions>): RawOptions;
|
|
2
10
|
//# sourceMappingURL=loadConfig.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadConfig.d.ts","sourceRoot":"","sources":["../../../src/config/loadConfig.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"loadConfig.d.ts","sourceRoot":"","sources":["../../../src/config/loadConfig.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAG7C;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,CAqBtE"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { printConfigLoaded, printConfigLoadError } from "../ui/shared/printConfigStatus.js";
|
|
4
|
+
/**
|
|
5
|
+
* Loads dotenv-diff.config.json (if present)
|
|
6
|
+
* and merges it with CLI flags.
|
|
7
|
+
* CLI options always take precedence.
|
|
8
|
+
* @param cliOptions - Options provided via CLI
|
|
9
|
+
* @return Merged options
|
|
10
|
+
*/
|
|
11
|
+
export function loadConfig(cliOptions) {
|
|
12
|
+
const cwd = process.cwd();
|
|
13
|
+
const configPath = path.join(cwd, "dotenv-diff.config.json");
|
|
14
|
+
let fileConfig = {};
|
|
15
|
+
if (fs.existsSync(configPath)) {
|
|
16
|
+
try {
|
|
17
|
+
const raw = fs.readFileSync(configPath, "utf8");
|
|
18
|
+
fileConfig = JSON.parse(raw);
|
|
19
|
+
printConfigLoaded(configPath);
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
printConfigLoadError(err);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
// Merge: config file first, then CLI options override
|
|
26
|
+
return {
|
|
27
|
+
...fileConfig,
|
|
28
|
+
...cliOptions,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=loadConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadConfig.js","sourceRoot":"","sources":["../../../src/config/loadConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAE5F;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,UAA+B;IACxD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC1B,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,yBAAyB,CAAC,CAAC;IAE7D,IAAI,UAAU,GAAwB,EAAE,CAAC;IAEzC,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9B,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;YAChD,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC7B,iBAAiB,CAAC,UAAU,CAAC,CAAC;QAChC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,oBAAoB,CAAC,GAAG,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IAED,sDAAsD;IACtD,OAAO;QACL,GAAG,UAAU;QACb,GAAG,UAAU;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../src/config/options.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../src/config/options.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,OAAO,EACZ,KAAK,UAAU,EAChB,MAAM,YAAY,CAAC;AA4DpB;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAiEzD"}
|