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

feat (doctor): add packager healthcheck to report if packager is running correctly #1941

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions packages/cli-doctor/src/tools/healthchecks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import iosDeploy from './iosDeploy';
import {Healthchecks, HealthCheckCategory} from '../../types';
import loadConfig from '@react-native-community/cli-config';
import xcodeEnv from './xcodeEnv';
import packager from './packager';

export const HEALTHCHECK_TYPES = {
ERROR: 'ERROR',
Expand Down Expand Up @@ -41,6 +42,7 @@ export const getHealthchecks = ({contributor}: Options): Healthchecks => {
nodeJS,
yarn,
npm,
packager,
...(process.platform === 'darwin' ? [watchman] : []),
],
},
Expand Down
51 changes: 51 additions & 0 deletions packages/cli-doctor/src/tools/healthchecks/packager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {
getDefaultUserTerminal,
isPackagerRunning,
} from '@react-native-community/cli-tools';
import {HealthCheckInterface} from '../../types';
import {logManualInstallation} from './common';
import {startServerInNewWindow} from '@react-native-community/cli-platform-android';

export default {
label: 'Metro',
isRequired: false,
description: 'Required for bundling the JavaScript code',
getDiagnostics: async () => {
const status = await isPackagerRunning();
const needsToBeFixed = status === 'not_running';
if (needsToBeFixed) {
return {
description: 'Metro Bundler is not running',
needsToBeFixed,
};
}
return {
needsToBeFixed,
};
},
runAutomaticFix: async ({loader, config}) => {
loader.fail();
try {
const terminal = getDefaultUserTerminal();
const port = Number(process.env.RCT_METRO_PORT) || 8081;
if (terminal && config) {
startServerInNewWindow(
port,
terminal,
config.root,
config.reactNativePath,
);
return loader.succeed();
}
return logManualInstallation({
message:
'Could not start the packager. Please run "react-native start" command manually.',
});
} catch (error) {
return logManualInstallation({
message:
'Could not start the packager. Please run "react-native start" command manually.',
});
}
},
} as HealthCheckInterface;
1 change: 1 addition & 0 deletions packages/cli-platform-android/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export {
} from './commands/runAndroid';
export {projectConfig, dependencyConfig} from './config';
export {getAndroidProject, getPackageName} from './config/getAndroidProject';
export {startServerInNewWindow} from './commands/buildAndroid/startServerInNewWindow';
szymonrybczak marked this conversation as resolved.
Show resolved Hide resolved