From 1edee8bdc59c933766c2e9f100fb5da33fb1ce6a Mon Sep 17 00:00:00 2001 From: Will Schurman Date: Mon, 4 Nov 2024 10:58:21 -0800 Subject: [PATCH] [updates] Update fingerprint diff algorithm --- packages/build-tools/src/utils/fingerprint.ts | 61 +++++++++++++------ 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/packages/build-tools/src/utils/fingerprint.ts b/packages/build-tools/src/utils/fingerprint.ts index daa3285a..d37a40d8 100644 --- a/packages/build-tools/src/utils/fingerprint.ts +++ b/packages/build-tools/src/utils/fingerprint.ts @@ -1,6 +1,6 @@ /** * DO NOT EDIT unless the same change is made in `@expo/fingerprint` - * The diffFingerprints function is a copy/paste from https://github.com/expo/expo/pull/29709 + * The diffFingerprints function is a copy/paste from that package. */ export type FingerprintSource = HashSource & { @@ -78,20 +78,41 @@ export interface DebugInfoContents { export type DebugInfo = DebugInfoFile | DebugInfoDir | DebugInfoContents; -export interface FingerprintDiffItem { - /** - * The operation type of the diff item. - */ - op: 'added' | 'removed' | 'changed'; - - /** - * The source of the diff item. - * - When type is 'added', the source is the new source. - * - When type is 'removed', the source is the old source. - * - When type is 'changed', the source is the new source. - */ - source: FingerprintSource; -} +export type FingerprintDiffItem = + | { + /** + * The operation type of the diff item. + */ + op: 'added'; + /** + * The added source. + */ + addedSource: FingerprintSource; + } + | { + /** + * The operation type of the diff item. + */ + op: 'removed'; + /** + * The removed source. + */ + removedSource: FingerprintSource; + } + | { + /** + * The operation type of the diff item. + */ + op: 'changed'; + /** + * The source before. + */ + beforeSource: FingerprintSource; + /** + * The source after. + */ + afterSource: FingerprintSource; + }; const typeOrder = { file: 0, @@ -136,25 +157,25 @@ export function diffFingerprints( const compareResult = compareSource(source1, source2); if (compareResult === 0) { if (source1.hash !== source2.hash) { - diff.push({ op: 'changed', source: source2 }); + diff.push({ op: 'changed', beforeSource: source1, afterSource: source2 }); } ++index1; ++index2; } else if (compareResult < 0) { - diff.push({ op: 'removed', source: source1 }); + diff.push({ op: 'removed', removedSource: source1 }); ++index1; } else { - diff.push({ op: 'added', source: source2 }); + diff.push({ op: 'added', addedSource: source2 }); ++index2; } } while (index1 < fingerprint1.sources.length) { - diff.push({ op: 'removed', source: fingerprint1.sources[index1] }); + diff.push({ op: 'removed', removedSource: fingerprint1.sources[index1] }); ++index1; } while (index2 < fingerprint2.sources.length) { - diff.push({ op: 'added', source: fingerprint2.sources[index2] }); + diff.push({ op: 'added', addedSource: fingerprint2.sources[index2] }); ++index2; }