{"id":15290353,"url":"https://github.com/npm/libnpmversion","last_synced_at":"2025-10-07T03:33:11.791Z","repository":{"id":46565068,"uuid":"246439333","full_name":"npm/libnpmversion","owner":"npm","description":"library to do the things that 'npm version' does","archived":true,"fork":false,"pushed_at":"2022-01-18T22:28:00.000Z","size":2132,"stargazers_count":20,"open_issues_count":0,"forks_count":5,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-10-01T16:07:11.499Z","etag":null,"topics":["npm-cli"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/npm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-11T00:39:43.000Z","updated_at":"2023-07-18T13:42:10.000Z","dependencies_parsed_at":"2022-09-13T06:51:03.989Z","dependency_job_id":null,"html_url":"https://github.com/npm/libnpmversion","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Flibnpmversion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Flibnpmversion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Flibnpmversion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Flibnpmversion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/npm","download_url":"https://codeload.github.com/npm/libnpmversion/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235586104,"owners_count":19014028,"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":["npm-cli"],"created_at":"2024-09-30T16:07:25.478Z","updated_at":"2025-10-07T03:33:06.377Z","avatar_url":"https://github.com/npm.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# We've Moved! 🚚\nThe code for this repo is now a workspace in the npm CLI repo.\n\n[github.com/npm/cli](https://github.com/npm/cli)\n\nYou can find the workspace in /workspaces/libnpmversion\n\nPlease file bugs and feature requests as issues on the CLI and tag the issue with \"libnpmversion\".\n\n[github.com/npm/cli/issues](https://github.com/npm/cli)\n\n# libnpmversion\n\nLibrary to do the things that 'npm version' does.\n\n## USAGE\n\n```js\nconst npmVersion = require('libnpmversion')\n\n// argument can be one of:\n// - any semver version string (set to that exact version)\n// - 'major', 'minor', 'patch', 'pre{major,minor,patch}' (increment at\n//   that value)\n// - 'from-git' (set to the latest semver-lookin git tag - this skips\n//   gitTagVersion, but will still sign if asked)\nnpmVersion(arg, {\n  path: '/path/to/my/pkg', // defaults to cwd\n\n  allowSameVersion: false, // allow tagging/etc to the current version\n  preid: '', // when arg=='pre', define the prerelease string, like 'beta' etc.\n  tagVersionPrefix: 'v', // tag as 'v1.2.3' when versioning to 1.2.3\n  commitHooks: true, // default true, run git commit hooks, default true\n  gitTagVersion: true, // default true, tag the version\n  signGitCommit: false, // default false, gpg sign the git commit\n  signGitTag: false, // default false, gpg sign the git tag\n  force: false, // push forward recklessly if any problems happen\n  ignoreScripts: false, // do not run pre/post/version lifecycle scripts\n  scriptShell: '/bin/bash', // shell to run lifecycle scripts in\n  message: 'v%s', // message for tag and commit, replace %s with the version\n}).then(newVersion =\u003e {\n  console.error('version updated!', newVersion)\n})\n```\n\n## Description\n\nRun this in a package directory to bump the version and write the new data\nback to `package.json`, `package-lock.json`, and, if present,\n`npm-shrinkwrap.json`.\n\nThe `newversion` argument should be a valid semver string, a valid second\nargument to [semver.inc](https://github.com/npm/node-semver#functions) (one\nof `patch`, `minor`, `major`, `prepatch`, `preminor`, `premajor`,\n`prerelease`), or `from-git`. In the second case, the existing version will\nbe incremented by 1 in the specified field.  `from-git` will try to read\nthe latest git tag, and use that as the new npm version.\n\nIf run in a git repo, it will also create a version commit and tag.  This\nbehavior is controlled by `gitTagVersion` (see below), and can be\ndisabled by setting `gitTagVersion: false` in the options.\nIt will fail if the working directory is not clean, unless `force: true` is\nset.\n\nIf supplied with a `message` string option, it will\nuse it as a commit message when creating a version commit.  If the\n`message` option contains `%s` then that will be replaced with the\nresulting version number.\n\nIf the `signGitTag` option is set, then the tag will be signed using\nthe `-s` flag to git.  Note that you must have a default GPG key set up in\nyour git config for this to work properly.\n\nIf `preversion`, `version`, or `postversion` are in the `scripts` property\nof the package.json, they will be executed in the appropriate sequence.\n\nThe exact order of execution is as follows:\n\n1. Check to make sure the git working directory is clean before we get\n   started.  Your scripts may add files to the commit in future steps.\n   This step is skipped if the `force` flag is set.\n2. Run the `preversion` script.  These scripts have access to the old\n   `version` in package.json.  A typical use would be running your full\n   test suite before deploying.  Any files you want added to the commit\n   should be explicitly added using `git add`.\n3. Bump `version` in `package.json` as requested (`patch`, `minor`,\n   `major`, explicit version number, etc).\n4. Run the `version` script. These scripts have access to the new `version`\n   in package.json (so they can incorporate it into file headers in\n   generated files for example).  Again, scripts should explicitly add\n   generated files to the commit using `git add`.\n5. Commit and tag.\n6. Run the `postversion` script. Use it to clean up the file system or\n   automatically push the commit and/or tag.\n\nTake the following example:\n\n```json\n{\n  \"scripts\": {\n    \"preversion\": \"npm test\",\n    \"version\": \"npm run build \u0026\u0026 git add -A dist\",\n    \"postversion\": \"git push \u0026\u0026 git push --tags \u0026\u0026 rm -rf build/temp\"\n  }\n}\n```\n\nThis runs all your tests, and proceeds only if they pass. Then runs your\n`build` script, and adds everything in the `dist` directory to the commit.\nAfter the commit, it pushes the new commit and tag up to the server, and\ndeletes the `build/temp` directory.\n\n## API\n\n### `npmVersion(newversion, options = {}) -\u003e Promise\u003cString\u003e`\n\nDo the things.  Returns a promise that resolves to the new version if\nall is well, or rejects if any errors are encountered.\n\n### Options\n\n#### `path` String\n\nThe path to the package being versionified.  Defaults to process.cwd().\n\n#### `allowSameVersion` Boolean\n\nAllow setting the version to the current version in package.json.  Default\n`false`.\n\n#### `preid` String\nWhen the `newversion` is pre, premajor, preminor, or prepatch, this\ndefines the prerelease string, like 'beta' etc.\n\n#### `tagVersionPrefix` String\n\nThe prefix to add to the raw semver string for the tag name.  Defaults to\n`'v'`.  (So, by default it tags as 'v1.2.3' when versioning to 1.2.3.)\n\n#### `commitHooks` Boolean\n\nRun git commit hooks.  Default true.\n\n#### `gitTagVersion` Boolean\n\nTag the version, default true.\n\n#### `signGitCommit` Boolean\n\nGPG sign the git commit.  Default `false`.\n\n#### `signGitTag` Boolean\n\nGPG sign the git tag.  Default `false`.\n\n#### `force` Boolean\n\nPush forward recklessly if any problems happen.  Default `false`.\n\n#### `ignoreScripts` Boolean\n\nDo not run pre/post/version lifecycle scripts.  Default `false`.\n\n#### `scriptShell` String\n\nPath to the shell, which should execute the lifecycle scripts.  Defaults to `/bin/sh` on unix, or `cmd.exe` on windows.\n\n#### `message` String\n\nThe message for the git commit and annotated git tag that are created.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpm%2Flibnpmversion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnpm%2Flibnpmversion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpm%2Flibnpmversion/lists"}