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
Show file tree
Hide file tree
Changes from 8 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
12 changes: 12 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,10 @@ class DevServerManager {
await serverInterface.cleanup();
}
});

if (!portManagerHasActiveServers()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

portManagerHasActiveServers is async so you'll need await here. The stop function is also async and we might want to wait for that so we can handle errors if there are any

stopPortManagerServer();
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"dependencies": {
"@hubspot/cli-lib": "^5.0.1",
"@hubspot/local-dev-lib": "^0.0.5",
"@hubspot/serverless-dev-runtime": "4.2.1-beta.3",
"@hubspot/ui-extensions-dev-server": "^0.8.0",
"archiver": "^5.3.0",
Expand Down
Loading
Loading