Skip to content

Commit

Permalink
fix: upgrade parser to handle binary delta diff (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
otakustay committed Mar 14, 2023
1 parent 1f3921d commit 5f3264f
Show file tree
Hide file tree
Showing 3 changed files with 319 additions and 232 deletions.
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,25 @@
"@types/refractor": "^2.8.0",
"@types/sha1": "^1.1.3",
"@types/warning": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.53.0",
"antd": "^5.2.2",
"autoprefixer": "^10.4.13",
"@typescript-eslint/eslint-plugin": "^5.55.0",
"@typescript-eslint/parser": "^5.55.0",
"antd": "^5.3.1",
"autoprefixer": "^10.4.14",
"babel-loader": "^9.1.2",
"babel-plugin-add-react-displayname": "0.0.5",
"babel-plugin-import": "^1.13.6",
"babel-plugin-lodash": "^3.3.4",
"babel-plugin-react-require": "^3.1.3",
"core-js": "^3.28.0",
"core-js": "^3.29.1",
"css-loader": "^6.7.3",
"cssnano": "^5.1.15",
"dedent": "^0.7.0",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.7",
"eslint": "^8.34.0",
"eslint": "^8.36.0",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"gitdiff-parser": "^0.3.0",
"gitdiff-parser": "^0.3.1",
"html-webpack-plugin": "^5.5.0",
"husky": "^8.0.3",
"identity-obj-proxy": "^3.0.0",
Expand All @@ -88,7 +88,7 @@
"nanoid": "^4.0.1",
"postcss": "^8.4.21",
"postcss-cli": "^10.1.0",
"postcss-custom-properties": "^13.1.3",
"postcss-custom-properties": "^13.1.4",
"prism-color-variables": "^1.0.1",
"prop-types": "^15.8.1",
"raw-loader": "^4.0.2",
Expand All @@ -99,7 +99,7 @@
"react-test-renderer": "^18.2.0",
"react-timeago": "^7.1.0",
"refractor": "^2.10.1",
"rollup": "^3.17.2",
"rollup": "^3.19.1",
"rollup-plugin-auto-external": "^2.0.0",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-commonjs": "^10.1.0",
Expand All @@ -108,11 +108,11 @@
"rollup-plugin-terser": "^7.0.2",
"sha1": "^1.1.1",
"standard-version": "^9.5.0",
"style-loader": "^3.3.1",
"style-loader": "^3.3.2",
"typescript": "^4.9.5",
"unidiff": "^1.0.2",
"vitest": "^0.28.5",
"webpack": "^5.75.0",
"vitest": "^0.29.2",
"webpack": "^5.76.1",
"webpack-cli": "^5.0.1",
"webpack-dev-server": "^4.11.1",
"worker-loader": "^3.0.8"
Expand Down
24 changes: 17 additions & 7 deletions site/components/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,22 @@ import InputArea from '../InputArea';
import styles from './index.less';
import './app.global.less';

const fakeIndex = () => sha(uniqueId()).slice(0, 9);
function fakeIndex() {
return sha(uniqueId()).slice(0, 9);
}

function appendGitDiffHeaderIfNeeded(diffText: string) {
if (diffText.startsWith('diff --git')) {
return diffText;
}

const segments = [
'diff --git a/a b/b',
`index ${fakeIndex()}..${fakeIndex()} 100644`,
diffText,
];
return segments.join('\n');
}

interface DiffData {
diff: string;
Expand All @@ -24,12 +39,7 @@ export default function App() {
return null;
}

const segments = [
'diff --git a/a b/b',
`index ${fakeIndex()}..${fakeIndex()} 100644`,
diff,
];
const [file] = parseDiff(segments.join('\n'), {nearbySequences: 'zip'});
const [file] = parseDiff(appendGitDiffHeaderIfNeeded(diff), {nearbySequences: 'zip'});
return file;
},
[diff]
Expand Down
Loading

0 comments on commit 5f3264f

Please sign in to comment.