Skip to content

Commit

Permalink
Migrate cli-plugin-metro into repo (facebook#38795)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#38795

## Context

RFC: Decoupling Flipper from React Native core: react-native-community/discussions-and-proposals#641

## Changes

Inits new package `react-native/community-cli-plugin`. This migrates [`react-native-community/cli-plugin-metro`](https://github.com/react-native-community/cli/tree/main/packages/cli-plugin-metro) into the React Native repo, to enable faster iteration by the React Native core team. Specifically:

- This package contains several `metro` dependencies, which when removed from CLI will no longer require us to ship new CLI releases to get Metro patches and features to users.
- This package contains the `start`, `bundle`, and `ram-bundle` commands (central to the React Native development experience), for which we have incoming debugging-related changes.
- This package now **only** exports commands to be attached via a RN CLI plugin. With this move, we're aiming to **internalise** the default implementations of these dev commands within React Native — other RN CLI plugins can continue to override these, but must do so wholesale. (See also the recent fix for this: react-native-community/cli#1999.)

In V15:
- (Microsoft feedback) Re-export  `unstable_buildBundleWithConfig`, marking as unstable. This gives us a time buffer to consider how we repackage this functionality in future.

The package source has been converted from TypeScript to Flow, with a number of new `flow-typed/` defs added to meet type coverage requirements.

## To dos

- For now, we aren't removing the existing [`react-native-community/cli-plugin-metro`](https://github.com/react-native-community/cli/tree/main/packages/cli-plugin-metro) source — until later PRs consolidate this move by changing dependencies in the `react-native` package.
- **Exported API is reduced!**: I'm working with szymonrybczak to decouple references from RN CLI packages react-native-community/cli#2021.

Changelog: [Internal]

Reviewed By: motiz88

Differential Revision: D46801501

fbshipit-source-id: ebd78383317b9b9f806d22a1e3d0e375b3b0f0aa
  • Loading branch information
huntie authored and facebook-github-bot committed Aug 9, 2023
1 parent 5657d2d commit 357cd4a
Show file tree
Hide file tree
Showing 35 changed files with 2,361 additions and 1 deletion.
49 changes: 49 additions & 0 deletions flow-typed/npm/@react-native-community/cli-server-api_v12.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* 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
* @format
* @oncall react_native
*/

declare module '@react-native-community/cli-server-api' {
import type {NextHandleFunction, Server} from 'connect';

declare type MiddlewareOptions = {
host?: string,
watchFolders: $ReadOnlyArray<string>,
port: number,
};

declare export function createDevServerMiddleware(
options: MiddlewareOptions,
): {
middleware: Server,
websocketEndpoints: {
'/debugger-proxy': ws$WebSocketServer,
'/message': ws$WebSocketServer,
'/events': ws$WebSocketServer,
},
debuggerProxyEndpoint: {
server: ws$WebSocketServer,
isDebuggerConnected: () => boolean,
},
messageSocketEndpoint: {
server: ws$WebSocketServer,
broadcast: (
method: string,
params?: Record<string, mixed> | null,
) => void,
},
eventsSocketEndpoint: {
server: ws$WebSocketServer,
reportEvent: (event: any) => void,
},
...
};

declare export const indexPageMiddleware: NextHandleFunction;
}
40 changes: 40 additions & 0 deletions flow-typed/npm/@react-native-community/cli-tools_v12.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* 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
* @format
* @oncall react_native
*/

declare module '@react-native-community/cli-tools' {
declare export class CLIError extends Error {
constructor(msg: string, originalError?: Error | mixed | string): this;
}

declare export function hookStdout(callback: Function): () => void;

declare export const logger: $ReadOnly<{
success: (...message: Array<string>) => void,
info: (...message: Array<string>) => void,
warn: (...message: Array<string>) => void,
error: (...message: Array<string>) => void,
debug: (...message: Array<string>) => void,
log: (...message: Array<string>) => void,
setVerbose: (level: boolean) => void,
isVerbose: () => boolean,
disable: () => void,
enable: () => void,
}>;

declare export function resolveNodeModuleDir(
root: string,
packageName: string,
): string;

declare export const version: $ReadOnly<{
logIfUpdateAvailable: (projectRoot: string) => Promise<void>,
}>;
}
30 changes: 30 additions & 0 deletions flow-typed/npm/@react-native-community/cli-types_v12.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* 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
* @oncall react_native
*/

declare module '@react-native-community/cli-types' {
declare type PlatformConfig = {
npmPackageName: string,
...
};

declare export type Config = {
root: string,
reactNativePath: string,
reactNativeVersion: string,
project: Object,
platforms: {
android: PlatformConfig,
ios: PlatformConfig,
[name: string]: PlatformConfig,
},
...
};
}
117 changes: 117 additions & 0 deletions flow-typed/npm/execa_v5.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/**
* 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
* @format
* @oncall react_native
*/

// Modified from flow-typed repo:
// https://github.com/flow-typed/flow-typed/blob/master/definitions/npm/execa_v2.x.x/flow_v0.104.x-/execa_v2.x.x.js#L2

declare module 'execa' {
declare type StdIoOption =
| 'pipe'
| 'ipc'
| 'ignore'
| 'inherit'
| stream$Stream
| number;

declare type CommonOptions = {
argv0?: string,
cleanup?: boolean,
cwd?: string,
detached?: boolean,
encoding?: string,
env?: {[string]: string | void, ...},
extendEnv?: boolean,
gid?: number,
killSignal?: string | number,
localDir?: string,
maxBuffer?: number,
preferLocal?: boolean,
reject?: boolean,
shell?: boolean | string,
stderr?: ?StdIoOption,
stdin?: ?StdIoOption,
stdio?: 'pipe' | 'ignore' | 'inherit' | $ReadOnlyArray<?StdIoOption>,
stdout?: ?StdIoOption,
stripEof?: boolean,
timeout?: number,
uid?: number,
windowsVerbatimArguments?: boolean,
buffer?: boolean,
all?: boolean,
stripFinalNewline?: boolean,
};

declare type SyncOptions = {
...CommonOptions,
input?: string | Buffer,
};

declare type Options = {
...CommonOptions,
input?: string | Buffer | stream$Readable,
};

declare type SyncResult = {
stdout: string,
stderr: string,
exitCode: number,
failed: boolean,
signal: ?string,
command: string,
timedOut: boolean,
};

declare type Result = {
...SyncResult,
killed: boolean,
};

declare interface ExecaPromise
extends Promise<Result>,
child_process$ChildProcess {}

declare interface ExecaError extends ErrnoError {
stdout: string;
stderr: string;
failed: boolean;
signal: ?string;
command: string;
timedOut: boolean;
exitCode: number;
}

declare interface Execa {
(
file: string,
args?: $ReadOnlyArray<string>,
options?: $ReadOnly<Options>,
): ExecaPromise;
(file: string, options?: $ReadOnly<Options>): ExecaPromise;

command(command: string, options?: $ReadOnly<Options>): ExecaPromise;
commandSync(command: string, options?: $ReadOnly<Options>): ExecaPromise;

node(
path: string,
args?: $ReadOnlyArray<string>,
options?: $ReadOnly<Options>,
): void;

sync(
file: string,
args?: $ReadOnlyArray<string>,
options?: $ReadOnly<SyncOptions>,
): SyncResult;
sync(file: string, options?: $ReadOnly<SyncOptions>): SyncResult;
}

declare module.exports: Execa;
}
Loading

0 comments on commit 357cd4a

Please sign in to comment.