{"id":13837693,"url":"https://github.com/usmanyunusov/nano-staged","last_synced_at":"2025-05-14T15:07:02.787Z","repository":{"id":37730089,"uuid":"418269565","full_name":"usmanyunusov/nano-staged","owner":"usmanyunusov","description":"Tiny tool to run commands for modified, staged, and committed files in a GIT repository.","archived":false,"fork":false,"pushed_at":"2024-11-25T19:17:45.000Z","size":289,"stargazers_count":527,"open_issues_count":10,"forks_count":15,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-14T10:35:43.167Z","etag":null,"topics":["changed","diff","git","lint","linter","runner","staged","task","unstaged"],"latest_commit_sha":null,"homepage":"https://npm.im/nano-staged","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/usmanyunusov.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-17T22:19:26.000Z","updated_at":"2025-05-13T19:23:18.000Z","dependencies_parsed_at":"2025-03-02T15:01:25.661Z","dependency_job_id":"480924ed-473b-4674-9468-c90916c9dd91","html_url":"https://github.com/usmanyunusov/nano-staged","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usmanyunusov%2Fnano-staged","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usmanyunusov%2Fnano-staged/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usmanyunusov%2Fnano-staged/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usmanyunusov%2Fnano-staged/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/usmanyunusov","download_url":"https://codeload.github.com/usmanyunusov/nano-staged/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254153352,"owners_count":22023598,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["changed","diff","git","lint","linter","runner","staged","task","unstaged"],"created_at":"2024-08-04T15:01:20.675Z","updated_at":"2025-05-14T15:07:02.751Z","avatar_url":"https://github.com/usmanyunusov.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","git","Utilities"],"sub_categories":["Git Hooks"],"readme":"\u003cp align=\"center\"\u003e\n   \u003cimg src=\"https://usmanyunusov.github.io/nano-staged/img/logo.svg\" height=\"96\"\u003e\n   \u003ch3 align=\"center\"\u003eNano Staged\u003c/h3\u003e\n   \u003cp align=\"center\"\u003eTiny tool to run commands for modified, staged, and committed files in a GIT repository.\u003cbr/\u003e It helps \u003cb\u003espeed up running of the tests, linters, scripts\u003c/b\u003e, and more.\u003c/p\u003e\n\u003c/p\u003e\n\n## Features\n\n- 📦 **Small**: [47kB](https://packagephobia.com/result?p=nano-staged) (142x+ lighter than **lint-staged**).\n- 🥇 **Single dependency** ([`picocolors`](https://github.com/alexeyraspopov/picocolors)).\n- ☯️ **Support multiple file states like staged, unstaged, last-commit, changed etc**\n\n## Benchmarks\n\nBenchmarks running time for 10 file:\n\n```diff\n$ node bench/running-time/index.js\n- lint-staged 1.394 ms\n+ nano-staged 0.968 ms\n```\n\nThe space in node_modules including sub-dependencies:\n\n```diff\n$ node bench/size/index.js\nData from packagephobia.com\n- lint-staged   6688 kB\n+ nano-staged     47 kB\n```\n\nThe performance results were generated on a MBP Late 2013, 2.3 GHz Intel Core i7 by running `npm run bench` in the library folder. See [bench/running-time/index.js](https://github.com/usmanyunusov/nano-staged/blob/master/bench/running-time/index.js)\n\n## Usage\n\n### Getting Started\n\n1. Install `nano-staged`:\n\n   ```terminal\n   npm install --save-dev nano-staged\n   ```\n   or\n   ```terminal\n   yarn add nano-staged -D\n   ```\n\n2. Add the `nano-staged` section and the commands to your `package.json`:\n\n   For example:\n\n   ```json\n   \"nano-staged\": {\n      \"*.{js,ts}\": \"prettier --write\",\n      \"*.css\": [\"stylelint\", \"eslint --fix\"]\n   },\n   ```\n\n3. Run commands with Nano Staged:\n\n   ```terminal\n   ./node_modules/.bin/nano-staged\n   ```\n\n   \u003e Nano Staged by default to run commands from the config for staged files.\n\n### Pre-commit Hook\n\n\u003e You can use Nano Staged with a pre-commit tools to run it automatically before every commit.\n\n\u003cdetails\u003e\n   \u003csummary\u003e\u003cb\u003eSimple Git Hooks\u003c/b\u003e\u003c/summary\u003e\n\n1. Install `simple-git-hooks` as a dev dependency:\n\n   ```terminal\n   npm install simple-git-hooks --save-dev\n   ```\n\n2. Add the `simple-git-hooks` section to your `package.json` and fill in the `pre-commit`:\n\n   For example:\n\n   ```json\n   \"simple-git-hooks\": {\n      \"pre-commit\": \"./node_modules/.bin/nano-staged\"\n   }\n   ```\n\n3. Run the CLI script to update the git hooks with the commands from the config:\n\n   ```terminal\n   npx simple-git-hooks\n   ```\n\n4. To automatically have Git hooks enabled after install, edit `package.json`:\n\n   ```json\n   \"scripts\": {\n      \"postinstall\": \"npx simple-git-hooks\"\n   }\n   ```\n\n   \u003c/details\u003e\n\n\u003cdetails\u003e\n   \u003csummary\u003e\u003cb\u003eHusky\u003c/b\u003e\u003c/summary\u003e\n\n1. Install `husky` as a dev dependency:\n\n   ```terminal\n   npm install husky --save-dev\n   ```\n\n2. Enable Git hooks:\n\n   ```terminal\n   npx husky install\n   ```\n\n3. Add a command to a hook:\n\n   ```terminal\n   npx husky add .husky/pre-commit \"./node_modules/.bin/nano-staged\"\n   ```\n\n4. To automatically have Git hooks enabled after install, edit `package.json`:\n\n   ```json\n   \"scripts\": {\n      \"postinstall\": \"npx husky install\"\n   }\n   ```\n\n\u003c/details\u003e\n\n## Configuration\n\nNano Staged supports multiple ways to define config.\n\n1. `nano-staged` section in `package.json`:\n\n   ```json\n   \"nano-staged\": {\n      \"*\": \"your-cmd\",\n      \"*.ext\": [\"your-cmd\", \"your-cmd\"]\n   }\n   ```\n\n2. or a separate `.nano-staged.json`, `nano-staged.json` or `.nanostagedrc` config file:\n\n   ```json\n   {\n     \"*\": \"your-cmd\",\n     \"*.ext\": [\"your-cmd\", \"your-cmd\"]\n   }\n   ```\n\n3. or a more flexible `.nano-staged.cjs` or `nano-staged.cjs` config file to CommonJS modules:\n\n   ```js\n   module.exports = {\n     '*': 'your-cmd',\n     '*.ext': ['your-cmd', 'your-cmd'],\n   }\n   ```\n\n4. or a more flexible `.nano-staged.mjs` or `nano-staged.mjs` config file to ECMAScript modules:\n\n   ```js\n   export default {\n     '*': 'your-cmd',\n     '*.ext': ['your-cmd', 'your-cmd'],\n   }\n   ```\n\n5. or a more flexible `.nano-staged.js` or `nano-staged.js` config file:\n\n   ```js\n   // package.json =\u003e \"type\": \"module\"\n   export default {\n     '*': 'your-cmd',\n     '*.ext': ['your-cmd', 'your-cmd'],\n   }\n\n   // package.json =\u003e \"type\": \"commonjs\"\n   module.exports = {\n     '*': 'your-cmd',\n     '*.ext': ['your-cmd', 'your-cmd'],\n   }\n   ```\n\n### Format priorities:\n\nIf there are multiple configuration files in the same directory, Nano Staged will only use one. The priority order is as follows:\n\n1. `.nano-staged.js`\n2. `nano-staged.js`\n3. `.nano-staged.cjs`\n4. `nano-staged.cjs`\n5. `.nano-staged.mjs`\n6. `nano-staged.mjs`\n7. `.nano-staged.json`\n8. `nano-staged.json`\n9. `.nanostagedrc`\n10. `package.json`\n\n### Config Function API:\n\nJS config files may export export either a single function or an object:\n\n```js\nexport default (api) =\u003e {\n  const jsFiles = api.filenames.filter((file) =\u003e path.extname(file) === '.js')\n\n  return [`eslint --fix ${jsFiles.join(' ')}`, `prettier --write ${jsFiles.join(' ')}`]\n}\n```\n\n```js\nexport default {\n  '*.js': (api) =\u003e `eslint --fix ${api.filenames.join(' ')}`,\n}\n```\n\nThe `api` object exposes:\n\n`api.filenames` - working filenames\n\n`api.type` - run type: `staged`, `unstaged`, `diff`\n\n## Command Line Interface\n\n#### `--config [\u003cpath\u003e]` or `-c [\u003cpath\u003e]`\n\nPath to file that contains your configuration object. The path should be either absolute or relative to the directory that your process is running from.\n\n#### `--unstaged` or `-u`\n\nRun commands from the config only for git unstaged files. Nano Staged by default uses only staged git files.\n\n#### `--diff [\u003cref1\u003e \u003cref2\u003e]`\n\nRun commands on files changed between the working tree and the index or a tree, on files changed between the index and a tree, files changed between two trees, or on files changed between two indexes (commit hashes).\n\n#### `--allow-empty`\n\nWill allow creating an empty commit.\n\n## Thanks\n\nSpecial thanks to [lint-staged](https://github.com/okonet/lint-staged). Some codes was borrowed from it.\n\n## Community\n\nThe Nano Staged community can be found on [GitHub Discussions](https://github.com/usmanyunusov/nano-staged/discussions), where you can ask questions, voice ideas, and share your projects.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusmanyunusov%2Fnano-staged","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fusmanyunusov%2Fnano-staged","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusmanyunusov%2Fnano-staged/lists"}