The library allows to modify the AST before executing Prettier.
const { hooks } = require('prettier-hook');
function parse(ast) {
// modify AST
return ast;
}
hooks.typescript.addHook(parse);
npx prettier-hook --require <filepath>
// or
yarn prettier-hook --require <filepath>
There is an example which is converting require to import.
// examples/simple/test.js
const fs = require('fs');
$ DEBUG=1 yarn ts-node dist/bin/prettier-hook.js --require examples/simple/index.ts examples/simple/test.js
// examples/simple/test.js
import * as fs from 'fs';