Add pre-commit and ./fmt.sh --test checks for yarn.lock file (#18112)

* Add yarn-lock-check pre-commit check

* Invoke yarn-lock-check pre-commit check from './fmt.sh --test'

* Run yarn-lock-check when yarn.lock changes
This commit is contained in:
Moisés Ackerman 2024-01-10 10:16:09 +01:00 committed by GitHub
parent da51efa1d1
commit 53372e3795
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 0 deletions

View File

@ -51,6 +51,12 @@ repos:
language: system
pass_filenames: false
entry: "pre-commit/platform-independence-check.sh"
- id: yarn-lock-check
name: yarn-lock-check
language: system
pass_filenames: false
files: ^(package.json|yarn.lock)$
entry: "pre-commit/yarn-lock-check.sh"
- id: mainonly
name: main only
description: Check for changes under packages with targets tagged with main-only

7
fmt.sh
View File

@ -129,6 +129,13 @@ echo "\
──██────▐█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█▌
"
# In 'test' mode, this checks that the 'yarn.lock' file doesn't need any changes.
# In 'format' mode, the 'yarn.lock' file will be updated ("formatted") by
# 'yarn install' below, if needed.
if [[ $is_test = 1 ]]; then
run pre-commit run yarn-lock-check
fi
# Make sure the current packages are installed so we can call pprettier
# via yarn because calling it via bazel results in very bad performance.
run yarn install --silent

16
pre-commit/yarn-lock-check.sh Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env bash
# Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
set -euo pipefail
TMP_DIR=$(mktemp -d)
cp package.json yarn.lock $TMP_DIR
(cd $TMP_DIR; yarn install --silent > /dev/null)
if ! diff yarn.lock $TMP_DIR/yarn.lock; then
echo "FAIL: yarn.lock could not satisfy package.json" 1>&2
echo "FAIL: yarn.lock requires all of the above changes" 1>&2
exit 1
fi