Registry / devops / rollup-plugin-git-info

rollup-plugin-git-info

JSON →
library1.0.0jsnpmunverified

A Rollup plugin that injects git build metadata (branch, commit hash, abbreviated hash, version, dates) into imported package.json files. Version 1.0.0 requires Node.js 12+ and Rollup 2+. This plugin is minimal and focused: it relies on @rollup/plugin-json for JSON handling and git CLI commands for data collection. Unlike alternatives that use environment variables or require manual configuration, it automatically populates standard fields like gitVersion and buildDate with no setup beyond adding the plugin.

npm install rollup-plugin-git-info
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-GIT-
R
rollup-plugin-git-info
devopsjavascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

gitInfo
import gitInfo from 'rollup-plugin-git-info';
const gitInfo = require('rollup-plugin-git-info');
ESM-only export; CommonJS require() will fail.
gitInfo
const gitInfo = require('rollup-plugin-git-info').default;
const gitInfo = require('rollup-plugin-git-info');
If using CommonJS, must access .default property.
gitInfo
import gitInfo from 'rollup-plugin-git-info';
import { gitInfo } from 'rollup-plugin-git-info';
Default export only; named import will be undefined.

Basic Rollup configuration using gitInfo plugin with @rollup/plugin-json to expose git metadata in package.json imports.

import gitInfo from 'rollup-plugin-git-info'; import json from '@rollup/plugin-json'; export default { input: 'src/index.js', output: { dir: 'dist', format: 'es', }, plugins: [ json(), gitInfo(), ], };
Debug
Known issues
breaking@rollup/plugin-json must be installed separately and declared before gitInfo in plugins array.
fix
npm install @rollup/plugin-json --save-dev and add json() before gitInfo().
affects: >=1.0.0
gotchaThe plugin only works if you import './package.json' in your source; importing from a different path will not include metadata.
fix
Ensure imports reference the correct package.json relative to the module.
affects: >=1.0.0
gotchagit version is computed from the repository where package.json resides; using a monorepo with multiple package.json files may produce unexpected results.
fix
Set cwd option to the correct directory for each package.
affects: >=1.0.0
gotchaThe gitBranch field will be 'HEAD' in detached head state, which may break tools expecting a proper branch name.
fix
Handle 'HEAD' in application logic or use a fallback branch name.
affects: >=1.0.0
deprecatedThe dateFormat option uses git log --date format; custom date formats may break with git version mismatches.
fix
Test date output across target git versions; consider using dateCommand for full control.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module '@rollup/plugin-json'
@rollup/plugin-json is a required peer dependency but not installed.
fix
Run: npm install @rollup/plugin-json --save-dev
TypeError: gitInfo is not a function
Incorrect import syntax, likely named import instead of default.
fix
Use: import gitInfo from 'rollup-plugin-git-info';
Error: No git repository found in /path/to/project
The plugin requires a .git directory in the project root.
fix
Initialize a git repository: git init
SyntaxError: Unexpected token 'export'
The plugin is ESM-only and cannot be used with CommonJS require directly.
fix
Switch to import syntax or use .default property: const gitInfo = require('rollup-plugin-git-info').default;
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
@rollup/plugin-jsonrequiredCore dependency for JSON file transformation; all options from that plugin are inherited.
Agent activity
8 hits · last 30 days
node
6
Resources
rollup-plugin-git-info — npm install rollup-plugin-git-info · libregistry