@hubspot/ui-extensions-dev-server 0.8.4 → 0.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,6 +18,12 @@ interface StartArguments {
18
18
  accountId?: number;
19
19
  debug?: boolean;
20
20
  httpClient?: ServiceConfiguration['httpClient'];
21
+ requestPorts?: (requestPortsData: Array<{
22
+ instanceId: string;
23
+ port?: number;
24
+ }>) => Promise<{
25
+ [instanceId: string]: number;
26
+ }>;
21
27
  projectConfig?: ProjectConfig;
22
28
  }
23
29
  interface AppExtensionMapping {
@@ -33,7 +39,7 @@ declare class DevModeInterface {
33
39
  _getPlatformVersion(projectConfig?: ProjectConfig): PlatformVersion;
34
40
  setup({ components, debug, extensionConfig, onUploadRequired, promptUser, }: SetupArguments): Promise<void>;
35
41
  fileChange(filePath: string, __event: unknown): Promise<void>;
36
- start({ accountId, debug, httpClient, projectConfig }: StartArguments): Promise<void>;
42
+ start({ requestPorts, accountId, debug, httpClient, projectConfig, }: StartArguments): Promise<void>;
37
43
  cleanup(): Promise<void>;
38
44
  }
39
45
  declare const _default: DevModeInterface;
@@ -13,6 +13,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  const dev_1 = require("./dev");
15
15
  const constants_1 = require("./constants");
16
+ const constants_2 = require("./constants");
16
17
  const config_1 = require("./config");
17
18
  // @ts-expect-error no type defs
18
19
  const logger_1 = require("@hubspot/cli-lib/logger");
@@ -45,13 +46,13 @@ class DevModeInterface {
45
46
  _getPlatformVersion(projectConfig) {
46
47
  const { platformVersion } = projectConfig !== null && projectConfig !== void 0 ? projectConfig : {};
47
48
  if (!platformVersion) {
48
- return constants_1.PLATFORM_VERSION.V20231;
49
+ return constants_2.PLATFORM_VERSION.V20231;
49
50
  }
50
51
  switch (platformVersion) {
51
- case constants_1.PLATFORM_VERSION.V20231:
52
- return constants_1.PLATFORM_VERSION.V20231;
53
- case constants_1.PLATFORM_VERSION.V20232:
54
- return constants_1.PLATFORM_VERSION.V20232;
52
+ case constants_2.PLATFORM_VERSION.V20231:
53
+ return constants_2.PLATFORM_VERSION.V20231;
54
+ case constants_2.PLATFORM_VERSION.V20232:
55
+ return constants_2.PLATFORM_VERSION.V20232;
55
56
  default:
56
57
  return (0, utils_1.throwUnhandledPlatformVersionError)(platformVersion);
57
58
  }
@@ -76,10 +77,14 @@ class DevModeInterface {
76
77
  type: 'checkbox',
77
78
  name: 'extensions',
78
79
  message: 'Which extension(s) would you like to run?',
79
- validate: input => {
80
+ validate: (input) => {
80
81
  if (!input || input.length === 0) {
81
82
  return 'Select at least one extension to run';
82
83
  }
84
+ const appNames = new Set(input.map(choice => choice.data.appName));
85
+ if (appNames.size > 1) {
86
+ return 'Running multiple extensions is only supported for a single application';
87
+ }
83
88
  return true;
84
89
  },
85
90
  choices,
@@ -101,16 +106,33 @@ class DevModeInterface {
101
106
  }
102
107
  });
103
108
  }
104
- start({ accountId, debug, httpClient, projectConfig }) {
109
+ start({ requestPorts, accountId, debug, httpClient, projectConfig, }) {
105
110
  return __awaiter(this, void 0, void 0, function* () {
106
111
  if (debug !== undefined) {
107
112
  (0, logger_1.setLogLevel)(debug ? logger_1.LOG_LEVEL.DEBUG : logger_1.LOG_LEVEL.LOG);
108
113
  }
114
+ let expressPort = constants_1.EXPRESS_DEFAULT_PORT;
115
+ let webSocketPort = constants_1.WEBSOCKET_DEFAULT_PORT;
116
+ if (requestPorts) {
117
+ try {
118
+ const portData = yield requestPorts([
119
+ { instanceId: constants_1.EXPRESS_SERVER_ID, port: constants_1.EXPRESS_DEFAULT_PORT },
120
+ { instanceId: constants_1.VITE_DEV_SERVER_ID, port: constants_1.WEBSOCKET_DEFAULT_PORT },
121
+ ]);
122
+ expressPort = portData[constants_1.EXPRESS_SERVER_ID];
123
+ webSocketPort = portData[constants_1.VITE_DEV_SERVER_ID];
124
+ }
125
+ catch (e) {
126
+ logger_1.logger.debug('Call to port manager failed, using default ports');
127
+ }
128
+ }
109
129
  this.devServerState = new DevServerState_1.DevServerState({
110
130
  extensionConfigs: this.configs,
111
131
  accountId,
112
132
  httpClient,
113
133
  platformVersion: this._getPlatformVersion(projectConfig),
134
+ expressPort,
135
+ webSocketPort,
114
136
  });
115
137
  this.shutdown = yield (0, dev_1.startDevMode)(this.devServerState);
116
138
  this.devServerState.extensionsMetadata.forEach(metadata => {
@@ -4,8 +4,8 @@ interface DevServerStateArgs {
4
4
  extensionConfigs?: ExtensionConfig[];
5
5
  accountId: number | undefined;
6
6
  httpClient: ServiceConfiguration['httpClient'] | undefined;
7
- expressPort?: number;
8
- webSocketPort?: number;
7
+ expressPort: number;
8
+ webSocketPort: number;
9
9
  platformVersion: PlatformVersion;
10
10
  }
11
11
  export declare class DevServerState {
@@ -7,9 +7,7 @@ exports.DevServerState = void 0;
7
7
  const constants_1 = require("./constants");
8
8
  const path_1 = __importDefault(require("path"));
9
9
  class DevServerState {
10
- constructor({ extensionConfigs, accountId, httpClient, expressPort = constants_1.VITE_DEFAULT_PORT, webSocketPort = constants_1.WEBSOCKET_PORT, platformVersion, }) {
11
- this._webSocketPort = constants_1.WEBSOCKET_PORT;
12
- this._expressPort = constants_1.VITE_DEFAULT_PORT;
10
+ constructor({ extensionConfigs, accountId, httpClient, expressPort, webSocketPort, platformVersion, }) {
13
11
  if (!extensionConfigs) {
14
12
  throw new Error('Unable to load the required extension configuration files');
15
13
  }
@@ -1,8 +1,10 @@
1
1
  export declare const OUTPUT_DIR = "dist";
2
2
  export declare const MAIN_APP_CONFIG = "app.json";
3
3
  export declare const MANIFEST_FILE = "manifest.json";
4
- export declare const VITE_DEFAULT_PORT = 5173;
5
- export declare const WEBSOCKET_PORT = 5174;
4
+ export declare const EXPRESS_SERVER_ID = "ui-extensions-dev-server";
5
+ export declare const VITE_DEV_SERVER_ID = "ui-extensions-vite-dev-server";
6
+ export declare const EXPRESS_DEFAULT_PORT = 5173;
7
+ export declare const WEBSOCKET_DEFAULT_PORT = 5174;
6
8
  export declare const ROLLUP_OPTIONS: {
7
9
  external: string[];
8
10
  output: {
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PLATFORM_VERSION = exports.SERVER_CAPABILITIES = exports.WEBSOCKET_MESSAGE_VERSION = exports.EXTENSIONS_MESSAGE_VERSION = exports.ROLLUP_OPTIONS = exports.WEBSOCKET_PORT = exports.VITE_DEFAULT_PORT = exports.MANIFEST_FILE = exports.MAIN_APP_CONFIG = exports.OUTPUT_DIR = void 0;
3
+ exports.PLATFORM_VERSION = exports.SERVER_CAPABILITIES = exports.WEBSOCKET_MESSAGE_VERSION = exports.EXTENSIONS_MESSAGE_VERSION = exports.ROLLUP_OPTIONS = exports.WEBSOCKET_DEFAULT_PORT = exports.EXPRESS_DEFAULT_PORT = exports.VITE_DEV_SERVER_ID = exports.EXPRESS_SERVER_ID = exports.MANIFEST_FILE = exports.MAIN_APP_CONFIG = exports.OUTPUT_DIR = void 0;
4
4
  exports.OUTPUT_DIR = 'dist';
5
5
  exports.MAIN_APP_CONFIG = 'app.json';
6
6
  exports.MANIFEST_FILE = 'manifest.json';
7
- exports.VITE_DEFAULT_PORT = 5173;
8
- exports.WEBSOCKET_PORT = 5174;
7
+ exports.EXPRESS_SERVER_ID = 'ui-extensions-dev-server';
8
+ exports.VITE_DEV_SERVER_ID = 'ui-extensions-vite-dev-server';
9
+ exports.EXPRESS_DEFAULT_PORT = 5173;
10
+ exports.WEBSOCKET_DEFAULT_PORT = 5174;
9
11
  exports.ROLLUP_OPTIONS = {
10
12
  // Deps to exclude from the bundle
11
13
  external: ['react', 'react-dom', '@remote-ui/react'],
package/dist/lib/dev.js CHANGED
@@ -18,8 +18,6 @@ const path_1 = __importDefault(require("path"));
18
18
  const server_1 = __importDefault(require("./server"));
19
19
  const devBuildPlugin_1 = __importDefault(require("./plugins/devBuildPlugin"));
20
20
  // @ts-expect-error no type defs
21
- const logger_1 = require("@hubspot/cli-lib/logger");
22
- // @ts-expect-error no type defs
23
21
  const detect_port_1 = __importDefault(require("detect-port"));
24
22
  function _createViteDevServer(devServerState) {
25
23
  return __awaiter(this, void 0, void 0, function* () {
@@ -66,12 +64,7 @@ function startDevMode(devServerState) {
66
64
  if (!devServerState || !devServerState.extensionsMetadata) {
67
65
  throw new Error('Unable to determine which extension to run');
68
66
  }
69
- const { expressPort, webSocketPort } = devServerState;
70
- yield throwIfPortTaken(expressPort);
71
- const actualWebSocketPort = yield (0, detect_port_1.default)(webSocketPort);
72
- if (actualWebSocketPort !== webSocketPort) {
73
- logger_1.logger.debug(`WebSocket port ${webSocketPort} is in use; using next available port ${actualWebSocketPort}`);
74
- }
67
+ yield throwIfPortTaken(devServerState.webSocketPort);
75
68
  const viteDevServer = yield _createViteDevServer(devServerState);
76
69
  const shutdownServer = yield (0, server_1.default)({
77
70
  devServerState,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/ui-extensions-dev-server",
3
- "version": "0.8.4",
3
+ "version": "0.8.6",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -63,5 +63,5 @@
63
63
  "optional": true
64
64
  }
65
65
  },
66
- "gitHead": "41e3484343d34136e81540d774a101ccf99642b3"
66
+ "gitHead": "621bee406c8dfa9ca133f1d76f4bde725a2b9f43"
67
67
  }