From 4a9899fe6d7de017562678f43f4b2e2293c876e6 Mon Sep 17 00:00:00 2001 From: tomg10 Date: Fri, 17 Nov 2023 17:55:19 +0100 Subject: [PATCH 1/2] feat: prettier using cache and output about changed files redirected to /dev/null --- infrastructure/zk/src/fmt.ts | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/infrastructure/zk/src/fmt.ts b/infrastructure/zk/src/fmt.ts index 4bb46dba7608..7da7013ccd97 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) { From 62a4deb463fb6e8b657c8639ef2850d87cc3a69f Mon Sep 17 00:00:00 2001 From: tomg10 Date: Fri, 17 Nov 2023 18:07:28 +0100 Subject: [PATCH 2/2] fix: removed space --- infrastructure/zk/src/fmt.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infrastructure/zk/src/fmt.ts b/infrastructure/zk/src/fmt.ts index 7da7013ccd97..fa8b5e79691b 100644 --- a/infrastructure/zk/src/fmt.ts +++ b/infrastructure/zk/src/fmt.ts @@ -37,7 +37,7 @@ async function prettierContracts(check: boolean, directory: string) { } async function prettierL1Contracts(check: boolean = false) { - await prettierContracts(check, ' contracts/ethereum'); + await prettierContracts(check, 'contracts/ethereum'); } async function prettierL2Contracts(check: boolean = false) {