Skip to content

Remove unmaintained dependency: disparity #1264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@
"@babel/traverse": "^7.1.4",
"@babel/types": "^7.1.3",
"ansi-html": "^0.0.7",
"ansi-styles": "^4.0.0",
"babelify": "^10.0.0",
"chalk": "^2.3.0",
"chokidar": "^2.0.4",
"concat-stream": "^1.6.0",
"disparity": "^2.0.0",
"diff": "^4.0.1",
"doctrine-temporary-fork": "2.1.0",
"get-port": "^4.0.0",
"git-url-parse": "^10.0.1",
Expand Down
41 changes: 34 additions & 7 deletions src/commands/readme.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const documentation = require('../');
const sharedOptions = require('./shared_options');
const inject = require('mdast-util-inject');
const chalk = require('chalk');
const disparity = require('disparity');
const diff = require('diff');
const ansi = require('ansi-styles');
const getReadmeFile = require('../get-readme-file');

module.exports.command = 'readme [input..]';
Expand Down Expand Up @@ -94,22 +95,48 @@ module.exports.handler = function readme(argv) {
.process(readmeContent)
)
.then(file => {
const diffOutput = disparity.unified(readmeContent, file.contents, {
paths: [argv.readmeFile, argv.readmeFile]
});
if (!diffOutput.length) {
const diffRaw = diff.createPatch(
'',
readmeContent,
file.contents,
'',
''
);
if (!diffRaw.length) {
log(`${argv.readmeFile} is up to date.`);
process.exit(0);
}

// Replace diff headers with real values
const cleanedDiff = diffRaw
.replace(/^([^\n]+)\n([^\n]+)\n/m, '')
.replace(/^---.*/gm, `--- ${argv.readmeFile}\tremoved`)
.replace(/^\+\+\+.*/gm, `+++ ${argv.readmeFile}\tadded`);

// Includes newlines for easier joins
const diffLines = cleanedDiff.split(/^/m);
const diffHeader = diffLines
.slice(0, 2)
.join('')
.replace(/[^\n\r]+/g, `${ansi.yellow.open}$&${ansi.yellow.close}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use the pre-existing chalk dependency for this styling instead of introducing ansi-styles?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. My original intention was to keep the logic as close to disparity as possible but using chalk makes much more sense.

const diffBody = diffLines
.slice(2)
.join('')
.replace(/^-[^\n\r]*/gm, `${ansi.red.open}$&${ansi.red.close}`)
.replace(/^\+[^\n\r]*/gm, `${ansi.green.open}$&${ansi.green.close}`)
.replace(/^@@.+@@/gm, `${ansi.magenta.open}$&${ansi.magenta.close}`);

if (argv.d) {
log(
chalk.bold(`${argv.readmeFile} needs the following updates:`),
`\n${diffOutput}`
`\n${diffHeader}${diffBody}`
);
process.exit(1);
} else {
log(chalk.bold(`Updating ${argv.readmeFile}`), `\n${diffOutput}`);
log(
chalk.bold(`Updating ${argv.readmeFile}`),
`\n${diffHeader}${diffBody}`
);
}

fs.writeFileSync(argv.readmeFile, file.contents);
Expand Down
35 changes: 24 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ ansi-regex@^4.1.0:
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.1.0.tgz#8b9f8f08cf1acb843756a839ca8c7e3168c51997"
integrity sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==

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

Expand All @@ -941,6 +941,13 @@ ansi-styles@^3.2.0, ansi-styles@^3.2.1:
dependencies:
color-convert "^1.9.0"

ansi-styles@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.0.0.tgz#f6b84e8fc97ea7add7a53b7530ef28f3fde0e048"
integrity sha512-8zjUtFJ3db/QoPXuuEMloS2AUf79/yeyttJ7Abr3hteopJu9HK8vsgGviGUMq+zyA6cZZO6gAyZoMTF6TgaEjA==
dependencies:
color-convert "^2.0.0"

any-observable@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/any-observable/-/any-observable-0.3.0.tgz#af933475e5806a67d0d7df090dd5e8bef65d119b"
Expand Down Expand Up @@ -1627,11 +1634,23 @@ color-convert@^1.9.0:
dependencies:
color-name "1.1.3"

color-convert@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.0.tgz#9851ac61cc0d3898a8a3088650d5bf447bf69d97"
integrity sha512-hzTicsCJIHdxih9+2aLR1tNGZX5qSJGRHDPVwSY26tVrEf55XNajLOBWz2UuWSIergszA09/bqnOiHyqx9fxQg==
dependencies:
color-name "~1.1.4"

[email protected]:
version "1.1.3"
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"
integrity sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=

color-name@~1.1.4:
version "1.1.4"
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==

combined-stream@^1.0.6, combined-stream@~1.0.6:
version "1.0.7"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.7.tgz#2d1d24317afb8abe95d6d2c0b07b57813539d828"
Expand Down Expand Up @@ -2070,20 +2089,14 @@ detective@^4.0.0:
acorn "^5.2.1"
defined "^1.0.0"

diff@^1.3.2:
version "1.4.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-1.4.0.tgz#7f28d2eb9ee7b15a97efd89ce63dcfdaa3ccbabf"

diff@^3.2.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"

disparity@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/disparity/-/disparity-2.0.0.tgz#57ddacb47324ae5f58d2cc0da886db4ce9eeb718"
dependencies:
ansi-styles "^2.0.1"
diff "^1.3.2"
diff@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.1.tgz#0c667cb467ebbb5cea7f14f135cc2dba7780a8ff"
integrity sha512-s2+XdvhPCOF01LRQBC8hf4vhbVmI2CGS5aZnxLJlT5FtdhPCDFq80q++zK2KlrVorVDdL5BOGZ/VfLrVtYNF+Q==

[email protected]:
version "2.1.0"
Expand Down