Skip to content

Commit c3b2e6b

Browse files
author
Piotr Paulski
committed
refactor: bundle puppeteer-core
1 parent 2ffe56a commit c3b2e6b

File tree

17 files changed

+68
-29
lines changed

17 files changed

+68
-29
lines changed

rollup.config.mjs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@ import license from 'rollup-plugin-license';
2929

3030
const isProduction = process.env.NODE_ENV === 'production';
3131

32-
/** @type {import('rollup').RollupOptions} */
33-
const sdk = {
34-
input: './build/src/third_party/modelcontextprotocol-sdk/index.js',
32+
const allowed_licenses = ['MIT', 'Apache 2.0', 'Apache-2.0', 'BSD-3-Clause', 'BSD-2-Clause', 'ISC', '0BSD'];
33+
34+
/** @returns {import('rollup').RollupOptions} */
35+
const bundleDependency = (wrapperIndexPath, extraOutputOptions = {}) => ({
36+
input: wrapperIndexPath,
3537
output: {
36-
file: './build/src/third_party/modelcontextprotocol-sdk/index.js',
38+
...extraOutputOptions,
39+
file: wrapperIndexPath,
3740
sourcemap: !isProduction,
3841
format: 'esm',
3942
},
@@ -48,7 +51,6 @@ const sdk = {
4851
thirdParty: {
4952
allow: {
5053
test: dependency => {
51-
let allowed_licenses = ['MIT', 'Apache 2.0', 'BSD-2-Clause', 'ISC'];
5254
return allowed_licenses.includes(dependency.license);
5355
},
5456
failOnUnlicensed: true,
@@ -90,6 +92,9 @@ const sdk = {
9092
json(),
9193
nodeResolve(),
9294
],
93-
};
95+
});
9496

95-
export default [sdk];
97+
export default [
98+
bundleDependency('./build/src/third_party/modelcontextprotocol-sdk/index.js'),
99+
bundleDependency('./build/src/third_party/puppeteer-core/index.js', {inlineDynamicImports: true}),
100+
];

src/McpContext.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import os from 'node:os';
88
import path from 'node:path';
99

1010
import type {Debugger} from 'debug';
11+
12+
import type {ListenerMap} from './PageCollector.js';
13+
import {NetworkCollector, PageCollector} from './PageCollector.js';
1114
import type {
1215
Browser,
1316
ConsoleMessage,
@@ -17,10 +20,7 @@ import type {
1720
Page,
1821
SerializedAXNode,
1922
PredefinedNetworkConditions,
20-
} from 'puppeteer-core';
21-
22-
import type {ListenerMap} from './PageCollector.js';
23-
import {NetworkCollector, PageCollector} from './PageCollector.js';
23+
} from './third_party/puppeteer-core';
2424
import {listPages} from './tools/pages.js';
2525
import {takeSnapshot} from './tools/snapshot.js';
2626
import {CLOSE_PAGE_ERROR} from './tools/ToolDefinition.js';

src/McpResponse.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
* Copyright 2025 Google LLC
44
* SPDX-License-Identifier: Apache-2.0
55
*/
6-
import type {ConsoleMessage, ResourceType} from 'puppeteer-core';
7-
86
import {formatConsoleEvent} from './formatters/consoleFormatter.js';
97
import {
108
getFormattedHeaderValue,
@@ -19,6 +17,7 @@ import type {
1917
ImageContent,
2018
TextContent,
2119
} from './third_party/modelcontextprotocol-sdk/index.js';
20+
import type {ConsoleMessage, ResourceType} from './third_party/puppeteer-core';
2221
import {handleDialog} from './tools/pages.js';
2322
import type {ImageContentData, Response} from './tools/ToolDefinition.js';
2423
import {paginate} from './utils/pagination.js';

src/PageCollector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
type HTTPRequest,
1212
type Page,
1313
type PageEvents,
14-
} from 'puppeteer-core';
14+
} from './third_party/puppeteer-core';
1515

1616
export type ListenerMap<EventMap extends PageEvents = PageEvents> = {
1717
[K in keyof EventMap]?: (event: EventMap[K]) => void;

src/WaitForHelper.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
* Copyright 2025 Google LLC
44
* SPDX-License-Identifier: Apache-2.0
55
*/
6-
import type {Page, Protocol} from 'puppeteer-core';
7-
import type {CdpPage} from 'puppeteer-core/internal/cdp/Page.js';
8-
96
import {logger} from './logger.js';
7+
import type {Page, Protocol} from './third_party/puppeteer-core';
8+
import type {CdpPage} from './third_party/puppeteer-core';
109

1110
export class WaitForHelper {
1211
#abortController = new AbortController();

src/browser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import type {
1313
ChromeReleaseChannel,
1414
LaunchOptions,
1515
Target,
16-
} from 'puppeteer-core';
17-
import puppeteer from 'puppeteer-core';
16+
} from './third_party/puppeteer-core';
17+
import {puppeteer} from './third_party/puppeteer-core/index.js';
1818

1919
let browser: Browser | undefined;
2020

src/formatters/networkFormatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import {isUtf8} from 'node:buffer';
88

9-
import type {HTTPRequest, HTTPResponse} from 'puppeteer-core';
9+
import type {HTTPRequest, HTTPResponse} from '../third_party/puppeteer-core/index.js';
1010

1111
const BODY_CONTEXT_SIZE_LIMIT = 10000;
1212

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
export type {
8+
Browser,
9+
ChromeReleaseChannel,
10+
ConsoleMessage,
11+
ConsoleMessageType,
12+
Dialog,
13+
ElementHandle,
14+
Frame,
15+
Handler,
16+
HTTPRequest,
17+
HTTPResponse,
18+
JSHandle,
19+
LaunchOptions,
20+
Page,
21+
PageEvents,
22+
Protocol,
23+
ProtocolError,
24+
ResourceType,
25+
SerializedAXNode,
26+
Target,
27+
} from 'puppeteer-core';
28+
export type {CdpPage} from 'puppeteer-core/internal/cdp/Page.js';
29+
export {Locator,PredefinedNetworkConditions} from 'puppeteer-core';
30+
export {default as puppeteer} from 'puppeteer-core';

src/tools/ToolDefinition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import type {Dialog, ElementHandle, Page} from 'puppeteer-core';
87
import z from 'zod';
98

109
import type {TextSnapshotNode} from '../McpContext.js';
10+
import type {Dialog, ElementHandle, Page} from '../third_party/puppeteer-core/index.js';
1111
import type {TraceResult} from '../trace-processing/parse.js';
1212
import type {PaginationOptions} from '../utils/types.js';
1313

src/tools/console.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import type {ConsoleMessageType} from 'puppeteer-core';
87
import z from 'zod';
98

9+
import type {ConsoleMessageType} from '../third_party/puppeteer-core/index.js';
10+
1011
import {ToolCategories} from './categories.js';
1112
import {defineTool} from './ToolDefinition.js';
1213

0 commit comments

Comments
 (0)