Skip to content

Commit 1c9cef4

Browse files
committed
Replace jsdom with node-html-parser for better bundling
1 parent d91e764 commit 1c9cef4

File tree

6 files changed

+89
-373
lines changed

6 files changed

+89
-373
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@mcp-pointer/server": patch
3+
---
4+
5+
Replace jsdom with node-html-parser for better bundling
6+
7+
- Reduced bundle size
8+
- Fixes bundling issues with esbuild
9+
- faster HTML parsing

packages/server/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@
2525
"dependencies": {
2626
"@modelcontextprotocol/sdk": "^0.5.0",
2727
"commander": "^11.1.0",
28-
"jsdom": "^27.0.0",
28+
"node-html-parser": "^7.0.1",
2929
"ws": "^8.16.0"
3030
},
3131
"devDependencies": {
3232
"@mcp-pointer/shared": "workspace:*",
3333
"@types/jest": "^30.0.0",
34-
"@types/jsdom": "^21.1.7",
3534
"@types/ws": "^8.5.10",
3635
"esbuild": "catalog:",
3736
"jest": "^30.1.3",

packages/server/src/services/element-processor.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ import logger from '../logger';
88

99
function safeGet<T>(obj: any, path: string, defaultValue: T): T {
1010
const keys = path.split('.');
11-
let result = obj;
12-
for (const key of keys) {
13-
result = result?.[key];
11+
return keys.reduce((result, key) => {
1412
if (result === undefined) return defaultValue;
15-
}
16-
return result ?? defaultValue;
13+
return result?.[key];
14+
}, obj) ?? defaultValue;
1715
}
1816

1917
export default class ElementProcessor {
@@ -89,7 +87,7 @@ export default class ElementProcessor {
8987
framework: 'react' as const,
9088
};
9189

92-
const sourceFile = safeGet(reactFiber, '_debugSource.fileName', '');
90+
const sourceFile = safeGet<string>(reactFiber, '_debugSource.fileName', '');
9391
if (sourceFile && typeof sourceFile === 'string') {
9492
const fileName = sourceFile.split('/').pop() || sourceFile;
9593
const lineNumber = safeGet(reactFiber, '_debugSource.lineNumber', 0);

packages/server/src/services/mcp-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default class MCPService {
6767
}
6868

6969
private async getPointedElement() {
70-
const processedElement = await this.sharedState.getProcessedElement();
70+
const processedElement = await this.sharedState.getPointedElement();
7171

7272
if (!processedElement) {
7373
return {

packages/server/src/utils/dom-extractor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { JSDOM } from 'jsdom';
1+
import { parse } from 'node-html-parser';
22

33
export function extractFromHTML(html: string) {
44
const warnings: string[] = [];
55

66
try {
7-
const fragment = JSDOM.fragment(html);
8-
const element = fragment.firstChild as Element;
7+
const root = parse(html);
8+
const element = root.firstChild as unknown as Element;
99

1010
if (!element) {
1111
warnings.push('No element found in HTML');

0 commit comments

Comments
 (0)