mirror of
https://github.com/react/react-native.git
synced 2026-09-28 13:23:09 +08:00
Summary: Pull Request resolved: https://github.com/react/react-native/pull/57490 See [**RFC0894: Removing deep imports from react-native**](https://github.com/react-native-community/discussions-and-proposals/pull/894) This is the **big switch** to enable the Strict TypeScript API (generated types + single index entry point) by default in React Native. **Opt-in → opt-out** After this change, the main `react-native` package resolves its `"types"` entry points only to `types_generated/index.d.ts` — with no other subpaths available. The new `"react-native-legacy-deep-imports"` condition maps to legacy `types/` and `Libraries/*.d.ts` sources. **Impact limitation**: For this stage of rollout, the `"default"` condition continues to resolve to source files. Only TypeScript is affected. **How to opt out** Opposite of today's opt-in, which we will update in [the docs](https://reactnative.dev/docs/strict-typescript-api). Again, the only impact area today is **TypeScript**. ```json5 // tsconfig.json { "extends": "react-native/typescript-config", "compilerOptions": { ... "customConditions": ["react-native-legacy-deep-imports"] } } ``` **Other changes** - Drop `react-native/typescript-config/strict` entry point, update README. - Update `__typetests__`. **Rollout plan** **Target release: 0.87**. This and the contributing stack will be cherry picked for RC1. - We've conducted testing against 100+ real Expo codebases, giving us the confidence that we've reduced breaking changes enough that the vast majority of RN codebases can migrate. - The Strict API includes a number of **intentional breaking changes**, and docs have been kept up to date. - We're shipping a `/migrate-to-strict-api` skill to migrate via agents, see https://github.com/react-native-community/skills/pull/3. **What's improved since 0.80?** Since the initial opt-in launch of the Strict API in 0.80, we've been making continuous improvements over the last year to get our generated types into a widely launchable state. Most notably: - 21+ new/updated root APIs and fixes due to community feedback ([discussion](https://github.com/react-native-community/discussions-and-proposals/discussions/893), [PRs](https://github.com/react/react-native/pulls?q=is%3Apr%20label%3A%22JS%20API%20stabilization%20(1.0)%22%20is%3Aclosed)). - Upstream encapsulation blocker in TypeScript, fixed in 6.0 (https://github.com/react/react-native/issues/53565). - Tailwind/Uniwind compatibility (`interface` types for props). - `*Instance` ref type exports for all built-in components (https://github.com/react-native-community/discussions-and-proposals/pull/1003). - Fixes to previously mistyped, high impact APIs, such as `Appearance`. - New subpath entry points for `asset-registry`, `setup-env`, and others. - Refinements to doc comments/type translation build. **Rollback plan** Revert this diff. IMPORTANT: We'll adopt a policy of **super-eager rollback**, if there are any unsolvable issues during the RC phase. Changelog: [General][Breaking] - React Native's default JavaScript API is now the [Strict TypeScript API](https://reactnative.dev/docs/strict-typescript-api). Use `customConditions: ["react-native-legacy-deep-imports"]` to opt out. Reviewed By: cortinico Differential Revision: D110458670 fbshipit-source-id: 4b0e0b458a5f895f783d6d936e7b11ccff2df076
107 lines
2.8 KiB
JavaScript
107 lines
2.8 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.
|
|
*
|
|
* @format
|
|
* @flow strict-local
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
/**
|
|
* This script runs JavaScript tests.
|
|
* Available arguments:
|
|
* --maxWorkers [num] - how many workers, default 1
|
|
* --jestBinary [path] - path to jest binary, defaults to local node modules
|
|
* --yarnBinary [path] - path to yarn binary, defaults to yarn
|
|
*/
|
|
|
|
const {execSync} = require('child_process');
|
|
const argv /*:Readonly<{
|
|
maxWorkers?: number,
|
|
jestBinary?: string,
|
|
yarnBinary?: string,
|
|
}> */ =
|
|
// $FlowFixMe[incompatible-type]
|
|
// $FlowFixMe[incompatible-exact]
|
|
// $FlowFixMe[incompatible-indexer]
|
|
require('yargs').argv;
|
|
|
|
const numberOfMaxWorkers = argv.maxWorkers ?? 1;
|
|
|
|
const JEST_BINARY = argv.jestBinary ?? './node_modules/.bin/jest';
|
|
const YARN_BINARY = argv.yarnBinary ?? 'yarn';
|
|
|
|
class ExecError extends Error {
|
|
constructor(cause /*: Error */) {
|
|
super(cause.message, {cause});
|
|
this.name = 'ExecError';
|
|
}
|
|
}
|
|
|
|
function describe(message /*: string */) {
|
|
console.log(`\n\n>>>>> ${message}\n\n\n`);
|
|
}
|
|
|
|
try {
|
|
console.log('Executing JavaScript tests');
|
|
|
|
describe('Test: feature flags codegen');
|
|
execAndLog(`${YARN_BINARY} run featureflags --verify-unchanged`);
|
|
|
|
describe('Test: eslint');
|
|
execAndLog(`${YARN_BINARY} run lint`);
|
|
|
|
describe('Test: Validate JS API snapshot');
|
|
execAndLog(`${YARN_BINARY} run build-types --validate`);
|
|
|
|
describe('Test: Flow check');
|
|
execAndLog(`${YARN_BINARY} run flow-check`);
|
|
|
|
/*
|
|
* Build @react-native/codegen and @react-native/codegen-typescript-test
|
|
*
|
|
* The typescript-test project use TypeScript to write test cases
|
|
* In order to make these tests discoverable to jest
|
|
* *-test.ts must be compiled to *-test.js before running jest
|
|
*/
|
|
|
|
describe('Test: Build @react-native/codegen');
|
|
execAndLog(`${YARN_BINARY} --cwd ./packages/react-native-codegen run build`);
|
|
describe('Test: Build @react-native/codegen-typescript-test');
|
|
execAndLog(
|
|
`${YARN_BINARY} --cwd ./private/react-native-codegen-typescript-test run build`,
|
|
);
|
|
|
|
describe('Test: Jest');
|
|
execAndLog(
|
|
`${JEST_BINARY} --maxWorkers=${numberOfMaxWorkers} --ci --reporters="default" --reporters="jest-junit"`,
|
|
);
|
|
|
|
describe('Test: TypeScript tests');
|
|
execAndLog(`${YARN_BINARY} run test-typescript-legacy`);
|
|
} catch (e) {
|
|
if (e instanceof ExecError) {
|
|
console.error(e.message);
|
|
process.exitCode = 1;
|
|
} else {
|
|
throw e;
|
|
}
|
|
} finally {
|
|
console.log('Finished.');
|
|
}
|
|
|
|
function execAndLog(command /*: string */) {
|
|
console.log(`Executing: ${command}`);
|
|
try {
|
|
execSync(command, {
|
|
stdio: ['ignore', 'inherit', 'inherit'],
|
|
encoding: 'utf8',
|
|
});
|
|
} catch (e) {
|
|
throw new ExecError(e);
|
|
}
|
|
}
|