1.0.0 • Published 10 months ago

esbuild-plugin-git-describe v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

esbuild-plugin-git-describe

An esbuild plugin to expose git-describe as a module in your application.

GitHub npm

This plugin was inspired by esbuild-plugin-version-injector.

Description

This plugin allows you to expose versioning information based on the results of git-describe at build time as a module that can be imported into front-end code.

For example:

import { hash, tag, raw } from 'git-describe';

console.log("App Version: ", { hash, tag, raw });

/* Will be something like:
 * {
 *   hash: "g8b914ab",
 *   raw: "v0.1.0-0-g8b914ab-dirty",
 *   tag: "v0.1.0"
 * }
 */

This git-describe object is generated by the plugin at compile time so there is no version management needed beyond git tags. See the git-describe example output for the list of available properties.

Installation

This plugin is available on npm as esbuild-plugin-git-describe and can be installed using npm with:

npm install --save-dev esbuild-plugin-git-describe

Usage

Add the plugin to your esbuild script. For example:

import * as esbuild from 'esbuild';
import { esbuildPluginGitDescribe } from 'esbuild-plugin-git-describe';

await esbuild.build({
  entryPoints: [resolve(__dirname, './src/index.ts'],
  plugins: [ esbuildPluginGitDescribe() ]
});

Configuration Options:

You can pass a configuration object to esbuildPluginGetDescribe() which accepts the following values:

Property NameProperty TypeDescription
dirtyMarkstringFrom git-describe, the dirty mark to use if repo state is dirty (see git describe's --dirty). Defaults to '-dirty'.
dirtySemverbooleanFrom git-describe, appends the dirty mark to semverString if repo state is dirty. Defaults to true.
longbooleanFrom git-describe, always adds commit distance and hash to raw, suffix and .toString() (matches the behaviour of git describe's --long). Defaults to true.
longSemverbooleanFrom git-describe, always adds commit distance and hash to semverString (similar to git describe's --long, but for semver). Defaults to false.
requireAnnotatedbooleanFrom git-describe, uses --tags if false, so that simple git tags are allowed. Defaults to false.
matchstringFrom git-describe, uses --match to filter tag names. By default only tags resembling a version number are considered. Defaults to 'v[0-9]*'.
customArgumentsArray<string>From git-describe, array of additional arguments to pass to git describe. Not all arguments are useful and some may even break the library, but things like --abbrev and --candidates should be safe to add. Defaults to [].
namespacestringNamespace to use as the source of the git-describe variables exposed to the application. Defaults to git-describe.
1.0.0

10 months ago