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

fix(bit-server-cli), skip bit-server for init command and when port file is not there #9077

Merged
merged 1 commit into from
Jul 31, 2024
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
6 changes: 4 additions & 2 deletions scopes/harmony/bit/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ if (process.argv.includes('--get-yargs-completions')) {
}

if (shouldUseBitServer()) {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
new ServerCommander().execute();
new ServerCommander().execute().catch(() => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
initApp();
});
} else {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
initApp();
Expand Down
20 changes: 16 additions & 4 deletions scopes/harmony/bit/server-commander.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ import { findScopePath } from '@teambit/scope.modules.find-scope-path';
import chalk from 'chalk';
import loader from '@teambit/legacy/dist/cli/loader';

export class ServerPortFileNotFound extends Error {
constructor(filePath: string) {
super(`server port file not found at ${filePath}`);
}
}
export class ServerNotFound extends Error {
constructor(port: number) {
super(`bit server is not running on port ${port}`);
}
}

export class ServerCommander {
private isJson = false;
async execute() {
Expand All @@ -28,6 +39,7 @@ export class ServerCommander {

process.exit(0);
} catch (err: any) {
if (err instanceof ServerPortFileNotFound || err instanceof ServerNotFound) throw err;
// eslint-disable-next-line no-console
console.error(chalk.red(err.message));
process.exit(1);
Expand Down Expand Up @@ -64,7 +76,7 @@ export class ServerCommander {
});
} catch (err: any) {
if (err.code === 'ECONNREFUSED') {
throw new Error(`bit server is not running on port ${port}`);
throw new ServerNotFound(port);
}
throw new Error(`failed to run command "${cmd}" on the server. ${err.message}`);
}
Expand Down Expand Up @@ -118,7 +130,7 @@ export class ServerCommander {
return parseInt(fileContent, 10);
} catch (err: any) {
if (err.code === 'ENOENT') {
throw new Error(`server port file not found at ${filePath}`);
throw new ServerPortFileNotFound(filePath);
}
throw err;
}
Expand All @@ -134,12 +146,12 @@ export class ServerCommander {
}

export function shouldUseBitServer() {
const longRunningCommands = ['start', 'run', 'watch'];
const commandsToSkip = ['start', 'run', 'watch', 'init'];
return (
process.env.BIT_CLI_SERVER &&
!process.argv.includes('--help') &&
!process.argv.includes('-h') &&
process.argv.length > 2 && // if it has no args, it shows the help
!longRunningCommands.includes(process.argv[2])
!commandsToSkip.includes(process.argv[2])
);
}