Files
react-native/packages/community-cli-plugin
Vitali Zaidman 23e738fb6d allow waiting for metro to be torn down (#46620)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/46620

The following error was thrown when the test `packages/metro/src/integration_tests/__tests__/server-test.js` was running on Metro:
{F1816961963}

It led me to investigate why don't we wait for Metro to be torn down.

Currently we close metro by closing the http server that it launches.
```
const httpServer = await Metro.runServer(/* ... */);
httpServer.close(callback);
```
While we can listen to the callback fired when the server is closed, it only covers one of the systems running internally in metro. The systems that are not covered are:
* File watchers
* File map workers
* Dependency graph
* Bundler

And many systems that were themselves listening to the above like "eslint file map" or the "dependency analysis".

**These systems are closed by us _after_ the server is closed.** This means that a listener to `server.on('close'` would only get the indication where these systems has started to close rather than actually got closed.
https://www.internalfb.com/code/fbsource/[17e03bc6bd86]/xplat/js/tools/metro/packages/metro/src/index.flow.js?lines=359-361

This diff introduces a way to wait for all of metro to be closed.

In this diff I use that new way of listening to Metro closure to get rid of the jest test warning mentioned above in `packages/metro/src/integration_tests/__tests__/server-test.js`:
```
  let serverClosedPromise;

  beforeEach(async () => {
    config = await Metro.loadConfig({
      config: require.resolve('../metro.config.js'),
    });

    let onCloseResolve;
    serverClosedPromise = new Promise(resolve => (onCloseResolve = resolve));
    httpServer = await Metro.runServer(config, {
      reporter: {update() {}},
      onClose: () => {
        onCloseResolve();
      },
    });
  });

  afterEach(async () => {
    httpServer.close();
    await serverClosedPromise;
  });
```

Changelog: [Feature] add `onClose` to `Metro.runServer` configuration allowing to wait for metro and all associated processes to be closed.

Reviewed By: huntie

Differential Revision: D61594124

fbshipit-source-id: e3c50ef986077503bce0caa42a9f9430efc65272
2024-09-26 03:42:49 -07:00
..
2024-09-12 09:23:23 -07:00

@react-native/community-cli-plugin

This is an internal dependency of React Native. Please don't depend on it directly.

CLI entry points supporting core React Native development features.

Formerly @react-native-community/cli-plugin-metro.

Commands

start

Start the React Native development server.

Usage

npx react-native start [options]

Options

Option Description
--port <number> Set the server port.
--host <string> Set the server host.
--projectRoot <path> Set the path to the project root.
--watchFolders <list> Specify additional folders to be added to the watch list.
--assetPlugins <list> Specify additional asset plugins.
--sourceExts <list> Specify additional source extensions to bundle.
--max-workers <number> Set the maximum number of workers the worker-pool will spawn for transforming files. Defaults to the number of the cores available on your machine.
--transformer <string> Specify a custom transformer.
--reset-cache Remove cached files.
--custom-log-reporter-path <string> Specify a module path exporting a replacement for TerminalReporter.
--https Enable HTTPS connections.
--key <path> Specify path to a custom SSL key.
--cert <path> Specify path to a custom SSL cert.
--config <string> Path to the CLI configuration file.
--no-interactive Disable interactive mode.

bundle

Build the bundle for the provided JavaScript entry file.

Usage

npx react-native bundle --entry-file <path> [options]

Options

Option Description
--entry-file <path> Set the path to the root JavaScript entry file.
--platform <string> Set the target platform (either "android" or "ios"). Defaults to "ios".
--transformer <string> Specify a custom transformer.
--dev [boolean] If false, warnings are disabled and the bundle is minified. Defaults to true.
--minify [boolean] Allows overriding whether bundle is minified. Defaults to false if --dev is set. Disabling minification can be useful for speeding up production builds for testing purposes.
--bundle-output <string> Specify the path to store the resulting bundle.
--bundle-encoding <string> Specify the encoding for writing the bundle (https://nodejs.org/api/buffer.html#buffer_buffer).
--resolver-option <string...> Custom resolver options of the form key=value. URL-encoded. May be specified multiple times.
--sourcemap-output <string> Specify the path to store the source map file for the resulting bundle.
--sourcemap-sources-root <string> Set the root path for source map entries.
--sourcemap-use-absolute-path Report SourceMapURL using its full path.
--max-workers <number> Set the maximum number of workers the worker-pool will spawn for transforming files. Defaults to the number of the cores available on your machine.
--assets-dest <string> Specify the directory path for storing assets referenced in the bundle.
--reset-cache Remove cached files.
--read-global-cache Attempt to fetch transformed JS code from the global cache, if configured. Defaults to false.
--config <string> Path to the CLI configuration file.

Contributing

Changes to this package can be made locally and tested against the rn-tester app, per the Contributing guide. During development, this package is automatically run from source with no build step.