Skip to content

Commit 226a666

Browse files
ben-turnertmcw
authored andcommitted
deps: Remove unmaintained dependency: disparity (#1264)
* Remove unmaintained dependency: disparity The dependency disparity has not been updated for 4 years and is using a very old version of the diff package which has a security alert. This alert is not relevant to the current usage of the package, however it does generate noise when installing. Additionally, it seems unwise to be relying on unmaintained packages. This commit replaces disparity with diff and adds some code to color the output which is based on disparity's logic. * Use chalk to color diff output instead of ansi-styles
1 parent 798d32e commit 226a666

File tree

3 files changed

+39
-19
lines changed

3 files changed

+39
-19
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"chalk": "^2.3.0",
3838
"chokidar": "^2.0.4",
3939
"concat-stream": "^1.6.0",
40-
"disparity": "^2.0.0",
40+
"diff": "^4.0.1",
4141
"doctrine-temporary-fork": "2.1.0",
4242
"get-port": "^4.0.0",
4343
"git-url-parse": "^10.0.1",

src/commands/readme.js

+33-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const documentation = require('../');
55
const sharedOptions = require('./shared_options');
66
const inject = require('mdast-util-inject');
77
const chalk = require('chalk');
8-
const disparity = require('disparity');
8+
const diff = require('diff');
99
const getReadmeFile = require('../get-readme-file');
1010

1111
module.exports.command = 'readme [input..]';
@@ -94,22 +94,48 @@ module.exports.handler = function readme(argv) {
9494
.process(readmeContent)
9595
)
9696
.then(file => {
97-
const diffOutput = disparity.unified(readmeContent, file.contents, {
98-
paths: [argv.readmeFile, argv.readmeFile]
99-
});
100-
if (!diffOutput.length) {
97+
const diffRaw = diff.createPatch(
98+
'',
99+
readmeContent,
100+
file.contents,
101+
'',
102+
''
103+
);
104+
if (!diffRaw.length) {
101105
log(`${argv.readmeFile} is up to date.`);
102106
process.exit(0);
103107
}
104108

109+
// Replace diff headers with real values
110+
const cleanedDiff = diffRaw
111+
.replace(/^([^\n]+)\n([^\n]+)\n/m, '')
112+
.replace(/^---.*/gm, `--- ${argv.readmeFile}\tremoved`)
113+
.replace(/^\+\+\+.*/gm, `+++ ${argv.readmeFile}\tadded`);
114+
115+
// Includes newlines for easier joins
116+
const diffLines = cleanedDiff.split(/^/m);
117+
const diffHeader = diffLines
118+
.slice(0, 2)
119+
.join('')
120+
.replace(/[^\n\r]+/g, chalk.yellow('$&'));
121+
const diffBody = diffLines
122+
.slice(2)
123+
.join('')
124+
.replace(/^-[^\n\r]*/gm, chalk.red('$&'))
125+
.replace(/^\+[^\n\r]*/gm, chalk.green('$&'))
126+
.replace(/^@@.+@@/gm, chalk.magenta('$&'));
127+
105128
if (argv.d) {
106129
log(
107130
chalk.bold(`${argv.readmeFile} needs the following updates:`),
108-
`\n${diffOutput}`
131+
`\n${diffHeader}${diffBody}`
109132
);
110133
process.exit(1);
111134
} else {
112-
log(chalk.bold(`Updating ${argv.readmeFile}`), `\n${diffOutput}`);
135+
log(
136+
chalk.bold(`Updating ${argv.readmeFile}`),
137+
`\n${diffHeader}${diffBody}`
138+
);
113139
}
114140

115141
fs.writeFileSync(argv.readmeFile, file.contents);

yarn.lock

+5-11
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ ansi-regex@^4.1.0:
930930
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.1.0.tgz#8b9f8f08cf1acb843756a839ca8c7e3168c51997"
931931
integrity sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==
932932

933-
ansi-styles@^2.0.1, ansi-styles@^2.2.1:
933+
ansi-styles@^2.2.1:
934934
version "2.2.1"
935935
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe"
936936

@@ -2070,20 +2070,14 @@ detective@^4.0.0:
20702070
acorn "^5.2.1"
20712071
defined "^1.0.0"
20722072

2073-
diff@^1.3.2:
2074-
version "1.4.0"
2075-
resolved "https://registry.yarnpkg.com/diff/-/diff-1.4.0.tgz#7f28d2eb9ee7b15a97efd89ce63dcfdaa3ccbabf"
2076-
20772073
diff@^3.2.0:
20782074
version "3.5.0"
20792075
resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"
20802076

2081-
disparity@^2.0.0:
2082-
version "2.0.0"
2083-
resolved "https://registry.yarnpkg.com/disparity/-/disparity-2.0.0.tgz#57ddacb47324ae5f58d2cc0da886db4ce9eeb718"
2084-
dependencies:
2085-
ansi-styles "^2.0.1"
2086-
diff "^1.3.2"
2077+
diff@^4.0.1:
2078+
version "4.0.1"
2079+
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.1.tgz#0c667cb467ebbb5cea7f14f135cc2dba7780a8ff"
2080+
integrity sha512-s2+XdvhPCOF01LRQBC8hf4vhbVmI2CGS5aZnxLJlT5FtdhPCDFq80q++zK2KlrVorVDdL5BOGZ/VfLrVtYNF+Q==
20872081

20882082
20892083
version "2.1.0"

0 commit comments

Comments
 (0)