diff --git a/infrastructure/zk/src/fmt.ts b/infrastructure/zk/src/fmt.ts index 4bb46dba7608..fa8b5e79691b 100644 --- a/infrastructure/zk/src/fmt.ts +++ b/infrastructure/zk/src/fmt.ts @@ -4,6 +4,10 @@ import * as utils from './utils'; const EXTENSIONS = ['ts', 'md', 'sol', 'js']; const CONFIG_PATH = 'etc/prettier-config'; +function prettierFlags(phaseName: string) { + phaseName = phaseName.replace('/', '-').replace('.', ''); + return ` --cache --cache-location node_modules/.cache/prettier/.prettier-cache-${phaseName}`; +} export async function prettier(extension: string, check: boolean = false) { if (!EXTENSIONS.includes(extension)) { throw new Error('Unsupported extension'); @@ -17,19 +21,31 @@ export async function prettier(extension: string, check: boolean = false) { return; } - await utils.spawn(`yarn --silent prettier --config ${CONFIG_PATH}/${extension}.js --${command} ${files}`); + await utils.spawn( + `yarn --silent prettier --config ${CONFIG_PATH}/${extension}.js --${command} ${files} ${prettierFlags( + extension + )} ${check ? '' : '> /dev/null'}` + ); +} + +async function prettierContracts(check: boolean, directory: string) { + await utils.spawn( + `yarn --silent --cwd ${directory} prettier:${check ? 'check' : 'fix'} ${prettierFlags(directory)} ${ + check ? '' : '> /dev/null' + }` + ); } async function prettierL1Contracts(check: boolean = false) { - await utils.spawn(`yarn --silent --cwd contracts/ethereum prettier:${check ? 'check' : 'fix'}`); + await prettierContracts(check, 'contracts/ethereum'); } async function prettierL2Contracts(check: boolean = false) { - await utils.spawn(`yarn --silent --cwd contracts/zksync prettier:${check ? 'check' : 'fix'}`); + await prettierContracts(check, 'contracts/zksync'); } async function prettierSystemContracts(check: boolean = false) { - await utils.spawn(`yarn --silent --cwd etc/system-contracts prettier:${check ? 'check' : 'fix'}`); + await prettierContracts(check, 'etc/system-contracts'); } export async function rustfmt(check: boolean = false) {