
Research
Security News
Lazarus Strikes npm Again with New Wave of Malicious Packages
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
libnpmversion
Advanced tools
Library to do the things that 'npm version' does.
const npmVersion = require('libnpmversion')
// argument can be one of:
// - any semver version string (set to that exact version)
// - 'major', 'minor', 'patch', 'pre{major,minor,patch}' (increment at
// that value)
// - 'from-git' (set to the latest semver-lookin git tag - this skips
// gitTagVersion, but will still sign if asked)
npmVersion(arg, {
path: '/path/to/my/pkg', // defaults to cwd
allowSameVersion: false, // allow tagging/etc to the current version
preid: '', // when arg=='pre', define the prerelease string, like 'beta' etc.
tagVersionPrefix: 'v', // tag as 'v1.2.3' when versioning to 1.2.3
commitHooks: true, // default true, run git commit hooks, default true
gitTagVersion: true, // default true, tag the version
signGitCommit: false, // default false, gpg sign the git commit
signGitTag: false, // default false, gpg sign the git tag
force: false, // push forward recklessly if any problems happen
ignoreScripts: false, // do not run pre/post/version lifecycle scripts
message: 'v%s', // message for tag and commit, replace %s with the version
}).then(pkg => {
console.error('version updated!', pkg)
})
Run this in a package directory to bump the version and write the new data
back to package.json
, package-lock.json
, and, if present,
npm-shrinkwrap.json
.
The newversion
argument should be a valid semver string, a valid second
argument to semver.inc (one
of patch
, minor
, major
, prepatch
, preminor
, premajor
,
prerelease
), or from-git
. In the second case, the existing version will
be incremented by 1 in the specified field. from-git
will try to read
the latest git tag, and use that as the new npm version.
If run in a git repo, it will also create a version commit and tag. This
behavior is controlled by gitTagVersion
(see below), and can be
disabled by setting gitTagVersion: false
in the options.
It will fail if the working directory is not clean, unless force: true
is
set.
If supplied with a message
string option, it will
use it as a commit message when creating a version commit. If the
message
option contains %s
then that will be replaced with the
resulting version number.
If the signGitTag
option is set, then the tag will be signed using
the -s
flag to git. Note that you must have a default GPG key set up in
your git config for this to work properly.
If preversion
, version
, or postversion
are in the scripts
property
of the package.json, they will be executed in the appropriate sequence.
The exact order of execution is as follows:
force
flag is set.preversion
script. These scripts have access to the old
version
in package.json. A typical use would be running your full
test suite before deploying. Any files you want added to the commit
should be explicitly added using git add
.version
in package.json
as requested (patch
, minor
,
major
, explicit version number, etc).version
script. These scripts have access to the new version
in package.json (so they can incorporate it into file headers in
generated files for example). Again, scripts should explicitly add
generated files to the commit using git add
.postversion
script. Use it to clean up the file system or
automatically push the commit and/or tag.Take the following example:
{
"scripts": {
"preversion": "npm test",
"version": "npm run build && git add -A dist",
"postversion": "git push && git push --tags && rm -rf build/temp"
}
}
This runs all your tests, and proceeds only if they pass. Then runs your
build
script, and adds everything in the dist
directory to the commit.
After the commit, it pushes the new commit and tag up to the server, and
deletes the build/temp
directory.
npmVersion(newversion, options = {}) -> Promise
Do the things. Returns a promise that resolves to the package manifest if all is well, or rejects if any errors are encountered.
path
StringThe path to the package being versionified. Defaults to process.cwd().
allowSameVersion
BooleanAllow setting the version to the current version in package.json. Default
false
.
preid
StringWhen the newversion
is pre, premajor, preminor, or prepatch, this
defines the prerelease string, like 'beta' etc.
tagVersionPrefix
StringThe prefix to add to the raw semver string for the tag name. Defaults to
'v'
. (So, by default it tags as 'v1.2.3' when versioning to 1.2.3.)
commitHooks
BooleanRun git commit hooks. Default true.
gitTagVersion
BooleanTag the version, default true.
signGitCommit
BooleanGPG sign the git commit. Default false
.
signGitTag
BooleanGPG sign the git tag. Default false
.
force
BooleanPush forward recklessly if any problems happen. Default false
.
ignoreScripts
BooleanDo not run pre/post/version lifecycle scripts. Default false
.
message
StringThe message for the git commit and annotated git tag that are created.
11.1.0 (2025-01-29)
7f6c997
#8009 add dry-run to deprecate/undeprecate commands (@wraithgar)1764a37
#8009 add npm undeprecate command (@wraithgar)31455b2
#8054 publish: honor force for no dist tag and registry version check (#8054) (@reggi)dc31c1b
#8038 remove max-len linting bypasses (@wraithgar)8a911ff
#8038 publish: disregard deprecated versions when calculating highest version (@wraithgar)7f72944
#8038 publish: accept publishConfig.tag to override highes semver check (@wraithgar)ab9ddc0
#7992 sbom: deduplicate sbom dependencies (#7992) (@bdehamer)f7da341
#7980 search: properly display multiple search terms (#7980) (@wraithgar)3644e79
#8055 update readme for Node.js versions, remove badges (#8055) (@wraithgar)f1af61f
#8041 fix typos in "package-json" (#8041) (@maxkoryukov)e90c6fe
#8051 depth flag default value (#8051) (@milaninfy)866b5ee
#8030 safer documentation urls, repos, packages (#8030) (@reggi)7ddfbad
#8053 @npmcli/package-json@6.1.1
9473a86
#8053 spdx-license-ids@3.0.21
a65e5ce
#8053 @sigstore/protobuf-specs@0.3.3
215ebe4
#8053 chalk@5.4.1
61f00e3
#8069 splits out smoke-tests from publish-dryrun tests (#8069) (@reggi)6d0f46e
#8058 stop publish smoke from check git clean (#8058) (@reggi)9281ebf
#8057 fix smoke tests prerelease needs separate string args (#8057) (@reggi)aa202e9
#8056 smoke tests using a preid (#8056) (@reggi)18e0449
#8053 dev dependency updates (@wraithgar)859a71c
#8052 update node versions for release integration tests (#8052) (@wraithgar)7e7961d
#8038 bump @npmcli/eslint-config to 5.1.0 (@wraithgar)@npmcli/config@10.0.1
FAQs
library to do the things that 'npm version' does
The npm package libnpmversion receives a total of 422,692 weekly downloads. As such, libnpmversion popularity was classified as popular.
We found that libnpmversion demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.
Security News
Opengrep continues building momentum with the alpha release of its Playground tool, demonstrating the project's rapid evolution just two months after its initial launch.