@hubspot/ui-extensions-dev-server 0.8.9 → 0.8.11
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/DevModeInterface.d.ts +10 -7
- package/dist/lib/DevModeInterface.js +25 -11
- package/dist/lib/DevServerState.d.ts +8 -3
- package/dist/lib/DevServerState.js +4 -2
- package/dist/lib/build.js +3 -3
- package/dist/lib/extensionsService.d.ts +1 -3
- package/dist/lib/plugins/codeBlockingPlugin.d.ts +4 -1
- package/dist/lib/plugins/codeBlockingPlugin.js +3 -5
- package/dist/lib/plugins/codeCheckingPlugin.d.ts +2 -0
- package/dist/lib/plugins/codeCheckingPlugin.js +3 -5
- package/dist/lib/plugins/devBuildPlugin.js +15 -12
- package/dist/lib/plugins/friendlyLoggingPlugin.d.ts +6 -3
- package/dist/lib/plugins/friendlyLoggingPlugin.js +2 -4
- package/dist/lib/plugins/relevantModulesPlugin.d.ts +2 -0
- package/dist/lib/plugins/relevantModulesPlugin.js +3 -5
- package/dist/lib/server.js +5 -7
- package/dist/lib/types.d.ts +6 -0
- package/package.json +4 -4
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import type { ExtensionConfig, PlatformVersion, ProjectComponentMap } from './types';
|
|
2
|
-
import type { ServiceConfiguration } from '@hubspot/app-functions-dev-server/dist/types';
|
|
1
|
+
import type { ExtensionConfig, Logger, PlatformVersion, ProjectComponentMap } from './types';
|
|
3
2
|
import { PromptModule } from 'inquirer';
|
|
4
3
|
import { DevServerState } from './DevServerState';
|
|
5
4
|
interface SetupArguments {
|
|
6
5
|
components: ProjectComponentMap;
|
|
7
|
-
debug?: boolean;
|
|
8
6
|
extensionConfig?: ExtensionConfig;
|
|
9
7
|
onUploadRequired?: VoidFunction;
|
|
10
8
|
promptUser: PromptModule;
|
|
9
|
+
logger: Logger;
|
|
10
|
+
urls: {
|
|
11
|
+
api: string;
|
|
12
|
+
web: string;
|
|
13
|
+
};
|
|
11
14
|
}
|
|
12
15
|
interface ProjectConfig {
|
|
13
16
|
name: string;
|
|
@@ -16,8 +19,6 @@ interface ProjectConfig {
|
|
|
16
19
|
}
|
|
17
20
|
interface StartArguments {
|
|
18
21
|
accountId?: number;
|
|
19
|
-
debug?: boolean;
|
|
20
|
-
httpClient?: ServiceConfiguration['httpClient'];
|
|
21
22
|
requestPorts?: (requestPortsData: Array<{
|
|
22
23
|
instanceId: string;
|
|
23
24
|
port?: number;
|
|
@@ -35,11 +36,13 @@ declare class DevModeInterface {
|
|
|
35
36
|
devServerState?: DevServerState;
|
|
36
37
|
onUploadRequired?: VoidFunction;
|
|
37
38
|
shutdown?: () => Promise<void>;
|
|
39
|
+
logger: Logger;
|
|
40
|
+
urls?: SetupArguments['urls'];
|
|
38
41
|
_generateAppExtensionMappings(components: ProjectComponentMap): AppExtensionMapping[];
|
|
39
42
|
_getPlatformVersion(projectConfig?: ProjectConfig): PlatformVersion;
|
|
40
|
-
setup({ components,
|
|
43
|
+
setup({ components, extensionConfig, onUploadRequired, promptUser, logger, urls, }: SetupArguments): Promise<void>;
|
|
41
44
|
fileChange(filePath: string, __event: unknown): Promise<void>;
|
|
42
|
-
start({ requestPorts, accountId,
|
|
45
|
+
start({ requestPorts, accountId, projectConfig }: StartArguments): Promise<void>;
|
|
43
46
|
cleanup(): Promise<void>;
|
|
44
47
|
}
|
|
45
48
|
declare const _default: DevModeInterface;
|
|
@@ -15,11 +15,26 @@ const dev_1 = require("./dev");
|
|
|
15
15
|
const constants_1 = require("./constants");
|
|
16
16
|
const constants_2 = require("./constants");
|
|
17
17
|
const config_1 = require("./config");
|
|
18
|
-
// @ts-expect-error no type defs
|
|
19
|
-
const logger_1 = require("@hubspot/cli-lib/logger");
|
|
20
18
|
const DevServerState_1 = require("./DevServerState");
|
|
21
19
|
const utils_1 = require("./utils");
|
|
20
|
+
const defaultLogger = {
|
|
21
|
+
info: (...args) => {
|
|
22
|
+
console.log(...args);
|
|
23
|
+
},
|
|
24
|
+
debug: (...args) => {
|
|
25
|
+
console.log(...args);
|
|
26
|
+
},
|
|
27
|
+
warn: (...args) => {
|
|
28
|
+
console.error(...args);
|
|
29
|
+
},
|
|
30
|
+
error: (...args) => {
|
|
31
|
+
console.error(...args);
|
|
32
|
+
},
|
|
33
|
+
};
|
|
22
34
|
class DevModeInterface {
|
|
35
|
+
constructor() {
|
|
36
|
+
this.logger = defaultLogger;
|
|
37
|
+
}
|
|
23
38
|
_generateAppExtensionMappings(components) {
|
|
24
39
|
// Loop over all of the app configs that are passed in
|
|
25
40
|
const allComponentNames = Object.keys(components);
|
|
@@ -57,10 +72,11 @@ class DevModeInterface {
|
|
|
57
72
|
return (0, utils_1.throwUnhandledPlatformVersionError)(platformVersion);
|
|
58
73
|
}
|
|
59
74
|
}
|
|
60
|
-
setup({ components,
|
|
75
|
+
setup({ components, extensionConfig, onUploadRequired, promptUser, logger, urls, }) {
|
|
61
76
|
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
|
|
77
|
+
this.logger = logger;
|
|
63
78
|
this.onUploadRequired = onUploadRequired;
|
|
79
|
+
this.urls = urls;
|
|
64
80
|
if (extensionConfig) {
|
|
65
81
|
this.configs = [extensionConfig];
|
|
66
82
|
return;
|
|
@@ -106,11 +122,8 @@ class DevModeInterface {
|
|
|
106
122
|
}
|
|
107
123
|
});
|
|
108
124
|
}
|
|
109
|
-
start({ requestPorts, accountId,
|
|
125
|
+
start({ requestPorts, accountId, projectConfig }) {
|
|
110
126
|
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
-
if (debug !== undefined) {
|
|
112
|
-
(0, logger_1.setLogLevel)(debug ? logger_1.LOG_LEVEL.DEBUG : logger_1.LOG_LEVEL.LOG);
|
|
113
|
-
}
|
|
114
127
|
let expressPort = constants_1.EXPRESS_DEFAULT_PORT;
|
|
115
128
|
let webSocketPort = constants_1.WEBSOCKET_DEFAULT_PORT;
|
|
116
129
|
if (requestPorts) {
|
|
@@ -123,21 +136,22 @@ class DevModeInterface {
|
|
|
123
136
|
webSocketPort = portData[constants_1.VITE_DEV_SERVER_ID];
|
|
124
137
|
}
|
|
125
138
|
catch (e) {
|
|
126
|
-
|
|
139
|
+
this.logger.debug('Call to port manager failed, using default ports');
|
|
127
140
|
}
|
|
128
141
|
}
|
|
129
142
|
this.devServerState = new DevServerState_1.DevServerState({
|
|
130
143
|
extensionConfigs: this.configs,
|
|
131
144
|
accountId,
|
|
132
|
-
httpClient,
|
|
133
145
|
platformVersion: this._getPlatformVersion(projectConfig),
|
|
134
146
|
expressPort,
|
|
135
147
|
webSocketPort,
|
|
148
|
+
logger: this.logger,
|
|
149
|
+
urls: this.urls,
|
|
136
150
|
});
|
|
137
151
|
this.shutdown = yield (0, dev_1.startDevMode)(this.devServerState);
|
|
138
152
|
this.devServerState.extensionsMetadata.forEach((metadata) => {
|
|
139
153
|
const { config: { data: { title, appName }, }, } = metadata;
|
|
140
|
-
|
|
154
|
+
this.logger.info(`Running extension '${title}' from app '${appName}'`);
|
|
141
155
|
});
|
|
142
156
|
});
|
|
143
157
|
}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import { ExtensionConfig, ExtensionMetadata, PlatformVersion } from './types';
|
|
1
|
+
import { ExtensionConfig, ExtensionMetadata, Logger, PlatformVersion } from './types';
|
|
2
2
|
import { ServiceConfiguration } from '@hubspot/app-functions-dev-server/dist/types';
|
|
3
3
|
interface DevServerStateArgs {
|
|
4
4
|
extensionConfigs?: ExtensionConfig[];
|
|
5
5
|
accountId: number | undefined;
|
|
6
|
-
httpClient: ServiceConfiguration['httpClient'] | undefined;
|
|
7
6
|
expressPort: number;
|
|
8
7
|
webSocketPort: number;
|
|
9
8
|
platformVersion: PlatformVersion;
|
|
9
|
+
logger: Logger;
|
|
10
|
+
urls: {
|
|
11
|
+
api: string;
|
|
12
|
+
web: string;
|
|
13
|
+
};
|
|
10
14
|
}
|
|
11
15
|
export declare class DevServerState {
|
|
12
16
|
private _webSocketPort;
|
|
@@ -16,7 +20,8 @@ export declare class DevServerState {
|
|
|
16
20
|
private _appPath;
|
|
17
21
|
private _extensionsMetadata;
|
|
18
22
|
private _portalId?;
|
|
19
|
-
|
|
23
|
+
logger: Logger;
|
|
24
|
+
constructor({ extensionConfigs, accountId, expressPort, webSocketPort, platformVersion, logger, urls, }: DevServerStateArgs);
|
|
20
25
|
get portalId(): number | undefined;
|
|
21
26
|
get webSocketPort(): number;
|
|
22
27
|
get expressPort(): number;
|
|
@@ -7,7 +7,7 @@ exports.DevServerState = void 0;
|
|
|
7
7
|
const constants_1 = require("./constants");
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
class DevServerState {
|
|
10
|
-
constructor({ extensionConfigs, accountId,
|
|
10
|
+
constructor({ extensionConfigs, accountId, expressPort, webSocketPort, platformVersion, logger, urls, }) {
|
|
11
11
|
if (!extensionConfigs) {
|
|
12
12
|
throw new Error('Unable to load the required extension configuration files');
|
|
13
13
|
}
|
|
@@ -35,9 +35,11 @@ class DevServerState {
|
|
|
35
35
|
this._functionsConfig = {
|
|
36
36
|
app: { path: this._appPath },
|
|
37
37
|
accountId,
|
|
38
|
-
httpClient,
|
|
39
38
|
platformVersion,
|
|
39
|
+
hubspotApiOrigin: urls.api,
|
|
40
|
+
hubspotWebsiteOrigin: urls.web,
|
|
40
41
|
};
|
|
42
|
+
this.logger = logger;
|
|
41
43
|
Object.freeze(this);
|
|
42
44
|
}
|
|
43
45
|
get portalId() {
|
package/dist/lib/build.js
CHANGED
|
@@ -18,8 +18,8 @@ const constants_1 = require("./constants");
|
|
|
18
18
|
const manifestPlugin_1 = __importDefault(require("./plugins/manifestPlugin"));
|
|
19
19
|
const path_1 = __importDefault(require("path"));
|
|
20
20
|
const utils_1 = require("./utils");
|
|
21
|
-
const codeInjectionPlugin_1 = __importDefault(require("./plugins/codeInjectionPlugin"));
|
|
22
21
|
const codeBlockingPlugin_1 = __importDefault(require("./plugins/codeBlockingPlugin"));
|
|
22
|
+
const friendlyLoggingPlugin_1 = __importDefault(require("./plugins/friendlyLoggingPlugin"));
|
|
23
23
|
const allowedExtensions = ['.js', '.ts', '.tsx', '.jsx'];
|
|
24
24
|
exports.extensionErrorBaseMessage = `Supported file extensions are [${allowedExtensions.join(', ')}], received:`;
|
|
25
25
|
function buildSingleExtension({ file, outputDir = constants_1.OUTPUT_DIR, emptyOutDir = true, minify = false, root = process.cwd(), // This is the vite default, so using that as our default
|
|
@@ -40,8 +40,8 @@ function buildSingleExtension({ file, outputDir = constants_1.OUTPUT_DIR, emptyO
|
|
|
40
40
|
},
|
|
41
41
|
rollupOptions: Object.assign(Object.assign({}, constants_1.ROLLUP_OPTIONS), { plugins: [
|
|
42
42
|
(0, manifestPlugin_1.default)({ output, extensionPath: root }),
|
|
43
|
-
(0,
|
|
44
|
-
(0, codeBlockingPlugin_1.default)(),
|
|
43
|
+
(0, friendlyLoggingPlugin_1.default)({ logger: console }),
|
|
44
|
+
(0, codeBlockingPlugin_1.default)({ logger: console }),
|
|
45
45
|
] }),
|
|
46
46
|
outDir: outputDir,
|
|
47
47
|
emptyOutDir,
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { Response } from 'express/lib/response';
|
|
2
|
-
import { Request } from 'express/lib/request';
|
|
3
|
-
import { Application } from 'express/lib/application';
|
|
4
1
|
import { DevServerState } from './DevServerState';
|
|
2
|
+
import { Request, Response, Application } from 'express';
|
|
5
3
|
declare class ExtensionsService {
|
|
6
4
|
endpoint: string;
|
|
7
5
|
constructor();
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { Rollup } from 'vite';
|
|
2
|
-
|
|
2
|
+
import { Logger } from '../types';
|
|
3
|
+
export type CodeBlockingPlugin = ({ logger, }: {
|
|
4
|
+
logger: Logger;
|
|
5
|
+
}) => Rollup.Plugin;
|
|
3
6
|
declare const codeBlockingPlugin: CodeBlockingPlugin;
|
|
4
7
|
export default codeBlockingPlugin;
|
|
@@ -3,9 +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
|
-
|
|
7
|
-
const logger_1 = require("@hubspot/cli-lib/logger");
|
|
8
|
-
const codeBlockingPlugin = () => {
|
|
6
|
+
const codeBlockingPlugin = ({ logger }) => {
|
|
9
7
|
return {
|
|
10
8
|
name: 'ui-extensions-code-blocking-plugin',
|
|
11
9
|
enforce: 'post',
|
|
@@ -25,12 +23,12 @@ const codeBlockingPlugin = () => {
|
|
|
25
23
|
]);
|
|
26
24
|
}
|
|
27
25
|
catch (e) {
|
|
28
|
-
|
|
26
|
+
logger.debug('Unable to parse and traverse source code');
|
|
29
27
|
return { code, map: null };
|
|
30
28
|
}
|
|
31
29
|
if (sourceCodeMetadata.functions[requireFunctionName] &&
|
|
32
30
|
sourceCodeMetadata.functions[requireFunctionName].scope === 'Global') {
|
|
33
|
-
|
|
31
|
+
logger.warn('require statements are not supported, replace require statements with import');
|
|
34
32
|
}
|
|
35
33
|
return { code, map: null };
|
|
36
34
|
},
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Rollup } from 'vite';
|
|
2
|
+
import { Logger } from '../types';
|
|
2
3
|
export interface CodeCheckingPluginOptions {
|
|
3
4
|
output: string;
|
|
5
|
+
logger: Logger;
|
|
4
6
|
}
|
|
5
7
|
export type CodeCheckingPlugin = (options: CodeCheckingPluginOptions) => Rollup.Plugin;
|
|
6
8
|
declare const codeCheckingPlugin: CodeCheckingPlugin;
|
|
@@ -4,10 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const fs_1 = __importDefault(require("fs"));
|
|
7
|
-
// @ts-expect-error no type defs for the logger
|
|
8
|
-
const logger_1 = require("@hubspot/cli-lib/logger");
|
|
9
7
|
const codeCheckingPlugin = (options) => {
|
|
10
|
-
const { output } = options;
|
|
8
|
+
const { output, logger } = options;
|
|
11
9
|
return {
|
|
12
10
|
name: 'ui-extensions-code-checking-plugin',
|
|
13
11
|
enforce: 'post',
|
|
@@ -16,11 +14,11 @@ const codeCheckingPlugin = (options) => {
|
|
|
16
14
|
const code = fs_1.default.readFileSync(output).toString();
|
|
17
15
|
if (!code.includes('const extend = (...args) => self.extend(...args);') &&
|
|
18
16
|
!code.includes('self.extend_V2(renderExtensionCallback)')) {
|
|
19
|
-
|
|
17
|
+
logger.warn('Unable to determine if your extension entry point is calling hubspot.extend, this may prevent it from rendering as expected');
|
|
20
18
|
}
|
|
21
19
|
}
|
|
22
20
|
catch (e) {
|
|
23
|
-
|
|
21
|
+
logger.error('Unable to load bundle for code checking');
|
|
24
22
|
}
|
|
25
23
|
},
|
|
26
24
|
};
|
|
@@ -43,8 +43,6 @@ const manifestPlugin_1 = __importDefault(require("./manifestPlugin"));
|
|
|
43
43
|
const utils_1 = require("../utils");
|
|
44
44
|
const codeCheckingPlugin_1 = __importDefault(require("./codeCheckingPlugin"));
|
|
45
45
|
const path_1 = __importDefault(require("path"));
|
|
46
|
-
// @ts-expect-error no type defs
|
|
47
|
-
const logger_1 = require("@hubspot/cli-lib/logger");
|
|
48
46
|
const friendlyLoggingPlugin_1 = __importDefault(require("./friendlyLoggingPlugin"));
|
|
49
47
|
const relevantModulesPlugin_1 = __importStar(require("./relevantModulesPlugin"));
|
|
50
48
|
const codeBlockingPlugin_1 = __importDefault(require("./codeBlockingPlugin"));
|
|
@@ -53,6 +51,7 @@ function addVersionToBaseMessage(baseMessage) {
|
|
|
53
51
|
}
|
|
54
52
|
const devBuildPlugin = (options) => {
|
|
55
53
|
const { devServerState } = options;
|
|
54
|
+
const { logger } = devServerState;
|
|
56
55
|
let lastBuildErrorContext;
|
|
57
56
|
const handleBuildError = (error, server) => {
|
|
58
57
|
const { error: { plugin, errors, frame, loc, id }, extensionMetadata, } = error;
|
|
@@ -100,10 +99,14 @@ const devBuildPlugin = (options) => {
|
|
|
100
99
|
}),
|
|
101
100
|
(0, codeCheckingPlugin_1.default)({
|
|
102
101
|
output: path_1.default.join(devServerState.outputDir, extensionConfig.output),
|
|
102
|
+
logger,
|
|
103
103
|
}),
|
|
104
|
-
(0, friendlyLoggingPlugin_1.default)(),
|
|
105
|
-
(0, relevantModulesPlugin_1.default)({
|
|
106
|
-
|
|
104
|
+
(0, friendlyLoggingPlugin_1.default)({ logger }),
|
|
105
|
+
(0, relevantModulesPlugin_1.default)({
|
|
106
|
+
output: extensionConfig.output,
|
|
107
|
+
logger,
|
|
108
|
+
}),
|
|
109
|
+
(0, codeBlockingPlugin_1.default)({ logger }),
|
|
107
110
|
], output: Object.assign(Object.assign({}, constants_1.ROLLUP_OPTIONS.output), { sourcemap: 'inline' }) }),
|
|
108
111
|
outDir: devServerState.outputDir,
|
|
109
112
|
emptyOutDir,
|
|
@@ -119,7 +122,7 @@ const devBuildPlugin = (options) => {
|
|
|
119
122
|
error: error,
|
|
120
123
|
extensionMetadata,
|
|
121
124
|
};
|
|
122
|
-
|
|
125
|
+
logger.debug(error);
|
|
123
126
|
handleBuildError(lastBuildErrorContext, server);
|
|
124
127
|
return false;
|
|
125
128
|
}
|
|
@@ -133,7 +136,7 @@ const devBuildPlugin = (options) => {
|
|
|
133
136
|
// See https://vitejs.dev/guide/api-plugin.html#configureserver for information on this pattern
|
|
134
137
|
localServer = server;
|
|
135
138
|
localServer.ws.on('connection', () => {
|
|
136
|
-
|
|
139
|
+
logger.info('Browser connected and listening for bundle updates');
|
|
137
140
|
devServerState.extensionsMetadata.forEach((metadata) => {
|
|
138
141
|
// @ts-expect-error Our websocket messages don't match Vite format
|
|
139
142
|
localServer.ws.send(Object.assign(Object.assign({}, addVersionToBaseMessage(metadata.baseMessage)), { event: 'start' }));
|
|
@@ -159,12 +162,12 @@ const devBuildPlugin = (options) => {
|
|
|
159
162
|
return [];
|
|
160
163
|
}
|
|
161
164
|
const { config: extensionConfig } = toRebuild;
|
|
162
|
-
|
|
165
|
+
logger.info(`Extension ${extensionConfig.data.title} updated, compiled`);
|
|
163
166
|
if (server.ws.clients.size === 0) {
|
|
164
|
-
|
|
167
|
+
logger.debug('Bundle updated, no browsers connected to notify');
|
|
165
168
|
return [];
|
|
166
169
|
}
|
|
167
|
-
|
|
170
|
+
logger.debug('Bundle updated, notifying connected browsers');
|
|
168
171
|
// @ts-expect-error Our websocket messages don't match Vite format
|
|
169
172
|
server.ws.send(Object.assign(Object.assign({}, addVersionToBaseMessage(toRebuild.baseMessage)), { event: 'update' }));
|
|
170
173
|
}
|
|
@@ -172,10 +175,10 @@ const devBuildPlugin = (options) => {
|
|
|
172
175
|
}),
|
|
173
176
|
buildEnd(error) {
|
|
174
177
|
if (error) {
|
|
175
|
-
|
|
178
|
+
logger.error(error);
|
|
176
179
|
}
|
|
177
180
|
if (localServer && localServer.ws) {
|
|
178
|
-
|
|
181
|
+
logger.debug('Sending shutdown message to connected browsers');
|
|
179
182
|
devServerState.extensionsMetadata.forEach((metadata) => {
|
|
180
183
|
// @ts-expect-error Our websocket messages don't match Vite format
|
|
181
184
|
localServer.ws.send(Object.assign(Object.assign({}, addVersionToBaseMessage(metadata.baseMessage)), { event: 'shutdown' }));
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { RollupLog } from 'rollup';
|
|
1
|
+
import { RollupLog, LogLevel } from 'rollup';
|
|
2
2
|
import Vite from 'vite';
|
|
3
|
+
import { Logger } from '../types';
|
|
3
4
|
export interface MappedLog {
|
|
4
5
|
message?: string;
|
|
5
|
-
level?: 'error' |
|
|
6
|
+
level?: 'error' | LogLevel;
|
|
6
7
|
}
|
|
7
8
|
export interface CodeToLogMapper {
|
|
8
9
|
[key: string]: (loggable: RollupLog) => MappedLog;
|
|
9
10
|
}
|
|
10
|
-
declare function friendlyLoggingPlugin(
|
|
11
|
+
declare function friendlyLoggingPlugin({ logger }: {
|
|
12
|
+
logger: Logger;
|
|
13
|
+
}): Vite.Plugin;
|
|
11
14
|
export default friendlyLoggingPlugin;
|
|
@@ -5,8 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
6
|
};
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
// @ts-expect-error no type defs
|
|
9
|
-
const logger_1 = require("@hubspot/cli-lib/logger");
|
|
10
8
|
const path_1 = __importDefault(require("path"));
|
|
11
9
|
const unfriendlyCodeMapper = Object.freeze({
|
|
12
10
|
UNRESOLVED_IMPORT: (loggable) => {
|
|
@@ -22,7 +20,7 @@ const unfriendlyCodeMapper = Object.freeze({
|
|
|
22
20
|
},
|
|
23
21
|
});
|
|
24
22
|
const unfriendlyCodeList = Object.freeze(Object.keys(unfriendlyCodeMapper));
|
|
25
|
-
function friendlyLoggingPlugin() {
|
|
23
|
+
function friendlyLoggingPlugin({ logger }) {
|
|
26
24
|
return {
|
|
27
25
|
name: 'ui-extensions-friendly-logging-plugin',
|
|
28
26
|
enforce: 'post',
|
|
@@ -30,7 +28,7 @@ function friendlyLoggingPlugin() {
|
|
|
30
28
|
if (unfriendlyCodeList.includes(log.code || '')) {
|
|
31
29
|
const { message, level } = _mapMessageToFriendlyVersion(log);
|
|
32
30
|
if (message && level) {
|
|
33
|
-
|
|
31
|
+
logger[level](message);
|
|
34
32
|
}
|
|
35
33
|
return false; // Filter the log message
|
|
36
34
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import Vite from 'vite';
|
|
2
|
+
import { Logger } from '../types';
|
|
2
3
|
export interface RelevantModules {
|
|
3
4
|
[key: string]: string[];
|
|
4
5
|
}
|
|
5
6
|
export declare function getRelevantModules(output: string): string[];
|
|
6
7
|
export interface RelevantModulesPluginOptions {
|
|
7
8
|
output: string;
|
|
9
|
+
logger: Logger;
|
|
8
10
|
}
|
|
9
11
|
export type RelevantModulesPlugin = (options: RelevantModulesPluginOptions) => Vite.Plugin;
|
|
10
12
|
declare const relevantModulesPlugin: RelevantModulesPlugin;
|
|
@@ -2,26 +2,24 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getRelevantModules = void 0;
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
|
-
// @ts-expect-error no type defs for the logger
|
|
6
|
-
const logger_1 = require("@hubspot/cli-lib/logger");
|
|
7
5
|
const relevantModules = {};
|
|
8
6
|
function getRelevantModules(output) {
|
|
9
7
|
return relevantModules[output] || [];
|
|
10
8
|
}
|
|
11
9
|
exports.getRelevantModules = getRelevantModules;
|
|
12
|
-
const relevantModulesPlugin = ({ output }) => {
|
|
10
|
+
const relevantModulesPlugin = ({ output, logger }) => {
|
|
13
11
|
return {
|
|
14
12
|
name: 'ui-extensions-relevant-modules-plugin',
|
|
15
13
|
generateBundle(_options, bundle) {
|
|
16
14
|
const subBundle = bundle[output];
|
|
17
15
|
if (!subBundle || !subBundle.moduleIds) {
|
|
18
16
|
// If this happens, something has gone horribly wrong
|
|
19
|
-
|
|
17
|
+
logger.error('Invalid bundle format, please try saving the extension again. If the problem persists try restarting `hs project dev`');
|
|
20
18
|
return;
|
|
21
19
|
}
|
|
22
20
|
const updatedRelevantModules = subBundle.moduleIds.filter((moduleId) => !(0, utils_1.isNodeModule)(moduleId));
|
|
23
21
|
if (updatedRelevantModules.length === 0) {
|
|
24
|
-
|
|
22
|
+
logger.error('Unable to determine relevant files to watch, please try saving the extension again. If the problem persists try restarting `hs project dev`');
|
|
25
23
|
return;
|
|
26
24
|
}
|
|
27
25
|
relevantModules[output] = updatedRelevantModules;
|
package/dist/lib/server.js
CHANGED
|
@@ -19,8 +19,6 @@ const cors_1 = __importDefault(require("cors"));
|
|
|
19
19
|
const constants_1 = require("./constants");
|
|
20
20
|
const extensionsService_1 = __importDefault(require("./extensionsService"));
|
|
21
21
|
const app_functions_dev_server_1 = require("@hubspot/app-functions-dev-server");
|
|
22
|
-
// @ts-expect-error no type defs
|
|
23
|
-
const logger_1 = require("@hubspot/cli-lib/logger");
|
|
24
22
|
function listen(app, port) {
|
|
25
23
|
return new Promise((resolve, reject) => {
|
|
26
24
|
const server = app
|
|
@@ -39,12 +37,12 @@ function startDevServer({ devServerState, viteDevServer, }) {
|
|
|
39
37
|
// Setup middleware
|
|
40
38
|
app.use((0, cors_1.default)());
|
|
41
39
|
app.use(express_1.default.static(devServerState.outputDir));
|
|
42
|
-
app.use('/api/crm-extensibility/execution/internal/v3', (0, app_functions_dev_server_1.AppFunctionExecutionService)(Object.assign(Object.assign({}, devServerState.functionsConfig), { logger:
|
|
43
|
-
|
|
40
|
+
app.use('/api/crm-extensibility/execution/internal/v3', (0, app_functions_dev_server_1.AppFunctionExecutionService)(Object.assign(Object.assign({}, devServerState.functionsConfig), { logger: devServerState.logger })));
|
|
41
|
+
devServerState.logger.info(`Serving app functions locally (platform version ${devServerState.functionsConfig.platformVersion})`);
|
|
44
42
|
const endpointsAdded = extensionsService_1.default.add(app, devServerState, constants_1.SERVER_CAPABILITIES);
|
|
45
43
|
const { expressPort } = devServerState;
|
|
46
44
|
endpointsAdded.forEach((endpoint) => {
|
|
47
|
-
|
|
45
|
+
devServerState.logger.debug(`Listening at http://hslocal.net:${expressPort}${endpoint}`);
|
|
48
46
|
});
|
|
49
47
|
// Vite middlewares needs to go last because it's greedy and will block other middleware
|
|
50
48
|
app.use(viteDevServer.middlewares);
|
|
@@ -60,14 +58,14 @@ function startDevServer({ devServerState, viteDevServer, }) {
|
|
|
60
58
|
}
|
|
61
59
|
(_a = devServerState.extensionsMetadata) === null || _a === void 0 ? void 0 : _a.forEach((metadata) => {
|
|
62
60
|
const { baseMessage } = metadata;
|
|
63
|
-
|
|
61
|
+
devServerState.logger.debug(`Listening at ${baseMessage.callback}`);
|
|
64
62
|
});
|
|
65
63
|
return function shutdown() {
|
|
66
64
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
65
|
yield viteDevServer.pluginContainer.close();
|
|
68
66
|
// Stop new connections to express server
|
|
69
67
|
server.close(() => { });
|
|
70
|
-
|
|
68
|
+
devServerState.logger.info('Extension dev server done cleaning up');
|
|
71
69
|
});
|
|
72
70
|
};
|
|
73
71
|
});
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -71,4 +71,10 @@ export interface FunctionInvocationCheck {
|
|
|
71
71
|
functionName: string;
|
|
72
72
|
}
|
|
73
73
|
export type SourceCodeChecks = FunctionInvocationCheck[];
|
|
74
|
+
export interface Logger {
|
|
75
|
+
info: (...args: any[]) => void;
|
|
76
|
+
debug: (...args: any[]) => void;
|
|
77
|
+
warn: (...args: any[]) => void;
|
|
78
|
+
error: (...args: any[]) => void;
|
|
79
|
+
}
|
|
74
80
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/ui-extensions-dev-server",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.11",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jest",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
],
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@hubspot/app-functions-dev-server": "^0.8.
|
|
28
|
+
"@hubspot/app-functions-dev-server": "^0.8.11",
|
|
29
29
|
"@hubspot/cli-lib": "^4.1.6",
|
|
30
30
|
"command-line-args": "^5.2.1",
|
|
31
31
|
"command-line-usage": "^7.0.1",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/estree": "^1.0.5",
|
|
42
|
-
"@types/express": "
|
|
42
|
+
"@types/express": "^4.17.17",
|
|
43
43
|
"@types/inquirer": "^9.0.3",
|
|
44
44
|
"@types/jest": "^29.5.4",
|
|
45
45
|
"acorn": "^8.11.2",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"optional": true
|
|
68
68
|
}
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "67d77644bf3e0748827773954c3c8024699f2717"
|
|
71
71
|
}
|