All files file.ts

100% Statements 28/28
91.67% Branches 11/12
100% Functions 8/8
100% Lines 25/25

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 341x 1x 1x   1x 103x 103x   1x 34x 30x   1x 21x 20x   1x 3x 2x   1x 2x 1x   1x 6x 12x   1x 2x 4x   1x  
import * as fs from 'fs-extra';
import {Path} from './path';
import {WritableFile} from './writable_file';
 
export class File extends WritableFile {
  constructor(public props?: ConstructorParameters<typeof WritableFile>[0] & {readonly?: boolean; forgive?: boolean}) {
    super(props);
  }
  get readonlyError(): void {
    if (this.props?.readonly) throw new Error('this file is readonly');
    return undefined;
  }
  async writeFromString(content: string) {
    this.readonlyError;
    return super.writeFromString(content);
  }
  async createFromString(content: string) {
    this.readonlyError;
    return super.createFromString(content);
  }
  async upsertFromString(content: string) {
    this.readonlyError;
    return super.upsertFromString(content);
  }
  async copy(dest: ConstructorParameters<typeof Path>[0] | Path) {
    const destPath = dest instanceof Path ? dest : new Path({cwd: this.cwd, ...dest});
    await fs.copy(this.path, destPath.path);
  }
  async move(dest: ConstructorParameters<typeof Path>[0] | Path) {
    const destPath = dest instanceof Path ? dest : new Path({cwd: this.cwd, ...dest});
    await fs.move(this.path, destPath.path);
  }
}