@pierre/diffs 1.0.0-beta.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/highlighter/languages/resolveLanguage.js +1 -1
- package/dist/highlighter/languages/resolveLanguage.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/parseLineType.d.ts.map +1 -1
- package/dist/utils/parsePatchFiles.d.ts.map +1 -1
- package/dist/utils/parsePatchFiles.js +3 -2
- package/dist/utils/parsePatchFiles.js.map +1 -1
- package/package.json +1 -4
|
@@ -9,7 +9,7 @@ async function resolveLanguage(lang) {
|
|
|
9
9
|
if (resolver != null) return resolver;
|
|
10
10
|
try {
|
|
11
11
|
const loader = bundledLanguages[lang];
|
|
12
|
-
if (loader == null) throw new Error(
|
|
12
|
+
if (loader == null) throw new Error(`resolveLanguage: "${lang}" not found in bundled languages`);
|
|
13
13
|
const resolver$1 = loader().then(({ default: data }) => {
|
|
14
14
|
const resolvedLang = {
|
|
15
15
|
name: lang,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveLanguage.js","names":["resolver"],"sources":["../../../src/highlighter/languages/resolveLanguage.ts"],"sourcesContent":["import { bundledLanguages } from 'shiki';\n\nimport type { SupportedLanguages } from '../../types';\nimport { isWorkerContext } from '../../utils/isWorkerContext';\nimport type { ResolvedLanguage } from '../../worker';\nimport { ResolvedLanguages, ResolvingLanguages } from './constants';\n\nexport async function resolveLanguage(\n lang: Exclude<SupportedLanguages, 'text'>\n): Promise<ResolvedLanguage> {\n // Prevent dynamic imports in worker contexts\n if (isWorkerContext()) {\n throw new Error(\n `resolveLanguage(\"${lang}\") cannot be called from a worker context. ` +\n 'Languages must be pre-resolved on the main thread and passed to the worker via the resolvedLanguages parameter.'\n );\n }\n\n const resolver = ResolvingLanguages.get(lang);\n if (resolver != null) {\n return resolver;\n }\n\n try {\n const loader = bundledLanguages[lang];\n if (loader == null) {\n throw new Error(\n
|
|
1
|
+
{"version":3,"file":"resolveLanguage.js","names":["resolver"],"sources":["../../../src/highlighter/languages/resolveLanguage.ts"],"sourcesContent":["import { bundledLanguages } from 'shiki';\n\nimport type { SupportedLanguages } from '../../types';\nimport { isWorkerContext } from '../../utils/isWorkerContext';\nimport type { ResolvedLanguage } from '../../worker';\nimport { ResolvedLanguages, ResolvingLanguages } from './constants';\n\nexport async function resolveLanguage(\n lang: Exclude<SupportedLanguages, 'text'>\n): Promise<ResolvedLanguage> {\n // Prevent dynamic imports in worker contexts\n if (isWorkerContext()) {\n throw new Error(\n `resolveLanguage(\"${lang}\") cannot be called from a worker context. ` +\n 'Languages must be pre-resolved on the main thread and passed to the worker via the resolvedLanguages parameter.'\n );\n }\n\n const resolver = ResolvingLanguages.get(lang);\n if (resolver != null) {\n return resolver;\n }\n\n try {\n const loader = bundledLanguages[lang];\n if (loader == null) {\n throw new Error(\n `resolveLanguage: \"${lang}\" not found in bundled languages`\n );\n }\n\n const resolver = loader().then(({ default: data }) => {\n const resolvedLang = { name: lang, data };\n if (!ResolvedLanguages.has(lang)) {\n ResolvedLanguages.set(lang, resolvedLang);\n }\n return resolvedLang;\n });\n ResolvingLanguages.set(lang, resolver);\n return await resolver;\n } finally {\n ResolvingLanguages.delete(lang);\n }\n}\n"],"mappings":";;;;;AAOA,eAAsB,gBACpB,MAC2B;AAE3B,KAAI,iBAAiB,CACnB,OAAM,IAAI,MACR,oBAAoB,KAAK,4JAE1B;CAGH,MAAM,WAAW,mBAAmB,IAAI,KAAK;AAC7C,KAAI,YAAY,KACd,QAAO;AAGT,KAAI;EACF,MAAM,SAAS,iBAAiB;AAChC,MAAI,UAAU,KACZ,OAAM,IAAI,MACR,qBAAqB,KAAK,kCAC3B;EAGH,MAAMA,aAAW,QAAQ,CAAC,MAAM,EAAE,SAAS,WAAW;GACpD,MAAM,eAAe;IAAE,MAAM;IAAM;IAAM;AACzC,OAAI,CAAC,kBAAkB,IAAI,KAAK,CAC9B,mBAAkB,IAAI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GF;iBACE;;;UAIA,sBAAA,SACP,KAAK;;kBAEG;YACN;;UAGK,uBAAA;;;eAGF;WACJ;;;;eAII;WACJ;;;;;UAMM,iBAAA;;eAEF;iBACE;;;;UAKA,QAAA;;;;;;;;;;;UAYA,UAAA;;;;;;;KAQL,iCAAiC,eAE3C,mBAAmB;KAGT,mBAAA;UAEK,qBAAA;YACL;YACA;;;UAIK,qBAAA;SACR;;;;UAKQ,gBAAA;QACT;;;;UAKS,gBAAA;QACT,wBAAwB;;;;UAKf,iBAAA;SACR,kBAAkB,yBAAyB;;;UAInC,iBAAA;SACR,kBAAkB,yBAAyB;;gBAEpC;;UAGC,gBAAA;UACP;WACC;;UAGM,gBAAA;UACP;WACC;;UAGM,oBAAA;QACT;;WAEG;UACD;;UAGO,oBAAA;QACT;;WAEG;UACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseLineType.d.ts","names":[],"sources":["../../src/utils/parseLineType.ts"],"sourcesContent":[],"mappings":";;;UAEiB,UAAA;;EAAjB,IAAiB,EAET,OAFS,CAED,YAFC,
|
|
1
|
+
{"version":3,"file":"parseLineType.d.ts","names":[],"sources":["../../src/utils/parseLineType.ts"],"sourcesContent":[],"mappings":";;;UAEiB,UAAA;;EAAjB,IAAiB,EAET,OAFS,CAED,YAFC,EAAA,UAED,CAAA;AAGhB;iBAAgB,aAAA,gBAA6B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parsePatchFiles.d.ts","names":[],"sources":["../../src/utils/parsePatchFiles.ts"],"sourcesContent":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"parsePatchFiles.d.ts","names":[],"sources":["../../src/utils/parsePatchFiles.ts"],"sourcesContent":[],"mappings":";;;;;;AAqRA;;;;;;iBAAgB,eAAA,yCAGb"}
|
|
@@ -85,6 +85,7 @@ function processPatch(data, cacheKeyPrefix) {
|
|
|
85
85
|
} else {
|
|
86
86
|
let currentContent;
|
|
87
87
|
let lastLineType;
|
|
88
|
+
while (lines.length > 0 && (lines[lines.length - 1] === "\n" || lines[lines.length - 1] === "")) lines.pop();
|
|
88
89
|
for (const rawLine of lines) {
|
|
89
90
|
const parsedLine = parseLineType(rawLine);
|
|
90
91
|
if (parsedLine == null) continue;
|
|
@@ -132,10 +133,10 @@ function processPatch(data, cacheKeyPrefix) {
|
|
|
132
133
|
splitLineStart: 0,
|
|
133
134
|
unifiedLineCount: lines.length,
|
|
134
135
|
unifiedLineStart: 0,
|
|
135
|
-
additionCount: parseInt(match[4] ?? "
|
|
136
|
+
additionCount: parseInt(match[4] ?? "1"),
|
|
136
137
|
additionStart: parseInt(match[3]),
|
|
137
138
|
additionLines,
|
|
138
|
-
deletionCount: parseInt(match[2] ?? "
|
|
139
|
+
deletionCount: parseInt(match[2] ?? "1"),
|
|
139
140
|
deletionStart: parseInt(match[1]),
|
|
140
141
|
deletionLines,
|
|
141
142
|
hunkContent,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parsePatchFiles.js","names":["patchMetadata: string | undefined","files: FileDiffMetadata[]","currentFile: FileDiffMetadata | undefined","hunkContent: (ContextContent | ChangeContent)[]","currentContent: ContextContent | ChangeContent | undefined","lastLineType: 'context' | 'addition' | 'deletion' | undefined","hunkData: Hunk","patches: ParsedPatch[]"],"sources":["../../src/utils/parsePatchFiles.ts"],"sourcesContent":["import {\n ALTERNATE_FILE_NAMES_GIT,\n COMMIT_METADATA_SPLIT,\n FILENAME_HEADER_REGEX,\n FILENAME_HEADER_REGEX_GIT,\n FILE_CONTEXT_BLOB,\n FILE_MODE_FROM_INDEX,\n GIT_DIFF_FILE_BREAK_REGEX,\n HUNK_HEADER,\n SPLIT_WITH_NEWLINES,\n UNIFIED_DIFF_FILE_BREAK_REGEX,\n} from '../constants';\nimport type {\n ChangeContent,\n ContextContent,\n FileDiffMetadata,\n Hunk,\n ParsedPatch,\n} from '../types';\nimport { cleanLastNewline } from './cleanLastNewline';\nimport { parseLineType } from './parseLineType';\n\nfunction processPatch(data: string, cacheKeyPrefix?: string): ParsedPatch {\n const isGitDiff = GIT_DIFF_FILE_BREAK_REGEX.test(data);\n const rawFiles = data.split(\n isGitDiff ? GIT_DIFF_FILE_BREAK_REGEX : UNIFIED_DIFF_FILE_BREAK_REGEX\n );\n let patchMetadata: string | undefined;\n const files: FileDiffMetadata[] = [];\n let currentFile: FileDiffMetadata | undefined;\n for (const file of rawFiles) {\n if (isGitDiff && !GIT_DIFF_FILE_BREAK_REGEX.test(file)) {\n if (patchMetadata == null) {\n patchMetadata = file;\n } else {\n console.error('parsePatchContent: unknown file blob:', file);\n }\n // If we get in here, it's most likely the introductory metadata from the\n // patch, or something is fucked with the diff format\n continue;\n } else if (!isGitDiff && !UNIFIED_DIFF_FILE_BREAK_REGEX.test(file)) {\n if (patchMetadata == null) {\n patchMetadata = file;\n } else {\n console.error('parsePatchContent: unknown file blob:', file);\n }\n continue;\n }\n let lastHunkEnd = 0;\n const hunks = file.split(FILE_CONTEXT_BLOB);\n currentFile = undefined;\n for (const hunk of hunks) {\n const lines = hunk.split(SPLIT_WITH_NEWLINES);\n const firstLine = lines.shift();\n if (firstLine == null) {\n console.error('parsePatchContent: invalid hunk', hunk);\n continue;\n }\n const match = firstLine.match(HUNK_HEADER);\n const hunkContent: (ContextContent | ChangeContent)[] = [];\n let additionLines = 0;\n let deletionLines = 0;\n if (match == null || currentFile == null) {\n if (currentFile != null) {\n console.error('parsePatchContent: Invalid hunk', hunk);\n continue;\n }\n currentFile = {\n name: '',\n prevName: undefined,\n type: 'change',\n hunks: [],\n splitLineCount: 0,\n unifiedLineCount: 0,\n cacheKey:\n cacheKeyPrefix != null\n ? `${cacheKeyPrefix}-${files.length}`\n : undefined,\n };\n // Push that first line back into the group of lines so we can properly\n // parse it out\n lines.unshift(firstLine);\n for (const line of lines) {\n const filenameMatch = line.match(\n isGitDiff ? FILENAME_HEADER_REGEX_GIT : FILENAME_HEADER_REGEX\n );\n if (line.startsWith('diff --git')) {\n const [, , prevName, , name] =\n line.trim().match(ALTERNATE_FILE_NAMES_GIT) ?? [];\n currentFile.name = name.trim();\n if (prevName !== name) {\n currentFile.prevName = prevName.trim();\n }\n } else if (filenameMatch != null) {\n const [, type, fileName] = filenameMatch;\n if (type === '---' && fileName !== '/dev/null') {\n currentFile.prevName = fileName.trim();\n currentFile.name = fileName.trim();\n } else if (type === '+++' && fileName !== '/dev/null') {\n currentFile.name = fileName.trim();\n }\n }\n // Git diffs have a bunch of additional metadata we can pull from\n else if (isGitDiff) {\n if (line.startsWith('new mode ')) {\n currentFile.mode = line.replace('new mode', '').trim();\n }\n if (line.startsWith('old mode ')) {\n currentFile.oldMode = line.replace('old mode', '').trim();\n }\n if (line.startsWith('new file mode')) {\n currentFile.type = 'new';\n currentFile.mode = line.replace('new file mode', '').trim();\n }\n if (line.startsWith('deleted file mode')) {\n currentFile.type = 'deleted';\n currentFile.mode = line.replace('deleted file mode', '').trim();\n }\n if (line.startsWith('similarity index')) {\n if (line.startsWith('similarity index 100%')) {\n currentFile.type = 'rename-pure';\n } else {\n currentFile.type = 'rename-changed';\n }\n }\n if (line.startsWith('index ')) {\n const [, mode] = line.trim().match(FILE_MODE_FROM_INDEX) ?? [];\n if (mode != null) {\n currentFile.mode = mode;\n }\n }\n // We have to handle these for pure renames because there won't be\n // --- and +++ lines\n if (line.startsWith('rename from ')) {\n currentFile.prevName = line.replace('rename from ', '');\n }\n if (line.startsWith('rename to ')) {\n currentFile.name = line.replace('rename to ', '').trim();\n }\n }\n }\n continue;\n } else {\n let currentContent: ContextContent | ChangeContent | undefined;\n let lastLineType: 'context' | 'addition' | 'deletion' | undefined;\n for (const rawLine of lines) {\n const parsedLine = parseLineType(rawLine);\n if (parsedLine == null) {\n continue;\n }\n const { type, line } = parsedLine;\n if (type === 'addition') {\n if (currentContent == null || currentContent.type !== 'change') {\n currentContent = createContentGroup('change');\n hunkContent.push(currentContent);\n }\n currentContent.additions.push(line);\n additionLines++;\n lastLineType = 'addition';\n } else if (type === 'deletion') {\n if (currentContent == null || currentContent.type !== 'change') {\n currentContent = createContentGroup('change');\n hunkContent.push(currentContent);\n }\n currentContent.deletions.push(line);\n deletionLines++;\n lastLineType = 'deletion';\n } else if (type === 'context') {\n if (currentContent == null || currentContent.type !== 'context') {\n currentContent = createContentGroup('context');\n hunkContent.push(currentContent);\n }\n currentContent.lines.push(line);\n lastLineType = 'context';\n } else if (type === 'metadata' && currentContent != null) {\n if (currentContent.type === 'context') {\n currentContent.noEOFCR = true;\n } else if (lastLineType === 'deletion') {\n currentContent.noEOFCRDeletions = true;\n const lastIndex = currentContent.deletions.length - 1;\n if (lastIndex >= 0) {\n currentContent.deletions[lastIndex] = cleanLastNewline(\n currentContent.deletions[lastIndex]\n );\n }\n } else if (lastLineType === 'addition') {\n currentContent.noEOFCRAdditions = true;\n const lastIndex = currentContent.additions.length - 1;\n if (lastIndex >= 0) {\n currentContent.additions[lastIndex] = cleanLastNewline(\n currentContent.additions[lastIndex]\n );\n }\n }\n }\n }\n }\n const hunkData: Hunk = {\n collapsedBefore: 0,\n splitLineCount: 0,\n splitLineStart: 0,\n unifiedLineCount: lines.length,\n unifiedLineStart: 0,\n additionCount: parseInt(match[4] ?? '0'),\n additionStart: parseInt(match[3]),\n additionLines,\n deletionCount: parseInt(match[2] ?? '0'),\n deletionStart: parseInt(match[1]),\n deletionLines,\n hunkContent,\n hunkContext: match[5],\n hunkSpecs: firstLine,\n };\n if (\n isNaN(hunkData.additionCount) ||\n isNaN(hunkData.deletionCount) ||\n isNaN(hunkData.additionStart) ||\n isNaN(hunkData.deletionStart)\n ) {\n console.error('parsePatchContent: invalid hunk metadata', hunkData);\n continue;\n }\n hunkData.collapsedBefore = Math.max(\n hunkData.additionStart - 1 - lastHunkEnd,\n 0\n );\n currentFile.hunks.push(hunkData);\n lastHunkEnd = hunkData.additionStart + hunkData.additionCount - 1;\n hunkData.splitLineCount = Math.max(\n hunkData.additionCount,\n hunkData.deletionCount\n );\n hunkData.splitLineStart = currentFile.splitLineCount;\n hunkData.unifiedLineStart = currentFile.unifiedLineCount;\n\n currentFile.splitLineCount += hunkData.splitLineCount;\n currentFile.unifiedLineCount += hunkData.unifiedLineCount;\n }\n if (currentFile != null) {\n if (\n !isGitDiff &&\n currentFile.prevName != null &&\n currentFile.name !== currentFile.prevName\n ) {\n if (currentFile.hunks.length > 0) {\n currentFile.type = 'rename-changed';\n } else {\n currentFile.type = 'rename-pure';\n }\n }\n if (\n currentFile.type !== 'rename-pure' &&\n currentFile.type !== 'rename-changed'\n ) {\n currentFile.prevName = undefined;\n }\n files.push(currentFile);\n }\n }\n return { patchMetadata, files };\n}\n\n/**\n * Parses a patch file string into an array of parsed patches.\n *\n * @param data - The raw patch file content (supports multi-commit patches)\n * @param cacheKeyPrefix - Optional prefix for generating cache keys. When provided,\n * each file in the patch will get a cache key in the format `prefix-patchIndex-fileIndex`.\n * This enables caching of rendered diff results in the worker pool.\n */\nexport function parsePatchFiles(\n data: string,\n cacheKeyPrefix?: string\n): ParsedPatch[] {\n // NOTE(amadeus): This function is pretty forgiving in that it can accept a\n // patch file that includes commit metdata, multiple commits, or not\n const patches: ParsedPatch[] = [];\n for (const patch of data.split(COMMIT_METADATA_SPLIT)) {\n try {\n patches.push(\n processPatch(\n patch,\n cacheKeyPrefix != null\n ? `${cacheKeyPrefix}-${patches.length}`\n : undefined\n )\n );\n } catch (error) {\n console.error(error);\n }\n }\n return patches;\n}\n\nfunction createContentGroup(type: 'change'): ChangeContent;\nfunction createContentGroup(type: 'context'): ContextContent;\nfunction createContentGroup(\n type: 'change' | 'context'\n): ChangeContent | ContextContent {\n if (type === 'change') {\n return {\n type: 'change',\n additions: [],\n deletions: [],\n noEOFCRAdditions: false,\n noEOFCRDeletions: false,\n };\n }\n return { type: 'context', lines: [], noEOFCR: false };\n}\n"],"mappings":";;;;;AAsBA,SAAS,aAAa,MAAc,gBAAsC;CACxE,MAAM,YAAY,0BAA0B,KAAK,KAAK;CACtD,MAAM,WAAW,KAAK,MAC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AC7B,MAAM,SAAS,cAAc,IAC7B,MAAM,SAAS,cAAc,EAC7B;AACA,YAAQ,MAAM,4CAA4C,SAAS;AACnE;;AAEF,YAAS,kBAAkB,KAAK,IAC9B,SAAS,gBAAgB,IAAI,aAC7B,EACD;AACD,eAAY,MAAM,KAAK,SAAS;AAChC,iBAAc,SAAS,gBAAgB,SAAS,gBAAgB;AAChE,YAAS,iBAAiB,KAAK,IAC7B,SAAS,eACT,SAAS,cACV;AACD,YAAS,iBAAiB,YAAY;AACtC,YAAS,mBAAmB,YAAY;AAExC,eAAY,kBAAkB,SAAS;AACvC,eAAY,oBAAoB,SAAS;;AAE3C,MAAI,eAAe,MAAM;AACvB,OACE,CAAC,aACD,YAAY,YAAY,QACxB,YAAY,SAAS,YAAY,SAEjC,KAAI,YAAY,MAAM,SAAS,EAC7B,aAAY,OAAO;OAEnB,aAAY,OAAO;AAGvB,OACE,YAAY,SAAS,iBACrB,YAAY,SAAS,iBAErB,aAAY,WAAW;AAEzB,SAAM,KAAK,YAAY;;;AAG3B,QAAO;EAAE;EAAe;EAAO;;;;;;;;;;AAWjC,SAAgB,gBACd,MACA,gBACe;CAGf,MAAMC,UAAyB,EAAE;AACjC,MAAK,MAAM,SAAS,KAAK,MAAM,sBAAsB,CACnD,KAAI;AACF,UAAQ,KACN,aACE,OACA,kBAAkB,OACd,GAAG,eAAe,GAAG,QAAQ,WAC7B,OACL,CACF;UACM,OAAO;AACd,UAAQ,MAAM,MAAM;;AAGxB,QAAO;;AAKT,SAAS,mBACP,MACgC;AAChC,KAAI,SAAS,SACX,QAAO;EACL,MAAM;EACN,WAAW,EAAE;EACb,WAAW,EAAE;EACb,kBAAkB;EAClB,kBAAkB;EACnB;AAEH,QAAO;EAAE,MAAM;EAAW,OAAO,EAAE;EAAE,SAAS;EAAO"}
|
|
1
|
+
{"version":3,"file":"parsePatchFiles.js","names":["patchMetadata: string | undefined","files: FileDiffMetadata[]","currentFile: FileDiffMetadata | undefined","hunkContent: (ContextContent | ChangeContent)[]","currentContent: ContextContent | ChangeContent | undefined","lastLineType: 'context' | 'addition' | 'deletion' | undefined","hunkData: Hunk","patches: ParsedPatch[]"],"sources":["../../src/utils/parsePatchFiles.ts"],"sourcesContent":["import {\n ALTERNATE_FILE_NAMES_GIT,\n COMMIT_METADATA_SPLIT,\n FILENAME_HEADER_REGEX,\n FILENAME_HEADER_REGEX_GIT,\n FILE_CONTEXT_BLOB,\n FILE_MODE_FROM_INDEX,\n GIT_DIFF_FILE_BREAK_REGEX,\n HUNK_HEADER,\n SPLIT_WITH_NEWLINES,\n UNIFIED_DIFF_FILE_BREAK_REGEX,\n} from '../constants';\nimport type {\n ChangeContent,\n ContextContent,\n FileDiffMetadata,\n Hunk,\n ParsedPatch,\n} from '../types';\nimport { cleanLastNewline } from './cleanLastNewline';\nimport { parseLineType } from './parseLineType';\n\nfunction processPatch(data: string, cacheKeyPrefix?: string): ParsedPatch {\n const isGitDiff = GIT_DIFF_FILE_BREAK_REGEX.test(data);\n const rawFiles = data.split(\n isGitDiff ? GIT_DIFF_FILE_BREAK_REGEX : UNIFIED_DIFF_FILE_BREAK_REGEX\n );\n let patchMetadata: string | undefined;\n const files: FileDiffMetadata[] = [];\n let currentFile: FileDiffMetadata | undefined;\n for (const file of rawFiles) {\n if (isGitDiff && !GIT_DIFF_FILE_BREAK_REGEX.test(file)) {\n if (patchMetadata == null) {\n patchMetadata = file;\n } else {\n console.error('parsePatchContent: unknown file blob:', file);\n }\n // If we get in here, it's most likely the introductory metadata from the\n // patch, or something is fucked with the diff format\n continue;\n } else if (!isGitDiff && !UNIFIED_DIFF_FILE_BREAK_REGEX.test(file)) {\n if (patchMetadata == null) {\n patchMetadata = file;\n } else {\n console.error('parsePatchContent: unknown file blob:', file);\n }\n continue;\n }\n let lastHunkEnd = 0;\n const hunks = file.split(FILE_CONTEXT_BLOB);\n currentFile = undefined;\n for (const hunk of hunks) {\n const lines = hunk.split(SPLIT_WITH_NEWLINES);\n const firstLine = lines.shift();\n if (firstLine == null) {\n console.error('parsePatchContent: invalid hunk', hunk);\n continue;\n }\n const match = firstLine.match(HUNK_HEADER);\n const hunkContent: (ContextContent | ChangeContent)[] = [];\n let additionLines = 0;\n let deletionLines = 0;\n if (match == null || currentFile == null) {\n if (currentFile != null) {\n console.error('parsePatchContent: Invalid hunk', hunk);\n continue;\n }\n currentFile = {\n name: '',\n prevName: undefined,\n type: 'change',\n hunks: [],\n splitLineCount: 0,\n unifiedLineCount: 0,\n cacheKey:\n cacheKeyPrefix != null\n ? `${cacheKeyPrefix}-${files.length}`\n : undefined,\n };\n // Push that first line back into the group of lines so we can properly\n // parse it out\n lines.unshift(firstLine);\n for (const line of lines) {\n const filenameMatch = line.match(\n isGitDiff ? FILENAME_HEADER_REGEX_GIT : FILENAME_HEADER_REGEX\n );\n if (line.startsWith('diff --git')) {\n const [, , prevName, , name] =\n line.trim().match(ALTERNATE_FILE_NAMES_GIT) ?? [];\n currentFile.name = name.trim();\n if (prevName !== name) {\n currentFile.prevName = prevName.trim();\n }\n } else if (filenameMatch != null) {\n const [, type, fileName] = filenameMatch;\n if (type === '---' && fileName !== '/dev/null') {\n currentFile.prevName = fileName.trim();\n currentFile.name = fileName.trim();\n } else if (type === '+++' && fileName !== '/dev/null') {\n currentFile.name = fileName.trim();\n }\n }\n // Git diffs have a bunch of additional metadata we can pull from\n else if (isGitDiff) {\n if (line.startsWith('new mode ')) {\n currentFile.mode = line.replace('new mode', '').trim();\n }\n if (line.startsWith('old mode ')) {\n currentFile.oldMode = line.replace('old mode', '').trim();\n }\n if (line.startsWith('new file mode')) {\n currentFile.type = 'new';\n currentFile.mode = line.replace('new file mode', '').trim();\n }\n if (line.startsWith('deleted file mode')) {\n currentFile.type = 'deleted';\n currentFile.mode = line.replace('deleted file mode', '').trim();\n }\n if (line.startsWith('similarity index')) {\n if (line.startsWith('similarity index 100%')) {\n currentFile.type = 'rename-pure';\n } else {\n currentFile.type = 'rename-changed';\n }\n }\n if (line.startsWith('index ')) {\n const [, mode] = line.trim().match(FILE_MODE_FROM_INDEX) ?? [];\n if (mode != null) {\n currentFile.mode = mode;\n }\n }\n // We have to handle these for pure renames because there won't be\n // --- and +++ lines\n if (line.startsWith('rename from ')) {\n currentFile.prevName = line.replace('rename from ', '');\n }\n if (line.startsWith('rename to ')) {\n currentFile.name = line.replace('rename to ', '').trim();\n }\n }\n }\n continue;\n } else {\n let currentContent: ContextContent | ChangeContent | undefined;\n let lastLineType: 'context' | 'addition' | 'deletion' | undefined;\n // Strip trailing bare newlines (format-patch separators between commits)\n while (\n lines.length > 0 &&\n (lines[lines.length - 1] === '\\n' || lines[lines.length - 1] === '')\n ) {\n lines.pop();\n }\n for (const rawLine of lines) {\n const parsedLine = parseLineType(rawLine);\n if (parsedLine == null) {\n continue;\n }\n const { type, line } = parsedLine;\n if (type === 'addition') {\n if (currentContent == null || currentContent.type !== 'change') {\n currentContent = createContentGroup('change');\n hunkContent.push(currentContent);\n }\n currentContent.additions.push(line);\n additionLines++;\n lastLineType = 'addition';\n } else if (type === 'deletion') {\n if (currentContent == null || currentContent.type !== 'change') {\n currentContent = createContentGroup('change');\n hunkContent.push(currentContent);\n }\n currentContent.deletions.push(line);\n deletionLines++;\n lastLineType = 'deletion';\n } else if (type === 'context') {\n if (currentContent == null || currentContent.type !== 'context') {\n currentContent = createContentGroup('context');\n hunkContent.push(currentContent);\n }\n currentContent.lines.push(line);\n lastLineType = 'context';\n } else if (type === 'metadata' && currentContent != null) {\n if (currentContent.type === 'context') {\n currentContent.noEOFCR = true;\n } else if (lastLineType === 'deletion') {\n currentContent.noEOFCRDeletions = true;\n const lastIndex = currentContent.deletions.length - 1;\n if (lastIndex >= 0) {\n currentContent.deletions[lastIndex] = cleanLastNewline(\n currentContent.deletions[lastIndex]\n );\n }\n } else if (lastLineType === 'addition') {\n currentContent.noEOFCRAdditions = true;\n const lastIndex = currentContent.additions.length - 1;\n if (lastIndex >= 0) {\n currentContent.additions[lastIndex] = cleanLastNewline(\n currentContent.additions[lastIndex]\n );\n }\n }\n }\n }\n }\n const hunkData: Hunk = {\n collapsedBefore: 0,\n splitLineCount: 0,\n splitLineStart: 0,\n unifiedLineCount: lines.length,\n unifiedLineStart: 0,\n additionCount: parseInt(match[4] ?? '1'),\n additionStart: parseInt(match[3]),\n additionLines,\n deletionCount: parseInt(match[2] ?? '1'),\n deletionStart: parseInt(match[1]),\n deletionLines,\n hunkContent,\n hunkContext: match[5],\n hunkSpecs: firstLine,\n };\n if (\n isNaN(hunkData.additionCount) ||\n isNaN(hunkData.deletionCount) ||\n isNaN(hunkData.additionStart) ||\n isNaN(hunkData.deletionStart)\n ) {\n console.error('parsePatchContent: invalid hunk metadata', hunkData);\n continue;\n }\n hunkData.collapsedBefore = Math.max(\n hunkData.additionStart - 1 - lastHunkEnd,\n 0\n );\n currentFile.hunks.push(hunkData);\n lastHunkEnd = hunkData.additionStart + hunkData.additionCount - 1;\n hunkData.splitLineCount = Math.max(\n hunkData.additionCount,\n hunkData.deletionCount\n );\n hunkData.splitLineStart = currentFile.splitLineCount;\n hunkData.unifiedLineStart = currentFile.unifiedLineCount;\n\n currentFile.splitLineCount += hunkData.splitLineCount;\n currentFile.unifiedLineCount += hunkData.unifiedLineCount;\n }\n if (currentFile != null) {\n if (\n !isGitDiff &&\n currentFile.prevName != null &&\n currentFile.name !== currentFile.prevName\n ) {\n if (currentFile.hunks.length > 0) {\n currentFile.type = 'rename-changed';\n } else {\n currentFile.type = 'rename-pure';\n }\n }\n if (\n currentFile.type !== 'rename-pure' &&\n currentFile.type !== 'rename-changed'\n ) {\n currentFile.prevName = undefined;\n }\n files.push(currentFile);\n }\n }\n return { patchMetadata, files };\n}\n\n/**\n * Parses a patch file string into an array of parsed patches.\n *\n * @param data - The raw patch file content (supports multi-commit patches)\n * @param cacheKeyPrefix - Optional prefix for generating cache keys. When provided,\n * each file in the patch will get a cache key in the format `prefix-patchIndex-fileIndex`.\n * This enables caching of rendered diff results in the worker pool.\n */\nexport function parsePatchFiles(\n data: string,\n cacheKeyPrefix?: string\n): ParsedPatch[] {\n // NOTE(amadeus): This function is pretty forgiving in that it can accept a\n // patch file that includes commit metdata, multiple commits, or not\n const patches: ParsedPatch[] = [];\n for (const patch of data.split(COMMIT_METADATA_SPLIT)) {\n try {\n patches.push(\n processPatch(\n patch,\n cacheKeyPrefix != null\n ? `${cacheKeyPrefix}-${patches.length}`\n : undefined\n )\n );\n } catch (error) {\n console.error(error);\n }\n }\n return patches;\n}\n\nfunction createContentGroup(type: 'change'): ChangeContent;\nfunction createContentGroup(type: 'context'): ContextContent;\nfunction createContentGroup(\n type: 'change' | 'context'\n): ChangeContent | ContextContent {\n if (type === 'change') {\n return {\n type: 'change',\n additions: [],\n deletions: [],\n noEOFCRAdditions: false,\n noEOFCRDeletions: false,\n };\n }\n return { type: 'context', lines: [], noEOFCR: false };\n}\n"],"mappings":";;;;;AAsBA,SAAS,aAAa,MAAc,gBAAsC;CACxE,MAAM,YAAY,0BAA0B,KAAK,KAAK;CACtD,MAAM,WAAW,KAAK,MACpB,YAAY,4BAA4B,8BACzC;CACD,IAAIA;CACJ,MAAMC,QAA4B,EAAE;CACpC,IAAIC;AACJ,MAAK,MAAM,QAAQ,UAAU;AAC3B,MAAI,aAAa,CAAC,0BAA0B,KAAK,KAAK,EAAE;AACtD,OAAI,iBAAiB,KACnB,iBAAgB;OAEhB,SAAQ,MAAM,yCAAyC,KAAK;AAI9D;aACS,CAAC,aAAa,CAAC,8BAA8B,KAAK,KAAK,EAAE;AAClE,OAAI,iBAAiB,KACnB,iBAAgB;OAEhB,SAAQ,MAAM,yCAAyC,KAAK;AAE9D;;EAEF,IAAI,cAAc;EAClB,MAAM,QAAQ,KAAK,MAAM,kBAAkB;AAC3C,gBAAc;AACd,OAAK,MAAM,QAAQ,OAAO;GACxB,MAAM,QAAQ,KAAK,MAAM,oBAAoB;GAC7C,MAAM,YAAY,MAAM,OAAO;AAC/B,OAAI,aAAa,MAAM;AACrB,YAAQ,MAAM,mCAAmC,KAAK;AAC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,MAAM,SAAS,EAC7B,aAAY,OAAO;OAEnB,aAAY,OAAO;AAGvB,OACE,YAAY,SAAS,iBACrB,YAAY,SAAS,iBAErB,aAAY,WAAW;AAEzB,SAAM,KAAK,YAAY;;;AAG3B,QAAO;EAAE;EAAe;EAAO;;;;;;;;;;AAWjC,SAAgB,gBACd,MACA,gBACe;CAGf,MAAMC,UAAyB,EAAE;AACjC,MAAK,MAAM,SAAS,KAAK,MAAM,sBAAsB,CACnD,KAAI;AACF,UAAQ,KACN,aACE,OACA,kBAAkB,OACd,GAAG,eAAe,GAAG,QAAQ,WAC7B,OACL,CACF;UACM,OAAO;AACd,UAAQ,MAAM,MAAM;;AAGxB,QAAO;;AAKT,SAAS,mBACP,MACgC;AAChC,KAAI,SAAS,SACX,QAAO;EACL,MAAM;EACN,WAAW,EAAE;EACb,WAAW,EAAE;EACb,kBAAkB;EAClB,kBAAkB;EACnB;AAEH,QAAO;EAAE,MAAM;EAAW,OAAO,EAAE;EAAE,SAAS;EAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pierre/diffs",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "apache-2.0",
|
|
6
6
|
"scripts": {
|
|
@@ -69,8 +69,5 @@
|
|
|
69
69
|
"peerDependencies": {
|
|
70
70
|
"react": "^18.3.1 || ^19.0.0",
|
|
71
71
|
"react-dom": "^18.3.1 || ^19.0.0"
|
|
72
|
-
},
|
|
73
|
-
"publishConfig": {
|
|
74
|
-
"tag": "beta"
|
|
75
72
|
}
|
|
76
73
|
}
|