A npm package to increase the developer experience and consistency by providing a set of hooks that can be opted-in the development lifecycle.

Overview

@jeliasson/husky-hooks

Libraries.io dependency status for latest release, scoped npm package GitHub issues NPM npm npm bundle size

This npm package aims to increase the developer experience and consistency by providing a set of hooks that can be opted-in the development lifecycle. It depends on husky for pre-commit and pre-push hooks, and a few other zero/low dependency packages.

⚠️ Note: This package is in development and comes with breaking changes, so move with caution.

Setup

First, make sure you have husky installed. See installation here or refer to below quick setup.

# Install husky dependency
yarn add --dev husky

# Install husky
yarn husky install

Once you have husky installed, let's proceed with setting up @jeliasson/husky-hooks and connect it with husky's pre-commit and pre-push hooks.

# Install dependency @jeliasson/husky-hooks
yarn add --dev @jeliasson/husky-hooks

# Add package pre-commit hook
npx husky add .husky/pre-commit "npx @jeliasson/husky-hooks pre-commit"

# Add package pre-push hook
npx husky add .husky/pre-push "npx @jeliasson/husky-hooks pre-push"

Now to create a config file. husky-hooks.config.js will be placed in the root folder of the project.

# Create config
npx @jeliasson/husky-hooks create-config

Let's test it out and see if we get some magic

# Make a new branch, create a test file, git add and commit
git checkout -b testing/jeliasson-husky-hooks
touch test.tmp && git add test.tmp
git commit -m "test(repo): keep calm and commit"

This should yield the following output...

Running hook test-sleep... ✅
Running hook check-branch... ✅
Running hook check-lock-files... ✅
Running hook run with argument 'echo Test'... ✅

...unless you have anything other than yarn.lock in your repo 😅

Running hook test-sleep... ✅
Running hook check-branch... ✅
Running hook check-lock-files... ❌

Invalid occurence of "package-lock.json" file. Remove it and only use "yarn.lock"

Hooks

Hooks to run is defined in the configuration file husky-hooks.config.js that was created as part of the setup. Below is a table of available built-in hooks, followed by it's respective specific configuration. Future hooks may be created that require additional dev dependencies, not included in this package, but those will be marked.

Name Description
check-branch Check which git branch we're currently on, and abort if it's a protected branch.
check-lock-files Check for package manager lock files, and abort if any are present lock file that we don't want.
run-cmd Run a ad-hoc command, and abort if the commands fails.

check-branch

Check which git branch we're currently on, and abort if it's a protected branch. This can be useful to make sure that commits stay away from branches that only being used for Pull Requests or CI/CD.

Setup

Add check-branch hook to pre-commit and/or pre-push.

{
  hooks: {
    'pre-commit': [
      'check-branch', /* This line */
      ...
    ],

    'pre-push': [
      'check-branch', /* This line */
      ...
    ],
  },
}

Settings

{
  settings: {
    'check-branch': {
      // Git branches that should be protected from accidental commit or push
      protectedBranches: ['main', 'dev'],
    },
  }
}

check-lock-files

Check for package manager lock files, and abort if any are present lock file that we don't want. This is useful to ensure that e.g. onlyyarn.lock is present in the repository.

Setup

Add check-lock-files hook to pre-commit and/or pre-push.

{
  hooks: {
    'pre-commit': [
      'check-lock-files', /* This line */
      ...
    ],

    'pre-push': [
      'check-lock-files', /* This line */
      ...
    ],
  },
}

Settings

{
  settings: {
    'check-lock-files': {
      // Package manager lock file that should be present in the repository
      allowLockFile: 'yarn.lock',

      // Package manager lock files that should yield a abort
      denyLockFiles: ['package-lock.json', 'pnpm-lock.yaml'],
    },
  }
}

run-cmd

Run a ad-hoc command, for example yarn lint, and abort if the commands fails. This can be useful if you have other commands, for exmaple in your husky hooks, that you want to run as part of this package.

⚠️ Note: Still figuring out the best approach to capture stdout/stderr and present them where appropriate. It works fine for now.

Setup

Add run-cmd hooks to pre-commit and/or pre-push. It should be shaped as an array where the first argument is run-cmd and the second argument would be the command to run, e.g. yarn lint. In below example we have two ad-hoc commands for each hook.

{
  hooks: {
    'pre-commit': [
      ['run-cmd', 'echo This is a pre-commit hook via run-cmd'],
      ['run-cmd', 'yarn lint'],
      ...
    ],

    'pre-push': [
      ['run-cmd', 'echo This is a pre-push hook via run-cmd'],
      ['run-cmd', 'yarn lint'],
      ...
    ],
  },
}

Other

Print output

Sometimes you may want to print the actual output of a hook, and passing --stdout will print the stdout of all hooks.

npx @jeliasson/husky-hooks pre-commit --stdout

Development

Prerequisites

  • NodeJS >= 14
  • yarn

From the package directory, run

yarn link

Start tsc watch

yarn dev

From the test project directory, run

yarn link @jeliasson/husky-hooks

Todo

See Issues

Contributing

See CONTRIBUTING ❤️

Comments
Releases(0.3.2)
  • 0.3.2(Sep 24, 2022)

    🧾 Summary

    Fixing issue with hook check-look-files used hard-coded values rather than reading from config.

    ✨ Significant changes

    • fix(hook): fixing check-lock-files in https://github.com/jeliasson/npm-husky-hooks/pull/74

    💥 Breaking changes

    No reports

    Full Changelog: https://github.com/jeliasson/npm-husky-hooks/compare/0.3.1...0.3.2

    Source code(tar.gz)
    Source code(zip)
  • 0.3.1(Sep 12, 2022)

    🧾 Summary

    Bumping dependencies and adding auto merge strategy, updating CI testing and minor docs updates.

    ✨ Significant changes

    • feat(deps): automerge strategy and label in https://github.com/jeliasson/npm-husky-hooks/pull/66

    💥 Breaking changes

    No reports

    Full Changelog: https://github.com/jeliasson/npm-husky-hooks/compare/0.3.0...0.3.1

    Source code(tar.gz)
    Source code(zip)
  • 0.3.0(Jun 5, 2022)

    🧾 Summary

    Replacing yargs with commander, using zod for config parsing, bumping dev dependencies and general refactoring.

    ✨ Significant changes

    • docs(repo): moving todo to Issues in https://github.com/jeliasson/npm-husky-hooks/pull/47
    • feat(repo): replacing yargs with commander in https://github.com/jeliasson/npm-husky-hooks/pull/46
    • feat(config): adding initial zod config schema w/ parsing in https://github.com/jeliasson/npm-husky-hooks/pull/50

    Full Changelog: https://github.com/jeliasson/npm-husky-hooks/compare/0.2.1...0.3.0

    💥 Breaking changes

    No reports

    Source code(tar.gz)
    Source code(zip)
  • 0.2.1(Jun 4, 2022)

    🧾 Summary

    Bumping dev dependencies, adding CI workflows and minor docs updates.

    ✨ Significant changes

    • feat(ci): adding initial ci workflows in https://github.com/jeliasson/npm-husky-hooks/pull/41

    Full Changelog: https://github.com/jeliasson/npm-husky-hooks/compare/0.2.0...0.2.1

    💥 Breaking changes

    No reports

    Source code(tar.gz)
    Source code(zip)
  • 0.2.0(Jun 3, 2022)

    🧾 Summary

    This release adds hook run-cmd, minor refactoring and use of dev branch.

    ✨ Significant changes

    • feat(hook): adding hook run-cmd in https://github.com/jeliasson/npm-husky-hooks/pull/21
    • cleanup(repo): general refactoring in https://github.com/jeliasson/npm-husky-hooks/pull/16 https://github.com/jeliasson/npm-husky-hooks/pull/19 https://github.com/jeliasson/npm-husky-hooks/pull/23
    • deps(repo): updating renovate bot target branch in https://github.com/jeliasson/npm-husky-hooks/pull/18
    • feat(repo): adding husky-hook config in https://github.com/jeliasson/npm-husky-hooks/pull/22

    Full Changelog: https://github.com/jeliasson/npm-husky-hooks/compare/0.1.3...0.2.0

    💥 Breaking changes

    No reports

    Source code(tar.gz)
    Source code(zip)
  • 0.1.3(May 31, 2022)

    What's Changed

    • feat(repo): 0.1.3 in https://github.com/jeliasson/npm-husky-hooks/pull/8

    Full Changelog: https://github.com/jeliasson/npm-husky-hooks/compare/0.1.2...0.1.3

    Source code(tar.gz)
    Source code(zip)
  • 0.1.2(May 26, 2022)

    What's Changed

    • feat(repo): 0.1.2 in https://github.com/jeliasson/npm-husky-hooks/pull/5

    Full Changelog: https://github.com/jeliasson/npm-husky-hooks/compare/0.1.1...0.1.2

    Source code(tar.gz)
    Source code(zip)
  • 0.1.1(May 25, 2022)

    What's Changed

    • feat(repo): minor post-release 0.1.0 fixes in https://github.com/jeliasson/npm-husky-hooks/pull/4
    • feat(repo): 0.1.1 in https://github.com/jeliasson/npm-husky-hooks/pull/4

    Full Changelog: https://github.com/jeliasson/npm-husky-hooks/compare/0.1.0...0.1.1

    Source code(tar.gz)
    Source code(zip)
  • 0.1.0(May 25, 2022)

Owner
Johan Eliasson
A king without a kingdom. End of random quote.
Johan Eliasson
:fire: A highly scalable, offline-first foundation with the best developer experience and a focus on performance and best practices.

Start your next react project in seconds A highly scalable, offline-first foundation with the best DX and a focus on performance and best practices Cr

react-boilerplate 28.9k Jan 6, 2023
Developer Dao FM is where you can chill and listen to Lofi music while building cool stuff!

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

Developer DAO 9 Jul 21, 2022
Recipe providing mobile app, User selects ingredients in pantry and is then provided recipes for those ingredients. App contains a signup/login, meal planner and grocery list pages.

Recipog Student Information Name Connor de Bruyn Username Destiro Assignment SWEN325 A2 Description “Recipog” is a recipe providing app that allows th

Connor de Bruyn 1 Dec 26, 2021
Further split the React Native code based on Metro build to improve performance, providing `Dll` and `Dynamic Imports` features

React-Native Code Splitting Further split the React Native code based on Metro build to improve performance, providing Dll and Dynamic Imports feature

Wuba 126 Dec 29, 2022
The CryptoVerse is a Cryptocurrency web application developed using Reactjs for providing the latest updates, value statistics, market cap, supply and news regarding the Cryptocurrency market.

CryptoVerse - A Crptocurrency Web Application Getting Started with Create React App This project was bootstrapped with Create React App. Available Scr

Eesha Srivastava 5 Oct 26, 2022
Utilities library built on top of Next.js providing feature extensions and helpers for common patterns

nextjs-utilites This library provides many helpful utilities for use in Next.js projects. Prerequisites This project requires NodeJS (version 8 or lat

Snehil K 5 Sep 7, 2022
⚛️ Hooks for building fast and extendable tables and datagrids for React

Hooks for building lightweight, fast and extendable datagrids for React Enjoy this library? Try them all! React Query, React Form, React Charts Visit

Tanner Linsley 20.3k Jan 3, 2023
Drop-in replacements for @apollo/client's useQuery, useMutation and useSubscription hooks with reduced overhead and additional functionality.

apollo-augmented-hooks Drop-in replacements for @apollo/client's useQuery, useMutation and useSubscription hooks with reduced overhead and additional

appmotion Devs 57 Nov 18, 2022
Fast, tiny and solid hooks system for Javascript and Node.js

Uncino ?? Fast, tiny and solid hooks system for Javascript and NodeJS Uncino is italian word for hook Do you know Wordpress hooks system? Uncino is a

Riccardo Tartaglia 201 Dec 7, 2022
Providing accessible components with Web Components & Material You

tiny-material Still on developing, DO NOT use for production environment Run well on Google Chrome, Firefox, Chrome for Android, Microsoft Edge (Chrom

HugePancake 11 Dec 31, 2022
⚛️ Hooks for fetching, caching and updating asynchronous data in React

Hooks for fetching, caching and updating asynchronous data in React Enjoy this library? Try the entire TanStack! React Table, React Form, React Charts

Tanner Linsley 32.1k Jan 9, 2023
Fully typed hooks and utility functions for the React Native StyleSheet API

react-native-style-utilities Fully typed hooks and utility functions for the React Native StyleSheet API npm i react-native-style-utilities ESLint Set

Marc Rousavy 73 Dec 17, 2022
Built a covid-19 trcaker app using React.js implementing hooks and materail UI

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

Aditya Dond 1 Dec 21, 2021
Add multiplayer presence (live cursors/avatars) to your react application using yjs and hooks

y-presence Easy way to add presence (live cursors/avatars) to any react application using react hooks. Installation yarn add y-presence # or npm i y-p

Nimesh Nayaju 126 Dec 29, 2022
preact.js with hooks and ES2021, without compilers

naked preact preact.js with hooks, without compilers Web development should be simple. No compilers, just ES2021 and preact+hooks. See comments in the

Oleksandr Nikitin 3 Jun 16, 2022
React components and hooks for creating VR/AR applications with @react-three/fiber

@react-three/xr React components and hooks for creating VR/AR applications with @react-three/fiber npm install @react-three/xr These demos are real,

Poimandres 1.4k Jan 4, 2023
React Hooks — 👍

Collaborative editing for your app. Support on Kickstarter! ?? react-use Collection of essential React Hooks. Port of libreact. Translations: ???? 汉语

Vadim Dalecky 34.9k Jan 3, 2023
📋 React Hooks for forms validation (Web + React Native)

English | 繁中 | 简中 | 日本語 | 한국어 | Français | Italiano | Português | Español | Русский | Deutsch | Türkçe Features Built with performance and DX in mind

React Hook Form 32.4k Dec 29, 2022
React Hooks library for remote data fetching

Introduction swr.vercel.app SWR is a React Hooks library for remote data fetching. The name “SWR” is derived from stale-while-revalidate, a cache inva

Vercel 25.2k Jan 4, 2023