@hubspot/ui-extensions-dev-server 0.7.3-canary.8 → 0.7.3

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.
@@ -20,6 +20,11 @@ class DevModeInterface {
20
20
  if (!component.config.extensions?.crm?.cards) {
21
21
  return appExtensionMappings; // It's not an app
22
22
  }
23
+
24
+ this.cardConfigs = component.config.extensions.crm.cards.map(card =>
25
+ path.join(component.path, card.file)
26
+ );
27
+
23
28
  // Load all of the extension configs for a particular app.json file
24
29
  const extensionsConfigForApp = loadExtensionConfig(
25
30
  component.config,
@@ -47,10 +52,12 @@ class DevModeInterface {
47
52
  promptUser,
48
53
  components,
49
54
  extensionConfig,
55
+ onUploadRequired,
50
56
  }) {
51
57
  setLogLevel(debug ? LOG_LEVEL.DEBUG : LOG_LEVEL.LOG);
52
58
  this.accountId = accountId;
53
59
  this.httpClient = httpClient;
60
+ this.onUploadRequired = onUploadRequired;
54
61
  if (extensionConfig) {
55
62
  this._setDataFromExtensionConfig(extensionConfig);
56
63
  return;
@@ -73,6 +80,18 @@ class DevModeInterface {
73
80
  }
74
81
  }
75
82
 
83
+ // The contract is for this to be async, so eslint can chill
84
+ // eslint-disable-next-line require-await
85
+ async fileChange(filePath, __event) {
86
+ if (
87
+ this.cardConfigs &&
88
+ this.cardConfigs.includes(filePath) &&
89
+ this.onUploadRequired
90
+ ) {
91
+ this.onUploadRequired();
92
+ }
93
+ }
94
+
76
95
  async start({ debug = null }) {
77
96
  if (debug !== null) {
78
97
  setLogLevel(debug ? LOG_LEVEL.DEBUG : LOG_LEVEL.LOG);
@@ -96,6 +115,7 @@ class DevModeInterface {
96
115
  outputDir: path.join(this.config.extensionPath, OUTPUT_DIR),
97
116
  functionsConfig,
98
117
  root: appPath,
118
+ cardConfigs: this.cardConfigs || [],
99
119
  });
100
120
 
101
121
  logger.info(`Running extension '${this.title}' from app '${this.appName}'`);
package/lib/build.js CHANGED
@@ -31,17 +31,8 @@ async function buildSingleExtension({
31
31
  emptyOutDir = true,
32
32
  minify = false,
33
33
  root = process.cwd(), // This is the vite default, so using that as our default
34
- logger = console,
35
- injectOverrides = true,
36
34
  }) {
37
35
  const output = getUrlSafeFileName(file);
38
-
39
- const plugins = [manifestPlugin({ minify, output, logger })];
40
-
41
- if (injectOverrides) {
42
- plugins.push(codeInjectionPlugin({ file }));
43
- }
44
-
45
36
  await build({
46
37
  root,
47
38
  define: {
@@ -58,7 +49,7 @@ async function buildSingleExtension({
58
49
  },
59
50
  rollupOptions: {
60
51
  ...ROLLUP_OPTIONS,
61
- plugins,
52
+ plugins: [manifestPlugin({ output }), codeInjectionPlugin({ file })],
62
53
  },
63
54
  outDir: outputDir,
64
55
  emptyOutDir,
@@ -67,26 +58,23 @@ async function buildSingleExtension({
67
58
  });
68
59
  }
69
60
 
70
- async function remoteBuild({
71
- root,
72
- entryPoint,
73
- outputDir = OUTPUT_DIR,
74
- injectOverrides = true,
75
- logger = console,
76
- }) {
61
+ async function remoteBuild(root, entryPoint, outputDir = OUTPUT_DIR) {
77
62
  const fileInfo = path.parse(entryPoint);
78
63
 
79
64
  if (!allowedExtensions.includes(fileInfo.ext)) {
80
65
  throw new Error(`${extensionErrorBaseMessage} ${fileInfo.ext}`);
81
66
  }
82
67
 
68
+ const output = getUrlSafeFileName(entryPoint);
83
69
  await buildSingleExtension({
84
70
  file: entryPoint,
71
+ outputFileName: output,
85
72
  outputDir,
73
+ plugins: {
74
+ rollup: [manifestPlugin({ minify: true, output })],
75
+ },
86
76
  minify: true,
87
77
  root,
88
- logger,
89
- injectOverrides,
90
78
  });
91
79
  }
92
80
 
package/lib/dev.js CHANGED
@@ -9,21 +9,23 @@ const {
9
9
  OUTPUT_DIR,
10
10
  } = require('./constants');
11
11
 
12
- async function _createViteDevServer(
12
+ async function _createViteDevServer({
13
13
  outputDir,
14
14
  extensionConfig,
15
- websocketPort,
15
+ webSocketPort,
16
16
  baseMessage,
17
- root
18
- ) {
17
+ root,
18
+ cardConfigs,
19
+ }) {
19
20
  return await createServer({
20
21
  root,
22
+ logLevel: 'silent',
21
23
  appType: 'custom',
22
24
  mode: 'development',
23
25
  server: {
24
26
  middlewareMode: true,
25
27
  hmr: {
26
- port: websocketPort,
28
+ port: webSocketPort,
27
29
  },
28
30
  watch: {
29
31
  ignored: [
@@ -46,6 +48,7 @@ async function _createViteDevServer(
46
48
  extensionConfig,
47
49
  outputDir,
48
50
  baseMessage,
51
+ cardConfigs,
49
52
  }),
50
53
  ],
51
54
  clearScreen: false,
@@ -59,6 +62,7 @@ async function startDevMode({
59
62
  expressPort = VITE_DEFAULT_PORT,
60
63
  webSocketPort = WEBSOCKET_PORT,
61
64
  root = process.cwd(),
65
+ cardConfigs,
62
66
  }) {
63
67
  if (!extensionConfig) {
64
68
  throw new Error('Unable to determine which extension to run');
@@ -70,13 +74,14 @@ async function startDevMode({
70
74
  callback: `http://hslocal.net:${expressPort}/${extensionConfig.output}`,
71
75
  });
72
76
 
73
- const viteDevServer = await _createViteDevServer(
77
+ const viteDevServer = await _createViteDevServer({
74
78
  outputDir,
75
79
  extensionConfig,
76
80
  webSocketPort,
77
81
  baseMessage,
78
- root
79
- );
82
+ root,
83
+ cardConfigs,
84
+ });
80
85
 
81
86
  return startDevServer({
82
87
  outputDir,
@@ -1,13 +1,16 @@
1
1
  const path = require('path');
2
2
 
3
- function codeInjectionPlugin() {
3
+ function codeInjectionPlugin(options = {}) {
4
+ const { file, root = process.cwd() } = options;
4
5
  return {
5
6
  name: 'ui-extensions-code-injection-plugin',
6
7
  enforce: 'post', // run after default rollup plugins
7
- transform(code, file) {
8
- const { dir } = path.parse(file);
8
+ transform(code, fileBeingTransformed) {
9
+ const absoluteFilePath = path.isAbsolute(file)
10
+ ? file
11
+ : path.join(root, file);
9
12
 
10
- if (dir.includes('node_modules')) {
13
+ if (fileBeingTransformed !== absoluteFilePath) {
11
14
  return { code, map: null }; // Not the file we care about, return the same code
12
15
  }
13
16
 
@@ -7,24 +7,21 @@ const path = require('path');
7
7
  const { logger } = require('@hubspot/cli-lib/logger');
8
8
 
9
9
  function devBuildPlugin(options = {}) {
10
- const { extensionConfig, outputDir, baseMessage } = options;
10
+ let lastBuildError;
11
+ const { extensionConfig, outputDir, baseMessage, cardConfigs } = options;
11
12
  const versionedBaseMessage = {
12
13
  ...baseMessage,
13
14
  version: WEBSOCKET_MESSAGE_VERSION,
14
15
  };
15
16
 
16
17
  const handleBuildError = (error, server) => {
17
- const { plugin, hook, code, errors, frame, loc, id } = error;
18
- if (
19
- plugin === 'vite:esbuild' &&
20
- hook === 'transform' &&
21
- code === 'PLUGIN_ERROR'
22
- ) {
18
+ const { plugin, errors, frame, loc, id } = error;
19
+ // Filter out our custom plugins, but send everything else
20
+ if (!plugin?.startsWith('ui-extensions')) {
23
21
  server.ws.send({
24
22
  ...versionedBaseMessage,
25
23
  event: 'error',
26
24
  error: {
27
- type: 'transformation',
28
25
  details: {
29
26
  errors,
30
27
  formattedError: stripAnsiColorCodes(frame),
@@ -82,8 +79,10 @@ function devBuildPlugin(options = {}) {
82
79
  },
83
80
  clearScreen: false,
84
81
  });
82
+ lastBuildError = null;
85
83
  return true;
86
84
  } catch (error) {
85
+ lastBuildError = error;
87
86
  logger.debug(error);
88
87
  handleBuildError(error, server);
89
88
  return false;
@@ -92,7 +91,7 @@ function devBuildPlugin(options = {}) {
92
91
 
93
92
  let localServer;
94
93
  return {
95
- name: 'ui-extensibility-dev-build-plugin',
94
+ name: 'ui-extensions-dev-build-plugin',
96
95
  enforce: 'pre',
97
96
  configureServer: async server => {
98
97
  // Store a reference to the server to be used in hooks that don't get the server injected
@@ -104,20 +103,18 @@ function devBuildPlugin(options = {}) {
104
103
  ...versionedBaseMessage,
105
104
  event: 'start',
106
105
  });
107
- });
108
- localServer.ws.on('build', async () => {
109
- logger.debug('Browser has requested a build, rebuilding');
110
- const successful = await devBuild(localServer);
111
- if (successful) {
112
- server.ws.send({
113
- ...versionedBaseMessage,
114
- event: 'update',
115
- });
106
+
107
+ if (lastBuildError) {
108
+ handleBuildError(lastBuildError, server);
116
109
  }
117
110
  });
111
+
118
112
  await devBuild(localServer);
119
113
  },
120
- handleHotUpdate: async ({ server }) => {
114
+ handleHotUpdate: async ({ file, server }) => {
115
+ if (cardConfigs.includes(file)) {
116
+ return [];
117
+ }
121
118
  const successful = await devBuild(server);
122
119
 
123
120
  if (!successful) {
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@hubspot/ui-extensions-dev-server",
3
- "version": "0.7.3-canary.8+f0ea707c",
3
+ "version": "0.7.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "jest",
8
8
  "build": "echo 'no build step for @hubspot/ui-extensions-dev-server'",
9
+ "lint": "echo 'no lint step for @hubspot/ui-extensions-dev-server'",
9
10
  "jest": "jest --watch"
10
11
  },
11
12
  "publishConfig": {
@@ -33,7 +34,7 @@
33
34
  ],
34
35
  "license": "MIT",
35
36
  "dependencies": {
36
- "@hubspot/app-functions-dev-server": "^0.7.2",
37
+ "@hubspot/app-functions-dev-server": "^0.7.3",
37
38
  "@hubspot/cli-lib": "^4.1.6",
38
39
  "command-line-args": "^5.2.1",
39
40
  "command-line-usage": "^7.0.1",
@@ -68,5 +69,5 @@
68
69
  "optional": true
69
70
  }
70
71
  },
71
- "gitHead": "f0ea707c3fdcb5cd043e5e34fb82354364ca156b"
72
+ "gitHead": "663cfa5f4b81bb923da5e8679e5be5437d1ddd00"
72
73
  }