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

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.
package/lib/build.js CHANGED
@@ -31,8 +31,17 @@ 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,
34
36
  }) {
35
37
  const output = getUrlSafeFileName(file);
38
+
39
+ const plugins = [manifestPlugin({ minify, output, logger })];
40
+
41
+ if (injectOverrides) {
42
+ plugins.push(codeInjectionPlugin({ file }));
43
+ }
44
+
36
45
  await build({
37
46
  root,
38
47
  define: {
@@ -49,7 +58,7 @@ async function buildSingleExtension({
49
58
  },
50
59
  rollupOptions: {
51
60
  ...ROLLUP_OPTIONS,
52
- plugins: [manifestPlugin({ output }), codeInjectionPlugin({ file })],
61
+ plugins,
53
62
  },
54
63
  outDir: outputDir,
55
64
  emptyOutDir,
@@ -58,23 +67,26 @@ async function buildSingleExtension({
58
67
  });
59
68
  }
60
69
 
61
- async function remoteBuild(root, entryPoint, outputDir = OUTPUT_DIR) {
70
+ async function remoteBuild({
71
+ root,
72
+ entryPoint,
73
+ outputDir = OUTPUT_DIR,
74
+ injectOverrides = true,
75
+ logger = console,
76
+ }) {
62
77
  const fileInfo = path.parse(entryPoint);
63
78
 
64
79
  if (!allowedExtensions.includes(fileInfo.ext)) {
65
80
  throw new Error(`${extensionErrorBaseMessage} ${fileInfo.ext}`);
66
81
  }
67
82
 
68
- const output = getUrlSafeFileName(entryPoint);
69
83
  await buildSingleExtension({
70
84
  file: entryPoint,
71
- outputFileName: output,
72
85
  outputDir,
73
- plugins: {
74
- rollup: [manifestPlugin({ minify: true, output })],
75
- },
76
86
  minify: true,
77
87
  root,
88
+ logger,
89
+ injectOverrides,
78
90
  });
79
91
  }
80
92
 
package/lib/dev.js CHANGED
@@ -29,6 +29,9 @@ async function _createViteDevServer(
29
29
  ignored: [
30
30
  path.join(outputDir, '/**/*'),
31
31
  '**/src/app/app.functions/**/*',
32
+ '**/app.json',
33
+ '**/package.json',
34
+ '**/package-lock.json',
32
35
  ],
33
36
  },
34
37
  },
@@ -0,0 +1,26 @@
1
+ const fs = require('fs');
2
+ const { logger } = require('@hubspot/cli-lib/logger');
3
+
4
+ function codeCheckingPlugin(options = {}) {
5
+ const { output } = options;
6
+ return {
7
+ name: 'ui-extensions-code-checking-plugin',
8
+ enforce: 'post',
9
+ writeBundle(__options, __bundle) {
10
+ try {
11
+ const code = fs.readFileSync(output).toString();
12
+ if (
13
+ !code.includes('const extend = (...args) => self.extend(...args);')
14
+ ) {
15
+ logger.warn(
16
+ 'Unable to determine if your extension entry point is calling hubspot.extend, this may prevent it from rendering as expected'
17
+ );
18
+ }
19
+ } catch (e) {
20
+ logger.error('Unable to load bundle for code checking');
21
+ }
22
+ },
23
+ };
24
+ }
25
+
26
+ module.exports = codeCheckingPlugin;
@@ -1,16 +1,13 @@
1
1
  const path = require('path');
2
2
 
3
- function codeInjectionPlugin(options = {}) {
4
- const { file, root = process.cwd() } = options;
3
+ function codeInjectionPlugin() {
5
4
  return {
6
5
  name: 'ui-extensions-code-injection-plugin',
7
6
  enforce: 'post', // run after default rollup plugins
8
- transform(code, fileBeingTransformed) {
9
- const absoluteFilePath = path.isAbsolute(file)
10
- ? file
11
- : path.join(root, file);
7
+ transform(code, file) {
8
+ const { dir } = path.parse(file);
12
9
 
13
- if (fileBeingTransformed !== absoluteFilePath) {
10
+ if (dir.includes('node_modules')) {
14
11
  return { code, map: null }; // Not the file we care about, return the same code
15
12
  }
16
13
 
@@ -2,6 +2,8 @@ const { ROLLUP_OPTIONS, WEBSOCKET_MESSAGE_VERSION } = require('../constants');
2
2
  const { build } = require('vite');
3
3
  const manifestPlugin = require('./manifestPlugin');
4
4
  const { stripAnsiColorCodes } = require('../utils');
5
+ const codeCheckingPlugin = require('./codeCheckingPlugin');
6
+ const path = require('path');
5
7
  const { logger } = require('@hubspot/cli-lib/logger');
6
8
 
7
9
  function devBuildPlugin(options = {}) {
@@ -65,6 +67,9 @@ function devBuildPlugin(options = {}) {
65
67
  minify: false,
66
68
  output: extensionConfig.output,
67
69
  }),
70
+ codeCheckingPlugin({
71
+ output: path.join(outputDir, extensionConfig.output),
72
+ }),
68
73
  ],
69
74
  output: {
70
75
  ...ROLLUP_OPTIONS.output,
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@hubspot/ui-extensions-dev-server",
3
- "version": "0.7.1",
3
+ "version": "0.7.3-canary.8+f0ea707c",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "jest",
8
+ "build": "echo 'no build step for @hubspot/ui-extensions-dev-server'",
8
9
  "jest": "jest --watch"
9
10
  },
10
11
  "publishConfig": {
@@ -32,7 +33,7 @@
32
33
  ],
33
34
  "license": "MIT",
34
35
  "dependencies": {
35
- "@hubspot/app-functions-dev-server": "^0.7.0",
36
+ "@hubspot/app-functions-dev-server": "^0.7.2",
36
37
  "@hubspot/cli-lib": "^4.1.6",
37
38
  "command-line-args": "^5.2.1",
38
39
  "command-line-usage": "^7.0.1",
@@ -67,5 +68,5 @@
67
68
  "optional": true
68
69
  }
69
70
  },
70
- "gitHead": "f3c6bfa9f758bdb23179e953a1826d1f0c3bd90f"
71
+ "gitHead": "f0ea707c3fdcb5cd043e5e34fb82354364ca156b"
71
72
  }