<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Krzysztof Kaczyński</title>
    <description>The latest articles on DEV Community by Krzysztof Kaczyński (@krzysztofkaczy9).</description>
    <link>https://dev.to/krzysztofkaczy9</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F516207%2Fffc1e16a-cff0-478e-a9fd-57fa285a7e35.jpg</url>
      <title>DEV Community: Krzysztof Kaczyński</title>
      <link>https://dev.to/krzysztofkaczy9</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/krzysztofkaczy9"/>
    <language>en</language>
    <item>
      <title>WebAssembly + Rust + TypeScript project setup</title>
      <dc:creator>Krzysztof Kaczyński</dc:creator>
      <pubDate>Sat, 16 Jan 2021 22:59:04 +0000</pubDate>
      <link>https://dev.to/krzysztofkaczy9/webassembly-rust-typescript-project-setup-4gio</link>
      <guid>https://dev.to/krzysztofkaczy9/webassembly-rust-typescript-project-setup-4gio</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;I created a repository with example project which you can find here: &lt;strong&gt;&lt;a href="https://github.com/kaczor6418/web-assembly-rust-typescript-template"&gt;web-assembly-rust-typescript-template&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What you will need:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="https://www.npmjs.com/get-npm"&gt;&lt;code&gt;npm and node.js&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="https://www.rust-lang.org/tools/install"&gt;&lt;code&gt;rust and cargo&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="https://rustwasm.github.io/wasm-pack/installer/"&gt;&lt;code&gt;wasm-pack&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href="https://webpack.js.org/"&gt;&lt;code&gt;webpack 5&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to set up project
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Set-up
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Web - TypeScript part
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Initialize npm project&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   npm init -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Install the following dependencies&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   npm i -D webpack webpack-cli webpack-dev-server html-webpack-plugin ts-loader typescript
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create &lt;em&gt;&lt;code&gt;index.js&lt;/code&gt;&lt;/em&gt; file and export your App (this will be an entry point of your application)&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;   &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./App&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create &lt;em&gt;&lt;code&gt;bootstrap.ts&lt;/code&gt;&lt;/em&gt; file in which you will import your &lt;em&gt;&lt;code&gt;index.js&lt;/code&gt;&lt;/em&gt; asynchronously. We have to load the app asynchronously because &lt;code&gt;.wasm&lt;/code&gt; files have to be loaded asynchronously&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;   &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./index&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error importing **index.ts**:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create &lt;code&gt;webpack.config.js&lt;/code&gt;. Here we have to use &lt;code&gt;experimetns: syncWebAssembly&lt;/code&gt; to load our &lt;code&gt;.wasm&lt;/code&gt; files&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;   &lt;span class="nx"&gt;experiments&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
         &lt;span class="nl"&gt;syncWebAssembly&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
       &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add &lt;code&gt;serve&lt;/code&gt; and &lt;code&gt;build&lt;/code&gt; script to your &lt;em&gt;&lt;code&gt;package.json&lt;/code&gt;&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
         &lt;/span&gt;&lt;span class="nl"&gt;"serve"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"webpack serve"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
         &lt;/span&gt;&lt;span class="nl"&gt;"build"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"webpack"&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  WebAssembly - Rust part
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;In root of your project create wasm project using &lt;code&gt;wasm-pack&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   wasm-pack new name-of-package
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Go to package directory&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ./name-of-package
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run &lt;code&gt;wasm-pack build&lt;/code&gt; to build your wasm package &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Link wasm-package with TypeScript code
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Install your wasm package (if you publish your wasm package then you can install it via &lt;code&gt;npm&lt;/code&gt;)&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   npm install wasm-package-name/pkg
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Make sure that you can find this dependecy in your &lt;em&gt;&lt;code&gt;package.json&lt;/code&gt;&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="nl"&gt;"dependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
     &lt;/span&gt;&lt;span class="nl"&gt;"wasm-package-name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"file:./wasm-package-name/pkg"&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make sure you have &lt;code&gt;"moduleResolution": "node"&lt;/code&gt; in your &lt;em&gt;&lt;code&gt;tsconfig.json&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;If you followed all those steps you should have all typing hints from your wasm-package in your typescript project&lt;/p&gt;

</description>
      <category>webassembly</category>
      <category>rust</category>
      <category>typescript</category>
      <category>webpack</category>
    </item>
    <item>
      <title>Git hook is the excellent alternative to Husky</title>
      <dc:creator>Krzysztof Kaczyński</dc:creator>
      <pubDate>Tue, 08 Dec 2020 20:17:02 +0000</pubDate>
      <link>https://dev.to/krzysztofkaczy9/do-you-really-need-husky-247b</link>
      <guid>https://dev.to/krzysztofkaczy9/do-you-really-need-husky-247b</guid>
      <description>&lt;h2&gt;
  
  
  Backstory
&lt;/h2&gt;

&lt;p&gt;Some time ago I was asked to introduce an automatization which would check if committed files fit linter rules responsible for uniform code formatting and code quality (e.g.: &lt;code&gt;eslint&lt;/code&gt;, &lt;code&gt;prettier&lt;/code&gt;, &lt;code&gt;stylelint&lt;/code&gt; e.t.c.)  &lt;/p&gt;

&lt;p&gt;After I did some research it came out that the most common way to do that is to use &lt;a href="https://github.com/typicode/husky"&gt;&lt;code&gt;husky&lt;/code&gt;&lt;/a&gt; with &lt;a href="https://github.com/okonet/lint-staged"&gt;&lt;code&gt;lint-staged&lt;/code&gt;&lt;/a&gt;. I installed and configured those tools. Everything worked as expected. If the file contained any errors which couldn't be auto-fixed by linter, committing process was interrupted and the error message was shown in the terminal. Unfortunately, this solution has one problem. Running &lt;code&gt;husky&lt;/code&gt; and &lt;code&gt;lint-staged&lt;/code&gt; takes much more time than I expected. Sometimes it even took more time than the committing process itself (including checking the files for any errors).&lt;/p&gt;

&lt;h2&gt;
  
  
  Git-hooks
&lt;/h2&gt;

&lt;p&gt;As I had some time left after I completed this task I decided that I will look for another solution. I searched a little more and I found &lt;a href="https://git-scm.com/docs/githooks"&gt;&lt;code&gt;git-hooks&lt;/code&gt;&lt;/a&gt;. I read a bit more about &lt;code&gt;git-hooks&lt;/code&gt; and it came out that &lt;code&gt;git&lt;/code&gt; offer native solution to do some custom actions at certain points in &lt;code&gt;git&lt;/code&gt; execution for example committing changes. &lt;a href="https://git-scm.com/docs/githooks#_pre_commit"&gt;&lt;code&gt;pre-commit&lt;/code&gt;&lt;/a&gt; caught my attention, which is briefly described like this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"This hook is invoked by &lt;a href="https://git-scm.com/docs/git-commit"&gt;git-commit[1]&lt;/a&gt;, and can be bypassed with the &lt;code&gt;--no-verify&lt;/code&gt; option. It takes no parameters, and is invoked before obtaining the proposed commit log message and making a commit. ..."&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;From the above text it follows, that before commit becomes submitted we have some time to execute custom operations like linting and auto-fixing staged files. All files changed in this phase can be added and included in the same commit (it means that we do not have to create a separated commit to apply changes from linters auto-fixes). After I read some about &lt;code&gt;shell&lt;/code&gt; scripting I was ready to create my first &lt;code&gt;git-hook&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;pre-commit&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/sh&lt;/span&gt;
&lt;span class="nv"&gt;RED&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\0&lt;/span&gt;&lt;span class="s2"&gt;33[1;31m"&lt;/span&gt;
&lt;span class="nv"&gt;GREEN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\0&lt;/span&gt;&lt;span class="s2"&gt;33[1;32m"&lt;/span&gt;
&lt;span class="nv"&gt;NC&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\0&lt;/span&gt;&lt;span class="s2"&gt;33[0m"&lt;/span&gt;
&lt;span class="nv"&gt;linter_exit_code&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1
&lt;span class="nv"&gt;all_ts_files&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;git diff &lt;span class="nt"&gt;--cached&lt;/span&gt; &lt;span class="nt"&gt;--diff-filter&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;d &lt;span class="nt"&gt;--name-only&lt;/span&gt; | &lt;span class="nb"&gt;grep&lt;/span&gt; .ts&lt;span class="nv"&gt;$)&lt;/span&gt;
&lt;span class="nv"&gt;all_scss_files&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;git diff &lt;span class="nt"&gt;--cached&lt;/span&gt; &lt;span class="nt"&gt;--diff-filter&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;d &lt;span class="nt"&gt;--name-only&lt;/span&gt; | &lt;span class="nb"&gt;grep&lt;/span&gt; .scss&lt;span class="nv"&gt;$)&lt;/span&gt;
./node_modules/.bin/eslint &lt;span class="nv"&gt;$all_ts_files&lt;/span&gt; &lt;span class="nt"&gt;--quiet&lt;/span&gt; &lt;span class="nt"&gt;--fix&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; ./node_modules/.bin/stylelint &lt;span class="nv"&gt;$all_scss_files&lt;/span&gt; &lt;span class="nt"&gt;--stdin&lt;/span&gt; &lt;span class="nt"&gt;--quiet&lt;/span&gt; &lt;span class="nt"&gt;--fix&lt;/span&gt;
&lt;span class="nv"&gt;linter_exit_code&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$?&lt;/span&gt;
git add &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="nv"&gt;$all_ts_files&lt;/span&gt; &lt;span class="nv"&gt;$all_scss_files&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;$linter_exit_code&lt;/span&gt; &lt;span class="nt"&gt;-ne&lt;/span&gt; 0 &lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;then
  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;RED&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; ❌ Linter errors have occurred ( ͡ಥ ͜ʖ ͡ಥ)&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;NC&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="nb"&gt;exit &lt;/span&gt;1
&lt;span class="k"&gt;else
  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GREEN&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; ✔ Eslint and Stylelint did not find any errors [̲̅&lt;/span&gt;&lt;span class="nv"&gt;$̲&lt;/span&gt;&lt;span class="s2"&gt;̅(̲̅ ͡° ͜ʖ ͡°̲̅)̲̅&lt;/span&gt;&lt;span class="nv"&gt;$̲&lt;/span&gt;&lt;span class="s2"&gt;̅]&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;NC&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="nb"&gt;exit &lt;/span&gt;0
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What is going on in above code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;git diff --cached --diff-filter=d --name-only | grep .ts$&lt;/code&gt;&lt;/strong&gt; → we are collecting all staged files, then we are filtering out deleted ones (if you do not do that your linter will throw an error for those files because this linter won't be able to resolve paths for deleted files) then I am using &lt;code&gt;grep&lt;/code&gt; to take only files which I am interested in. In my case, I am collecting &lt;code&gt;.ts&lt;/code&gt; files for &lt;code&gt;eslint&lt;/code&gt; and &lt;code&gt;.scss&lt;/code&gt; for stylelint,&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;linter_exit_code=$?&lt;/code&gt;&lt;/strong&gt; → save &lt;em&gt;exit code&lt;/em&gt; of last executed action(&lt;code&gt;0&lt;/code&gt; in case no errors or errors that can be auto-fixed by linter or &lt;code&gt;1&lt;/code&gt; in case of errors not fixable by linters)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;git add -f $all_ts_files $all_scss_files&lt;/code&gt;&lt;/strong&gt; → add files auto-fixed by linters. We need to use &lt;code&gt;-f&lt;/code&gt; flag to force &lt;code&gt;git add&lt;/code&gt; in case of &lt;code&gt;$all_ts_files&lt;/code&gt; and &lt;code&gt;$all_scss_files&lt;/code&gt; are empty&lt;/li&gt;
&lt;li&gt;At the end of this script I am displaying proper information basing on &lt;em&gt;exit code&lt;/em&gt; value&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After we create a &lt;code&gt;git-hook&lt;/code&gt; we have to remember to update &lt;code&gt;git&lt;/code&gt; configuration or create a symlink between &lt;code&gt;git&lt;/code&gt; configuration and created &lt;code&gt;git-hook&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;git&lt;/code&gt; command (should work for every operating system)&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config core.hooksPath ./git-hooks
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;symlink (Linux)&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ln -s -f ../../git-hooks/pre-commit .git/hooks/pre-commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is worth to add above scripts to &lt;code&gt;npm postinstall&lt;/code&gt;, because of that every developer which will clone our repository and run &lt;code&gt;npm install&lt;/code&gt; script will also configure &lt;code&gt;git-hooks&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Using &lt;code&gt;git-hooks&lt;/code&gt; instead of &lt;code&gt;husky&lt;/code&gt; and &lt;code&gt;lint-staged&lt;/code&gt; came out to be an excellent idea because committing time was sped up about twice. In addition, I got rid of two additional dependencies in the project, what can become very useful &lt;del&gt;especially in case of &lt;code&gt;husky&lt;/code&gt; because from &lt;code&gt;Husky 5&lt;/code&gt; documentation we can find out that &lt;code&gt;Husky 5&lt;/code&gt; will be &lt;a href="https://typicode.github.io/husky/#/"&gt;&lt;strong&gt;free only for open-source projects&lt;/strong&gt;&lt;/a&gt;&lt;/del&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Seven steps to set up &lt;code&gt;git-hooks&lt;/code&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;In project directory create &lt;em&gt;&lt;code&gt;git-hooks&lt;/code&gt;&lt;/em&gt; directory&lt;/li&gt;
&lt;li&gt;Go to &lt;em&gt;&lt;code&gt;.git/hooks&lt;/code&gt;&lt;/em&gt; directory&lt;/li&gt;
&lt;li&gt;From the name of hook which you want to use remove &lt;code&gt;.sample&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Move this hook into created &lt;em&gt;&lt;code&gt;git-hooks&lt;/code&gt;&lt;/em&gt; directory&lt;/li&gt;
&lt;li&gt;Create your &lt;code&gt;git-hook&lt;/code&gt; body&lt;/li&gt;
&lt;li&gt;Update &lt;code&gt;git&lt;/code&gt; configuration or create a symlink from &lt;em&gt;&lt;code&gt;git-hooks&lt;/code&gt;&lt;/em&gt; to &lt;em&gt;&lt;code&gt;.git/hooks&lt;/code&gt;&lt;/em&gt; directory&lt;/li&gt;
&lt;li&gt;Add the appropriate script to &lt;code&gt;npm postinstall&lt;/code&gt; command &lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Simple example
&lt;/h2&gt;

&lt;p&gt;I prepared a simple repository &lt;a href="https://github.com/kaczor6418/git-hooks-example/tree/master"&gt;git-hooks-example&lt;/a&gt; to prove that those &lt;code&gt;git-hooks&lt;/code&gt; will work on &lt;code&gt;Linux&lt;/code&gt; / &lt;code&gt;Windows&lt;/code&gt; / &lt;code&gt;Mac&lt;/code&gt;. In &lt;code&gt;Redme.md&lt;/code&gt; I wrote how you can test this &lt;code&gt;pre-commit&lt;/code&gt; hook.&lt;/p&gt;

</description>
      <category>git</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
