Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[updates] Update fingerprint diff algorithm #461

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 41 additions & 20 deletions packages/build-tools/src/utils/fingerprint.ts
Original file line number Diff line number Diff line change
@@ -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 & {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

Expand Down
Loading