Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
libnpmdiff
Advanced tools
The libnpmdiff package is a tool for comparing different versions of npm packages. It helps developers understand the changes between versions by providing a detailed diff of the package contents.
Compare two versions of a package
This feature allows you to compare two specific versions of a package. The code sample demonstrates how to use libnpmdiff to compare version 1.0.0 and version 2.0.0 of a package named 'package-name'.
const libnpmdiff = require('libnpmdiff');
libnpmdiff('package-name@1.0.0', 'package-name@2.0.0').then(diff => {
console.log(diff);
}).catch(err => {
console.error(err);
});
Compare local package with a published version
This feature allows you to compare your local package with the latest published version. The code sample shows how to compare the current local package (denoted by '.') with the latest version of 'package-name'.
const libnpmdiff = require('libnpmdiff');
libnpmdiff('.', 'package-name@latest').then(diff => {
console.log(diff);
}).catch(err => {
console.error(err);
});
Output diff in different formats
This feature allows you to output the diff in different formats such as JSON. The code sample demonstrates how to get the diff in JSON format for two versions of 'package-name'.
const libnpmdiff = require('libnpmdiff');
libnpmdiff('package-name@1.0.0', 'package-name@2.0.0', { format: 'json' }).then(diff => {
console.log(JSON.stringify(diff, null, 2));
}).catch(err => {
console.error(err);
});
The 'diff' package provides a general-purpose text diffing utility. It can be used to compare any two strings or files, not just npm packages. While it is more versatile, it does not provide the npm-specific context that libnpmdiff does.
The 'npm-diff' package is another tool for comparing npm packages. It offers similar functionality to libnpmdiff but may have different options and output formats. It is a good alternative if you are looking for different features or performance characteristics.
The 'diff2html' package converts diff output to HTML. It is useful for visualizing changes in a more readable format. While it does not directly compare npm packages, it can be used in conjunction with other diff tools to present the results in a user-friendly way.
const libdiff = require('libnpmdiff')
const patch = await libdiff([
'abbrev@1.1.0',
'abbrev@1.1.1'
])
console.log(
patch
)
Returns:
diff --git a/package.json b/package.json
index v1.1.0..v1.1.1 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "abbrev",
- "version": "1.1.0",
+ "version": "1.1.1",
"description": "Like ruby's abbrev module, but in js",
"author": "Isaac Z. Schlueter <i@izs.me>",
"main": "abbrev.js",
$ npm install libnpmdiff
The npm team enthusiastically welcomes contributions and project participation! There's a bunch of things you can do if you want to contribute! The Contributor Guide outlines the process for community interaction and contribution. Please don't hesitate to jump in if you'd like to, or even ask us questions if something isn't clear.
All participants and maintainers in this project are expected to follow the npm Code of Conduct, and just generally be excellent to each other.
Please refer to the Changelog for project history details, too.
Happy hacking!
> libnpmdif([ a, b ], [opts]) -> Promise<String>
Fetches the registry tarballs and compare files between a spec a
and spec b
. npm spec types are usually described in <pkg-name>@<version>
form but multiple other types are alsos supported, for more info on valid specs take a look at npm-package-arg
.
Options:
color <Boolean>
: Should add ANSI colors to string output? Defaults to false
.tagVersionPrefix <Sring>
: What prefix should be used to define version numbers. Defaults to v
diffUnified <Number>
: How many lines of code to print before/after each diff. Defaults to 3
.diffFiles <Array<String>>
: If set only prints patches for the files listed in this array (also accepts globs). Defaults to undefined
.diffIgnoreAllSpace <Boolean>
: Whether or not should ignore changes in whitespace (very useful to avoid indentation changes extra diff lines). Defaults to false
.diffNameOnly <Boolean>
: Prints only file names and no patch diffs. Defaults to false
.diffNoPrefix <Boolean>
: If true then skips printing any prefixes in filenames. Defaults to false
.diffSrcPrefix <String>
: Prefix to be used in the filenames from a
. Defaults to a/
.diffDstPrefix <String>
: Prefix to be used in the filenames from b
. Defaults to b/
.diffText <Boolean>
: Should treat all files as text and try to print diff for binary files. Defaults to false
.cache
, registry
, where
and other common options accepted by pacoteReturns a Promise
that fullfils with a String
containing the resulting patch diffs.
Throws an error if either a
or b
are missing or if trying to diff more than two specs.
FAQs
The registry diff
The npm package libnpmdiff receives a total of 380,694 weekly downloads. As such, libnpmdiff popularity was classified as popular.
We found that libnpmdiff 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.