Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify occupied port handling in start command #39078

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 4 additions & 39 deletions flow-typed/npm/@react-native-community/cli-tools_v12.x.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,50 +18,15 @@ declare module '@react-native-community/cli-tools' {
constructor(msg: string, originalError?: Error | mixed | string): this;
}

declare export function getPidFromPort(port: number): number | null;

declare export function handlePortUnavailable(
initialPort: number,
projectRoot: string,
initialPackager?: boolean,
): Promise<{
port: number,
packager: boolean,
}>;

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

declare export function isPackagerRunning(
packagerPort: string | number | void,
): Promise<
| {
status: 'running',
root: string,
}
| 'not_running'
| 'unrecognized',
>;

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,
error: (...message: Array<string>) => void,
log: (...message: Array<string>) => void,
setVerbose: (level: boolean) => void,
isVerbose: () => boolean,
disable: () => void,
enable: () => void,
info: (...message: Array<string>) => void,
warn: (...message: Array<string>) => void,
...
}>;

declare export function logAlreadyRunningBundler(port: number): void;

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

declare export const version: $ReadOnly<{
logIfUpdateAvailable: (projectRoot: string) => Promise<void>,
}>;
Expand Down
4 changes: 2 additions & 2 deletions packages/community-cli-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
],
"dependencies": {
"@react-native/dev-middleware": "^0.73.0",
"@react-native-community/cli-server-api": "12.0.0-alpha.9",
"@react-native-community/cli-tools": "12.0.0-alpha.9",
"@react-native-community/cli-server-api": "12.0.0-alpha.11",
"@react-native-community/cli-tools": "12.0.0-alpha.11",
"@react-native/metro-babel-transformer": "^0.73.11",
"chalk": "^4.0.0",
"execa": "^5.1.1",
Expand Down
45 changes: 35 additions & 10 deletions packages/community-cli-plugin/src/commands/bundle/buildBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,57 @@
import type {Config} from '@react-native-community/cli-types';
import type {RequestOptions} from 'metro/src/shared/types.flow';
import type {ConfigT} from 'metro-config';
import type {CommandLineArgs} from './bundleCommandLineArgs';

import Server from 'metro/src/Server';
const outputBundle = require('metro/src/shared/output/bundle');
import metroBundle from 'metro/src/shared/output/bundle';
import metroRamBundle from 'metro/src/shared/output/RamBundle';
import path from 'path';
import chalk from 'chalk';
import saveAssets from './saveAssets';
import {default as loadMetroConfig} from '../../utils/loadMetroConfig';
import loadMetroConfig from '../../utils/loadMetroConfig';
import {logger} from '@react-native-community/cli-tools';

export type BundleCommandArgs = {
assetsDest?: string,
assetCatalogDest?: string,
entryFile: string,
resetCache: boolean,
resetGlobalCache: boolean,
transformer?: string,
minify?: boolean,
config?: string,
platform: string,
dev: boolean,
bundleOutput: string,
bundleEncoding?: 'utf8' | 'utf16le' | 'ascii',
maxWorkers?: number,
sourcemapOutput?: string,
sourcemapSourcesRoot?: string,
sourcemapUseAbsolutePath: boolean,
verbose: boolean,
unstableTransformProfile: string,
indexedRamBundle?: boolean,
};

async function buildBundle(
args: CommandLineArgs,
_argv: Array<string>,
ctx: Config,
output: typeof outputBundle = outputBundle,
args: BundleCommandArgs,
bundleImpl: typeof metroBundle | typeof metroRamBundle = metroBundle,
): Promise<void> {
const config = await loadMetroConfig(ctx, {
maxWorkers: args.maxWorkers,
resetCache: args.resetCache,
config: args.config,
});

return buildBundleWithConfig(args, config, output);
return buildBundleWithConfig(args, config, bundleImpl);
}

async function buildBundleWithConfig(
args: CommandLineArgs,
args: BundleCommandArgs,
config: ConfigT,
output: typeof outputBundle = outputBundle,
bundleImpl: typeof metroBundle | typeof metroRamBundle = metroBundle,
): Promise<void> {
if (config.resolver.platforms.indexOf(args.platform) === -1) {
logger.error(
Expand Down Expand Up @@ -80,11 +103,13 @@ async function buildBundleWithConfig(
const server = new Server(config);

try {
const bundle = await output.build(server, requestOpts);
const bundle = await bundleImpl.build(server, requestOpts);

// $FlowIgnore[class-object-subtyping]
// $FlowIgnore[incompatible-call]
await output.save(bundle, args, logger.info);
// $FlowIgnore[prop-missing]
// $FlowIgnore[incompatible-exact]
await bundleImpl.save(bundle, args, logger.info);

// Save the assets of the bundle
const outputAssets = await server.getAssets({
Expand Down
38 changes: 0 additions & 38 deletions packages/community-cli-plugin/src/commands/bundle/bundle.js

This file was deleted.

This file was deleted.

Loading