Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
Merged
3 changes: 1 addition & 2 deletions Composer/packages/types/src/runtime.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { IBotProject } from './server';
import { DialogSetting } from './settings';

Expand Down Expand Up @@ -63,7 +62,7 @@ export type RuntimeTemplate = {
eject?: (project: IBotProject, localDisk?: any, isReplace?: boolean) => Promise<string>;

/** build method used for local publish */
build: (runtimePath: string, project: IBotProject) => Promise<void>;
build: (runtimePath: string, project: IBotProject, fullSettings?: DialogSetting, port?: number) => Promise<void>;

run: (project: IBotProject, localDisk?: any) => Promise<void>;

Expand Down
34 changes: 17 additions & 17 deletions extensions/localPublish/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,21 @@ class LocalPublisher implements PublishPlugin<PublishConfig> {
);
};

private publishAsync = async (botId: string, version: string, fullSettings: any, project: any, user) => {
private publishAsync = async (botId: string, version: string, fullSettings: DialogSetting, project: any, user) => {
try {
let port;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Needed to move the port selection up in the code a bit so that it can be passed to the build step.

if (LocalPublisher.runningBots[botId]) {
this.composer.log('Bot already running. Stopping bot...');
// this may or may not be set based on the status of the bot
port = LocalPublisher.runningBots[botId].port;
await this.stopBot(botId);
}
if (!port) {
// Portfinder is the stablest amongst npm libraries for finding ports. https://github.com/http-party/node-portfinder/issues/61. It does not support supplying an array of ports to pick from as we can have a race conidtion when starting multiple bots at the same time. As a result, getting the max port number out of the range and starting the range from the max.
const maxPort = max(map(LocalPublisher.runningBots, 'port')) ?? 3979;
port = await portfinder.getPortPromise({ port: maxPort + 1, stopPort: 6000 });
}

// if enableCustomRuntime is not true, initialize the runtime code in a tmp folder
// and export the content into that folder as well.
const runtime = this.composer.getRuntimeByProject(project);
Expand All @@ -140,11 +153,11 @@ class LocalPublisher implements PublishPlugin<PublishConfig> {
await this.saveContent(botId, version, project.dataDir, user);
} else if (project.settings.runtime.path && project.settings.runtime.command) {
const runtimePath = project.getRuntimePath();
await runtime.build(runtimePath, project);
await runtime.build(runtimePath, project, fullSettings, port);
} else {
throw new Error('Custom runtime settings are incomplete. Please specify path and command.');
}
await this.setBot(botId, version, fullSettings, project);
await this.setBot(botId, version, fullSettings, project, port);
} catch (error) {
await this.stopBot(botId);
this.setBotStatus(botId, {
Expand Down Expand Up @@ -332,22 +345,9 @@ class LocalPublisher implements PublishPlugin<PublishConfig> {
};

// start bot in current version
private setBot = async (botId: string, version: string, settings: any, project: any) => {
private setBot = async (botId: string, version: string, settings: any, project: any, port: number) => {
// get port, and stop previous bot if exist
try {
let port;
if (LocalPublisher.runningBots[botId]) {
this.composer.log('Bot already running. Stopping bot...');
// this may or may not be set based on the status of the bot
port = LocalPublisher.runningBots[botId].port;
await this.stopBot(botId);
}
if (!port) {
// Portfinder is the stablest amongst npm libraries for finding ports. https://github.com/http-party/node-portfinder/issues/61. It does not support supplying an array of ports to pick from as we can have a race conidtion when starting multiple bots at the same time. As a result, getting the max port number out of the range and starting the range from the max.
const maxPort = max(map(LocalPublisher.runningBots, 'port')) ?? 3979;
port = await portfinder.getPortPromise({ port: maxPort + 1, stopPort: 6000 });
}

// if not using custom runtime, update assets in tmp older
if (!settings.runtime || settings.runtime.customRuntime !== true) {
this.composer.log('Updating bot assets');
Expand Down
1 change: 1 addition & 0 deletions extensions/runtimes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"watch": "yarn build --watch"
},
"dependencies": {
"@botframework-composer/types": "file:../../Composer/packages/types",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this how published packages should be expressing dependencies? Not as familiar with file references.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is how the extensions currently reference these libraries that are in a different yarn workspace. I'm not sure if they should be updated to point to the published packages...

"fs-extra": "^9.0.1",
"path": "^0.12.7",
"rimraf": "^3.0.2"
Expand Down
Loading