@hubspot/ui-extensions-dev-server 0.10.2 → 1.0.1

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.
Files changed (95) hide show
  1. package/README.md +23 -4
  2. package/dist/index.d.ts +3 -3
  3. package/dist/index.js +4 -45
  4. package/dist/lib/DevModeInterface.d.ts +2 -2
  5. package/dist/lib/DevModeInterface.js +12 -28
  6. package/dist/lib/DevModeParentInterface.d.ts +2 -2
  7. package/dist/lib/DevModeParentInterface.js +138 -154
  8. package/dist/lib/DevModeUnifiedInterface.d.ts +2 -2
  9. package/dist/lib/DevModeUnifiedInterface.js +28 -49
  10. package/dist/lib/DevServerState.d.ts +9 -5
  11. package/dist/lib/DevServerState.js +37 -18
  12. package/dist/lib/ExtensionsWebSocket.d.ts +25 -0
  13. package/dist/lib/ExtensionsWebSocket.js +110 -0
  14. package/dist/lib/__mocks__/config.d.ts +2 -0
  15. package/dist/lib/__mocks__/config.js +5 -0
  16. package/dist/lib/__mocks__/isExtensionFile.d.ts +5 -0
  17. package/dist/lib/__mocks__/isExtensionFile.js +11 -0
  18. package/dist/lib/__tests__/DevModeInterface.spec.d.ts +1 -0
  19. package/dist/lib/__tests__/DevModeInterface.spec.js +155 -0
  20. package/dist/lib/__tests__/DevModeParentInterface.spec.d.ts +1 -0
  21. package/dist/lib/__tests__/DevModeParentInterface.spec.js +179 -0
  22. package/dist/lib/__tests__/DevModeUnifiedInterface.spec.d.ts +1 -0
  23. package/dist/lib/__tests__/DevModeUnifiedInterface.spec.js +236 -0
  24. package/dist/lib/__tests__/ExtensionsWebSocket.spec.d.ts +1 -0
  25. package/dist/lib/__tests__/ExtensionsWebSocket.spec.js +304 -0
  26. package/dist/lib/__tests__/ast.spec.d.ts +1 -0
  27. package/dist/lib/__tests__/ast.spec.js +737 -0
  28. package/dist/lib/__tests__/build.spec.d.ts +1 -0
  29. package/dist/lib/__tests__/build.spec.js +159 -0
  30. package/dist/lib/__tests__/config.spec.d.ts +1 -0
  31. package/dist/lib/__tests__/config.spec.js +291 -0
  32. package/dist/lib/__tests__/dev.spec.d.ts +1 -0
  33. package/dist/lib/__tests__/dev.spec.js +80 -0
  34. package/dist/lib/__tests__/extensionsService.spec.d.ts +1 -0
  35. package/dist/lib/__tests__/extensionsService.spec.js +150 -0
  36. package/dist/lib/__tests__/factories.d.ts +48 -0
  37. package/dist/lib/__tests__/factories.js +32 -0
  38. package/dist/lib/__tests__/fixtures/extensionConfig.d.ts +182 -0
  39. package/dist/lib/__tests__/fixtures/extensionConfig.js +304 -0
  40. package/dist/lib/__tests__/fixtures/urls.d.ts +4 -0
  41. package/dist/lib/__tests__/fixtures/urls.js +4 -0
  42. package/dist/lib/__tests__/parsing-utils.spec.d.ts +1 -0
  43. package/dist/lib/__tests__/parsing-utils.spec.js +467 -0
  44. package/dist/lib/__tests__/plugins/codeBlockingPlugin.spec.d.ts +1 -0
  45. package/dist/lib/__tests__/plugins/codeBlockingPlugin.spec.js +112 -0
  46. package/dist/lib/__tests__/plugins/codeCheckingPlugin.spec.d.ts +1 -0
  47. package/dist/lib/__tests__/plugins/codeCheckingPlugin.spec.js +82 -0
  48. package/dist/lib/__tests__/plugins/devBuildPlugin.spec.d.ts +1 -0
  49. package/dist/lib/__tests__/plugins/devBuildPlugin.spec.js +256 -0
  50. package/dist/lib/__tests__/plugins/friendlyLoggingPlugin.spec.d.ts +1 -0
  51. package/dist/lib/__tests__/plugins/friendlyLoggingPlugin.spec.js +65 -0
  52. package/dist/lib/__tests__/plugins/manifestPlugin.spec.d.ts +1 -0
  53. package/dist/lib/__tests__/plugins/manifestPlugin.spec.js +455 -0
  54. package/dist/lib/__tests__/plugins/relevantModulesPlugin.spec.d.ts +1 -0
  55. package/dist/lib/__tests__/plugins/relevantModulesPlugin.spec.js +81 -0
  56. package/dist/lib/__tests__/server.spec.d.ts +1 -0
  57. package/dist/lib/__tests__/server.spec.js +152 -0
  58. package/dist/lib/__tests__/test-utils/ast.d.ts +1 -0
  59. package/dist/lib/__tests__/test-utils/ast.js +4 -0
  60. package/dist/lib/__tests__/utils.spec.d.ts +1 -0
  61. package/dist/lib/__tests__/utils.spec.js +176 -0
  62. package/dist/lib/ast.d.ts +1 -1
  63. package/dist/lib/ast.js +22 -29
  64. package/dist/lib/bin/cli.js +52 -72
  65. package/dist/lib/build.d.ts +1 -1
  66. package/dist/lib/build.js +60 -78
  67. package/dist/lib/config.d.ts +1 -1
  68. package/dist/lib/config.js +31 -34
  69. package/dist/lib/constants.d.ts +0 -2
  70. package/dist/lib/constants.js +20 -27
  71. package/dist/lib/dev.d.ts +1 -1
  72. package/dist/lib/dev.js +52 -69
  73. package/dist/lib/extensionsService.d.ts +1 -1
  74. package/dist/lib/extensionsService.js +21 -15
  75. package/dist/lib/parsing-utils.d.ts +1 -1
  76. package/dist/lib/parsing-utils.js +7 -11
  77. package/dist/lib/plugins/codeBlockingPlugin.d.ts +1 -1
  78. package/dist/lib/plugins/codeBlockingPlugin.js +5 -8
  79. package/dist/lib/plugins/codeCheckingPlugin.d.ts +1 -1
  80. package/dist/lib/plugins/codeCheckingPlugin.js +10 -11
  81. package/dist/lib/plugins/devBuildPlugin.d.ts +2 -2
  82. package/dist/lib/plugins/devBuildPlugin.js +74 -99
  83. package/dist/lib/plugins/friendlyLoggingPlugin.d.ts +2 -2
  84. package/dist/lib/plugins/friendlyLoggingPlugin.js +4 -12
  85. package/dist/lib/plugins/manifestPlugin.d.ts +1 -1
  86. package/dist/lib/plugins/manifestPlugin.js +46 -26
  87. package/dist/lib/plugins/relevantModulesPlugin.d.ts +2 -2
  88. package/dist/lib/plugins/relevantModulesPlugin.js +4 -7
  89. package/dist/lib/server.d.ts +7 -2
  90. package/dist/lib/server.js +85 -84
  91. package/dist/lib/types.d.ts +1 -1
  92. package/dist/lib/types.js +4 -7
  93. package/dist/lib/utils.d.ts +1 -1
  94. package/dist/lib/utils.js +23 -40
  95. package/package.json +44 -31
package/README.md CHANGED
@@ -1,7 +1,26 @@
1
- # UI Extensions Dev Server
1
+ # UI Extensions Dev Server
2
2
 
3
- Development server library to run your HubSpot UI Extensions.
3
+ This package is a development server library for HubSpot UI Extensions. It provides a Vite and Express-powered server for local development of extensions, which is run via the HubSpot CLI. There is also a `remoteBuild` function, used by Artifactor to generate production builds of extensions.
4
4
 
5
- ## Overview
6
- This package contains the library functions for running HubSpot UI extensions locally, as well as running a production build for debugging purposes.
5
+ ## Installation
7
6
 
7
+ You can install the package directly to run the CLI command to execute the production build locally:
8
+
9
+ ```bash
10
+ npm install @hubspot/ui-extensions-dev-server
11
+ ```
12
+
13
+ However, most people will use this package indirectly via the [HubSpot cli](https://git.hubteam.com/HubSpot/hubspot-cli-private):
14
+
15
+ ```bash
16
+ hs project dev
17
+ ```
18
+
19
+ ## Key Documentation
20
+
21
+ - [Architectural Overview](./docs/uie-dev-server-overview.md)
22
+ - [How to Contribute](./CONTRIBUTING.md)
23
+
24
+ ## Ownership and Issue Management
25
+
26
+ We centerally manage issues in our [primary `ui-extensibility` repo](https://git.hubteam.com/hubspot/ui-extensibility/)
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { remoteBuild, buildSingleExtension } from './lib/build';
2
- import DevModeInterface, { DevModeInterfaceNonSingleton } from './lib/DevModeInterface';
3
- import DevModeUnifiedInterface, { DevModeUnifiedInterfaceNonSingleton } from './lib/DevModeUnifiedInterface';
1
+ import { remoteBuild, buildSingleExtension } from './lib/build.ts';
2
+ import DevModeInterface, { DevModeInterfaceNonSingleton } from './lib/DevModeInterface.ts';
3
+ import DevModeUnifiedInterface, { DevModeUnifiedInterfaceNonSingleton } from './lib/DevModeUnifiedInterface.ts';
4
4
  export { remoteBuild, buildSingleExtension, DevModeInterface, DevModeInterfaceNonSingleton, DevModeUnifiedInterface, DevModeUnifiedInterfaceNonSingleton, };
package/dist/index.js CHANGED
@@ -1,45 +1,4 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.DevModeUnifiedInterfaceNonSingleton = exports.DevModeUnifiedInterface = exports.DevModeInterfaceNonSingleton = exports.DevModeInterface = exports.buildSingleExtension = exports.remoteBuild = void 0;
37
- const build_1 = require("./lib/build");
38
- Object.defineProperty(exports, "remoteBuild", { enumerable: true, get: function () { return build_1.remoteBuild; } });
39
- Object.defineProperty(exports, "buildSingleExtension", { enumerable: true, get: function () { return build_1.buildSingleExtension; } });
40
- const DevModeInterface_1 = __importStar(require("./lib/DevModeInterface"));
41
- exports.DevModeInterface = DevModeInterface_1.default;
42
- Object.defineProperty(exports, "DevModeInterfaceNonSingleton", { enumerable: true, get: function () { return DevModeInterface_1.DevModeInterfaceNonSingleton; } });
43
- const DevModeUnifiedInterface_1 = __importStar(require("./lib/DevModeUnifiedInterface"));
44
- exports.DevModeUnifiedInterface = DevModeUnifiedInterface_1.default;
45
- Object.defineProperty(exports, "DevModeUnifiedInterfaceNonSingleton", { enumerable: true, get: function () { return DevModeUnifiedInterface_1.DevModeUnifiedInterfaceNonSingleton; } });
1
+ import { remoteBuild, buildSingleExtension } from "./lib/build.js";
2
+ import DevModeInterface, { DevModeInterfaceNonSingleton, } from "./lib/DevModeInterface.js";
3
+ import DevModeUnifiedInterface, { DevModeUnifiedInterfaceNonSingleton, } from "./lib/DevModeUnifiedInterface.js";
4
+ export { remoteBuild, buildSingleExtension, DevModeInterface, DevModeInterfaceNonSingleton, DevModeUnifiedInterface, DevModeUnifiedInterfaceNonSingleton, };
@@ -1,5 +1,5 @@
1
- import { ProjectComponentMap, AppExtensionMapping, DevModeSetupArguments } from './types';
2
- import { DevModeParentInterface } from './DevModeParentInterface';
1
+ import { ProjectComponentMap, AppExtensionMapping, DevModeSetupArguments } from './types.ts';
2
+ import { DevModeParentInterface } from './DevModeParentInterface.ts';
3
3
  declare class DevModeInterface extends DevModeParentInterface {
4
4
  _generateAppExtensionMappings(components: ProjectComponentMap): AppExtensionMapping[];
5
5
  setup(args: DevModeSetupArguments): Promise<void>;
@@ -1,37 +1,23 @@
1
- "use strict";
2
- /* hs-eslint ignored failing-rules */
3
- /* eslint-disable hubspot-dev/no-unsupported-ts-syntax */
4
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
5
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6
- return new (P || (P = Promise))(function (resolve, reject) {
7
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
8
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
9
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
10
- step((generator = generator.apply(thisArg, _arguments || [])).next());
11
- });
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.DevModeInterfaceNonSingleton = void 0;
15
- const constants_1 = require("./constants");
16
- const config_1 = require("./config");
17
- const DevModeParentInterface_1 = require("./DevModeParentInterface");
18
- class DevModeInterface extends DevModeParentInterface_1.DevModeParentInterface {
1
+ import { SUPPORTED_APP_TYPES, PUBLIC_APP } from "./constants.js";
2
+ import { loadExtensionConfig } from "./config.js";
3
+ import { DevModeParentInterface } from "./DevModeParentInterface.js";
4
+ class DevModeInterface extends DevModeParentInterface {
19
5
  _generateAppExtensionMappings(components) {
20
6
  // Loop over all of the app configs that are passed in
21
7
  const allComponentNames = Object.keys(components);
22
8
  return allComponentNames.reduce((appExtensionMappings, componentName) => {
23
9
  const component = components[componentName];
24
- if (!constants_1.SUPPORTED_APP_TYPES.includes(component.type)) {
10
+ if (!SUPPORTED_APP_TYPES.includes(component.type)) {
25
11
  return appExtensionMappings; // It's not a modern app, skip it
26
12
  }
27
13
  // Load all of the extension configs for a particular app.json file
28
- const extensionsConfigForApp = (0, config_1.loadExtensionConfig)(component.config, component.path);
14
+ const extensionsConfigForApp = loadExtensionConfig(component.config, component.path);
29
15
  const extensionConfigKeys = Object.keys(extensionsConfigForApp);
30
16
  // Loop over the loaded extension configs and generate the list of choices to use to prompt the user for input
31
17
  extensionConfigKeys.forEach((extensionKey) => {
32
18
  const extensionConfig = extensionsConfigForApp[extensionKey];
33
19
  if (extensionConfig.appConfig) {
34
- extensionConfig.appConfig.isPublicApp = component.type === constants_1.PUBLIC_APP;
20
+ extensionConfig.appConfig.isPublicApp = component.type === PUBLIC_APP;
35
21
  }
36
22
  appExtensionMappings.push({
37
23
  name: `${componentName}/${extensionConfig.data.title}`,
@@ -41,12 +27,10 @@ class DevModeInterface extends DevModeParentInterface_1.DevModeParentInterface {
41
27
  return appExtensionMappings;
42
28
  }, []);
43
29
  }
44
- setup(args) {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- args.choices = this._generateAppExtensionMappings(args.components);
47
- yield this.parentSetup(args);
48
- });
30
+ async setup(args) {
31
+ args.choices = this._generateAppExtensionMappings(args.components);
32
+ await this.parentSetup(args);
49
33
  }
50
34
  }
51
- exports.DevModeInterfaceNonSingleton = DevModeInterface;
52
- exports.default = new DevModeInterface();
35
+ export { DevModeInterface as DevModeInterfaceNonSingleton };
36
+ export default new DevModeInterface();
@@ -1,5 +1,5 @@
1
- import { PlatformVersion, ProjectConfig, Logger, ExtensionOutputConfig, ProjectComponentMap, AppExtensionMapping, DevModeStartArguments, DevModeSetupArguments, UnifiedProjectComponentMap, DevModeBaseSetupArguments } from './types';
2
- import { DevServerState } from './DevServerState';
1
+ import { PlatformVersion, ProjectConfig, Logger, ExtensionOutputConfig, ProjectComponentMap, AppExtensionMapping, DevModeStartArguments, DevModeSetupArguments, UnifiedProjectComponentMap, DevModeBaseSetupArguments } from './types.ts';
2
+ import { DevServerState } from './DevServerState.ts';
3
3
  export declare abstract class DevModeParentInterface {
4
4
  configs?: ExtensionOutputConfig[];
5
5
  devServerState?: DevServerState;
@@ -1,25 +1,10 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.DevModeParentInterface = void 0;
16
- const constants_1 = require("./constants");
17
- const dev_1 = require("./dev");
18
- const config_1 = require("./config");
19
- const constants_2 = require("./constants");
20
- const utils_1 = require("./utils");
21
- const DevServerState_1 = require("./DevServerState");
22
- const inquirer_1 = __importDefault(require("inquirer"));
1
+ import { PLATFORM_VERSION } from "./constants.js";
2
+ import { startDevMode } from "./dev.js";
3
+ import { loadLocalConfig } from "./config.js";
4
+ import { throwUnhandledPlatformVersionError } from "./utils.js";
5
+ import { DevServerState } from "./DevServerState.js";
6
+ import inquirer from 'inquirer';
7
+ import { EXPRESS_DEFAULT_PORT, EXPRESS_SERVER_ID } from "./constants.js";
23
8
  const defaultLogger = {
24
9
  info: (...args) => {
25
10
  console.log(...args);
@@ -34,27 +19,32 @@ const defaultLogger = {
34
19
  console.error(...args);
35
20
  },
36
21
  };
37
- class DevModeParentInterface {
38
- constructor() {
39
- this.logger = defaultLogger;
40
- }
22
+ export class DevModeParentInterface {
23
+ configs;
24
+ devServerState;
25
+ onUploadRequired;
26
+ logger = defaultLogger;
27
+ urls;
28
+ isConfigured;
29
+ isRunning;
30
+ shutdown;
41
31
  _getPlatformVersion(projectConfig) {
42
- const { platformVersion } = projectConfig !== null && projectConfig !== void 0 ? projectConfig : {};
32
+ const { platformVersion } = projectConfig ?? {};
43
33
  if (!platformVersion) {
44
- return constants_1.PLATFORM_VERSION.V20231;
34
+ return PLATFORM_VERSION.V20231;
45
35
  }
46
36
  switch (platformVersion) {
47
- case constants_1.PLATFORM_VERSION.V20231:
48
- return constants_1.PLATFORM_VERSION.V20231;
49
- case constants_1.PLATFORM_VERSION.V20232:
50
- return constants_1.PLATFORM_VERSION.V20232;
51
- case constants_1.PLATFORM_VERSION.V20251:
52
- return constants_1.PLATFORM_VERSION.V20251;
53
- case constants_1.PLATFORM_VERSION.V20252:
54
- case constants_1.PLATFORM_VERSION.UNSTABLE:
55
- return constants_1.PLATFORM_VERSION.V20252;
37
+ case PLATFORM_VERSION.V20231:
38
+ return PLATFORM_VERSION.V20231;
39
+ case PLATFORM_VERSION.V20232:
40
+ return PLATFORM_VERSION.V20232;
41
+ case PLATFORM_VERSION.V20251:
42
+ return PLATFORM_VERSION.V20251;
43
+ case PLATFORM_VERSION.V20252:
44
+ case PLATFORM_VERSION.UNSTABLE:
45
+ return PLATFORM_VERSION.V20252;
56
46
  default:
57
- return (0, utils_1.throwUnhandledPlatformVersionError)(platformVersion);
47
+ return throwUnhandledPlatformVersionError(platformVersion);
58
48
  }
59
49
  }
60
50
  _reset() {
@@ -67,131 +57,125 @@ class DevModeParentInterface {
67
57
  this.isConfigured = false;
68
58
  this.isRunning = false;
69
59
  }
70
- parentSetup(_a) {
71
- return __awaiter(this, arguments, void 0, function* ({ onUploadRequired, logger, urls, setActiveApp, choices = [], }) {
72
- var _b, _c, _d;
73
- if (this.isConfigured) {
74
- logger.debug('Dev server has already been configured, skipping');
75
- return;
76
- }
77
- this.logger = logger;
78
- this.onUploadRequired = onUploadRequired;
79
- this.urls = urls;
80
- if (choices.length === 0) {
81
- throw new Error('No extensions to run');
82
- }
83
- else if (choices.length === 1) {
84
- this.configs = [choices[0].value];
85
- }
86
- else {
87
- const promptModule = inquirer_1.default.createPromptModule();
88
- const answers = yield promptModule({
89
- type: 'checkbox',
90
- name: 'extensions',
91
- message: 'Which extension(s) would you like to run?',
92
- validate: (input) => {
93
- if (!input || input.length === 0) {
94
- return 'Select at least one extension to run';
95
- }
96
- const appNames = new Set(input.map((choice) => choice.data.appName));
97
- if (appNames.size > 1) {
98
- return 'Running multiple extensions is only supported for a single application';
99
- }
100
- return true;
101
- },
102
- choices,
103
- });
104
- this.configs = answers.extensions;
105
- }
106
- this.isConfigured = true;
107
- if (typeof setActiveApp === 'function') {
108
- yield setActiveApp((_d = (_c = (_b = this.configs) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.appConfig) === null || _d === void 0 ? void 0 : _d.uid);
109
- }
110
- });
111
- }
112
- start(_a) {
113
- return __awaiter(this, arguments, void 0, function* ({ requestPorts, accountId, projectConfig, }) {
114
- var _b, _c, _d, _e;
115
- this.logger.debug('Start function was invoked', {
116
- accountId,
117
- projectConfig,
118
- });
119
- if (this.isRunning) {
120
- this.logger.debug('Dev server is already running, not starting again');
121
- return;
122
- }
123
- let expressPort = constants_2.EXPRESS_DEFAULT_PORT;
124
- let webSocketPort = constants_2.WEBSOCKET_DEFAULT_PORT;
125
- if (requestPorts) {
126
- try {
127
- const portData = yield requestPorts([
128
- { instanceId: constants_2.EXPRESS_SERVER_ID, port: constants_2.EXPRESS_DEFAULT_PORT },
129
- { instanceId: constants_2.VITE_DEV_SERVER_ID, port: constants_2.WEBSOCKET_DEFAULT_PORT },
130
- ]);
131
- expressPort = portData[constants_2.EXPRESS_SERVER_ID];
132
- webSocketPort = portData[constants_2.VITE_DEV_SERVER_ID];
133
- }
134
- catch (e) {
135
- if ((e === null || e === void 0 ? void 0 : e.status) === 409) {
136
- throw new Error('Another instance is already running. To proceed, please stop the existing server and try again.');
60
+ async parentSetup({ onUploadRequired, logger, urls, setActiveApp, choices = [], }) {
61
+ if (this.isConfigured) {
62
+ logger.debug('Dev server has already been configured, skipping');
63
+ return;
64
+ }
65
+ this.logger = logger;
66
+ this.onUploadRequired = onUploadRequired;
67
+ this.urls = urls;
68
+ if (choices.length === 0) {
69
+ throw new Error('No extensions to run');
70
+ }
71
+ else if (choices.length === 1) {
72
+ this.configs = [choices[0].value];
73
+ }
74
+ else {
75
+ const promptModule = inquirer.createPromptModule();
76
+ const answers = await promptModule({
77
+ type: 'checkbox',
78
+ name: 'extensions',
79
+ message: 'Which extension(s) would you like to run?',
80
+ validate: (selectedChoices) => {
81
+ if (!selectedChoices || selectedChoices.length === 0) {
82
+ return 'Select at least one extension to run';
137
83
  }
138
- this.logger.debug('Call to port manager failed, using default ports');
139
- }
140
- }
141
- const { proxy: localDevUrlMapping } = (0, config_1.loadLocalConfig)(((_c = (_b = this.configs) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.path) || '', this.logger) || {};
142
- try {
143
- this.devServerState = new DevServerState_1.DevServerState({
144
- localDevUrlMapping,
145
- extensionConfigs: this.configs,
146
- accountId,
147
- platformVersion: this._getPlatformVersion(projectConfig),
148
- expressPort,
149
- webSocketPort,
150
- logger: this.logger,
151
- urls: this.urls,
152
- appConfig: (_e = (_d = this.configs) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.appConfig,
153
- });
154
- }
155
- catch (e) {
156
- this.logger.debug('Error setting up DevServerState', e);
157
- throw e;
158
- }
84
+ const configs = selectedChoices
85
+ .map((choice) => choice.value)
86
+ .filter((value) => {
87
+ return (typeof value === 'object' && value !== null && 'data' in value);
88
+ });
89
+ if (configs.length !== selectedChoices.length) {
90
+ return 'Invalid extension configuration';
91
+ }
92
+ const appNames = new Set(configs.map((config) => config.data.appName));
93
+ if (appNames.size > 1) {
94
+ return 'Running multiple extensions is only supported for a single application';
95
+ }
96
+ return true;
97
+ },
98
+ choices,
99
+ });
100
+ this.configs = answers.extensions;
101
+ }
102
+ this.isConfigured = true;
103
+ if (typeof setActiveApp === 'function') {
104
+ await setActiveApp(this.configs?.[0]?.appConfig?.uid);
105
+ }
106
+ }
107
+ async start({ requestPorts, accountId, projectConfig, }) {
108
+ this.logger.debug('Start function was invoked', {
109
+ accountId,
110
+ projectConfig,
111
+ });
112
+ if (this.isRunning) {
113
+ this.logger.debug('Dev server is already running, not starting again');
114
+ return;
115
+ }
116
+ let expressPort = EXPRESS_DEFAULT_PORT;
117
+ if (requestPorts) {
159
118
  try {
160
- this.shutdown = yield (0, dev_1.startDevMode)(this.devServerState);
119
+ const portData = await requestPorts([
120
+ { instanceId: EXPRESS_SERVER_ID, port: EXPRESS_DEFAULT_PORT },
121
+ ]);
122
+ expressPort = portData[EXPRESS_SERVER_ID];
161
123
  }
162
124
  catch (e) {
163
- this.logger.debug('Error starting dev mode', e);
164
- throw e;
125
+ if (e?.status === 409) {
126
+ throw new Error('Another instance is already running. To proceed, please stop the existing server and try again.');
127
+ }
128
+ this.logger.debug('Call to port manager failed, using default ports');
165
129
  }
166
- const { extensionsMetadata } = this.devServerState;
167
- extensionsMetadata.forEach((metadata) => {
168
- const { config: { data: { title, appName }, }, } = metadata;
169
- this.logger.info(`Running extension '${title}' from app '${appName}'`);
130
+ }
131
+ const { proxy: localDevUrlMapping } = loadLocalConfig(this.configs?.[0]?.path || '', this.logger) || {};
132
+ try {
133
+ this.devServerState = new DevServerState({
134
+ localDevUrlMapping,
135
+ extensionConfigs: this.configs,
136
+ accountId,
137
+ platformVersion: this._getPlatformVersion(projectConfig),
138
+ expressPort,
139
+ logger: this.logger,
140
+ urls: this.urls,
141
+ appConfig: this.configs?.[0]?.appConfig,
170
142
  });
171
- this.isRunning = true;
143
+ }
144
+ catch (e) {
145
+ this.logger.debug('Error setting up DevServerState', e);
146
+ throw e;
147
+ }
148
+ try {
149
+ this.shutdown = await startDevMode(this.devServerState);
150
+ }
151
+ catch (e) {
152
+ this.logger.debug('Error starting dev mode', e);
153
+ throw e;
154
+ }
155
+ const { extensionsMetadata } = this.devServerState;
156
+ extensionsMetadata.forEach((metadata) => {
157
+ const { config: { data: { title, appName }, }, } = metadata;
158
+ this.logger.info(`Running extension '${title}' from app '${appName}'`);
172
159
  });
160
+ this.isRunning = true;
173
161
  }
174
- // The contract is for this to be async, so eslint can chill
162
+ // The contract is for this to be async, with the __event param. Eslint doesn't like it.
175
163
  // eslint-disable-next-line require-await
176
- fileChange(filePath, __event) {
177
- return __awaiter(this, void 0, void 0, function* () {
178
- if (!this.devServerState || !this.devServerState.extensionsMetadata) {
179
- return;
180
- }
181
- const relevantConfigFileChanged = this.devServerState.extensionsMetadata.some((metadata) => metadata.config.extensionConfigPath === filePath);
182
- if (relevantConfigFileChanged && this.onUploadRequired) {
183
- this.onUploadRequired();
184
- }
185
- });
164
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
165
+ async fileChange(filePath, __event) {
166
+ if (!this.devServerState || !this.devServerState.extensionsMetadata) {
167
+ return;
168
+ }
169
+ const relevantConfigFileChanged = this.devServerState.extensionsMetadata.some((metadata) => metadata.config.extensionConfigPath === filePath);
170
+ if (relevantConfigFileChanged && this.onUploadRequired) {
171
+ this.onUploadRequired();
172
+ }
186
173
  }
187
- cleanup() {
188
- return __awaiter(this, void 0, void 0, function* () {
189
- if (this.shutdown) {
190
- yield this.shutdown();
191
- }
192
- // Since the DevModeInterface is a singleton, we need to wipe out the state when we shutdown
193
- this._reset();
194
- });
174
+ async cleanup() {
175
+ if (this.shutdown) {
176
+ await this.shutdown();
177
+ }
178
+ // Since the DevModeInterface is a singleton, we need to wipe out the state when we shutdown
179
+ this._reset();
195
180
  }
196
181
  }
197
- exports.DevModeParentInterface = DevModeParentInterface;
@@ -1,5 +1,5 @@
1
- import { AppExtensionMapping, UnifiedProjectComponentMap, UnifiedDevModeSetupArguments, ProfileVariables } from './types';
2
- import { DevModeParentInterface } from './DevModeParentInterface';
1
+ import { AppExtensionMapping, UnifiedProjectComponentMap, UnifiedDevModeSetupArguments, ProfileVariables } from './types.ts';
2
+ import { DevModeParentInterface } from './DevModeParentInterface.ts';
3
3
  declare class DevModeUnifiedInterface extends DevModeParentInterface {
4
4
  _generateAppExtensionMappings(components: UnifiedProjectComponentMap, profileData?: ProfileVariables): AppExtensionMapping[];
5
5
  setup(args: UnifiedDevModeSetupArguments): Promise<void>;