There is no event listener available for automatic restart in watch mode, try using `launchBus`, it only works on first launch
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 43.3k
- Forks
- 2.7k
- PR merge metrics
- No merged PRs in 30d
Description
What's going wrong?
There is no event listener available for automatic restart in watch mode, try using launchBus, it only works on first launch
How could we reproduce this issue?
I tried re-running the following code using my own bun+yargs CLI
bun --bun src/console/bin.ts
export const startPM2 = async (
configure: Configure,
args: Arguments<StartCommandArguments>,
config: CLIConfig,
) => {
const { name } = await configure.get<AppConfig>('app');
const script = args.typescript ? config.paths.ts : config.paths.js;
const pm2Config = await getPm2Config(
configure,
{
command: 'start',
...pick(args, ['watch', 'typescript']),
},
config,
script,
);
const connectCallback = (error?: any) => {
if (!isNil(error)) {
console.error(error);
process.exit(2);
}
};
const startCallback = (error?: any) => {
if (!isNil(error)) {
console.error(error);
exit(1);
}
pm2.disconnect();
};
const restartCallback = (error?: any) => {
if (!isNil(error)) {
pm2.start(pm2Config, (serr) => startCallback(serr));
} else {
pm2.disconnect();
}
};
pm2.connect((cerr) => {
connectCallback(cerr);
args.force ? pm2.restart(name, restartCallback) : pm2.reload(name, restartCallback);
});
// eslint-disable-next-line func-names
pm2.launchBus(function (err, bus) {
// eslint-disable-next-line func-names
bus.on('process:event', function (data: any) {
console.log(data.event)
// generateSwaggerMetadata(config, false);
});
});
};
On the first start, working fine
But using pm2 restart or automatic restart through watch is invalid.
Supporting information
$ pm2 report
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at src/console/bin.ts and inspect the pm2.connect, pm2.launchBus, and process:event flow shown in the report. Reproduce the initial start followed by pm2 restart or a watch-triggered restart with the Bun command; done means the event listener remains available and reports events after subsequent launches.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- bun, javascript, node.js, typescript
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100