@hubspot/ui-extensions-dev-server 0.8.40 → 0.8.41

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/dist/lib/ast.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { SourceCodeChecks } from './types';
2
2
  import { Program } from 'estree';
3
- export declare function traverseAbstractSyntaxTree(ast: Program, checks: SourceCodeChecks): {
3
+ export declare function traverseAbstractSyntaxTree(ast: Program, checks: SourceCodeChecks, extensionPath: string): {
4
4
  functions: {};
5
+ badImports: never[];
5
6
  };
package/dist/lib/ast.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  /* eslint-disable hubspot-dev/no-unsupported-ts-syntax */
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
3
6
  Object.defineProperty(exports, "__esModule", { value: true });
4
7
  exports.traverseAbstractSyntaxTree = void 0;
8
+ const path_1 = __importDefault(require("path"));
5
9
  // @ts-expect-error no type defs
6
10
  const estraverse_1 = require("estraverse");
7
11
  function _isVariableImported(node, variableName) {
@@ -47,16 +51,35 @@ function _checkForFunctionMetadata(node, parent, output, functionName) {
47
51
  output.functions[functionName].defined = true;
48
52
  }
49
53
  }
54
+ /**
55
+ * We only support imports that are within the extension directory.
56
+ * This function will check if an import is out of bounds and collect any that are out of bounds, so we can warn the user before they run into build issues.
57
+ */
58
+ function _checkForOutOfBoundsImports(node, output, extensionPath) {
59
+ if (!node) {
60
+ return;
61
+ }
62
+ if (node.type === 'ImportDeclaration' &&
63
+ typeof node.source.value === 'string') {
64
+ const importPath = path_1.default.join(extensionPath, node.source.value);
65
+ const { dir } = path_1.default.parse(importPath);
66
+ if (!dir.includes(extensionPath)) {
67
+ output.badImports.push(importPath);
68
+ }
69
+ }
70
+ }
50
71
  // Traverses an ESTree as defined by the EsTree spec https://github.com/estree/estree
51
72
  // Uses the checks array to search the source code for matches
52
- function traverseAbstractSyntaxTree(ast, checks) {
73
+ function traverseAbstractSyntaxTree(ast, checks, extensionPath) {
53
74
  const state = {
54
75
  functions: {},
76
+ badImports: [],
55
77
  };
56
78
  (0, estraverse_1.traverse)(ast, {
57
79
  enter(node, parent) {
58
80
  checks.forEach((check) => {
59
81
  _checkForFunctionMetadata(node, parent, state, check.functionName);
82
+ _checkForOutOfBoundsImports(node, state, extensionPath);
60
83
  });
61
84
  },
62
85
  });
package/dist/lib/build.js CHANGED
@@ -42,7 +42,7 @@ logLevel = 'info', }) {
42
42
  rollupOptions: Object.assign(Object.assign({}, constants_1.ROLLUP_OPTIONS), { plugins: [
43
43
  (0, manifestPlugin_1.default)({ output, extensionPath: root, logger: console }),
44
44
  (0, friendlyLoggingPlugin_1.default)({ logger: console }),
45
- (0, codeBlockingPlugin_1.default)({ logger: console }),
45
+ (0, codeBlockingPlugin_1.default)({ logger: console, extensionPath: root }),
46
46
  ] }),
47
47
  outDir: outputDir,
48
48
  emptyOutDir,
@@ -1,7 +1,8 @@
1
1
  import { Rollup } from 'vite';
2
2
  import { Logger } from '../types';
3
- export type CodeBlockingPlugin = ({ logger, }: {
3
+ export type CodeBlockingPlugin = ({ logger, extensionPath, }: {
4
4
  logger: Logger;
5
+ extensionPath: string;
5
6
  }) => Rollup.Plugin;
6
7
  declare const codeBlockingPlugin: CodeBlockingPlugin;
7
8
  export default codeBlockingPlugin;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const utils_1 = require("../utils");
5
5
  const ast_1 = require("../ast");
6
- const codeBlockingPlugin = ({ logger }) => {
6
+ const codeBlockingPlugin = ({ logger, extensionPath }) => {
7
7
  return {
8
8
  name: 'ui-extensions-code-blocking-plugin',
9
9
  enforce: 'post',
@@ -11,16 +11,22 @@ const codeBlockingPlugin = ({ logger }) => {
11
11
  if ((0, utils_1.isNodeModule)(filename)) {
12
12
  return { code, map: null }; // We don't want to parse node modules
13
13
  }
14
- let sourceCodeMetadata = { functions: {} };
14
+ let sourceCodeMetadata = {
15
+ functions: {},
16
+ badImports: [],
17
+ };
15
18
  const requireFunctionName = 'require';
16
19
  try {
17
20
  // Not sure why the types don't match for this.parse and the Rollup docs, but
18
21
  // the docs over on rollup's site specify ESTree.Program as the return type,
19
22
  // and the underlying data matches that https://rollupjs.org/plugin-development/#this-parse
20
23
  const abstractSyntaxTree = this.parse(code);
21
- sourceCodeMetadata = (0, ast_1.traverseAbstractSyntaxTree)(abstractSyntaxTree, [
22
- { functionName: requireFunctionName },
23
- ]);
24
+ sourceCodeMetadata = (0, ast_1.traverseAbstractSyntaxTree)(abstractSyntaxTree, [{ functionName: requireFunctionName }], extensionPath);
25
+ if (sourceCodeMetadata.badImports) {
26
+ for (const badImport of sourceCodeMetadata.badImports) {
27
+ logger.warn(`Importing files from outside of the extension directory is not supported. Please move the import ${badImport} into the extension directory.`);
28
+ }
29
+ }
24
30
  }
25
31
  catch (e) {
26
32
  logger.debug('Unable to parse and traverse source code');
@@ -71,6 +71,7 @@ const devBuildPlugin = (options) => {
71
71
  const devBuild = (server, extensionMetadata, emptyOutDir = false) => __awaiter(void 0, void 0, void 0, function* () {
72
72
  try {
73
73
  const { config: extensionConfig } = extensionMetadata;
74
+ const { extensionPath } = extensionConfig;
74
75
  yield (0, vite_1.build)({
75
76
  logLevel: 'warn',
76
77
  mode: 'development',
@@ -95,7 +96,7 @@ const devBuildPlugin = (options) => {
95
96
  (0, manifestPlugin_1.default)({
96
97
  minify: false,
97
98
  output: extensionConfig.output,
98
- extensionPath: extensionConfig.extensionPath,
99
+ extensionPath,
99
100
  logger,
100
101
  }),
101
102
  (0, codeCheckingPlugin_1.default)({
@@ -107,7 +108,7 @@ const devBuildPlugin = (options) => {
107
108
  output: extensionConfig.output,
108
109
  logger,
109
110
  }),
110
- (0, codeBlockingPlugin_1.default)({ logger }),
111
+ (0, codeBlockingPlugin_1.default)({ logger, extensionPath }),
111
112
  ], output: Object.assign(Object.assign({}, constants_1.ROLLUP_OPTIONS.output), { sourcemap: 'inline' }) }),
112
113
  outDir: devServerState.outputDir,
113
114
  emptyOutDir,
@@ -119,6 +119,7 @@ export interface SourceCodeMetadata {
119
119
  functions: {
120
120
  [functionName: string]: FunctionMetadata;
121
121
  };
122
+ badImports: string[];
122
123
  }
123
124
  export interface FunctionInvocationCheck {
124
125
  functionName: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/ui-extensions-dev-server",
3
- "version": "0.8.40",
3
+ "version": "0.8.41",
4
4
  "description": "",
5
5
  "bin": {
6
6
  "uie": "./dist/lib/bin/cli.js"
@@ -27,7 +27,7 @@
27
27
  ],
28
28
  "license": "MIT",
29
29
  "dependencies": {
30
- "@hubspot/app-functions-dev-server": "0.8.40",
30
+ "@hubspot/app-functions-dev-server": "0.8.41",
31
31
  "chalk": "^5.4.1",
32
32
  "commander": "^13.0.0",
33
33
  "cors": "^2.8.5",
@@ -69,5 +69,5 @@
69
69
  "optional": true
70
70
  }
71
71
  },
72
- "gitHead": "1f4550a901eeba1e56943ef50c6ea7af30f95bc1"
72
+ "gitHead": "ce6d6332d471d5c5ac127de88a8fa51dd7506c3e"
73
73
  }