From a9462533de7a0b6448037c3146b4148adee7a982 Mon Sep 17 00:00:00 2001 From: Gustavo Perdomo Date: Sat, 14 Oct 2023 11:58:00 -0300 Subject: [PATCH] chore: updated git hooks scripts --- .husky/commit-msg | 2 +- .husky/pre-commit | 4 ++-- package.json | 2 +- .../{check-lock-files.js => check-lock-files.mjs} | 11 ++++++----- 4 files changed, 10 insertions(+), 9 deletions(-) rename tools/scripts/{check-lock-files.js => check-lock-files.mjs} (75%) diff --git a/.husky/commit-msg b/.husky/commit-msg index 1a089f45..b5676766 100755 --- a/.husky/commit-msg +++ b/.husky/commit-msg @@ -1,4 +1,4 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" -npx --no-install commitlint --edit $1 +npx --no -- commitlint --edit "$1" diff --git a/.husky/pre-commit b/.husky/pre-commit index 9d50c12c..f59a1ab8 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,6 +1,6 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" -npx validate-branch-name -r "^(master|main|develop){1}$|^(feature|fix|hotfix|release|renovate)/.+$" +npx --no -- validate-branch-name -r "^(master|main|develop){1}$|^(feature|fix|hotfix|release|renovate)/.+$" +npx --no -- lint-staged npm run check-lock-files -npx --no-install lint-staged --concurrent false \ No newline at end of file diff --git a/package.json b/package.json index 3a91b208..f9cccda4 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "license": "MIT", "scripts": { "commit": "cz", - "check-lock-files": "node ./tools/scripts/check-lock-files.js", + "check-lock-files": "node ./tools/scripts/check-lock-files.mjs", "prepare": "is-ci || husky install" }, "private": true, diff --git a/tools/scripts/check-lock-files.js b/tools/scripts/check-lock-files.mjs similarity index 75% rename from tools/scripts/check-lock-files.js rename to tools/scripts/check-lock-files.mjs index 2011beea..8b15732e 100644 --- a/tools/scripts/check-lock-files.js +++ b/tools/scripts/check-lock-files.mjs @@ -1,6 +1,6 @@ -const { readFileSync, existsSync } = require('node:fs'); +import { existsSync, readFileSync } from 'node:fs'; -function checkLockFiles() { +async function checkLockFiles() { const errors = []; if (existsSync('yarn.lock')) { errors.push('Invalid occurence of "yarn.lock" file. Please remove it and use only "package-lock.json"'); @@ -16,8 +16,7 @@ function checkLockFiles() { ); } - // eslint-disable-next-line global-require - const packageJson = require('../../package-lock.json'); + const { default: packageJson } = await import('../../package-lock.json', { assert: { type: 'json' } }); if (packageJson.lockfileVersion !== 3) { errors.push( @@ -30,11 +29,13 @@ function checkLockFiles() { return errors; } -const invalid = checkLockFiles(); +console.log('🔒🔒🔒 Validating lock files 🔒🔒🔒\n'); +const invalid = await checkLockFiles(); if (invalid.length > 0) { invalid.forEach((e) => console.log(e)); process.exit(1); } else { + console.log('Lock file is valid 👍'); process.exit(0); }