function getRelativePath(filenameOrURL) { const dir = Path.join(Path.resolve(), 'x').slice(0, -1); const filename = filenameOrURL.startsWith('file://') ? fileURLToPath(filenameOrURL) : filenameOrURL; // Change path to relative, if possible if (filename.indexOf(dir) === 0) { return filename.slice(dir.length); } return filename; }