Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/cli/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ export interface Options {
inconsistentNamingWarnings: boolean;
}

export type EnvPatternName = 'process.env' | 'import.meta.env' | 'sveltekit';

/**
* Represents a single usage of an environment variable in the codebase.
*/
Expand All @@ -150,7 +152,7 @@ export interface EnvUsage {
/** The column number where the usage was detected */
column: number;
/** The pattern used to access the environment variable */
pattern: 'process.env' | 'import.meta.env' | 'sveltekit';
pattern: EnvPatternName;
/** List of imported env modules (for sveltekit) */
imports?: string[];
/** The actual line content where the usage was detected */
Expand Down
10 changes: 6 additions & 4 deletions packages/cli/src/core/scan/patterns.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { EnvPatternName } from '../../config/types.js';

type Pattern = {
name: 'process.env' | 'import.meta.env' | 'sveltekit';
name: EnvPatternName;
regex: RegExp;
processor?: (match: RegExpExecArray) => string[];
};
Expand All @@ -19,7 +21,7 @@ export const ENV_PATTERNS: Pattern[] = [
* process.env['MY_KEY']
*/
{
name: 'process.env',
name: 'process.env' as const,
regex:
/process\.env\.([A-Z_][A-Z0-9_]*)|process\.env\[['"]([A-Z_][A-Z0-9_]*)['"]]/g,
processor: (match) => {
Expand All @@ -38,7 +40,7 @@ export const ENV_PATTERNS: Pattern[] = [
* const { MY_KEY, OTHER_KEY: alias, THIRD_KEY = "fallback" } = process.env
*/
{
name: 'process.env',
name: 'process.env' as const,
regex: /\{([^}]*)\}\s*=\s*process\.env\b/g,
processor: (match) => {
const content = match[1];
Expand Down Expand Up @@ -69,7 +71,7 @@ export const ENV_PATTERNS: Pattern[] = [
* import.meta.env['MY_KEY']
*/
{
name: 'import.meta.env',
name: 'import.meta.env' as const,
regex:
/import\.meta\.env\.([A-Z_][A-Z0-9_]*)|import\.meta\.env\[['"]([A-Z_][A-Z0-9_]*)['"]]/g,
processor: (match) => {
Expand Down