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 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
1 change: 1 addition & 0 deletions packages/cli-doctor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@react-native-community/cli-platform-android": "12.0.0-alpha.3",
"@react-native-community/cli-platform-ios": "12.0.0-alpha.3",
"@react-native-community/cli-tools": "12.0.0-alpha.3",
"@react-native-community/cli-plugin-metro": "12.0.0-alpha.3",
"chalk": "^4.1.2",
"command-exists": "^1.2.8",
"envinfo": "^7.7.2",
Expand Down
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-plugin-metro';

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 bundler. Please run "react-native start" command manually.',
});
} catch (error) {
return logManualInstallation({
message:
'Could not start the bundler. Please run "react-native start" command manually.',
});
}
},
} as HealthCheckInterface;
3 changes: 2 additions & 1 deletion packages/cli-doctor/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{"path": "../cli-types"},
{"path": "../cli-config"},
{"path": "../cli-platform-android"},
{"path": "../cli-platform-ios"}
{"path": "../cli-platform-ios"},
{"path": "../cli-plugin-metro"},
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import execa from 'execa';
import {getAndroidProject} from '../../config/getAndroidProject';
import adb from '../runAndroid/adb';
import getAdbPath from '../runAndroid/getAdbPath';
import {startServerInNewWindow} from './startServerInNewWindow';
import {startServerInNewWindow} from '@react-native-community/cli-plugin-metro';
import {getTaskNames} from '../runAndroid/getTaskNames';
import {promptForTaskSelection} from '../runAndroid/listAndroidTasks';

Expand Down
6 changes: 5 additions & 1 deletion packages/cli-platform-android/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@
"rootDir": "src",
"outDir": "build"
},
"references": [{"path": "../cli-tools"}, {"path": "../cli-types"}]
"references": [
{"path": "../cli-tools"},
{"path": "../cli-types"},
{"path": "../cli-plugin-metro"}
]
}
1 change: 1 addition & 0 deletions packages/cli-plugin-metro/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ import startCommand from './start';
export default [bundleCommand, ramBundleCommand, startCommand];
export {buildBundleWithConfig} from './bundle';
export type {CommandLineArgs} from './bundle';
export {startServerInNewWindow} from './start';
2 changes: 2 additions & 0 deletions packages/cli-plugin-metro/src/commands/start/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,5 @@ export default {
},
],
};

export {startServerInNewWindow} from './startServerInNewWindow';
1 change: 1 addition & 0 deletions packages/cli-plugin-metro/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export {
default as commands,
buildBundleWithConfig,
CommandLineArgs,
startServerInNewWindow,
} from './commands';