@subramanyaks/env-drift 1.0.0 → 1.1.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/dist/index.d.cts CHANGED
@@ -2,13 +2,14 @@ interface EnvReference {
2
2
  name: string;
3
3
  file: string;
4
4
  line: number;
5
- source: "process.env" | "import.meta.env";
5
+ source: "process.env" | "import.meta.env" | "Bun.env" | "Deno.env";
6
6
  }
7
7
  interface ParsedEnvFile {
8
8
  filePath: string;
9
9
  exists: boolean;
10
10
  keys: string[];
11
11
  values: Record<string, string>;
12
+ lines: Record<string, number>;
12
13
  duplicates: string[];
13
14
  }
14
15
  interface SecretExposureWarning {
@@ -17,35 +18,58 @@ interface SecretExposureWarning {
17
18
  matchedKeyword: string;
18
19
  references: EnvReference[];
19
20
  }
21
+ interface ExampleSecretLeak {
22
+ name: string;
23
+ reason: string;
24
+ file: string;
25
+ line: number;
26
+ }
20
27
  interface AuditResult {
21
28
  rootDir: string;
22
29
  scannedFiles: number;
30
+ envFileExists: boolean;
31
+ exampleFileExists: boolean;
23
32
  usedInCode: Record<string, EnvReference[]>;
24
33
  missingInEnv: string[];
25
34
  missingInExample: string[];
35
+ emptyInEnv: string[];
26
36
  unusedInEnv: string[];
27
37
  unusedInExample: string[];
28
38
  secretExposures: SecretExposureWarning[];
39
+ exampleSecretLeaks: ExampleSecretLeak[];
29
40
  duplicateKeys: {
30
41
  env: string[];
31
42
  example: string[];
32
43
  };
33
44
  }
34
- interface AuditOptions {
35
- rootDir?: string;
45
+ interface EnvDriftConfig {
36
46
  envFile?: string;
37
47
  exampleFile?: string;
38
48
  ignore?: string[];
49
+ ignoreDirs?: string[];
50
+ publicPrefixes?: string[];
51
+ sensitiveKeywords?: string[];
52
+ }
53
+ interface AuditOptions extends EnvDriftConfig {
54
+ rootDir?: string;
39
55
  }
40
56
 
41
57
  declare const BUILTIN_ENV_VARS: Set<string>;
42
58
  declare const PUBLIC_ENV_PREFIXES: readonly ["NEXT_PUBLIC_", "VITE_", "REACT_APP_", "NUXT_PUBLIC_", "PUBLIC_", "EXPO_PUBLIC_", "GATSBY_"];
43
59
  declare const SENSITIVE_KEYWORDS: readonly ["SECRET", "PASSWORD", "PASSWD", "PRIVATE_KEY", "PRIVATE", "DATABASE_URL", "DB_URL", "DB_PASS", "JWT_SECRET", "AUTH_TOKEN", "ACCESS_KEY", "API_SECRET", "SERVICE_ROLE", "CREDENTIALS"];
60
+ /**
61
+ * Detects whether an `.env.example` value looks like a real committed secret
62
+ * rather than an empty or placeholder value.
63
+ */
64
+ declare function detectExampleSecretLeak(_name: string, value: string): string | null;
44
65
  /**
45
66
  * Detects whether an environment variable name combines a client-exposed prefix
46
67
  * with a sensitive keyword (e.g. `NEXT_PUBLIC_DB_PASSWORD`).
47
68
  */
48
- declare function detectSecretExposure(name: string): {
69
+ declare function detectSecretExposure(name: string, options?: {
70
+ publicPrefixes?: readonly string[];
71
+ sensitiveKeywords?: readonly string[];
72
+ }): {
49
73
  prefix: string;
50
74
  matchedKeyword: string;
51
75
  } | null;
@@ -54,12 +78,19 @@ declare function detectSecretExposure(name: string): {
54
78
  */
55
79
  declare function auditEnv(options?: AuditOptions): AuditResult;
56
80
 
81
+ /**
82
+ * Loads optional project configuration from `.envdriftrc.json` or the `"env-drift"`
83
+ * field in `package.json`.
84
+ */
85
+ declare function loadConfig(rootDir: string): EnvDriftConfig;
86
+
57
87
  /**
58
88
  * Parses the text contents of a .env file without external dependencies.
59
89
  */
60
90
  declare function parseEnvContent(content: string): {
61
91
  keys: string[];
62
92
  values: Record<string, string>;
93
+ lines: Record<string, number>;
63
94
  duplicates: string[];
64
95
  };
65
96
  /**
@@ -77,7 +108,8 @@ declare function syncEnvExample(examplePath: string, missingKeys: string[]): {
77
108
  declare const DEFAULT_IGNORE_DIRS: Set<string>;
78
109
  declare const DEFAULT_EXTENSIONS: Set<string>;
79
110
  /**
80
- * Extracts all `process.env` and `import.meta.env` references from a source string.
111
+ * Extracts all `process.env`, `import.meta.env`, `Bun.env`, and `Deno.env.get()`
112
+ * references from a source string.
81
113
  */
82
114
  declare function extractEnvReferences(content: string, filePath: string): EnvReference[];
83
115
  interface ScanOptions {
@@ -105,15 +137,30 @@ declare function writeEnvTypes(outputPath: string, result: AuditResult): {
105
137
  };
106
138
 
107
139
  /**
108
- * Returns true if the audit found blocking issues (missing vars or exposed public secrets).
140
+ * Returns true if the audit found blocking issues (missing vars, exposed public secrets,
141
+ * or real secrets committed in `.env.example`).
142
+ * When no local `.env` file exists (e.g. in CI where `.env` is gitignored), `missingInEnv`
143
+ * is skipped by default unless `requireEnvFile` is true.
109
144
  */
110
- declare function hasBlockingIssues(result: AuditResult): boolean;
145
+ declare function hasBlockingIssues(result: AuditResult, options?: {
146
+ requireEnvFile?: boolean;
147
+ }): boolean;
111
148
  /**
112
149
  * Formats an AuditResult into a colorized terminal report.
113
150
  */
114
151
  declare function formatAuditReport(result: AuditResult, options?: {
115
152
  envFile?: string;
116
153
  exampleFile?: string;
154
+ ci?: boolean;
155
+ }): string;
156
+ /**
157
+ * Formats an AuditResult as GitHub Actions workflow commands (`::error` / `::warning`)
158
+ * so findings render inline on Pull Request diffs.
159
+ */
160
+ declare function formatGitHubAnnotations(result: AuditResult, options?: {
161
+ envFile?: string;
162
+ exampleFile?: string;
163
+ ci?: boolean;
117
164
  }): string;
118
165
 
119
- export { type AuditOptions, type AuditResult, BUILTIN_ENV_VARS, DEFAULT_EXTENSIONS, DEFAULT_IGNORE_DIRS, type EnvReference, PUBLIC_ENV_PREFIXES, type ParsedEnvFile, SENSITIVE_KEYWORDS, type SecretExposureWarning, auditEnv, detectSecretExposure, extractEnvReferences, formatAuditReport, generateEnvTypes, hasBlockingIssues, parseEnvContent, parseEnvFile, scanFiles, syncEnvExample, writeEnvTypes };
166
+ export { type AuditOptions, type AuditResult, BUILTIN_ENV_VARS, DEFAULT_EXTENSIONS, DEFAULT_IGNORE_DIRS, type EnvDriftConfig, type EnvReference, type ExampleSecretLeak, PUBLIC_ENV_PREFIXES, type ParsedEnvFile, SENSITIVE_KEYWORDS, type SecretExposureWarning, auditEnv, detectExampleSecretLeak, detectSecretExposure, extractEnvReferences, formatAuditReport, formatGitHubAnnotations, generateEnvTypes, hasBlockingIssues, loadConfig, parseEnvContent, parseEnvFile, scanFiles, syncEnvExample, writeEnvTypes };
package/dist/index.d.ts CHANGED
@@ -2,13 +2,14 @@ interface EnvReference {
2
2
  name: string;
3
3
  file: string;
4
4
  line: number;
5
- source: "process.env" | "import.meta.env";
5
+ source: "process.env" | "import.meta.env" | "Bun.env" | "Deno.env";
6
6
  }
7
7
  interface ParsedEnvFile {
8
8
  filePath: string;
9
9
  exists: boolean;
10
10
  keys: string[];
11
11
  values: Record<string, string>;
12
+ lines: Record<string, number>;
12
13
  duplicates: string[];
13
14
  }
14
15
  interface SecretExposureWarning {
@@ -17,35 +18,58 @@ interface SecretExposureWarning {
17
18
  matchedKeyword: string;
18
19
  references: EnvReference[];
19
20
  }
21
+ interface ExampleSecretLeak {
22
+ name: string;
23
+ reason: string;
24
+ file: string;
25
+ line: number;
26
+ }
20
27
  interface AuditResult {
21
28
  rootDir: string;
22
29
  scannedFiles: number;
30
+ envFileExists: boolean;
31
+ exampleFileExists: boolean;
23
32
  usedInCode: Record<string, EnvReference[]>;
24
33
  missingInEnv: string[];
25
34
  missingInExample: string[];
35
+ emptyInEnv: string[];
26
36
  unusedInEnv: string[];
27
37
  unusedInExample: string[];
28
38
  secretExposures: SecretExposureWarning[];
39
+ exampleSecretLeaks: ExampleSecretLeak[];
29
40
  duplicateKeys: {
30
41
  env: string[];
31
42
  example: string[];
32
43
  };
33
44
  }
34
- interface AuditOptions {
35
- rootDir?: string;
45
+ interface EnvDriftConfig {
36
46
  envFile?: string;
37
47
  exampleFile?: string;
38
48
  ignore?: string[];
49
+ ignoreDirs?: string[];
50
+ publicPrefixes?: string[];
51
+ sensitiveKeywords?: string[];
52
+ }
53
+ interface AuditOptions extends EnvDriftConfig {
54
+ rootDir?: string;
39
55
  }
40
56
 
41
57
  declare const BUILTIN_ENV_VARS: Set<string>;
42
58
  declare const PUBLIC_ENV_PREFIXES: readonly ["NEXT_PUBLIC_", "VITE_", "REACT_APP_", "NUXT_PUBLIC_", "PUBLIC_", "EXPO_PUBLIC_", "GATSBY_"];
43
59
  declare const SENSITIVE_KEYWORDS: readonly ["SECRET", "PASSWORD", "PASSWD", "PRIVATE_KEY", "PRIVATE", "DATABASE_URL", "DB_URL", "DB_PASS", "JWT_SECRET", "AUTH_TOKEN", "ACCESS_KEY", "API_SECRET", "SERVICE_ROLE", "CREDENTIALS"];
60
+ /**
61
+ * Detects whether an `.env.example` value looks like a real committed secret
62
+ * rather than an empty or placeholder value.
63
+ */
64
+ declare function detectExampleSecretLeak(_name: string, value: string): string | null;
44
65
  /**
45
66
  * Detects whether an environment variable name combines a client-exposed prefix
46
67
  * with a sensitive keyword (e.g. `NEXT_PUBLIC_DB_PASSWORD`).
47
68
  */
48
- declare function detectSecretExposure(name: string): {
69
+ declare function detectSecretExposure(name: string, options?: {
70
+ publicPrefixes?: readonly string[];
71
+ sensitiveKeywords?: readonly string[];
72
+ }): {
49
73
  prefix: string;
50
74
  matchedKeyword: string;
51
75
  } | null;
@@ -54,12 +78,19 @@ declare function detectSecretExposure(name: string): {
54
78
  */
55
79
  declare function auditEnv(options?: AuditOptions): AuditResult;
56
80
 
81
+ /**
82
+ * Loads optional project configuration from `.envdriftrc.json` or the `"env-drift"`
83
+ * field in `package.json`.
84
+ */
85
+ declare function loadConfig(rootDir: string): EnvDriftConfig;
86
+
57
87
  /**
58
88
  * Parses the text contents of a .env file without external dependencies.
59
89
  */
60
90
  declare function parseEnvContent(content: string): {
61
91
  keys: string[];
62
92
  values: Record<string, string>;
93
+ lines: Record<string, number>;
63
94
  duplicates: string[];
64
95
  };
65
96
  /**
@@ -77,7 +108,8 @@ declare function syncEnvExample(examplePath: string, missingKeys: string[]): {
77
108
  declare const DEFAULT_IGNORE_DIRS: Set<string>;
78
109
  declare const DEFAULT_EXTENSIONS: Set<string>;
79
110
  /**
80
- * Extracts all `process.env` and `import.meta.env` references from a source string.
111
+ * Extracts all `process.env`, `import.meta.env`, `Bun.env`, and `Deno.env.get()`
112
+ * references from a source string.
81
113
  */
82
114
  declare function extractEnvReferences(content: string, filePath: string): EnvReference[];
83
115
  interface ScanOptions {
@@ -105,15 +137,30 @@ declare function writeEnvTypes(outputPath: string, result: AuditResult): {
105
137
  };
106
138
 
107
139
  /**
108
- * Returns true if the audit found blocking issues (missing vars or exposed public secrets).
140
+ * Returns true if the audit found blocking issues (missing vars, exposed public secrets,
141
+ * or real secrets committed in `.env.example`).
142
+ * When no local `.env` file exists (e.g. in CI where `.env` is gitignored), `missingInEnv`
143
+ * is skipped by default unless `requireEnvFile` is true.
109
144
  */
110
- declare function hasBlockingIssues(result: AuditResult): boolean;
145
+ declare function hasBlockingIssues(result: AuditResult, options?: {
146
+ requireEnvFile?: boolean;
147
+ }): boolean;
111
148
  /**
112
149
  * Formats an AuditResult into a colorized terminal report.
113
150
  */
114
151
  declare function formatAuditReport(result: AuditResult, options?: {
115
152
  envFile?: string;
116
153
  exampleFile?: string;
154
+ ci?: boolean;
155
+ }): string;
156
+ /**
157
+ * Formats an AuditResult as GitHub Actions workflow commands (`::error` / `::warning`)
158
+ * so findings render inline on Pull Request diffs.
159
+ */
160
+ declare function formatGitHubAnnotations(result: AuditResult, options?: {
161
+ envFile?: string;
162
+ exampleFile?: string;
163
+ ci?: boolean;
117
164
  }): string;
118
165
 
119
- export { type AuditOptions, type AuditResult, BUILTIN_ENV_VARS, DEFAULT_EXTENSIONS, DEFAULT_IGNORE_DIRS, type EnvReference, PUBLIC_ENV_PREFIXES, type ParsedEnvFile, SENSITIVE_KEYWORDS, type SecretExposureWarning, auditEnv, detectSecretExposure, extractEnvReferences, formatAuditReport, generateEnvTypes, hasBlockingIssues, parseEnvContent, parseEnvFile, scanFiles, syncEnvExample, writeEnvTypes };
166
+ export { type AuditOptions, type AuditResult, BUILTIN_ENV_VARS, DEFAULT_EXTENSIONS, DEFAULT_IGNORE_DIRS, type EnvDriftConfig, type EnvReference, type ExampleSecretLeak, PUBLIC_ENV_PREFIXES, type ParsedEnvFile, SENSITIVE_KEYWORDS, type SecretExposureWarning, auditEnv, detectExampleSecretLeak, detectSecretExposure, extractEnvReferences, formatAuditReport, formatGitHubAnnotations, generateEnvTypes, hasBlockingIssues, loadConfig, parseEnvContent, parseEnvFile, scanFiles, syncEnvExample, writeEnvTypes };