Проблема с путями до файла

Рейтинг: 0Ответов: 0Опубликовано: 13.08.2023

Файлы лежат в папке fixtures, при выполнении команды: gendiff __fixtures__/file1.json __fixtures__/file2.json утилита работает исправно, но когда пытаюсь выполнить gendiff file1.json file2.json выскакивает ошибка Error: ENOENT: no such file or directory, вот код из index.js где прописаны пути до файла:

import path from 'path';
import fs from 'fs';
import parse from './parsers.js';
import ast from './format/index.js';
import compare from './build.js';

const getPath = (filename) => path.resolve(process.cwd(), filename);

const getFileFormat = (filename) => path.extname(filename).slice(1);

const readFile = (filepath) => fs.readFileSync(filepath, 'utf8');

const getDiff = (file1, file2, formatName = 'stylish') => {
  const path1 = getPath(file1);
  const data1 = parse(readFile(path1), getFileFormat(file1));

  const path2 = getPath(file2);
  const data2 = parse(readFile(path2), getFileFormat(file2));

  const diff = compare(data1, data2);
  const formattedDiff = ast(diff, formatName);
  return formattedDiff;
};

export default getDiff;

Ответы

Ответов пока нет.