Skip to content

Commit d39004b

Browse files
huntiefacebook-github-bot
authored andcommitted
Migrate cli-plugin-metro into repo (facebook#38795)
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: f704ff908eec1e7c2dd5aa71ee48204e5bd0a571
1 parent 0a84952 commit d39004b

36 files changed

+2555
-3
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict
8+
* @format
9+
* @oncall react_native
10+
*/
11+
12+
declare module '@react-native-community/cli-server-api' {
13+
import type {NextHandleFunction, Server} from 'connect';
14+
15+
declare type MiddlewareOptions = {
16+
host?: string,
17+
watchFolders: $ReadOnlyArray<string>,
18+
port: number,
19+
};
20+
21+
declare export function createDevServerMiddleware(
22+
options: MiddlewareOptions,
23+
): {
24+
middleware: Server,
25+
websocketEndpoints: {
26+
'/debugger-proxy': ws$WebSocketServer,
27+
'/message': ws$WebSocketServer,
28+
'/events': ws$WebSocketServer,
29+
},
30+
debuggerProxyEndpoint: {
31+
server: ws$WebSocketServer,
32+
isDebuggerConnected: () => boolean,
33+
},
34+
messageSocketEndpoint: {
35+
server: ws$WebSocketServer,
36+
broadcast: (
37+
method: string,
38+
params?: Record<string, mixed> | null,
39+
) => void,
40+
},
41+
eventsSocketEndpoint: {
42+
server: ws$WebSocketServer,
43+
reportEvent: (event: any) => void,
44+
},
45+
...
46+
};
47+
48+
declare export const indexPageMiddleware: NextHandleFunction;
49+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict
8+
* @format
9+
* @oncall react_native
10+
*/
11+
12+
declare module '@react-native-community/cli-tools' {
13+
declare export class CLIError extends Error {
14+
constructor(msg: string, originalError?: Error | mixed | string): this;
15+
}
16+
17+
declare export function hookStdout(callback: Function): () => void;
18+
19+
declare export const logger: $ReadOnly<{
20+
success: (...message: Array<string>) => void,
21+
info: (...message: Array<string>) => void,
22+
warn: (...message: Array<string>) => void,
23+
error: (...message: Array<string>) => void,
24+
debug: (...message: Array<string>) => void,
25+
log: (...message: Array<string>) => void,
26+
setVerbose: (level: boolean) => void,
27+
isVerbose: () => boolean,
28+
disable: () => void,
29+
enable: () => void,
30+
}>;
31+
32+
declare export function resolveNodeModuleDir(
33+
root: string,
34+
packageName: string,
35+
): string;
36+
37+
declare export const version: $ReadOnly<{
38+
logIfUpdateAvailable: (projectRoot: string) => Promise<void>,
39+
}>;
40+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
* @format
9+
* @oncall react_native
10+
*/
11+
12+
declare module '@react-native-community/cli-types' {
13+
declare type PlatformConfig = {
14+
npmPackageName: string,
15+
...
16+
};
17+
18+
declare export type Config = {
19+
root: string,
20+
reactNativePath: string,
21+
reactNativeVersion: string,
22+
project: Object,
23+
platforms: {
24+
android: PlatformConfig,
25+
ios: PlatformConfig,
26+
[name: string]: PlatformConfig,
27+
},
28+
...
29+
};
30+
}

flow-typed/npm/execa_v5.x.x.js

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict
8+
* @format
9+
* @oncall react_native
10+
*/
11+
12+
// Modified from flow-typed repo:
13+
// 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
14+
15+
declare module 'execa' {
16+
declare type StdIoOption =
17+
| 'pipe'
18+
| 'ipc'
19+
| 'ignore'
20+
| 'inherit'
21+
| stream$Stream
22+
| number;
23+
24+
declare type CommonOptions = {
25+
argv0?: string,
26+
cleanup?: boolean,
27+
cwd?: string,
28+
detached?: boolean,
29+
encoding?: string,
30+
env?: {[string]: string | void, ...},
31+
extendEnv?: boolean,
32+
gid?: number,
33+
killSignal?: string | number,
34+
localDir?: string,
35+
maxBuffer?: number,
36+
preferLocal?: boolean,
37+
reject?: boolean,
38+
shell?: boolean | string,
39+
stderr?: ?StdIoOption,
40+
stdin?: ?StdIoOption,
41+
stdio?: 'pipe' | 'ignore' | 'inherit' | $ReadOnlyArray<?StdIoOption>,
42+
stdout?: ?StdIoOption,
43+
stripEof?: boolean,
44+
timeout?: number,
45+
uid?: number,
46+
windowsVerbatimArguments?: boolean,
47+
buffer?: boolean,
48+
all?: boolean,
49+
stripFinalNewline?: boolean,
50+
};
51+
52+
declare type SyncOptions = {
53+
...CommonOptions,
54+
input?: string | Buffer,
55+
};
56+
57+
declare type Options = {
58+
...CommonOptions,
59+
input?: string | Buffer | stream$Readable,
60+
};
61+
62+
declare type SyncResult = {
63+
stdout: string,
64+
stderr: string,
65+
exitCode: number,
66+
failed: boolean,
67+
signal: ?string,
68+
command: string,
69+
timedOut: boolean,
70+
};
71+
72+
declare type Result = {
73+
...SyncResult,
74+
killed: boolean,
75+
};
76+
77+
declare interface ExecaPromise
78+
extends Promise<Result>,
79+
child_process$ChildProcess {}
80+
81+
declare interface ExecaError extends ErrnoError {
82+
stdout: string;
83+
stderr: string;
84+
failed: boolean;
85+
signal: ?string;
86+
command: string;
87+
timedOut: boolean;
88+
exitCode: number;
89+
}
90+
91+
declare interface Execa {
92+
(
93+
file: string,
94+
args?: $ReadOnlyArray<string>,
95+
options?: $ReadOnly<Options>,
96+
): ExecaPromise;
97+
(file: string, options?: $ReadOnly<Options>): ExecaPromise;
98+
99+
command(command: string, options?: $ReadOnly<Options>): ExecaPromise;
100+
commandSync(command: string, options?: $ReadOnly<Options>): ExecaPromise;
101+
102+
node(
103+
path: string,
104+
args?: $ReadOnlyArray<string>,
105+
options?: $ReadOnly<Options>,
106+
): void;
107+
108+
sync(
109+
file: string,
110+
args?: $ReadOnlyArray<string>,
111+
options?: $ReadOnly<SyncOptions>,
112+
): SyncResult;
113+
sync(file: string, options?: $ReadOnly<SyncOptions>): SyncResult;
114+
}
115+
116+
declare module.exports: Execa;
117+
}

0 commit comments

Comments
 (0)