chore(deps): update dependency diff to v8 #1412
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains the following updates:
^5.0.0
->^8.0.0
Release Notes
kpdecker/jsdiff (diff)
v8.0.1
Compare Source
diffJson
which were broken by 8.0.0. The new bundled types in 8.0.0 only alloweddiffJson
to be passed string arguments, but it should've been possible to pass either strings or objects (and now is). Thanks to Josh Kelley for the fix.v8.0.0
Compare Source
diffSentences
:["foo.", " ", "bar."]
but "foo. bar" tokenized to["foo.", " bar"]
- i.e. whether the space between sentences was treated as a separate token depended upon whether the final sentence had trailing punctuation or not. This was arbitrary and surprising; it is no longer the case.)diffWords
taking O(n^2) time in pathological cases.push()
using.apply
or the spread operator and hitting the JS-implementation-specific limit on the maximum number of arguments to a function, as shown at https://stackoverflow.com/a/56809779/1709587; thus the exact threshold to hit the error will depend on the environment in which you were running JsDiff.)merge
function. Previously JsDiff included an undocumented function calledmerge
that was meant to, in some sense, merge patches. It had at least a couple of serious bugs that could lead to it returning unambiguously wrong results, and it was difficult to simply "fix" because it was unclear precisely what it was meant to do. For now, the fix is to remove it entirely.the
diff
package on npm now includes its own TypeScript type definitions. Users who previously used the@types/diff
npm package from DefinitelyTyped should remove that dependency when upgrading JsDiff to v8.Note that the transition from the DefinitelyTyped types to JsDiff's own type definitions includes multiple fixes and also removes many exported types previously used for
options
arguments to diffing and patch-generation functions. (There are now different exported options types for abortable calls - ones with atimeout
ormaxEditLength
that may give a result ofundefined
- and non-abortable calls.) See the TypeScript section of the README for some usage tips.The
Diff
object is now a class. Custom extensions ofDiff
, as described in the "Defining custom diffing behaviors" section of the README, can therefore now be done by writing aclass CustomDiff extends Diff
and overriding methods, instead of the old way based on prototype inheritance. (I think code that did things the old way should still work, though!)diff/lib/index.es6.js
anddiff/lib/index.mjs
no longer exist, and the ESM version of the library is no longer bundled into a single file.The
ignoreWhitespace
option fordiffWords
is no longer included in the type declarations. The effect of passingignoreWhitespace: true
has always been to makediffWords
just calldiffWordsWithSpace
instead, which was confusing, because that behaviour doesn't seem properly described as "ignoring" whitespace at all. The property remains available to non-TypeScript applications for the sake of backwards compatability, but TypeScript applications will now see a type error if they try to passignoreWhitespace: true
todiffWords
and should change their code to calldiffWordsWithSpace
instead.JsDiff no longer purports to support ES3 environments. (I'm pretty sure it never truly did, despite claiming to in its README, since even the 1.0.0 release used
Array.map
which was added in ES5.)diffJson
'sstringifyReplacer
option behaves more likeJSON.stringify
'sreplacer
argument now. In particular:key
passed to the replacer when the top-level object is passed in asvalue
is now""
(previously, wasundefined
), and thekey
passed with an array element is the array index as a string, like"0"
or"1"
(previously was whatever the key for the entire array was). Both the new behaviours match that ofJSON.stringify
.undefined
when called in async mode (i.e. with a callback). Previously, there was an odd quirk where they would returntrue
if the strings being diffed were equal andundefined
otherwise.v7.0.0
Compare Source
Just a single (breaking) bugfix, undoing a behaviour change introduced accidentally in 6.0.0:
diffWords
treats numbers and underscores as word characters again. This behaviour was broken in v6.0.0.v6.0.0
Compare Source
This is a release containing many, many breaking changes. The objective of this release was to carry out a mass fix, in one go, of all the open bugs and design problems that required breaking changes to fix. A substantial, but exhaustive, changelog is below.
Commits
#497
diffWords
behavior has been radically changed. Previously, even withignoreWhitespace: true
, runs of whitespace were tokens, which led to unhelpful and unintuitive diffing behavior in typical texts. Specifically, even when two texts contained overlapping passages,diffWords
would sometimes choose to delete all the words from the old text and insert them anew in their new positions in order to avoid having to delete or insert whitespace tokens. Whitespace sequences are no longer tokens as of this release, which affects both the generated diffs and thecount
s.Runs of whitespace are still tokens in
diffWordsWithSpace
.As part of the changes to
diffWords
, a new.postProcess
method has been added on the baseDiff
type, which can be overridden in customDiff
implementations.diffLines
withignoreWhitespace: true
will no longer ignore the insertion or deletion of entire extra lines of whitespace at the end of the text. Previously, these would not show up as insertions or deletions, as a side effect of a hack in the base diffing algorithm meant to help ignore whitespace indiffWords
. More generally, the undocumented special handling in the core algorithm for ignored terminals has been removed entirely. (This special case behavior used to rewrite the final two change objects in a scenario where the final change object was an addition or deletion and itsvalue
was treated as equal to the empty string when compared using the diff object's.equals
method.)#500
diffChars
now diffs Unicode code points instead of UTF-16 code units.#508
parsePatch
now always runs in what was previously "strict" mode; the undocumentedstrict
option has been removed. Previously, by default,parsePatch
(and other patch functions that use it under the hood to parse patches) would accept a patch where the line counts in the headers were inconsistent with the actual patch content - e.g. where a hunk started with the header@@​ -1,3 +1,6 @​@​
, indicating that the content below spanned 3 lines in the old file and 6 lines in the new file, but then the actual content below the header consisted of some different number of lines, say 10 lines of context, 5 deletions, and 1 insertion. Actually trying to work with these patches usingapplyPatch
ormerge
, however, would produce incorrect results instead of just ignoring the incorrect headers, making this "feature" more of a trap than something actually useful. It's been ripped out, and now we are always "strict" and will reject patches where the line counts in the headers aren't consistent with the actual patch content.#435 Fix
parsePatch
handling of control characters.parsePatch
used to interpret various unusual control characters - namely vertical tabs, form feeds, lone carriage returns without a line feed, and EBCDIC NELs - as line breaks when parsing a patch file. This was inconsistent with the behavior of both JsDiff's owndiffLines
method and also the Unixdiff
andpatch
utils, which all simply treat those control characters as ordinary characters. The result of this discrepancy was that some well-formed patches - produced either bydiff
or by JsDiff itself and handled properly by thepatch
util - would be wrongly parsed byparsePatch
, with the effect that it would disregard the remainder of a hunk after encountering one of these control characters.#439 Prefer diffs that order deletions before insertions. When faced with a choice between two diffs with an equal total edit distance, the Myers diff algorithm generally prefers one that does deletions before insertions rather than insertions before deletions. For instance, when diffing
abcd
againstacbd
, it will prefer a diff that says to delete theb
and then insert a newb
after thec
, over a diff that says to insert ac
before theb
and then delete the existingc
. JsDiff deviated from the published Myers algorithm in a way that led to it having the opposite preference in many cases, including that example. This is now fixed, meaning diffs output by JsDiff will more accurately reflect what the published Myers diff algorithm would output.#455 The
added
andremoved
properties of change objects are now guaranteed to be set to a boolean value. (Previously, they would be set toundefined
or omitted entirely instead of setting them to false.)#464 Specifying
{maxEditLength: 0}
now sets a max edit length of 0 instead of no maximum.#460 Added
oneChangePerToken
option.#467 Consistent ordering of arguments to
comparator(left, right)
. Values from the old array will now consistently be passed as the first argument (left
) and values from the new array as the second argument (right
). Previously this was almost (but not quite) always the other way round.#480 Passing
maxEditLength
tocreatePatch
&createTwoFilesPatch
now works properly (i.e. returns undefined if the max edit distance is exceeded; previous behavior was to crash with aTypeError
if the edit distance was exceeded).#486 The
ignoreWhitespace
option ofdiffLines
behaves more sensibly now.value
s in returned change objects now include leading/trailing whitespace even whenignoreWhitespace
is used, just like how withignoreCase
thevalue
s still reflect the case of one of the original texts instead of being all-lowercase.ignoreWhitespace
is also now compatible withnewlineIsToken
. Finally,diffTrimmedLines
is deprecated (and removed from the docs) in favour of usingdiffLines
withignoreWhitespace: true
; the two are, and always have been, equivalent.#490 When calling diffing functions in async mode by passing a
callback
option, the diff result will now be passed as the first argument to the callback instead of the second. (Previously, the first argument was never used at all and would always have valueundefined
.)#489
this.options
no longer exists onDiff
objects. Instead,options
is now passed as an argument to methods that rely on options, likeequals(left, right, options)
. This fixes a race condition in async mode, where diffing behaviour could be changed mid-execution if a concurrent usage of the sameDiff
instances overwrote itsoptions
.#518
linedelimiters
no longer exists on patch objects; instead, when a patch with Windows-style CRLF line endings is parsed, the lines inlines
will end with\r
. There is now a newautoConvertLineEndings
option, on by default, which makes it so that when a patch with Windows-style line endings is applied to a source file with Unix style line endings, the patch gets autoconverted to use Unix-style line endings, and when a patch with Unix-style line endings is applied to a source file with Windows-style line endings, it gets autoconverted to use Windows-style line endings.#521 the
callback
option is now supported bystructuredPatch
,createPatch
, andcreateTwoFilesPatch
#529
parsePatch
can now parse patches where lines starting with--
or++
are deleted/inserted; previously, there were edge cases where the parser would choke on valid patches or give wrong results.#530 Added
ignoreNewlineAtEof
option todiffLines
#533
applyPatch
uses an entirely new algorithm for fuzzy matching. Differences between the old and new algorithm are as follows:fuzzFactor
now indicates the maximum Levenshtein distance that there can be between the context shown in a hunk and the actual file content at a location where we try to apply the hunk. (Previously, it represented a maximum Hamming distance, meaning that a single insertion or deletion in the source file could stop a hunk from applying even with a highfuzzFactor
.)applyPatch
would apply the hunk anyway and delete a completely different line.)#535 A bug in patch generation functions is now fixed that would sometimes previously cause
\ No newline at end of file
to appear in the wrong place in the generated patch, resulting in the patch being invalid. These invalid patches can also no longer be applied successfully withapplyPatch
. (It was already the case that tools other than jsdiff, like GNUpatch
, would consider them malformed and refuse to apply them; versions of jsdiff with this fix now do the same thing if you ask them to apply a malformed patch emitted by jsdiff v5.)#535 Passing
newlineIsToken: true
to patch-generation functions is no longer allowed. (Passing it todiffLines
is still supported - it's only functions likecreatePatch
where passingnewlineIsToken
is now an error.) Allowing it to be passed never really made sense, since in cases where the option had any effect on the output at all, the effect tended to be causing a garbled patch to be created that couldn't actually be applied to the source file.#539
diffWords
now takes an optionalintlSegmenter
option which should be anIntl.Segmenter
with word-level granularity. This provides better tokenization of text into words than the default behaviour, even for English but especially for some other languages for which the default behaviour is poor.Configuration
📅 Schedule: Branch creation - Between 12:00 AM and 03:59 AM, only on Monday ( * 0-3 * * 1 ) (UTC), Automerge - At any time (no schedule defined).
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR was generated by Mend Renovate. View the repository job log.