Skip to content

Commit ea732cd

Browse files
reExport diffFile from component package
1 parent 720f83d commit ea732cd

17 files changed

Lines changed: 37 additions & 24 deletions

File tree

packages/core/src/cache.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
export class Cache<K, V> extends Map<K, V> {
22
#keyArray: K[] = [];
33

4+
name: string;
5+
46
#maxLength = 30;
57

68
setMaxLength(length: number) {
@@ -21,4 +23,4 @@ export class Cache<K, V> extends Map<K, V> {
2123
this.delete(key);
2224
}
2325
}
24-
}
26+
}

packages/core/src/file.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,20 @@ const map = new Cache<string, File>();
77

88
map.setMaxLength(50);
99

10+
map.name = "@git-diff-view/core";
11+
1012
if (__DEV__ && typeof globalThis !== "undefined") {
11-
if (typeof globalThis.__diff_cache__ === "object") {
12-
console.warn("there are multiple version of @git-diff-view/core in the one environment!");
13+
if (Array.isArray(globalThis.__diff_cache__)) {
14+
globalThis.__diff_cache__ = globalThis.__diff_cache__.filter((i) => i !== map);
15+
16+
if (globalThis.__diff_cache__.length > 0) {
17+
console.warn("there are multiple instance of @git-diff-view/core in the one environment!");
18+
}
19+
20+
globalThis.__diff_cache__.push(map);
21+
} else {
22+
globalThis.__diff_cache__ = [map];
1323
}
14-
globalThis.__diff_cache__ = map;
1524
}
1625

1726
export type SyntaxNode = {
@@ -254,3 +263,5 @@ export const getFile = (raw: string, lang: string, fileName?: string) => {
254263

255264
return file;
256265
};
266+
267+
export const _cacheMap = map;

packages/core/src/global.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ declare global {
55
const __VERSION__: string;
66

77
interface globalThis {
8-
__diff_cache__: Map<string, File>;
8+
__diff_cache__: Map<string, File>[];
99
}
1010

1111
namespace NodeJS {

packages/react/src/components/DiffView.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
22
/* eslint-disable @typescript-eslint/ban-ts-comment */
3-
import { DiffFile } from "@git-diff-view/core";
3+
import { DiffFile, _cacheMap } from "@git-diff-view/core";
44
import { memo, useEffect, useMemo, forwardRef, useImperativeHandle } from "react";
55
import * as React from "react";
66
import { createStore, ref } from "reactivity-store";
@@ -16,6 +16,8 @@ import type { CSSProperties, ForwardedRef, ReactNode } from "react";
1616

1717
const diffFontSizeName = "--diff-font-size--";
1818

19+
_cacheMap.name = "@git-diff-view/react";
20+
1921
export enum SplitSide {
2022
old = 1,
2123
new = 2,

packages/react/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
export * from "./components/DiffView";
22
export * from "./components/DiffViewContext";
3+
4+
export * from "@git-diff-view/core";

packages/react/src/index.withStyle.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ import "./tailwind.css";
44
export * from "./components/DiffView";
55
export * from "./components/DiffViewContext";
66

7+
export * from "@git-diff-view/core";

packages/vue/src/components/DiffView.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DiffFile } from "@git-diff-view/core";
1+
import { DiffFile, _cacheMap } from "@git-diff-view/core";
22
import { defineComponent, provide, ref, watch, watchEffect, computed, onUnmounted } from "vue";
33

44
import {
@@ -52,6 +52,8 @@ export type DiffViewProps<T> = {
5252
diffViewAddWidget?: boolean;
5353
};
5454

55+
_cacheMap.name = "@git-diff-view/vue";
56+
5557
const diffFontSizeName = "--diff-font-size--";
5658

5759
type typeSlots = SlotsType<{

packages/vue/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
export * from "./components/DiffView";
2+
3+
export * from "@git-diff-view/core";

packages/vue/src/index.withStyle.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ import "highlight.js/styles/github.css";
22
import "./tailwind.css";
33

44
export * from "./components/DiffView";
5+
6+
export * from "@git-diff-view/core";

pnpm-lock.yaml

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)