All files / core/src/dotenv source.ts

100% Statements 6/6
100% Branches 2/2
100% Functions 4/4
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40                    5x   5x         5x       1x       1x       1x                    
import path from 'node:path';
import { KeyInfo } from '../types';
import { SourceModule } from '../modules';
import { read, readSync } from './utils/dotenv';
 
export class DotEnvSourceModule extends SourceModule {
  private options: Omit<DotEnvSourceModule.Options, keyof SourceModule.Options>;
  private keyInfos: KeyInfo[];
 
  constructor({ targets, prefix, file, ...options }: DotEnvSourceModule.Options) {
    super({ targets, prefix });
 
    this.options = {
      ...options,
      file: path.isAbsolute(file) ? file : path.join(process.cwd(), file),
    };
 
    this.keyInfos = readSync(this.options.file, this.options.properties);
  }
 
  get name(): string {
    return 'dotenv';
  }
 
  get originalKeyInfos(): KeyInfo[] {
    return this.keyInfos;
  }
 
  async source(): Promise<KeyInfo[]> {
    return await read(this.options.file, this.options.properties);
  }
}
 
export namespace DotEnvSourceModule {
  export type Options = {
    file: string;
    properties?: string[];
  } & SourceModule.Options;
}