Skip to content

Commit e045afe

Browse files
committed
fix: switch to @dmsnell/diff-match-patch fix #378
1 parent 44ad4c2 commit e045afe

File tree

8 files changed

+82
-235
lines changed

8 files changed

+82
-235
lines changed

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,11 @@ In a browser, you can load a bundle using a tool like [esm.sh](https://esm.sh) o
199199

200200
## Options
201201

202-
```tsimport * as jsondiffpatch from 'jsondiffpatch';
202+
```ts
203+
import * as jsondiffpatch from 'jsondiffpatch';
203204

204205
// Only import if you want text diffs using diff-match-patch
205-
import DiffMatchPatch from 'diff-match-patch';
206+
import { diff_match_patch } from '@dmsnell/diff-match-patch';
206207

207208
const jsondiffpatchInstance = jsondiffpatch.create({
208209
// used to match objects when diffing arrays, by default only === operator is used
@@ -219,8 +220,8 @@ const jsondiffpatchInstance = jsondiffpatch.create({
219220
textDiff: {
220221
// If using text diffs, it's required to pass in the diff-match-patch library in through this proprty.
221222
// Alternatively, you can import jsondiffpatch using `jsondiffpatch/with-text-diffs` to avoid having to pass in diff-match-patch through the options.
222-
diffMatchPatch: DiffMatchPatch,
223-
// default 60, minimum string length (left and right sides) to use text diff algorythm: google-diff-match-patch
223+
diffMatchPatch: diff_match_patch,
224+
// default 60, minimum string length (left and right sides) to use text diff algorithm: google-diff-match-patch
224225
minLength: 60,
225226
},
226227
propertyFilter: function (name, context) {

package-lock.json

+53-207
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/jsondiffpatch/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@
4343
"patch"
4444
],
4545
"dependencies": {
46-
"@types/diff-match-patch": "^1.0.36",
47-
"diff-match-patch": "^1.0.5"
46+
"@dmsnell/diff-match-patch": "^1.1.0"
4847
},
4948
"devDependencies": {
5049
"@types/jest": "^29.5.10",

packages/jsondiffpatch/src/filters/texts.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type dmp from 'diff-match-patch';
1+
import type { diff_match_patch } from '@dmsnell/diff-match-patch';
22
import type DiffContext from '../contexts/diff.js';
33
import type PatchContext from '../contexts/patch.js';
44
import type ReverseContext from '../contexts/reverse.js';
@@ -31,7 +31,7 @@ function getDiffMatchPatch(
3131
): DiffPatch | null;
3232
function getDiffMatchPatch(options: Options | undefined, required?: boolean) {
3333
if (!cachedDiffPatch) {
34-
let instance: dmp;
34+
let instance: diff_match_patch;
3535
if (options?.textDiff?.diffMatchPatch) {
3636
instance = new options.textDiff.diffMatchPatch();
3737
} else {

packages/jsondiffpatch/src/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type dmp from 'diff-match-patch';
1+
import type { diff_match_patch } from '@dmsnell/diff-match-patch';
22
import type Context from './contexts/context.js';
33
import type DiffContext from './contexts/diff.js';
44

@@ -10,7 +10,7 @@ export interface Options {
1010
includeValueOnMove?: boolean;
1111
};
1212
textDiff?: {
13-
diffMatchPatch: typeof dmp;
13+
diffMatchPatch: typeof diff_match_patch;
1414
minLength?: number;
1515
};
1616
propertyFilter?: (name: string, context: DiffContext) => boolean;

packages/jsondiffpatch/src/with-text-diffs.ts

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import DiffMatchPatch from 'diff-match-patch';
2-
import DiffPatcher from './diffpatcher.js';
3-
import dateReviver from './date-reviver.js';
4-
import type { Delta, Options } from './types.js';
1+
import { diff_match_patch } from '@dmsnell/diff-match-patch';
2+
53
import type Context from './contexts/context.js';
64
import type DiffContext from './contexts/diff.js';
75
import type PatchContext from './contexts/patch.js';
86
import type ReverseContext from './contexts/reverse.js';
7+
import dateReviver from './date-reviver.js';
8+
import DiffPatcher from './diffpatcher.js';
9+
import type { Delta, Options } from './types.js';
910

10-
export { DiffPatcher, dateReviver };
11+
export { dateReviver, DiffPatcher };
1112

1213
export type * from './types.js';
1314
export type { Context, DiffContext, PatchContext, ReverseContext };
@@ -19,7 +20,7 @@ export function create(
1920
) {
2021
return new DiffPatcher({
2122
...options,
22-
textDiff: { ...options?.textDiff, diffMatchPatch: DiffMatchPatch },
23+
textDiff: { ...options?.textDiff, diffMatchPatch: diff_match_patch },
2324
});
2425
}
2526

@@ -28,7 +29,7 @@ let defaultInstance: DiffPatcher;
2829
export function diff(left: unknown, right: unknown) {
2930
if (!defaultInstance) {
3031
defaultInstance = new DiffPatcher({
31-
textDiff: { diffMatchPatch: DiffMatchPatch },
32+
textDiff: { diffMatchPatch: diff_match_patch },
3233
});
3334
}
3435
return defaultInstance.diff(left, right);
@@ -37,7 +38,7 @@ export function diff(left: unknown, right: unknown) {
3738
export function patch(left: unknown, delta: Delta) {
3839
if (!defaultInstance) {
3940
defaultInstance = new DiffPatcher({
40-
textDiff: { diffMatchPatch: DiffMatchPatch },
41+
textDiff: { diffMatchPatch: diff_match_patch },
4142
});
4243
}
4344
return defaultInstance.patch(left, delta);
@@ -46,7 +47,7 @@ export function patch(left: unknown, delta: Delta) {
4647
export function unpatch(right: unknown, delta: Delta) {
4748
if (!defaultInstance) {
4849
defaultInstance = new DiffPatcher({
49-
textDiff: { diffMatchPatch: DiffMatchPatch },
50+
textDiff: { diffMatchPatch: diff_match_patch },
5051
});
5152
}
5253
return defaultInstance.unpatch(right, delta);
@@ -55,7 +56,7 @@ export function unpatch(right: unknown, delta: Delta) {
5556
export function reverse(delta: Delta) {
5657
if (!defaultInstance) {
5758
defaultInstance = new DiffPatcher({
58-
textDiff: { diffMatchPatch: DiffMatchPatch },
59+
textDiff: { diffMatchPatch: diff_match_patch },
5960
});
6061
}
6162
return defaultInstance.reverse(delta);
@@ -64,7 +65,7 @@ export function reverse(delta: Delta) {
6465
export function clone(value: unknown) {
6566
if (!defaultInstance) {
6667
defaultInstance = new DiffPatcher({
67-
textDiff: { diffMatchPatch: DiffMatchPatch },
68+
textDiff: { diffMatchPatch: diff_match_patch },
6869
});
6970
}
7071
return defaultInstance.clone(value);

packages/jsondiffpatch/test/examples/diffpatch.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import DiffMatchPatch from 'diff-match-patch';
1+
import { diff_match_patch } from '@dmsnell/diff-match-patch';
22
import type { Delta, Options } from '../../src/index.js';
33

44
interface Example {
@@ -580,7 +580,7 @@ const text: ExampleGroup = [
580580
right: largeText,
581581
delta: [shortText, largeText],
582582
reverse: [largeText, shortText],
583-
options: { textDiff: { diffMatchPatch: DiffMatchPatch } },
583+
options: { textDiff: { diffMatchPatch: diff_match_patch } },
584584
},
585585
{
586586
left: largeText,
@@ -600,13 +600,13 @@ const text: ExampleGroup = [
600600
2,
601601
],
602602
exactReverse: false,
603-
options: { textDiff: { diffMatchPatch: DiffMatchPatch } },
603+
options: { textDiff: { diffMatchPatch: diff_match_patch } },
604604
},
605605
{
606606
name: 'larger than min length',
607607
options: {
608608
textDiff: {
609-
diffMatchPatch: DiffMatchPatch,
609+
diffMatchPatch: diff_match_patch,
610610
minLength: 10,
611611
},
612612
},
@@ -620,7 +620,7 @@ const text: ExampleGroup = [
620620
name: 'shorter than min length',
621621
options: {
622622
textDiff: {
623-
diffMatchPatch: DiffMatchPatch,
623+
diffMatchPatch: diff_match_patch,
624624
minLength: 10,
625625
},
626626
},

packages/jsondiffpatch/test/formatters/html.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import DiffMatchPatch from 'diff-match-patch';
1+
import { diff_match_patch } from '@dmsnell/diff-match-patch';
22
import * as htmlFormatter from '../../src/formatters/html.js';
33
import * as jsondiffpatch from '../../src/index.js';
44

@@ -10,7 +10,7 @@ describe('formatters.html', () => {
1010

1111
beforeAll(() => {
1212
instance = new DiffPatcher({
13-
textDiff: { diffMatchPatch: DiffMatchPatch, minLength: 10 },
13+
textDiff: { diffMatchPatch: diff_match_patch, minLength: 10 },
1414
});
1515
formatter = htmlFormatter;
1616
});

0 commit comments

Comments
 (0)