Skip to content

Commit 37ec01e

Browse files
authored
fix: refactored post-install to a bin call, fixed wrong namings (#847)
1 parent e8afd0d commit 37ec01e

12 files changed

+3447
-738
lines changed

.lintstagedrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const config = require("./packages/lint-staged-config");
1+
const config = require("./packages/lint-staged-config/dist");
22

33
module.exports = {
44
...config,
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"extends": "@anolilab/semantic-release-preset/npm"
2+
"extends": "@anolilab/semantic-release-preset/pnpm"
33
}

packages/lint-staged-config/README.md

+43-15
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<h1>Shareable Lint-Staged Config</h1>
44

5-
Package that contains shareable configuration for [lint-staged](https://github.com/okonet/lint-staged) — a popular tool for running linters on staged Git files.
5+
Package that contains shareable configuration for [lint-staged][lint-staged] / [nano-staged][nano-staged] — a popular tool for running linters on staged Git files.
66

77
And optionally for [husky](https://github.com/typicode/husky) — a popular choice for configuring git hooks.
88

@@ -24,19 +24,21 @@ And optionally for [husky](https://github.com/typicode/husky) — a popular choi
2424

2525
Simplify your project setup with our comprehensive collection of preconfigured configuration files.
2626
Designed for effortless integration, these ready-to-use files can be seamlessly imported into your projects.
27-
These functions streamline the utilization of [lint-staged](https://github.com/okonet/lint-staged) alongside popular tools such as [ESLint](https://eslint.org), [Prettier](https://prettier.io), [StyleLint](https://stylelint.io) and [SecretLint](https://github.com/secretlint/secretlint).
27+
These functions streamline the utilization of [lint-staged][lint-staged] / [nano-staged][nano-staged] alongside popular tools such as [ESLint](https://eslint.org), [Prettier](https://prettier.io), [StyleLint](https://stylelint.io) and [SecretLint](https://github.com/secretlint/secretlint).
2828

2929
Say goodbye to complex configurations and enjoy a smoother development experience with our all-inclusive package.
3030

3131
## Purpose
3232

33-
- Enhance your development workflow with hassle-free and readily shareable lint-staged configuration files.
33+
- Enhance your development workflow with hassle-free and readily shareable lint-staged / nano-staged configuration files.
3434
- These files empower developers to maintain a uniform coding style and detect prevalent errors even before they are added to the source control system.
3535
- Additionally, our inclusive helper module offers convenient utility functions that seamlessly integrate lint-staged with popular linting and formatting tools.
3636

3737
## Install
3838

3939
```bash
40+
npm install --dev-save @anolilab/lint-staged-config nano-staged
41+
// or
4042
npm install --dev-save @anolilab/lint-staged-config lint-staged
4143

4244
Optional:
@@ -45,6 +47,8 @@ npm install --dev-save husky is-ci
4547
```
4648

4749
```sh
50+
yarn add -D @anolilab/lint-staged-config nano-staged
51+
// or
4852
yarn add -D @anolilab/lint-staged-config lint-staged
4953

5054
Optional:
@@ -53,6 +57,8 @@ yarn add -D husky is-ci
5357
```
5458

5559
```sh
60+
pnpm add -D @anolilab/lint-staged-config nano-staged
61+
// or
5662
pnpm add -D @anolilab/lint-staged-config lint-staged
5763

5864
Optional:
@@ -62,22 +68,28 @@ pnpm add -D husky is-ci
6268

6369
## Usage
6470

65-
If you don’t have a `.lintstagedrc.js`, we will create the file for you after installing `@anolilab/lint-staged-config`.
71+
If you don’t have a `.lintstagedrc.js` or `.nano-staged.js`, we can create the file for you after installing `@anolilab/lint-staged-config`, call `pnpm lint-stage-config:install`.
6672

67-
If you already have a `.lintstagedrc.js`, then you can extend the `.lintstagedrc.js`, with `@anolilab/lint-staged-config`.
73+
If you already have a `.lintstagedrc.js` or `.nano-staged.js`, then you can extend the `.lintstagedrc.js` or `.nano-staged.js`, with `@anolilab/lint-staged-config`.
6874

69-
> Note: If the script detects an existing `.lintstagedrc.js` file, it will not overwrite it.
75+
> Note: If the script detects an existing `.lintstagedrc.js` or `.nano-staged.js` file, it will not overwrite it.
7076
71-
> Note: It can happen that the postinstall script don't run, then you have to add the `.lintstagedrc.js` manually.
72-
73-
The content of the `.lintstagedrc.js` should look like this:
77+
The content of the `.lintstagedrc.js` or `.nano-staged.js` should look like this:
7478

7579
```js
7680
const config = require("@anolilab/lint-staged-config");
7781

7882
module.exports = {
7983
...config,
8084
};
85+
86+
// or
87+
88+
import config from "@anolilab/lint-staged-config";
89+
90+
export default {
91+
...config,
92+
};
8193
```
8294
### Config
8395

@@ -173,8 +185,6 @@ Adding the following script to your root `package.json` file makes it easier to
173185
pnpm pkg set scripts.prepare="is-ci || husky install || exit 0"
174186
```
175187

176-
For `npm` users, replace `pnpm` with `npm` in the above command.
177-
178188
This script will install husky only if it is not running in a CI environment.
179189

180190
After that you can find a `.husky` folder in your root directory, with a `pre-commit` (if not please create it) file.
@@ -192,16 +202,32 @@ The file content can look like this:
192202
echo --------------------------------------------
193203
echo Starting Git hook: pre-commit
194204

195-
pnpx lint-staged --verbose --concurrent false
205+
./node_modules/.bin/lint-staged --verbose --concurrent false
196206

197207
echo Finished Git hook: pre-commit
198208
echo --------------------------------------------
199-
200209
```
201210

202-
Our package includes a `postinstall` script to automatically add the `pre-commit`, `common.sh`, `prepare-commit-msg hooks to your `.husky` folder.
211+
or with `nano-staged`:
212+
213+
```bash
214+
#!/bin/sh
215+
216+
. "$(dirname "$0")/_/husky.sh"
217+
218+
# The hook should exit with non-zero status after issuing
219+
# an appropriate message if it wants to stop the commit.
220+
221+
echo --------------------------------------------
222+
echo Starting Git hook: pre-commit
223+
224+
./node_modules/.bin/nano-staged
225+
226+
echo Finished Git hook: pre-commit
227+
echo --------------------------------------------
228+
```
203229

204-
> Note: It can be that the postinstall script don't run, then you have to add the hooks manually.
230+
Our package includes a `lint-stage-config:install` command to add the `pre-commit`, `common.sh`, `prepare-commit-msg hooks to your `.husky` folder.
205231

206232
If `commitzen` is installed, the `prepare-commit-msg` hook with predefined content will be added to your `.husky` folder.
207233

@@ -235,3 +261,5 @@ The anolilab javascript-style-guide is open-sourced software licensed under the
235261
[license-url]: LICENSE.md "license"
236262
[npm-image]: https://img.shields.io/npm/v/@anolilab/lint-staged-config/latest.svg?style=for-the-badge&logo=npm
237263
[npm-url]: https://www.npmjs.com/package/@anolilab/lint-staged-config/v/latest "npm"
264+
[lint-staged]: https://github.com/okonet/lint-staged
265+
[nano-staged]: https://github.com/usmanyunusov/nano-staged

packages/lint-staged-config/group/package.json

-44
This file was deleted.

0 commit comments

Comments
 (0)