@hubspot/ui-extensions-dev-server 0.8.1 → 0.8.2

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.
@@ -27,7 +27,7 @@ function loadExtensionConfig(appConfig, appPath) {
27
27
  const entryPointPath = path_1.default.join(cardConfigDir, (_b = (_a = cardConfig.data) === null || _a === void 0 ? void 0 : _a.module) === null || _b === void 0 ? void 0 : _b.file);
28
28
  cardConfig.data.module.file = entryPointPath;
29
29
  const sourceId = (0, utils_1.buildSourceId)(appConfig, cardConfig);
30
- outputConfig[sourceId || `${entryPointPath}-${cardConfig.data.location}`] = Object.assign(Object.assign({}, cardConfig), { output: (0, utils_1.getUrlSafeFileName)(entryPointPath), path: appPath, extensionPath: path_1.default.parse(entryPointPath).dir, data: Object.assign(Object.assign({}, cardConfig.data), { appName: appConfig.name, sourceId }) });
30
+ outputConfig[sourceId || `${entryPointPath}-${cardConfig.data.location}`] = Object.assign(Object.assign({}, cardConfig), { output: (0, utils_1.getUrlSafeFileName)(entryPointPath), path: appPath, extensionPath: path_1.default.parse(entryPointPath).dir, extensionConfigPath: cardConfigPath, data: Object.assign(Object.assign({}, cardConfig.data), { appName: appConfig.name, sourceId }) });
31
31
  }
32
32
  }
33
33
  catch (e) {
@@ -21,7 +21,7 @@ declare class DevModeInterface {
21
21
  config?: ExtensionConfig;
22
22
  appName?: string;
23
23
  title?: string;
24
- cardConfigs?: string[];
24
+ extensionConfigPath?: string;
25
25
  onUploadRequired?: VoidFunction;
26
26
  shutdown?: () => Promise<void>;
27
27
  _setDataFromExtensionConfig(extensionConfig: ExtensionConfig): void;
@@ -21,6 +21,7 @@ const logger_1 = require("@hubspot/cli-lib/logger");
21
21
  class DevModeInterface {
22
22
  _setDataFromExtensionConfig(extensionConfig) {
23
23
  this.config = extensionConfig;
24
+ this.extensionConfigPath = extensionConfig.extensionConfigPath;
24
25
  this.appName = extensionConfig.data.appName;
25
26
  this.title = extensionConfig.data.title;
26
27
  }
@@ -33,7 +34,6 @@ class DevModeInterface {
33
34
  if (!((_b = (_a = component.config.extensions) === null || _a === void 0 ? void 0 : _a.crm) === null || _b === void 0 ? void 0 : _b.cards)) {
34
35
  return appExtensionMappings; // It's not an app
35
36
  }
36
- this.cardConfigs = component.config.extensions.crm.cards.map(card => path_1.default.join(component.path, card.file));
37
37
  // Load all of the extension configs for a particular app.json file
38
38
  const extensionsConfigForApp = (0, config_1.loadExtensionConfig)(component.config, component.path);
39
39
  const extensionConfigKeys = Object.keys(extensionsConfigForApp);
@@ -78,8 +78,8 @@ class DevModeInterface {
78
78
  // eslint-disable-next-line require-await
79
79
  fileChange(filePath, __event) {
80
80
  return __awaiter(this, void 0, void 0, function* () {
81
- if (this.cardConfigs &&
82
- this.cardConfigs.includes(filePath) &&
81
+ if (this.extensionConfigPath &&
82
+ this.extensionConfigPath === filePath &&
83
83
  this.onUploadRequired) {
84
84
  this.onUploadRequired();
85
85
  }
@@ -105,7 +105,6 @@ class DevModeInterface {
105
105
  outputDir: path_1.default.join(this.config.extensionPath, constants_1.OUTPUT_DIR),
106
106
  functionsConfig,
107
107
  root: appPath,
108
- cardConfigs: this.cardConfigs || [],
109
108
  });
110
109
  logger_1.logger.info(`Running extension '${this.title}' from app '${this.appName}'`);
111
110
  });
package/dist/lib/dev.d.ts CHANGED
@@ -7,7 +7,6 @@ interface StartDevModeArgs {
7
7
  expressPort?: number;
8
8
  root?: string;
9
9
  functionsConfig: Partial<ServiceConfiguration>;
10
- cardConfigs: string[];
11
10
  }
12
- export declare function startDevMode({ extensionConfig, functionsConfig, outputDir, expressPort, webSocketPort, root, cardConfigs, }: StartDevModeArgs): Promise<() => Promise<void>>;
11
+ export declare function startDevMode({ extensionConfig, functionsConfig, outputDir, expressPort, webSocketPort, root, }: StartDevModeArgs): Promise<() => Promise<void>>;
13
12
  export {};
package/dist/lib/dev.js CHANGED
@@ -17,13 +17,12 @@ const vite_1 = require("vite");
17
17
  const path_1 = __importDefault(require("path"));
18
18
  const server_1 = __importDefault(require("./server"));
19
19
  const devBuildPlugin_1 = __importDefault(require("./plugins/devBuildPlugin"));
20
- const utils_1 = require("./utils");
21
20
  const constants_1 = require("./constants");
22
21
  // @ts-expect-error no type defs
23
22
  const logger_1 = require("@hubspot/cli-lib/logger");
24
23
  // @ts-expect-error no type defs
25
24
  const detect_port_1 = __importDefault(require("detect-port"));
26
- function _createViteDevServer({ outputDir, extensionConfig, webSocketPort, baseMessage, root, cardConfigs, }) {
25
+ function _createViteDevServer({ outputDir, extensionConfig, webSocketPort, baseMessage, root, }) {
27
26
  return __awaiter(this, void 0, void 0, function* () {
28
27
  return yield (0, vite_1.createServer)({
29
28
  root,
@@ -45,18 +44,11 @@ function _createViteDevServer({ outputDir, extensionConfig, webSocketPort, baseM
45
44
  ],
46
45
  },
47
46
  },
48
- build: {
49
- rollupOptions: {
50
- input: extensionConfig.data.module.file,
51
- output: { file: (0, utils_1.getUrlSafeFileName)(extensionConfig.data.module.file) },
52
- },
53
- },
54
47
  plugins: [
55
48
  (0, devBuildPlugin_1.default)({
56
49
  extensionConfig,
57
50
  outputDir,
58
51
  baseMessage,
59
- cardConfigs,
60
52
  }),
61
53
  ],
62
54
  clearScreen: false,
@@ -72,7 +64,7 @@ function throwIfPortTaken(port) {
72
64
  }
73
65
  });
74
66
  }
75
- function startDevMode({ extensionConfig, functionsConfig, outputDir = constants_1.OUTPUT_DIR, expressPort = constants_1.VITE_DEFAULT_PORT, webSocketPort = constants_1.WEBSOCKET_PORT, root = process.cwd(), cardConfigs, }) {
67
+ function startDevMode({ extensionConfig, functionsConfig, outputDir = constants_1.OUTPUT_DIR, expressPort = constants_1.VITE_DEFAULT_PORT, webSocketPort = constants_1.WEBSOCKET_PORT, root = process.cwd(), }) {
76
68
  return __awaiter(this, void 0, void 0, function* () {
77
69
  if (!extensionConfig) {
78
70
  throw new Error('Unable to determine which extension to run');
@@ -96,7 +88,6 @@ function startDevMode({ extensionConfig, functionsConfig, outputDir = constants_
96
88
  webSocketPort: actualWebSocketPort,
97
89
  baseMessage,
98
90
  root,
99
- cardConfigs,
100
91
  });
101
92
  const shutdownServer = yield (0, server_1.default)({
102
93
  outputDir,
@@ -4,7 +4,6 @@ export interface DevBuildPluginOptions {
4
4
  extensionConfig: ExtensionConfig;
5
5
  outputDir: string;
6
6
  baseMessage: BaseMessage;
7
- cardConfigs: string[];
8
7
  }
9
8
  export type DevBuildPlugin = (options: DevBuildPluginOptions) => Vite.Plugin;
10
9
  declare const devBuildPlugin: DevBuildPlugin;
@@ -1,4 +1,27 @@
1
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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -21,9 +44,10 @@ const path_1 = __importDefault(require("path"));
21
44
  // @ts-expect-error no type defs
22
45
  const logger_1 = require("@hubspot/cli-lib/logger");
23
46
  const friendlyLoggingPlugin_1 = __importDefault(require("./friendlyLoggingPlugin"));
47
+ const relevantModulesPlugin_1 = __importStar(require("./relevantModulesPlugin"));
24
48
  const devBuildPlugin = options => {
25
49
  let lastBuildError;
26
- const { extensionConfig, outputDir, baseMessage, cardConfigs } = options;
50
+ const { extensionConfig, outputDir, baseMessage } = options;
27
51
  const versionedBaseMessage = Object.assign(Object.assign({}, baseMessage), { version: constants_1.WEBSOCKET_MESSAGE_VERSION });
28
52
  const handleBuildError = (error, server) => {
29
53
  const { plugin, errors, frame, loc, id } = error;
@@ -72,6 +96,7 @@ const devBuildPlugin = options => {
72
96
  output: path_1.default.join(outputDir, extensionConfig.output),
73
97
  }),
74
98
  (0, friendlyLoggingPlugin_1.default)(),
99
+ (0, relevantModulesPlugin_1.default)({ output: extensionConfig.output }),
75
100
  ], output: Object.assign(Object.assign({}, constants_1.ROLLUP_OPTIONS.output), { sourcemap: 'inline' }) }),
76
101
  outDir: outputDir,
77
102
  emptyOutDir: true,
@@ -108,7 +133,8 @@ const devBuildPlugin = options => {
108
133
  yield devBuild(localServer);
109
134
  }),
110
135
  handleHotUpdate: ({ file, server }) => __awaiter(void 0, void 0, void 0, function* () {
111
- if (cardConfigs.includes(file)) {
136
+ // If the file is not in the relevantModules list, it's update is inconsequential
137
+ if (!(0, relevantModulesPlugin_1.getRelevantModules)(extensionConfig.output).includes(file)) {
112
138
  return [];
113
139
  }
114
140
  const successful = yield devBuild(server);
@@ -9,6 +9,7 @@ const constants_1 = require("../constants");
9
9
  const path_2 = __importDefault(require("path"));
10
10
  // @ts-expect-error no type defs for the logger
11
11
  const logger_1 = require("@hubspot/cli-lib/logger");
12
+ const utils_1 = require("../utils");
12
13
  const PACKAGE_LOCK_FILE = 'package-lock.json';
13
14
  const PACKAGE_FILE = 'package.json';
14
15
  const EXTENSIONS_PATH = 'src/app/extensions/';
@@ -78,13 +79,12 @@ function _buildModulesInfo(moduleIds, modules) {
78
79
  external: [],
79
80
  };
80
81
  return moduleIds.reduce((acc, mod) => {
81
- var _a;
82
82
  const { renderedExports } = modules[mod];
83
83
  const moduleData = {
84
84
  module: _stripPathPriorToExtDir(mod),
85
85
  renderedExports,
86
86
  };
87
- if ((_a = moduleData.module) === null || _a === void 0 ? void 0 : _a.includes('node_modules')) {
87
+ if ((0, utils_1.isNodeModule)(moduleData.module)) {
88
88
  acc.external.push(moduleData);
89
89
  }
90
90
  else {
@@ -0,0 +1,11 @@
1
+ import Vite from 'vite';
2
+ export interface RelevantModules {
3
+ [key: string]: string[];
4
+ }
5
+ export declare function getRelevantModules(output: string): string[];
6
+ export interface RelevantModulesPluginOptions {
7
+ output: string;
8
+ }
9
+ export type RelevantModulesPlugin = (options: RelevantModulesPluginOptions) => Vite.Plugin;
10
+ declare const relevantModulesPlugin: RelevantModulesPlugin;
11
+ export default relevantModulesPlugin;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRelevantModules = void 0;
4
+ const utils_1 = require("../utils");
5
+ // @ts-expect-error no type defs for the logger
6
+ const logger_1 = require("@hubspot/cli-lib/logger");
7
+ const relevantModules = {};
8
+ function getRelevantModules(output) {
9
+ return relevantModules[output] || [];
10
+ }
11
+ exports.getRelevantModules = getRelevantModules;
12
+ const relevantModulesPlugin = ({ output }) => {
13
+ return {
14
+ name: 'ui-extensions-relevant-modules-plugin',
15
+ generateBundle(_options, bundle) {
16
+ const subBundle = bundle[output];
17
+ if (!subBundle || !subBundle.moduleIds) {
18
+ // If this happens, something has gone horribly wrong
19
+ logger_1.logger.error('Invalid bundle format, please try saving the extension again. If the problem persists try restarting `hs project dev`');
20
+ return;
21
+ }
22
+ const updatedRelevantModules = subBundle.moduleIds.filter(moduleId => !(0, utils_1.isNodeModule)(moduleId));
23
+ if (updatedRelevantModules.length === 0) {
24
+ logger_1.logger.error('Unable to determine relevant files to watch, please try saving the extension again. If the problem persists try restarting `hs project dev`');
25
+ return;
26
+ }
27
+ relevantModules[output] = updatedRelevantModules;
28
+ },
29
+ };
30
+ };
31
+ exports.default = relevantModulesPlugin;
@@ -6,6 +6,7 @@ export interface ExtensionConfig {
6
6
  output: string;
7
7
  path: string;
8
8
  extensionPath: string;
9
+ extensionConfigPath: string;
9
10
  data: {
10
11
  appName: string;
11
12
  title: string;
@@ -3,3 +3,4 @@ export declare function getUrlSafeFileName(filePath: string): string;
3
3
  export declare function stripAnsiColorCodes(stringWithColorCodes: string | undefined | null): string | null;
4
4
  export declare function loadManifest(outputDir: string, output: string): any;
5
5
  export declare function buildSourceId(appConfig: AppConfig, extensionConfig: ExtensionConfig): string | null;
6
+ export declare function isNodeModule(filepath: string | undefined): boolean;
package/dist/lib/utils.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.buildSourceId = exports.loadManifest = exports.stripAnsiColorCodes = exports.getUrlSafeFileName = void 0;
6
+ exports.isNodeModule = exports.buildSourceId = exports.loadManifest = exports.stripAnsiColorCodes = exports.getUrlSafeFileName = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const fs_1 = __importDefault(require("fs"));
9
9
  const constants_1 = require("./constants");
@@ -40,3 +40,11 @@ function buildSourceId(appConfig, extensionConfig) {
40
40
  return null;
41
41
  }
42
42
  exports.buildSourceId = buildSourceId;
43
+ function isNodeModule(filepath) {
44
+ if (!filepath) {
45
+ return false;
46
+ }
47
+ const directory = path_1.default.parse(filepath).dir;
48
+ return directory.includes('node_modules');
49
+ }
50
+ exports.isNodeModule = isNodeModule;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/ui-extensions-dev-server",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -24,7 +24,7 @@
24
24
  ],
25
25
  "license": "MIT",
26
26
  "dependencies": {
27
- "@hubspot/app-functions-dev-server": "^0.8.0",
27
+ "@hubspot/app-functions-dev-server": "^0.8.2",
28
28
  "@hubspot/cli-lib": "^4.1.6",
29
29
  "command-line-args": "^5.2.1",
30
30
  "command-line-usage": "^7.0.1",
@@ -66,5 +66,5 @@
66
66
  "optional": true
67
67
  }
68
68
  },
69
- "gitHead": "5fd5fe43bc0b09750653dd7121d56bf0d60788bb"
69
+ "gitHead": "19c43b6956e7a2397e0b4435b3829bd3e3b5e5bc"
70
70
  }