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

Use port manager #936

Merged
merged 10 commits into from
Nov 13, 2023
Merged
14 changes: 14 additions & 0 deletions packages/cli/lib/DevServerManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ const { COMPONENT_TYPES } = require('./projectStructure');
const { i18n } = require('./lang');
const { promptUser } = require('./prompts/promptUtils');
const { DevModeInterface } = require('@hubspot/ui-extensions-dev-server');
const {
startPortManagerServer,
portManagerHasActiveServers,
stopPortManagerServer,
requestPorts,
} = require('@hubspot/local-dev-lib/portManager');

const i18nKey = 'cli.lib.DevServerManager';

Expand Down Expand Up @@ -61,6 +67,7 @@ class DevServerManager {
this.debug = debug;
this.componentsByType = this.arrangeComponentsByType(components);

await startPortManagerServer();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My comment here is relevant. It should enable you to catch port conflicts when attempting to start up the server manager and log a useful error here

await this.iterateDevServers(
async (serverInterface, compatibleComponents) => {
if (serverInterface.setup) {
Expand All @@ -86,6 +93,7 @@ class DevServerManager {
debug: this.debug,
httpClient,
projectConfig,
requestPorts,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker - I wonder if this is something that we should be passing down to the servers or if they should just import it directly from local-dev-lib. They will likely already have local-dev-lib as a dep anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I thought about this a bit. I ended up going with this approach because the CLI is responsible for starting the port manager server. So when the server gets it from the DevServerManager, it comes with a guarantee that the port manager is actually running. In practice though I don't think it would really make a difference, so not opposed to changing this.

});
}
});
Expand Down Expand Up @@ -113,6 +121,12 @@ class DevServerManager {
await serverInterface.cleanup();
}
});

const hasActiveServers = await portManagerHasActiveServers();

if (!hasActiveServers) {
await stopPortManagerServer();
}
}
}
}
Expand Down
Loading
Loading