libnpmdiff
Advanced tools
Comparing version 6.0.9 to 6.1.0
@@ -1,4 +0,1 @@ | ||
const EOL = '\n' | ||
const colorizeDiff = require('@npmcli/disparity-colors') | ||
const jsDiff = require('diff') | ||
@@ -8,2 +5,19 @@ | ||
const colors = { | ||
// red | ||
removed: { open: '\x1B[31m', close: '\x1B[39m' }, | ||
// green | ||
added: { open: '\x1B[32m', close: '\x1B[39m' }, | ||
// blue | ||
header: { open: '\x1B[34m', close: '\x1B[39m' }, | ||
// cyan | ||
section: { open: '\x1B[36m', close: '\x1B[39m' }, | ||
} | ||
const color = (colorStr, colorId) => { | ||
const { open, close } = colors[colorId] | ||
// avoid highlighting the "\n" (would highlight till the end of the line) | ||
return colorStr.replace(/[^\n\r]+/g, open + '$&' + close) | ||
} | ||
const formatDiff = ({ files, opts = {}, refs, versions }) => { | ||
@@ -39,3 +53,3 @@ let res = '' | ||
if (opts.diffNameOnly) { | ||
res += `${filename}${EOL}` | ||
res += `${filename}\n` | ||
continue | ||
@@ -48,3 +62,3 @@ } | ||
headerLength++ | ||
patch += `${str}${EOL}` | ||
patch += `${str}\n` | ||
} | ||
@@ -91,5 +105,13 @@ | ||
res += (opts.color | ||
? colorizeDiff(patch, { headerLength }) | ||
: patch) | ||
if (opts.color) { | ||
// this RegExp will include all the `\n` chars into the lines, easier to join | ||
const lines = patch.split(/^/m) | ||
res += color(lines.slice(0, headerLength).join(''), 'header') | ||
res += lines.slice(headerLength).join('') | ||
.replace(/^-.*/gm, color('$&', 'removed')) | ||
.replace(/^\+.*/gm, color('$&', 'added')) | ||
.replace(/^@@.+@@/gm, color('$&', 'section')) | ||
} else { | ||
res += patch | ||
} | ||
} | ||
@@ -96,0 +118,0 @@ |
{ | ||
"name": "libnpmdiff", | ||
"version": "6.0.9", | ||
"version": "6.1.0", | ||
"description": "The registry diff", | ||
@@ -50,9 +50,8 @@ "repository": { | ||
"@npmcli/arborist": "^7.2.1", | ||
"@npmcli/disparity-colors": "^3.0.0", | ||
"@npmcli/installed-package-contents": "^2.0.2", | ||
"@npmcli/installed-package-contents": "^2.1.0", | ||
"binary-extensions": "^2.3.0", | ||
"diff": "^5.1.0", | ||
"minimatch": "^9.0.4", | ||
"npm-package-arg": "^11.0.1", | ||
"pacote": "^17.0.4", | ||
"npm-package-arg": "^11.0.2", | ||
"pacote": "^18.0.1", | ||
"tar": "^6.2.1" | ||
@@ -59,0 +58,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14503
8
289
- Removed@npmcli/disparity-colors@^3.0.0
- Removed@npmcli/disparity-colors@3.0.1(transitive)
- Removed@npmcli/redact@1.1.0(transitive)
- Removed@npmcli/run-script@7.0.4(transitive)
- Removedminipass-json-stream@1.0.2(transitive)
- Removednpm-registry-fetch@16.2.1(transitive)
- Removedpacote@17.0.7(transitive)
- Removedread-package-json@7.0.1(transitive)
Updatednpm-package-arg@^11.0.2
Updatedpacote@^18.0.1