Another utility that I am bound to reuse between open-source projects. (I'll consider making a package combining my shared utilities in due time.) Here is the code with JSDoc comments:
export const getSourceCodeFromFilePath = (
absolutePath,
{ languageOptions = typeScriptAndJSXCompatible, linter = new Linter() } = {}
) => {
const text = fs.readFileSync(absolutePath, "utf8");
linter.verify(text, { languageOptions });
const sourceCode = linter.getSourceCode();
if (!sourceCode) return null;
else return sourceCode;
};