Files
Eli WhiteandFacebook GitHub Bot 60e3921f9c Initial Open Sourcing of React Native Compatibility Check (#49340)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/49340

This tool enables checking the boundary between JavaScript and Native for
backwards incompatible changes to protect against crashes.

This is useful for:

- Local Development
- Over the Air updates on platforms that support it
- Theoretically: Server Components with React Native

Check out the Readme for more information

Changelog: [General][Added] Open Sourcing React Native's Compatibility Check

Reviewed By: panagosg7

Differential Revision: D69476742

fbshipit-source-id: 8af6039839c5475c1258fa82d9750a9320cf0751
2025-02-12 08:24:13 -08:00

55 lines
1.3 KiB
JavaScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
*/
import type {
DiffSummary,
ExportableSchemaDiff,
FormattedDiffSummary,
SchemaDiff,
} from './DiffResults';
import type {SchemaType} from '@react-native/codegen/src/CodegenSchema';
import {schemaDiffExporter} from './DiffResults.js';
import {formatDiffSet} from './ErrorFormatting.js';
import {buildSchemaDiff, summarizeDiffSet} from './VersionDiffing.js';
class CompatCheckResult {
#schemaDiff: Set<SchemaDiff>;
#summary: ?DiffSummary;
constructor(schemaDiff: Set<SchemaDiff>) {
this.#schemaDiff = schemaDiff;
}
getSummary(): DiffSummary {
if (this.#summary == null) {
this.#summary = summarizeDiffSet(this.#schemaDiff);
}
return this.#summary;
}
getErrors(): FormattedDiffSummary {
return formatDiffSet(this.getSummary());
}
getDebugInfo(): Array<ExportableSchemaDiff> {
return Array.from(this.#schemaDiff, schemaDiffExporter);
}
}
export function compareSchemas(
newSchema: SchemaType,
oldSchema: SchemaType,
): CompatCheckResult {
return new CompatCheckResult(buildSchemaDiff(newSchema, oldSchema));
}