diff --git a/yarn-project/package.json b/yarn-project/package.json index 041dcde0235..9769892147b 100644 --- a/yarn-project/package.json +++ b/yarn-project/package.json @@ -6,7 +6,7 @@ "prepare": "node ./yarn-project-base/scripts/update_package_jsons.mjs && yarn workspaces foreach run prepare && workspaces-to-typescript-project-references --tsconfigPath tsconfig.json && prettier -w */tsconfig.json", "prepare:check": "node ./yarn-project-base/scripts/update_package_jsons.mjs --check && workspaces-to-typescript-project-references --check --tsconfigPath tsconfig.json", "docs": "typedoc --out docs/dist && cd docs && yarn serve", - "formatting": "FORCE_COLOR=true yarn workspaces foreach -p -j unlimited -v run formatting", + "formatting": "./run_nargo_fmt.sh --check && FORCE_COLOR=true yarn workspaces foreach -p -j unlimited -v run formatting", "formatting:fix": "./run_nargo_fmt.sh && FORCE_COLOR=true yarn workspaces foreach -p -v run formatting:fix", "lint": "yarn eslint --cache --ignore-pattern l1-artifacts .", "format": "yarn prettier --cache -w .", diff --git a/yarn-project/run_nargo_fmt.sh b/yarn-project/run_nargo_fmt.sh index 253b53e7ede..03642a32a23 100755 --- a/yarn-project/run_nargo_fmt.sh +++ b/yarn-project/run_nargo_fmt.sh @@ -1,6 +1,23 @@ -#!/bin/bash +#!/usr/bin/env bash -nargo_executable="$(git rev-parse --show-toplevel)/noir/target/release/nargo" +# Note: This script formats the files multiple times when the given project is included in a workspace. +# Tackling this became a time sink, so I decided to leave it as is for now. + +set -eu + +# We set the executable path as if we were in CI +nargo_executable="/usr/src/noir/target/release/nargo" + +# Check if nargo_executable exists and is executable +if [ ! -x "$nargo_executable" ]; then + # If not, we try to set a nargo path as if the script was run locally + nargo_executable="$(git rev-parse --show-toplevel)/noir/target/release/nargo" + + if [ ! -x "$nargo_executable" ]; then + echo "Error: nargo executable not found" + exit 1 + fi +fi # Find all Nargo.toml files and run 'nargo fmt' find . -name "Nargo.toml" | while read -r file; do