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-infoVerified import paths — ran on the pinned version, not inferred.
Basic Rollup configuration using gitInfo plugin with @rollup/plugin-json to expose git metadata in package.json imports.
npm install @rollup/plugin-json --save-dev and add json() before gitInfo().
Ensure imports reference the correct package.json relative to the module.
Set cwd option to the correct directory for each package.
Handle 'HEAD' in application logic or use a fallback branch name.
Test date output across target git versions; consider using dateCommand for full control.
Run: npm install @rollup/plugin-json --save-dev
Use: import gitInfo from 'rollup-plugin-git-info';
Initialize a git repository: git init
Switch to import syntax or use .default property: const gitInfo = require('rollup-plugin-git-info').default;