@hubspot/ui-extensions-dev-server 0.10.2 → 1.0.0
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/README.md +23 -4
- package/dist/index.d.ts +3 -3
- package/dist/index.js +4 -45
- package/dist/lib/DevModeInterface.d.ts +2 -2
- package/dist/lib/DevModeInterface.js +12 -28
- package/dist/lib/DevModeParentInterface.d.ts +2 -2
- package/dist/lib/DevModeParentInterface.js +138 -154
- package/dist/lib/DevModeUnifiedInterface.d.ts +2 -2
- package/dist/lib/DevModeUnifiedInterface.js +28 -49
- package/dist/lib/DevServerState.d.ts +9 -5
- package/dist/lib/DevServerState.js +37 -18
- package/dist/lib/ExtensionsWebSocket.d.ts +25 -0
- package/dist/lib/ExtensionsWebSocket.js +110 -0
- package/dist/lib/__mocks__/config.d.ts +2 -0
- package/dist/lib/__mocks__/config.js +5 -0
- package/dist/lib/__mocks__/isExtensionFile.d.ts +5 -0
- package/dist/lib/__mocks__/isExtensionFile.js +11 -0
- package/dist/lib/__tests__/DevModeInterface.spec.d.ts +1 -0
- package/dist/lib/__tests__/DevModeInterface.spec.js +155 -0
- package/dist/lib/__tests__/DevModeParentInterface.spec.d.ts +1 -0
- package/dist/lib/__tests__/DevModeParentInterface.spec.js +179 -0
- package/dist/lib/__tests__/DevModeUnifiedInterface.spec.d.ts +1 -0
- package/dist/lib/__tests__/DevModeUnifiedInterface.spec.js +236 -0
- package/dist/lib/__tests__/ExtensionsWebSocket.spec.d.ts +1 -0
- package/dist/lib/__tests__/ExtensionsWebSocket.spec.js +304 -0
- package/dist/lib/__tests__/ast.spec.d.ts +1 -0
- package/dist/lib/__tests__/ast.spec.js +737 -0
- package/dist/lib/__tests__/build.spec.d.ts +1 -0
- package/dist/lib/__tests__/build.spec.js +159 -0
- package/dist/lib/__tests__/config.spec.d.ts +1 -0
- package/dist/lib/__tests__/config.spec.js +291 -0
- package/dist/lib/__tests__/dev.spec.d.ts +1 -0
- package/dist/lib/__tests__/dev.spec.js +80 -0
- package/dist/lib/__tests__/extensionsService.spec.d.ts +1 -0
- package/dist/lib/__tests__/extensionsService.spec.js +150 -0
- package/dist/lib/__tests__/factories.d.ts +48 -0
- package/dist/lib/__tests__/factories.js +32 -0
- package/dist/lib/__tests__/fixtures/extensionConfig.d.ts +182 -0
- package/dist/lib/__tests__/fixtures/extensionConfig.js +304 -0
- package/dist/lib/__tests__/fixtures/urls.d.ts +4 -0
- package/dist/lib/__tests__/fixtures/urls.js +4 -0
- package/dist/lib/__tests__/parsing-utils.spec.d.ts +1 -0
- package/dist/lib/__tests__/parsing-utils.spec.js +467 -0
- package/dist/lib/__tests__/plugins/codeBlockingPlugin.spec.d.ts +1 -0
- package/dist/lib/__tests__/plugins/codeBlockingPlugin.spec.js +112 -0
- package/dist/lib/__tests__/plugins/codeCheckingPlugin.spec.d.ts +1 -0
- package/dist/lib/__tests__/plugins/codeCheckingPlugin.spec.js +73 -0
- package/dist/lib/__tests__/plugins/devBuildPlugin.spec.d.ts +1 -0
- package/dist/lib/__tests__/plugins/devBuildPlugin.spec.js +256 -0
- package/dist/lib/__tests__/plugins/friendlyLoggingPlugin.spec.d.ts +1 -0
- package/dist/lib/__tests__/plugins/friendlyLoggingPlugin.spec.js +65 -0
- package/dist/lib/__tests__/plugins/manifestPlugin.spec.d.ts +1 -0
- package/dist/lib/__tests__/plugins/manifestPlugin.spec.js +455 -0
- package/dist/lib/__tests__/plugins/relevantModulesPlugin.spec.d.ts +1 -0
- package/dist/lib/__tests__/plugins/relevantModulesPlugin.spec.js +81 -0
- package/dist/lib/__tests__/server.spec.d.ts +1 -0
- package/dist/lib/__tests__/server.spec.js +152 -0
- package/dist/lib/__tests__/test-utils/ast.d.ts +1 -0
- package/dist/lib/__tests__/test-utils/ast.js +4 -0
- package/dist/lib/__tests__/utils.spec.d.ts +1 -0
- package/dist/lib/__tests__/utils.spec.js +176 -0
- package/dist/lib/ast.d.ts +1 -1
- package/dist/lib/ast.js +22 -29
- package/dist/lib/bin/cli.js +52 -72
- package/dist/lib/build.d.ts +1 -1
- package/dist/lib/build.js +60 -78
- package/dist/lib/config.d.ts +1 -1
- package/dist/lib/config.js +31 -34
- package/dist/lib/constants.d.ts +0 -2
- package/dist/lib/constants.js +20 -27
- package/dist/lib/dev.d.ts +1 -1
- package/dist/lib/dev.js +52 -69
- package/dist/lib/extensionsService.d.ts +1 -1
- package/dist/lib/extensionsService.js +21 -15
- package/dist/lib/parsing-utils.d.ts +1 -1
- package/dist/lib/parsing-utils.js +7 -11
- package/dist/lib/plugins/codeBlockingPlugin.d.ts +1 -1
- package/dist/lib/plugins/codeBlockingPlugin.js +5 -8
- package/dist/lib/plugins/codeCheckingPlugin.d.ts +1 -1
- package/dist/lib/plugins/codeCheckingPlugin.js +4 -9
- package/dist/lib/plugins/devBuildPlugin.d.ts +2 -2
- package/dist/lib/plugins/devBuildPlugin.js +74 -99
- package/dist/lib/plugins/friendlyLoggingPlugin.d.ts +2 -2
- package/dist/lib/plugins/friendlyLoggingPlugin.js +4 -12
- package/dist/lib/plugins/manifestPlugin.d.ts +1 -1
- package/dist/lib/plugins/manifestPlugin.js +46 -26
- package/dist/lib/plugins/relevantModulesPlugin.d.ts +2 -2
- package/dist/lib/plugins/relevantModulesPlugin.js +4 -7
- package/dist/lib/server.d.ts +7 -2
- package/dist/lib/server.js +85 -84
- package/dist/lib/types.d.ts +1 -1
- package/dist/lib/types.js +4 -7
- package/dist/lib/utils.d.ts +1 -1
- package/dist/lib/utils.js +23 -40
- package/package.json +44 -31
package/dist/lib/dev.js
CHANGED
|
@@ -1,75 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const detect_port_1 = __importDefault(require("detect-port"));
|
|
22
|
-
function _createViteDevServer(devServerState) {
|
|
23
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
return yield (0, vite_1.createServer)({
|
|
25
|
-
root: devServerState.appPath,
|
|
26
|
-
logLevel: 'silent',
|
|
27
|
-
appType: 'custom',
|
|
28
|
-
mode: 'development',
|
|
29
|
-
server: {
|
|
30
|
-
middlewareMode: true,
|
|
31
|
-
hmr: {
|
|
32
|
-
port: devServerState.webSocketPort,
|
|
33
|
-
},
|
|
34
|
-
watch: {
|
|
35
|
-
ignored: [
|
|
36
|
-
path_1.default.join(devServerState.outputDir, '/**/*'),
|
|
37
|
-
'**/src/app/app.functions/**/*',
|
|
38
|
-
'**/app.json',
|
|
39
|
-
'**/package.json',
|
|
40
|
-
'**/package-lock.json',
|
|
41
|
-
],
|
|
42
|
-
},
|
|
1
|
+
import { createServer } from 'vite';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import startDevServer from "./server.js";
|
|
4
|
+
import devBuildPlugin from "./plugins/devBuildPlugin.js";
|
|
5
|
+
import { ALLOWED_ORIGIN_PATTERNS } from "./ExtensionsWebSocket.js";
|
|
6
|
+
import detect from 'detect-port';
|
|
7
|
+
async function _createViteDevServer(devServerState) {
|
|
8
|
+
return await createServer({
|
|
9
|
+
root: devServerState.appPath,
|
|
10
|
+
logLevel: 'silent',
|
|
11
|
+
appType: 'custom',
|
|
12
|
+
mode: 'development',
|
|
13
|
+
server: {
|
|
14
|
+
middlewareMode: true,
|
|
15
|
+
hmr: {
|
|
16
|
+
server: null, // We use our own WebSocket server (ExtensionsWebSocket) instead of Vite's
|
|
17
|
+
},
|
|
18
|
+
cors: {
|
|
19
|
+
origin: ALLOWED_ORIGIN_PATTERNS,
|
|
20
|
+
credentials: true,
|
|
43
21
|
},
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
devServerState,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
22
|
+
watch: {
|
|
23
|
+
ignored: [
|
|
24
|
+
path.join(devServerState.outputDir, '/**/*'),
|
|
25
|
+
'**/src/app/app.functions/**/*',
|
|
26
|
+
'**/app.json',
|
|
27
|
+
'**/package.json',
|
|
28
|
+
'**/package-lock.json',
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
plugins: [
|
|
33
|
+
devBuildPlugin({
|
|
34
|
+
devServerState,
|
|
35
|
+
}),
|
|
36
|
+
],
|
|
37
|
+
clearScreen: false,
|
|
51
38
|
});
|
|
52
39
|
}
|
|
53
|
-
function throwIfPortTaken(port) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
});
|
|
40
|
+
async function throwIfPortTaken(port) {
|
|
41
|
+
// detect takes a port and returns the next available port
|
|
42
|
+
// so a mismatch means the requested port was not available
|
|
43
|
+
if ((await detect(port)) !== port) {
|
|
44
|
+
throw new Error(`Unable to start because port ${port} is already in use`);
|
|
45
|
+
}
|
|
61
46
|
}
|
|
62
|
-
function startDevMode(devServerState) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
viteDevServer,
|
|
72
|
-
});
|
|
73
|
-
return shutdownServer;
|
|
47
|
+
export async function startDevMode(devServerState) {
|
|
48
|
+
if (!devServerState || !devServerState.extensionsMetadata) {
|
|
49
|
+
throw new Error('Unable to determine which extension to run');
|
|
50
|
+
}
|
|
51
|
+
await throwIfPortTaken(devServerState.expressPort);
|
|
52
|
+
const viteDevServer = await _createViteDevServer(devServerState);
|
|
53
|
+
const { shutdown } = await startDevServer({
|
|
54
|
+
devServerState,
|
|
55
|
+
viteDevServer,
|
|
74
56
|
});
|
|
57
|
+
return shutdown;
|
|
75
58
|
}
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
/* eslint-disable hubspot-dev/no-unsupported-ts-syntax */
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const constants_1 = require("./constants");
|
|
9
|
-
const utils_1 = require("./utils");
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { EXTENSIONS_MESSAGE_VERSION } from "./constants.js";
|
|
3
|
+
import { loadManifest } from "./utils.js";
|
|
10
4
|
class ExtensionsService {
|
|
5
|
+
endpoint;
|
|
11
6
|
constructor() {
|
|
12
7
|
this.endpoint = '/extensions';
|
|
13
8
|
}
|
|
@@ -20,15 +15,26 @@ class ExtensionsService {
|
|
|
20
15
|
try {
|
|
21
16
|
const extensions = devServerState.extensionsMetadata.map((metadata) => {
|
|
22
17
|
const { baseMessage } = metadata;
|
|
23
|
-
const output =
|
|
24
|
-
return
|
|
18
|
+
const output = path.parse(baseMessage.callback).name;
|
|
19
|
+
return {
|
|
20
|
+
...baseMessage,
|
|
21
|
+
manifest: loadManifest(devServerState.outputDir, output),
|
|
22
|
+
};
|
|
25
23
|
});
|
|
26
|
-
const response =
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
const response = {
|
|
25
|
+
websocket: `ws://localhost:${devServerState.expressPort}`,
|
|
26
|
+
version: EXTENSIONS_MESSAGE_VERSION,
|
|
27
|
+
capabilities,
|
|
28
|
+
portalId: devServerState.portalId,
|
|
29
|
+
extensions,
|
|
30
|
+
...(devServerState.functionsConfig.platformVersion && {
|
|
31
|
+
platformVersion: devServerState.functionsConfig.platformVersion,
|
|
32
|
+
}),
|
|
33
|
+
};
|
|
29
34
|
res.status(200).json(response);
|
|
30
35
|
}
|
|
31
36
|
catch (e) {
|
|
37
|
+
devServerState.logger.error(`Error in /extensions endpoint: ${e}`);
|
|
32
38
|
res.status(500).json({
|
|
33
39
|
message: 'Unable to determine which extensions are running',
|
|
34
40
|
});
|
|
@@ -36,4 +42,4 @@ class ExtensionsService {
|
|
|
36
42
|
};
|
|
37
43
|
}
|
|
38
44
|
}
|
|
39
|
-
|
|
45
|
+
export default new ExtensionsService();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Node } from 'estree';
|
|
2
|
-
import { NodeValue, SourceCodeMetadata } from './types';
|
|
2
|
+
import { NodeValue, SourceCodeMetadata } from './types.ts';
|
|
3
3
|
/**
|
|
4
4
|
* Extracts the value from a given AST node based on its type.
|
|
5
5
|
* This function handles various node types such as Literal, Identifier (aka variables), ArrayExpression,
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getValueFromNode = getValueFromNode;
|
|
4
|
-
exports.isVariableImported = isVariableImported;
|
|
5
|
-
exports.isIdentifierDefined = isIdentifierDefined;
|
|
6
|
-
exports.isFunctionInvoked = isFunctionInvoked;
|
|
7
1
|
/**
|
|
8
2
|
* Extracts the value from a given AST node based on its type.
|
|
9
3
|
* This function handles various node types such as Literal, Identifier (aka variables), ArrayExpression,
|
|
@@ -25,7 +19,7 @@ exports.isFunctionInvoked = isFunctionInvoked;
|
|
|
25
19
|
* If the status is 'SUCCESS', nodeValue will contain the extracted value.
|
|
26
20
|
* If the status is 'FAIL', error will contain the error message.
|
|
27
21
|
*/
|
|
28
|
-
function getValueFromNode(node, state) {
|
|
22
|
+
export function getValueFromNode(node, state) {
|
|
29
23
|
try {
|
|
30
24
|
switch (node.type) {
|
|
31
25
|
case 'Literal':
|
|
@@ -268,24 +262,26 @@ function getValueFromNode(node, state) {
|
|
|
268
262
|
};
|
|
269
263
|
}
|
|
270
264
|
}
|
|
271
|
-
function isVariableImported(node, variableName) {
|
|
265
|
+
export function isVariableImported(node, variableName) {
|
|
272
266
|
if (!node) {
|
|
273
267
|
return false;
|
|
274
268
|
}
|
|
275
|
-
return ((node.type === 'ImportSpecifier' &&
|
|
269
|
+
return ((node.type === 'ImportSpecifier' &&
|
|
270
|
+
node.imported.type === 'Identifier' &&
|
|
271
|
+
node.imported.name === variableName) ||
|
|
276
272
|
(node.type === 'ImportDefaultSpecifier' &&
|
|
277
273
|
node.local.name === variableName) ||
|
|
278
274
|
(node.type === 'ImportNamespaceSpecifier' &&
|
|
279
275
|
node.local.name === variableName));
|
|
280
276
|
}
|
|
281
|
-
function isIdentifierDefined(node, parent, name) {
|
|
277
|
+
export function isIdentifierDefined(node, parent, name) {
|
|
282
278
|
if (parent &&
|
|
283
279
|
(parent.type === 'MemberExpression' || parent.type === 'CallExpression')) {
|
|
284
280
|
return false;
|
|
285
281
|
}
|
|
286
282
|
return node.type === 'Identifier' && node.name === name;
|
|
287
283
|
}
|
|
288
|
-
function isFunctionInvoked(node, functionName) {
|
|
284
|
+
export function isFunctionInvoked(node, functionName) {
|
|
289
285
|
return (node.type === 'CallExpression' &&
|
|
290
286
|
node.callee &&
|
|
291
287
|
'name' in node.callee &&
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const utils_1 = require("../utils");
|
|
5
|
-
const ast_1 = require("../ast");
|
|
1
|
+
import { isNodeModule } from "../utils.js";
|
|
2
|
+
import { traverseAbstractSyntaxTree } from "../ast.js";
|
|
6
3
|
const codeBlockingPlugin = ({ logger, extensionPath }) => {
|
|
7
4
|
return {
|
|
8
5
|
name: 'ui-extensions-code-blocking-plugin',
|
|
9
6
|
enforce: 'post', // run after default rollup plugins
|
|
10
7
|
transform(code, filename) {
|
|
11
|
-
if (
|
|
8
|
+
if (isNodeModule(filename)) {
|
|
12
9
|
return { code, map: null }; // We don't want to parse node modules
|
|
13
10
|
}
|
|
14
11
|
let sourceCodeMetadata = {
|
|
@@ -26,7 +23,7 @@ const codeBlockingPlugin = ({ logger, extensionPath }) => {
|
|
|
26
23
|
// the docs over on rollup's site specify ESTree.Program as the return type,
|
|
27
24
|
// and the underlying data matches that https://rollupjs.org/plugin-development/#this-parse
|
|
28
25
|
const abstractSyntaxTree = this.parse(code);
|
|
29
|
-
sourceCodeMetadata =
|
|
26
|
+
sourceCodeMetadata = traverseAbstractSyntaxTree(abstractSyntaxTree, [{ functionName: requireFunctionName }], extensionPath, logger);
|
|
30
27
|
if (sourceCodeMetadata.badImports) {
|
|
31
28
|
for (const badImport of sourceCodeMetadata.badImports) {
|
|
32
29
|
logger.warn(`Importing files from outside of the extension directory is not supported. Please move the import ${badImport} into the extension directory.`);
|
|
@@ -45,4 +42,4 @@ const codeBlockingPlugin = ({ logger, extensionPath }) => {
|
|
|
45
42
|
},
|
|
46
43
|
};
|
|
47
44
|
};
|
|
48
|
-
|
|
45
|
+
export default codeBlockingPlugin;
|
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const fs_1 = __importDefault(require("fs"));
|
|
1
|
+
import fs from 'fs';
|
|
7
2
|
const codeCheckingPlugin = (options) => {
|
|
8
3
|
const { output, logger } = options;
|
|
9
4
|
return {
|
|
10
5
|
name: 'ui-extensions-code-checking-plugin',
|
|
11
6
|
enforce: 'post',
|
|
12
|
-
writeBundle(
|
|
7
|
+
writeBundle() {
|
|
13
8
|
try {
|
|
14
|
-
const code =
|
|
9
|
+
const code = fs.readFileSync(output).toString();
|
|
15
10
|
if (!code.includes('const extend = (...args) => self.extend(...args);') &&
|
|
16
11
|
!code.includes('self.extend_V2(renderExtensionCallback)')) {
|
|
17
12
|
logger.warn('Unable to determine if your extension entry point is calling hubspot.extend, this may prevent it from rendering as expected');
|
|
@@ -23,4 +18,4 @@ const codeCheckingPlugin = (options) => {
|
|
|
23
18
|
},
|
|
24
19
|
};
|
|
25
20
|
};
|
|
26
|
-
|
|
21
|
+
export default codeCheckingPlugin;
|
|
@@ -1,63 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Object.defineProperty(o, k2, desc);
|
|
11
|
-
}) : (function(o, m, k, k2) {
|
|
12
|
-
if (k2 === undefined) k2 = k;
|
|
13
|
-
o[k2] = m[k];
|
|
14
|
-
}));
|
|
15
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
-
}) : function(o, v) {
|
|
18
|
-
o["default"] = v;
|
|
19
|
-
});
|
|
20
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
21
|
-
var ownKeys = function(o) {
|
|
22
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
23
|
-
var ar = [];
|
|
24
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
25
|
-
return ar;
|
|
26
|
-
};
|
|
27
|
-
return ownKeys(o);
|
|
28
|
-
};
|
|
29
|
-
return function (mod) {
|
|
30
|
-
if (mod && mod.__esModule) return mod;
|
|
31
|
-
var result = {};
|
|
32
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
33
|
-
__setModuleDefault(result, mod);
|
|
34
|
-
return result;
|
|
35
|
-
};
|
|
36
|
-
})();
|
|
37
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
38
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
39
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
40
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
41
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
42
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
43
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
47
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
48
|
-
};
|
|
49
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
const constants_1 = require("../constants");
|
|
51
|
-
const vite_1 = require("vite");
|
|
52
|
-
const manifestPlugin_1 = __importDefault(require("./manifestPlugin"));
|
|
53
|
-
const utils_1 = require("../utils");
|
|
54
|
-
const codeCheckingPlugin_1 = __importDefault(require("./codeCheckingPlugin"));
|
|
55
|
-
const path_1 = __importDefault(require("path"));
|
|
56
|
-
const friendlyLoggingPlugin_1 = __importDefault(require("./friendlyLoggingPlugin"));
|
|
57
|
-
const relevantModulesPlugin_1 = __importStar(require("./relevantModulesPlugin"));
|
|
58
|
-
const codeBlockingPlugin_1 = __importDefault(require("./codeBlockingPlugin"));
|
|
1
|
+
import { ROLLUP_OPTIONS, WEBSOCKET_MESSAGE_VERSION } from "../constants.js";
|
|
2
|
+
import { build } from 'vite';
|
|
3
|
+
import manifestPlugin from "./manifestPlugin.js";
|
|
4
|
+
import { stripAnsiColorCodes } from "../utils.js";
|
|
5
|
+
import codeCheckingPlugin from "./codeCheckingPlugin.js";
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import friendlyLoggingPlugin from "./friendlyLoggingPlugin.js";
|
|
8
|
+
import relevantModulesPlugin, { getRelevantModules, } from "./relevantModulesPlugin.js";
|
|
9
|
+
import codeBlockingPlugin from "./codeBlockingPlugin.js";
|
|
59
10
|
function addVersionToBaseMessage(baseMessage) {
|
|
60
|
-
return
|
|
11
|
+
return {
|
|
12
|
+
...baseMessage,
|
|
13
|
+
version: WEBSOCKET_MESSAGE_VERSION,
|
|
14
|
+
};
|
|
61
15
|
}
|
|
62
16
|
function isValidVariablesRecord(obj) {
|
|
63
17
|
if (!obj || typeof obj !== 'object')
|
|
@@ -71,22 +25,25 @@ const devBuildPlugin = (options) => {
|
|
|
71
25
|
const { devServerState } = options;
|
|
72
26
|
const { logger } = devServerState;
|
|
73
27
|
let lastBuildErrorContext;
|
|
74
|
-
const handleBuildError = (error
|
|
28
|
+
const handleBuildError = (error) => {
|
|
75
29
|
const { error: { plugin, errors, frame, loc, id }, extensionMetadata, } = error;
|
|
76
30
|
// Filter out our custom plugins, but send everything else
|
|
77
|
-
if (!
|
|
78
|
-
|
|
79
|
-
|
|
31
|
+
if (!plugin?.startsWith('ui-extensions')) {
|
|
32
|
+
devServerState.getExtensionsWebSocket().broadcast({
|
|
33
|
+
...addVersionToBaseMessage(extensionMetadata.baseMessage),
|
|
34
|
+
event: 'error',
|
|
35
|
+
error: {
|
|
80
36
|
details: {
|
|
81
37
|
errors,
|
|
82
|
-
formattedError:
|
|
38
|
+
formattedError: stripAnsiColorCodes(frame),
|
|
83
39
|
location: loc,
|
|
84
40
|
file: id,
|
|
85
41
|
},
|
|
86
|
-
}
|
|
42
|
+
},
|
|
43
|
+
});
|
|
87
44
|
}
|
|
88
45
|
};
|
|
89
|
-
const devBuild =
|
|
46
|
+
const devBuild = async (server, extensionMetadata, emptyOutDir = false) => {
|
|
90
47
|
try {
|
|
91
48
|
const { config: extensionConfig } = extensionMetadata;
|
|
92
49
|
const { extensionPath } = extensionConfig;
|
|
@@ -98,7 +55,7 @@ const devBuildPlugin = (options) => {
|
|
|
98
55
|
variables: devServerState.appConfig.variables,
|
|
99
56
|
};
|
|
100
57
|
}
|
|
101
|
-
|
|
58
|
+
await build({
|
|
102
59
|
logLevel: 'warn',
|
|
103
60
|
mode: 'development',
|
|
104
61
|
define: {
|
|
@@ -118,28 +75,35 @@ const devBuildPlugin = (options) => {
|
|
|
118
75
|
formats: ['iife'],
|
|
119
76
|
fileName: () => extensionConfig.output,
|
|
120
77
|
},
|
|
121
|
-
rollupOptions:
|
|
122
|
-
|
|
78
|
+
rollupOptions: {
|
|
79
|
+
...ROLLUP_OPTIONS,
|
|
80
|
+
plugins: [
|
|
81
|
+
manifestPlugin({
|
|
123
82
|
minify: false,
|
|
124
83
|
output: extensionConfig.output,
|
|
125
84
|
extensionPath,
|
|
126
85
|
logger,
|
|
127
86
|
manifestConfig,
|
|
128
87
|
}),
|
|
129
|
-
(
|
|
130
|
-
output:
|
|
88
|
+
codeCheckingPlugin({
|
|
89
|
+
output: path.join(devServerState.outputDir, extensionConfig.output),
|
|
131
90
|
logger,
|
|
132
91
|
}),
|
|
133
|
-
(
|
|
134
|
-
(
|
|
92
|
+
friendlyLoggingPlugin({ logger }),
|
|
93
|
+
relevantModulesPlugin({
|
|
135
94
|
output: extensionConfig.output,
|
|
136
95
|
logger,
|
|
137
96
|
}),
|
|
138
|
-
(
|
|
139
|
-
],
|
|
97
|
+
codeBlockingPlugin({ logger, extensionPath }),
|
|
98
|
+
],
|
|
99
|
+
output: {
|
|
100
|
+
...ROLLUP_OPTIONS.output,
|
|
101
|
+
},
|
|
102
|
+
},
|
|
140
103
|
outDir: devServerState.outputDir,
|
|
141
104
|
emptyOutDir,
|
|
142
105
|
minify: false,
|
|
106
|
+
sourcemap: 'inline',
|
|
143
107
|
},
|
|
144
108
|
clearScreen: false,
|
|
145
109
|
});
|
|
@@ -152,68 +116,79 @@ const devBuildPlugin = (options) => {
|
|
|
152
116
|
extensionMetadata,
|
|
153
117
|
};
|
|
154
118
|
logger.debug(error);
|
|
155
|
-
handleBuildError(lastBuildErrorContext
|
|
119
|
+
handleBuildError(lastBuildErrorContext);
|
|
156
120
|
return false;
|
|
157
121
|
}
|
|
158
|
-
}
|
|
122
|
+
};
|
|
159
123
|
let localServer;
|
|
160
124
|
return {
|
|
161
125
|
name: 'ui-extensions-dev-build-plugin',
|
|
162
126
|
enforce: 'pre',
|
|
163
|
-
configureServer: (server) =>
|
|
127
|
+
configureServer: async (server) => {
|
|
164
128
|
// Store a reference to the server to be used in hooks that don't get the server injected
|
|
165
129
|
// See https://vitejs.dev/guide/api-plugin.html#configureserver for information on this pattern
|
|
166
130
|
localServer = server;
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
devServerState.
|
|
170
|
-
|
|
171
|
-
|
|
131
|
+
// Store the WebSocket setup to be called after the WebSocket is initialized
|
|
132
|
+
devServerState.setWebSocketSetupCallback(() => {
|
|
133
|
+
devServerState.getExtensionsWebSocket().onConnection(() => {
|
|
134
|
+
logger.info('Browser connected and listening for bundle updates');
|
|
135
|
+
devServerState.extensionsMetadata.forEach((metadata) => {
|
|
136
|
+
devServerState.getExtensionsWebSocket().broadcast({
|
|
137
|
+
...addVersionToBaseMessage(metadata.baseMessage),
|
|
138
|
+
event: 'start',
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
if (lastBuildErrorContext) {
|
|
142
|
+
handleBuildError(lastBuildErrorContext);
|
|
143
|
+
}
|
|
172
144
|
});
|
|
173
|
-
if (lastBuildErrorContext) {
|
|
174
|
-
handleBuildError(lastBuildErrorContext, server);
|
|
175
|
-
}
|
|
176
145
|
});
|
|
177
146
|
for (let i = 0; i < devServerState.extensionsMetadata.length; ++i) {
|
|
178
|
-
|
|
147
|
+
await devBuild(localServer, devServerState.extensionsMetadata[i], i === 0);
|
|
179
148
|
}
|
|
180
|
-
}
|
|
181
|
-
handleHotUpdate:
|
|
149
|
+
},
|
|
150
|
+
handleHotUpdate: async ({ file, server }) => {
|
|
182
151
|
// If the file is not in the relevantModules list, it's update is inconsequential
|
|
183
152
|
const extensionsToRebuild = devServerState.extensionsMetadata.filter((metadata) => {
|
|
184
153
|
const { config } = metadata;
|
|
185
|
-
return
|
|
154
|
+
return getRelevantModules(config.output).includes(file);
|
|
186
155
|
});
|
|
187
156
|
for (let i = 0; i < extensionsToRebuild.length; ++i) {
|
|
188
157
|
const toRebuild = extensionsToRebuild[i];
|
|
189
|
-
const successful =
|
|
158
|
+
const successful = await devBuild(server, toRebuild);
|
|
190
159
|
if (!successful) {
|
|
191
160
|
return [];
|
|
192
161
|
}
|
|
193
162
|
const { config: extensionConfig } = toRebuild;
|
|
194
163
|
logger.info(`Extension ${extensionConfig.data.title} updated, compiled`);
|
|
195
|
-
|
|
164
|
+
const ws = devServerState.getExtensionsWebSocket();
|
|
165
|
+
if (ws.clientCount === 0) {
|
|
196
166
|
logger.debug('Bundle updated, no browsers connected to notify');
|
|
197
167
|
return [];
|
|
198
168
|
}
|
|
199
169
|
logger.debug('Bundle updated, notifying connected browsers');
|
|
200
|
-
|
|
201
|
-
|
|
170
|
+
ws.broadcast({
|
|
171
|
+
...addVersionToBaseMessage(toRebuild.baseMessage),
|
|
172
|
+
event: 'update',
|
|
173
|
+
});
|
|
202
174
|
}
|
|
203
175
|
return [];
|
|
204
|
-
}
|
|
176
|
+
},
|
|
205
177
|
buildEnd(error) {
|
|
206
178
|
if (error) {
|
|
207
179
|
logger.error(error);
|
|
208
180
|
}
|
|
209
|
-
|
|
181
|
+
const ws = devServerState.extensionsWebSocket;
|
|
182
|
+
if (ws) {
|
|
210
183
|
logger.debug('Sending shutdown message to connected browsers');
|
|
211
184
|
devServerState.extensionsMetadata.forEach((metadata) => {
|
|
212
|
-
|
|
213
|
-
|
|
185
|
+
ws.broadcast({
|
|
186
|
+
...addVersionToBaseMessage(metadata.baseMessage),
|
|
187
|
+
event: 'shutdown',
|
|
188
|
+
});
|
|
214
189
|
});
|
|
215
190
|
}
|
|
216
191
|
},
|
|
217
192
|
};
|
|
218
193
|
};
|
|
219
|
-
|
|
194
|
+
export default devBuildPlugin;
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
/* hs-eslint ignored failing-rules */
|
|
3
|
-
/* eslint-disable hubspot-dev/no-unsupported-ts-syntax */
|
|
4
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
-
};
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
1
|
+
import path from 'path';
|
|
9
2
|
const unfriendlyCodeMapper = Object.freeze({
|
|
10
3
|
UNRESOLVED_IMPORT: (loggable) => {
|
|
11
4
|
const { exporter, id } = loggable;
|
|
12
|
-
const { base: extension } =
|
|
5
|
+
const { base: extension } = path.parse(id);
|
|
13
6
|
return {
|
|
14
7
|
message: `${exporter} is imported by ${extension}, but ${exporter} cannot be resolved. Make sure ${exporter} is installed.`,
|
|
15
8
|
level: 'error',
|
|
@@ -37,8 +30,7 @@ function friendlyLoggingPlugin({ logger }) {
|
|
|
37
30
|
};
|
|
38
31
|
}
|
|
39
32
|
function _mapMessageToFriendlyVersion(loggable) {
|
|
40
|
-
var _a, _b;
|
|
41
33
|
const { code } = loggable;
|
|
42
|
-
return
|
|
34
|
+
return unfriendlyCodeMapper[code]?.(loggable) ?? {};
|
|
43
35
|
}
|
|
44
|
-
|
|
36
|
+
export default friendlyLoggingPlugin;
|