npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hugojosefson/fork-version

v1.6.0-deno-jsonc.2

Published

Fork-Version automates version control tasks such as determining, updating, and committing versions, files, and changelogs, simplifying the process when adhering to the conventional commit standard.

Downloads

9

Readme

Fork-Version

NPM Version JSR Version Package Publish Package

What Does Fork-Version Do?

By following the conventional commit standard Fork-Version can automate the following tasks for you:

  1. Determine the current and next version
  2. Update the version in the selected files
  3. Update your changelog
  4. Commit the changed files
  5. Create a tag for the new version

Fork-Version won't attempt to push changes to git or to a package manager, this allows you to decide how you publish your changes.

Using Fork-Version

Primarily designed to be used with npx, Fork-Version can also be installed globally or directly to the node package you're working on. The only software prerequisites you need are git and node.

Fork-Version can be configured either through a config file or by passing options to the tool when ran, see the Configuration File and Command Line Options sections below for details on the supported options.

[!NOTE] Command line options get merged with config file options, any options that are declared through the cli will override options that are also in the config file (Except for the list of files which get merged).

Using npx (Recommended)

To use Fork-Version with npx you can use the following command, by using npx you can also use Fork-Version without installation and on other projects including non node projects.

npx fork-version

[!NOTE] If you want to use a specific version you can add a version tag to the end of the name.

Example: npx [email protected]

The version tag needs to match against one of the published versions on npm.

Install Locally

To install the package locally to your project you can use one of the following commands:

| Package Manager | Install Command | | --------------- | ------------------------------------- | | npm | npm install fork-version --save-dev | | yarn | yarn add fork-version --dev | | pnpm | pnpm add fork-version --save-dev |

You can then add the following entry to your package.json scripts section and use it like any other script you already use in your project.

{
  "scripts": {
    "release": "fork-version"
  }
}

For example if you use npm you can now use npm run release to run Fork-Version.

Command Line Options

Usage:
  $ fork-version [options]

Commands:
  --help                           Show this help message.
  --version                        Show the current version of Fork-Version.
  --inspect-version                If set, Fork-Version will print the current project version and exit.

Options:
  --file, -F                       List of the files to be updated. [Default: ["bower.json", "deno.json", "deno.jsonc", "jsr.json", "jsr.jsonc", "manifest.json", "npm-shrinkwrap.json", "package-lock.json", "package.json"]]
  --glob, -G                       Glob pattern to match files to be updated.
  --path, -P                       The path Fork-Version will run from. [Default: process.cwd()]
  --changelog                      Name of the changelog file. [Default: "CHANGELOG.md"]
  --header                         The header text for the changelog.
  --tag-prefix                     Specify a prefix for the created tag. [Default: "v"]
  --pre-release                    Mark this release as a pre-release.
  --pre-release-tag                Mark this release with a tagged pre-release. [Example: "alpha", "beta", "rc"]
  --current-version                If set, Fork-Version will use this version instead of trying to determine one.
  --next-version                   If set, Fork-Version will attempt to update to this version, instead of incrementing using "conventional-commit".
  --release-as                     Release as increments the version by the specified level. [Choices: "major", "minor", "patch"]

Flags:
  --allow-multiple-versions        Don't throw an error if multiple versions are found in the given files. [Default: true]
  --commit-all                     Commit all changes, not just files updated by Fork-Version.
  --changelog-all                  If this flag is set, all default commit types will be added to the changelog.
  --debug                          Output debug information.
  --dry-run                        No output will be written to disk or committed.
  --silent                         Run without logging to the terminal.
  --git-tag-fallback               If unable to find a version in the given files, fallback and attempt to use the latest git tag. [Default: true]
  --sign                           If true, git will sign the commit with the systems GPG key.
  --verify                         If true, git will run user defined git hooks before committing.

  To negate a flag you can prefix it with "no-", for example "--no-git-tag-fallback" will not fallback to the latest git tag.

Skip Steps:
  --skip-bump                      Skip the version bump step.
  --skip-changelog                 Skip updating the changelog.
  --skip-commit                    Skip committing the changes.
  --skip-tag                       Skip tagging the commit.

Conventional Changelog Overrides:
  --commit-url-format              Override the default commit URL format.
  --compare-url-format             Override the default compare URL format.
  --issue-url-format               Override the default issue URL format.
  --user-url-format                Override the default user URL format.
  --release-commit-message-format  Override the default release commit message format.
  --release-message-suffix         Add a suffix to the end of the release message.

Examples:
  $ fork-version
    Run fork-version in the current directory with default options.

  $ fork-version --path ./packages/my-package
    Run fork-version in the "./packages/my-package" directory.

  $ fork-version --file package.json --file MyApi.csproj
    Run fork-version and update the "package.json" and "MyApi.csproj" files.

  $ fork-version --glob "*/package.json"
    Run fork-version and update all "package.json" files in subdirectories.

Configuration File

You can configure Fork-Version using one of the following files:

  • A javascript file:
    • fork.config.ts
    • fork.config.js
    • fork.config.cjs
    • fork.config.mjs
  • A json file:
    • fork.config.json
    • package.json >> Key Name: "fork-version"

Javascript Config

Configuring using a javascript file is the most flexible option. You can use any javascript file type you prefer including typescript. Both commonjs and esm exports styles are supported. The defineConfig function in the following snippet is optional, using it will give you intellisense information in your code editor of choice.

import { defineConfig } from 'fork-version';

export default defineConfig({
  header: `# My Changelog`,
  files: ["package.json", "package-lock.json"],
});

Alternatively you can use typescript type annotations in a typescript file:

import type { Config } from 'fork-version';

const config: Config = {
  header: `# My Changelog`,
  files: ["package.json", "package-lock.json"],
};

export default config;

Or jsdocs in a javascript file:

/** @type {import("fork-version").Config} */
export default {
  header: `# My Changelog`,
  files: ["package.json", "package-lock.json"],
};

Or just raw dog it without type information. ಠ_ಠ

Json Config

Another way you can configure Fork-Version is by using a json file called fork.config.json. This is a good option if you're using Fork-Version on a non javascript project, or without installation.

If you still want intellisense information you can use the following schema in your json file, otherwise $schema is an optional key.

{
  "$schema": "https://raw.githubusercontent.com/eglavin/fork-version/main/schema/latest.json",
  "header": "# My Changelog",
  "files": [
    "package.json",
    "package-lock.json"
  ]
}

Internally we're using zod-to-json-schema to generate the schema. Checkout the schema folder to see the current state.

Alternatively you can define your config using a key in your package.json file called fork-version:

{
  "name": "my-js-project",
  "version": "1.2.3",
  "fork-version": {
    "header": "# My Changelog",
    "files": [
      "package.json",
      "package-lock.json"
    ]
  }
}

Config Properties

| Property | Type | Default | Description | | :---------------------------------------------------- | :--------------- | :---------------------- | :------------------------------------------------------------------------------------------------------------------ | | inspectVersion | boolean | - | Print the current version and exits | | files | Array<string> | ["package.json", ...] | List of the files to be updated | | glob | string | - | Glob pattern to match files to be updated | | path | string | process.cwd() | The path Fork-Version will run from | | changelog | string | CHANGELOG.md | Name of the changelog file | | header | string | # Changelog... | The header text for the changelog | | tagPrefix | string | v | Prefix for the created tag | | preRelease | string / boolean | - | Make a pre-release with optional label if given value is a string | | currentVersion | string | - | Use this version instead of trying to determine one | | nextVersion | string | - | Attempt to update to this version, instead of incrementing using "conventional-commit" | | releaseAs | string | - | Release as increments the version by the specified level. Overrides the default behaviour of "conventional-commit". | | allowMultipleVersions | boolean | true | Don't throw an error if multiple versions are found in the given files. | | commitAll | boolean | false | Commit all changes, not just files updated by Fork-Version | | changelogAll | boolean | false | If this flag is set, all default commit types will be added to the changelog, not just feat and fix. | | debug | boolean | false | Output debug information | | dryRun | boolean | false | No output will be written to disk or committed | | silent | boolean | false | Run without logging to the terminal | | gitTagFallback | boolean | true | If unable to find a version in the given files, fallback and attempt to use the latest git tag | | sign | boolean | false | Sign the commit with the systems GPG key | | verify | boolean | false | Run user defined git hooks before committing | | skipBump | boolean | false | Skip the bump step | | skipChangelog | boolean | false | Skip the changelog step | | skipCommit | boolean | false | Skip the commit step | | skipTag | boolean | false | Skip the tag step | | changelogPresetConfig | object | {} | Override defaults from the "conventional-changelog-conventionalcommits" preset configuration | | releaseMessageSuffix | string | - | Add a suffix to the end of the release message |

config.files

By default Fork-Version will attempt to read versions from and update these files, if you define your own list it will override the default list instead of merging.

  • "package.json"
  • "package-lock.json"
  • "npm-shrinkwrap.json"
  • "jsr.json"
  • "jsr.jsonc"
  • "deno.json"
  • "deno.jsonc"
  • "manifest.json"
  • "bower.json"

See the Supported File Types section below to see the currently supported file types.

config.glob

An alternative to config.files, a glob allows you to search for files using wildcard characters.

For example if you have the following folder structure:

API/
- MyAPI.csproj
Library/
- MyLibrary.csproj
Web/
- package.json

Running npx fork-version -G "{*/*.csproj,*/package.json}" will update both csproj files and the package.json file.

Internally Fork-Version uses isaacs glob to match files. Read more about the pattern syntax here.

[!WARNING] Ensure you wrap your glob pattern in quotes to prevent shell expansion.

config.tagPrefix

Allows you to control the prefix for the created tag. This is useful if your using a mono-repo in which you version multiple projects separately or simply want to use a different prefix for your tags.

| Example Value | Tag Created | |:-------------------------|:------------------------------| | "v" (Default) | v1.2.3 | | "" | 1.2.3 | | "version/" | version/1.2.3 | | "@eglavin/fork-version-" | @eglavin/fork-version-1.2.3 |

config.preRelease

Marking a release as a pre-release allows you to define a change as a patch to a specific version. This allows you to mark a fix for a version or an alpha build for example.

| Example Value | Version Created | |:--------------|:----------------| | true | 1.2.3-0 | | alpha | 1.2.3-alpha-0 |

Fork-Version uses meow to parse cli arguments which is unable to take a single argument and parse it as either a string and or a boolean. So to do the above through the cli interface you'll need to use two different arguments:

| Example CLI Usage | Version Created | |:---------------------------------------|:----------------| | fork-version --pre-release | 1.2.3-0 | | fork-version --pre-release-tag alpha | 1.2.3-alpha-0 |

config.releaseAs

Allows you to override the default versioning behaviour of Fork-Version and increment by the specified level. For example if the current version is 1.2.3 and you run Fork-Version with one of the following arguments, the version will be incremented as shown below.

| Example Value | Version Created | |:--------------|:----------------| | major | 2.0.0 | | minor | 1.3.0 | | patch | 1.2.4 |

config.changelogPresetConfig

Fork-Version uses the conventional changelog config spec. The following is an excerpt of the configurable options.

| Property | Type | Default | Description | |:-------------------------------------------|:---------------|:-----------------------------------------------------------------------------|:------------------------------------------------------------------------| | types | Array<Type> | {} | List of explicitly supported commit message types | | commitUrlFormat | string | {{host}}/{{owner}}/{{repository}}/commit/{{hash}} | A URL representing a specific commit at a hash | | compareUrlFormat | string | {{host}}/{{owner}}/{{repository}}/compare/{{previousTag}}...{{currentTag}} | A URL representing the comparison between two git SHAs | | issueUrlFormat | string | {{host}}/{{owner}}/{{repository}}/issues/{{id}} | A URL representing the issue format | | userUrlFormat | string | {{host}}/{{user}} | A URL representing a user's profile | | releaseCommitMessageFormat | string | chore(release): {{currentTag}} | A string to be used to format the auto-generated release commit message | | issuePrefixes | Array<string> | ["#"] | List of prefixes used to detect references to issues |

config.changelogPresetConfig.types

By default only feat and fix commits are added to your changelog, you can configure extra sections to show by modifying this section.

Checkout the fork.config.js file here to see an example of modifying the types.

| Property | Type | Description | |:---------|:--------|:-------------------------------------------------------------------------| | type | string | The type of commit message. "feat", "fix", "chore", etc.. | | scope | string | The scope of the commit message. | | section | string | The name of the section in the CHANGELOG the commit should show up in. | | hidden | boolean | Should show in the generated changelog message? |

config.releaseMessageSuffix

Adds a suffix to the end of the release message, useful to add a [skip ci] message to the end of the created commit.

Supported File Types

Json Package

A json package is a json file which contains a version property, such as a npm package.json file.

{
  "name": "my-project",
  "version": "1.2.3",
  "private": false,
}

Plain Text

A plain text file will have just the version as the content.

1.2.3

MS Build

A MS build project is an xml file with with a Version property under the Project > PropertyGroup node group.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <Version>1.2.3</Version>
  </PropertyGroup>
</Project>

Fork-Version currently supports reading and updating the following file extensions: .csproj .dbproj .esproj .fsproj .props .vbproj .vcxproj

Custom File Updater's

TODO add support for custom file readers and writers through config #5

Code Usage

[!WARNING] Code usage is not recommended as the public api is not stable and may change between versions.

In the future the api may be stabilized and documented but this is not a focus at this time.