Files
Alex Hunt 9c3fddf9cd Move core-cli-utils to private/ as a reference implementation (#56922)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/56922

Move `react-native/core-cli-utils` from `packages/` to `private/`, stop publishing it to npm, and reframe it as a reference implementation of React Native CLI tooling.

The package has no known external consumers and is only used internally by `private/helloworld/` and `packages/rn-tester/`. Publishing it to npm creates a maintenance surface for a package that serves no external users.

See https://github.com/react-native-community/discussions-and-proposals/pull/1002.

#### Changes

- Move `packages/core-cli-utils/` to `private/core-cli-utils/`.
- Convert all source files to CJS (require/module.exports) with Flow comment syntax (/*:: */), eliminating the runtime Babel dependency.
 - Remove from the JS build pipeline (`scripts/build/config.js`).
 - Remove the defunct `patchCoreCLIUtilsPackageJSON()` runtime patching from both `helloworld/cli.js` and `rn-tester/cli.js`, and delete both `monorepo.js` files that contained it.
  - Add as `devDependency` to `rn-tester` and `helloworld`.
  - Skip `"*"` version deps in `_prepareHelloWorld()` so they aren't rewritten to the Verdaccio-published version.
  - Remove redundant desktop import ignore entry (`private/**` already covers it).
  - Rewrite README as reference implementation documentation.

Changelog:
[General][Breaking] - The `react-native/core-cli-utils` package is no longer published. It remains available in the React Native repo as a reference implementation.

Reviewed By: cortinico

Differential Revision: D105959855

fbshipit-source-id: 42e439a45273bdeca76029eff306cdf2451308e2
2026-05-22 12:36:57 -07:00

108 lines
2.4 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
* @format
*/
import type {BabelCoreOptions} from '@babel/core';
const {ModuleResolutionKind} = require('typescript');
export type BuildOptions = Readonly<{
// The target runtime to compile for.
target: 'node',
// Whether to emit Flow definition files (.js.flow) (default: true).
emitFlowDefs?: boolean,
// Whether to emit TypeScript definition files (.d.ts) (default: false).
emitTypeScriptDefs?: boolean,
}>;
export type BuildConfig = Readonly<{
// The packages to include for build and their build options.
packages: Readonly<{[packageName: string]: BuildOptions}>,
}>;
/**
* - BUILD CONFIG -
*
* Add packages here to configure them as part of the monorepo `yarn build`
* setup. These must use a consistent package structure and (today) target
* Node.js packages only.
*/
const buildConfig: BuildConfig = {
/* eslint sort-keys: "error" */
packages: {
'community-cli-plugin': {
target: 'node',
},
'debugger-shell': {
emitTypeScriptDefs: true,
target: 'node',
},
'dev-middleware': {
emitTypeScriptDefs: true,
target: 'node',
},
'metro-config': {
emitTypeScriptDefs: true,
target: 'node',
},
'react-native-compatibility-check': {
emitTypeScriptDefs: true,
target: 'node',
},
},
};
const defaultBuildOptions = {
emitFlowDefs: true,
emitTypeScriptDefs: false,
};
function getBuildOptions(
packageName: keyof BuildConfig['packages'],
): Required<BuildOptions> {
return {
...defaultBuildOptions,
...buildConfig.packages[packageName],
};
}
function getBabelConfig(
packageName: keyof BuildConfig['packages'],
): BabelCoreOptions {
const {target} = getBuildOptions(packageName);
switch (target) {
case 'node':
return require('./babel/node.config.js');
}
}
function getTypeScriptCompilerOptions(
packageName: keyof BuildConfig['packages'],
): Object {
const {target} = getBuildOptions(packageName);
switch (target) {
case 'node':
return {
...require('@tsconfig/node22/tsconfig.json').compilerOptions,
moduleResolution: ModuleResolutionKind.Node16,
};
}
}
module.exports = {
buildConfig,
getBabelConfig,
getBuildOptions,
getTypeScriptCompilerOptions,
};