@hubspot/ui-extensions-dev-server 1.1.0 → 1.1.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.
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/lib/DevModeInterface.d.ts +9 -0
- package/dist/lib/DevModeInterface.js +36 -0
- package/dist/lib/DevModeParentInterface.d.ts +19 -0
- package/dist/lib/DevModeParentInterface.js +181 -0
- package/dist/lib/DevModeUnifiedInterface.d.ts +9 -0
- package/dist/lib/DevModeUnifiedInterface.js +118 -0
- package/dist/lib/DevServerState.d.ts +44 -0
- package/dist/lib/DevServerState.js +95 -0
- 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 +124 -0
- package/dist/lib/__tests__/plugins/devBuildPlugin.spec.d.ts +1 -0
- package/dist/lib/__tests__/plugins/devBuildPlugin.spec.js +396 -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 +115 -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 +16 -0
- package/dist/lib/ast.js +281 -0
- package/dist/lib/bin/cli.d.ts +2 -0
- package/dist/lib/bin/cli.js +143 -0
- package/dist/lib/build.d.ts +24 -0
- package/dist/lib/build.js +73 -0
- package/dist/lib/config.d.ts +7 -0
- package/dist/lib/config.js +124 -0
- package/dist/lib/constants.d.ts +32 -0
- package/dist/lib/constants.js +43 -0
- package/dist/lib/dev.d.ts +2 -0
- package/dist/lib/dev.js +58 -0
- package/dist/lib/extensionsService.d.ts +10 -0
- package/dist/lib/extensionsService.js +45 -0
- package/dist/lib/parsing-utils.d.ts +31 -0
- package/dist/lib/parsing-utils.js +289 -0
- package/dist/lib/plugins/codeBlockingPlugin.d.ts +8 -0
- package/dist/lib/plugins/codeBlockingPlugin.js +45 -0
- package/dist/lib/plugins/codeCheckingPlugin.d.ts +8 -0
- package/dist/lib/plugins/codeCheckingPlugin.js +93 -0
- package/dist/lib/plugins/devBuildPlugin.d.ts +8 -0
- package/dist/lib/plugins/devBuildPlugin.js +212 -0
- package/dist/lib/plugins/friendlyLoggingPlugin.d.ts +14 -0
- package/dist/lib/plugins/friendlyLoggingPlugin.js +36 -0
- package/dist/lib/plugins/manifestPlugin.d.ts +12 -0
- package/dist/lib/plugins/manifestPlugin.js +158 -0
- package/dist/lib/plugins/relevantModulesPlugin.d.ts +14 -0
- package/dist/lib/plugins/relevantModulesPlugin.js +33 -0
- package/dist/lib/server.d.ts +13 -0
- package/dist/lib/server.js +99 -0
- package/dist/lib/types.d.ts +290 -0
- package/dist/lib/types.js +12 -0
- package/dist/lib/utils.d.ts +25 -0
- package/dist/lib/utils.js +113 -0
- package/package.json +2 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AppConfig, ExtensionConfig } from './types.ts';
|
|
2
|
+
export declare function getUrlSafeFileName(filePath: string): string;
|
|
3
|
+
export declare function stripAnsiColorCodes(stringWithColorCodes: string | undefined | null): string | null;
|
|
4
|
+
export declare function loadManifest(outputDir: string, output: string): any;
|
|
5
|
+
export declare function buildSourceId(appConfig: AppConfig, extensionConfig: ExtensionConfig): string | null;
|
|
6
|
+
export declare function isNodeModule(filepath: string | undefined): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Check if a given file is within the extension path
|
|
9
|
+
*/
|
|
10
|
+
export declare function isExtensionFile(filepath: string | undefined, extensionPath: string): boolean;
|
|
11
|
+
export declare class UnhandledPlatformVersionError extends Error {
|
|
12
|
+
constructor(platformVersion: never);
|
|
13
|
+
}
|
|
14
|
+
export declare function throwUnhandledPlatformVersionError(platformVersion: never): never;
|
|
15
|
+
export declare function extractAllowedUrls(appConfig?: AppConfig): string[];
|
|
16
|
+
/**
|
|
17
|
+
* This function generates a deterministic hash from any number of arguments
|
|
18
|
+
* Arrays and objects are stringified to ensure it works for all types.
|
|
19
|
+
* Uses the same simple hash algorithm as the browser version for consistency.
|
|
20
|
+
*/
|
|
21
|
+
export declare function generateHash(...args: unknown[]): string;
|
|
22
|
+
/**
|
|
23
|
+
* Check if a given URL is an image (of a type we support)
|
|
24
|
+
*/
|
|
25
|
+
export declare function isImage(url: string): boolean;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { MANIFEST_FILE } from "./constants.js";
|
|
4
|
+
export function getUrlSafeFileName(filePath) {
|
|
5
|
+
const { name } = path.parse(filePath);
|
|
6
|
+
return encodeURIComponent(`${name}.js`);
|
|
7
|
+
}
|
|
8
|
+
// Strips ANSI color codes out of strings because we don't want to pass them to the browser
|
|
9
|
+
export function stripAnsiColorCodes(stringWithColorCodes) {
|
|
10
|
+
if (!stringWithColorCodes) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
return stringWithColorCodes.replace(
|
|
14
|
+
// eslint-disable-next-line no-control-regex
|
|
15
|
+
/[\u001b][[]*([0-9]{1,4};?)*[m]/g, '');
|
|
16
|
+
}
|
|
17
|
+
export function loadManifest(outputDir, output) {
|
|
18
|
+
try {
|
|
19
|
+
return JSON.parse(fs
|
|
20
|
+
.readFileSync(path.join(outputDir, `${output}-${MANIFEST_FILE}`))
|
|
21
|
+
.toString());
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function buildSourceId(appConfig, extensionConfig) {
|
|
28
|
+
if (appConfig.uid && extensionConfig.data.uid) {
|
|
29
|
+
return `${appConfig.uid}::${extensionConfig.data.uid}`;
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
export function isNodeModule(filepath) {
|
|
34
|
+
if (!filepath) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const directory = path.parse(filepath).dir;
|
|
38
|
+
return directory.includes('node_modules');
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Check if a given file is within the extension path
|
|
42
|
+
*/
|
|
43
|
+
export function isExtensionFile(filepath, extensionPath) {
|
|
44
|
+
if (!filepath) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const absoluteFilePath = fs.realpathSync(filepath);
|
|
49
|
+
const absoluteExtensionDirPath = fs.realpathSync(extensionPath);
|
|
50
|
+
const relativePath = path.relative(absoluteExtensionDirPath, absoluteFilePath);
|
|
51
|
+
return !relativePath.startsWith('..') && !path.isAbsolute(relativePath);
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
console.log(`Error checking if ${filepath} is in extension path: ${e}`);
|
|
55
|
+
// If there's an error, we can't determine if the file is in the extension path, so return false.
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export class UnhandledPlatformVersionError extends Error {
|
|
60
|
+
constructor(platformVersion) {
|
|
61
|
+
super(`Unsupported platform version "${platformVersion}"`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export function throwUnhandledPlatformVersionError(platformVersion) {
|
|
65
|
+
throw new UnhandledPlatformVersionError(platformVersion);
|
|
66
|
+
}
|
|
67
|
+
export function extractAllowedUrls(appConfig) {
|
|
68
|
+
if (!appConfig || !('allowedUrls' in appConfig) || !appConfig.allowedUrls) {
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
return appConfig.allowedUrls;
|
|
72
|
+
}
|
|
73
|
+
function simpleHash(input) {
|
|
74
|
+
let hash = 0;
|
|
75
|
+
for (let i = 0; i < input.length; i++) {
|
|
76
|
+
const char = input.charCodeAt(i);
|
|
77
|
+
hash = (hash * 31 + char) % 2147483647;
|
|
78
|
+
}
|
|
79
|
+
return Math.abs(hash).toString(16);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* This function generates a deterministic hash from any number of arguments
|
|
83
|
+
* Arrays and objects are stringified to ensure it works for all types.
|
|
84
|
+
* Uses the same simple hash algorithm as the browser version for consistency.
|
|
85
|
+
*/
|
|
86
|
+
export function generateHash(...args) {
|
|
87
|
+
try {
|
|
88
|
+
// First make sure all the values are strings
|
|
89
|
+
const normalizedArgs = args.map((arg) => {
|
|
90
|
+
if (Array.isArray(arg)) {
|
|
91
|
+
return [...arg].sort().join('-');
|
|
92
|
+
}
|
|
93
|
+
if (arg && typeof arg === 'object') {
|
|
94
|
+
return JSON.stringify(arg, Object.keys(arg).sort());
|
|
95
|
+
}
|
|
96
|
+
return String(arg);
|
|
97
|
+
});
|
|
98
|
+
// Return the hash of the joined strings.
|
|
99
|
+
const input = [...normalizedArgs].join('::');
|
|
100
|
+
return simpleHash(input);
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
console.error('Error generating hash: ', e);
|
|
104
|
+
// Just return an empty string if anything goes wrong.
|
|
105
|
+
return '';
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Check if a given URL is an image (of a type we support)
|
|
110
|
+
*/
|
|
111
|
+
export function isImage(url) {
|
|
112
|
+
return /\.(png|jpg|jpeg|gif|svg|webp|avif|raw|url|inline)$/.test(url);
|
|
113
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/ui-extensions-dev-server",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"build": "npm run clean && tsc",
|
|
13
13
|
"watch": "npm run clean && tsc --watch",
|
|
14
14
|
"prepare": "husky",
|
|
15
|
+
"prepublishOnly": "npm run build",
|
|
15
16
|
"prettier:write": "prettier --write '**/*.{ts,js,json}'",
|
|
16
17
|
"lint": "echo 'Linting is disabled for Blazar'",
|
|
17
18
|
"lint:local": "eslint . && prettier --check '**/*.{ts,js,json}'",
|