Skip to content

Commit 48d9a66

Browse files
committed
build: bundle devtools frontend
1 parent 7a3b4e7 commit 48d9a66

File tree

11 files changed

+79
-68
lines changed

11 files changed

+79
-68
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"start": "npm run build && node build/src/index.js",
1818
"start-debug": "DEBUG=mcp:* DEBUG_COLORS=false npm run build && node build/src/index.js",
1919
"test:node20": "node --require ./build/tests/setup.js --test-reporter spec --test-force-exit --test build/tests",
20-
"test": "npm run build && node --require ./build/tests/setup.js --no-warnings=ExperimentalWarning --test-reporter spec --test-force-exit --test \"build/tests/**/*.test.js\"",
20+
"test": "npm run build && node --require ./build/tests/setup.js --no-warnings=ExperimentalWarning --experimental-print-required-tla --test-reporter spec --test-force-exit --test \"build/tests/**/*.test.js\"",
2121
"test:only": "npm run build && node --require ./build/tests/setup.js --no-warnings=ExperimentalWarning --test-reporter spec --test-force-exit --test --test-only \"build/tests/**/*.test.js\"",
2222
"test:only:no-build": "node --require ./build/tests/setup.js --no-warnings=ExperimentalWarning --test-reporter spec --test-force-exit --test --test-only \"build/tests/**/*.test.js\"",
2323
"test:update-snapshots": "npm run build && node --require ./build/tests/setup.js --no-warnings=ExperimentalWarning --test-force-exit --test --test-update-snapshots \"build/tests/**/*.test.js\"",

rollup.config.mjs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121

2222
import path from 'node:path';
23+
import fs from 'node:fs';
2324

2425
import commonjs from '@rollup/plugin-commonjs';
2526
import json from '@rollup/plugin-json';
@@ -95,6 +96,35 @@ const bundleDependency = (
9596
}
9697
return arr.join('\n');
9798
});
99+
100+
// Manual license handling for chrome-devtools-frontend third_party
101+
const tsConfig = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'tsconfig.json'), 'utf-8'));
102+
const thirdPartyDirectories = tsConfig.include.filter(location => {
103+
return location.includes(
104+
'node_modules/chrome-devtools-frontend/front_end/third_party',
105+
);
106+
});
107+
108+
const manualLicenses = [];
109+
// Add chrome-devtools-frontend main license
110+
const cdtfLicensePath = path.join(process.cwd(), 'node_modules/chrome-devtools-frontend/LICENSE');
111+
if (fs.existsSync(cdtfLicensePath)) {
112+
manualLicenses.push(['Name: chrome-devtools-frontend', 'License: Apache-2.0', '', fs.readFileSync(cdtfLicensePath, 'utf-8')].join('\n'));
113+
}
114+
115+
for (const thirdPartyDir of thirdPartyDirectories) {
116+
const fullPath = path.join(process.cwd(), thirdPartyDir);
117+
const licenseFile = path.join(fullPath, 'LICENSE');
118+
if (fs.existsSync(licenseFile)) {
119+
const name = path.basename(thirdPartyDir);
120+
manualLicenses.push([`Name: ${name}`, `License: Custom`, '', fs.readFileSync(licenseFile, 'utf-8').replaceAll('\r', '')].join('\n'));
121+
}
122+
}
123+
124+
if (manualLicenses.length > 0) {
125+
stringified_dependencies.push(...manualLicenses);
126+
}
127+
98128
const divider =
99129
'\n\n-------------------- DEPENDENCY DIVIDER --------------------\n\n';
100130
return stringified_dependencies.join(divider);

scripts/post-build.ts

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import * as fs from 'node:fs';
88
import * as path from 'node:path';
99

10-
import tsConfig from '../tsconfig.json' with {type: 'json'};
11-
1210
import {sed} from './sed.ts';
1311

1412
const BUILD_DIR = path.join(process.cwd(), 'build');
@@ -22,28 +20,6 @@ function writeFile(filePath: string, content: string): void {
2220
fs.writeFileSync(filePath, content, 'utf-8');
2321
}
2422

25-
/**
26-
* Ensures that licenses for third party files we use gets copied into the build/ dir.
27-
*/
28-
function copyThirdPartyLicenseFiles() {
29-
const thirdPartyDirectories = tsConfig.include.filter(location => {
30-
return location.includes(
31-
'node_modules/chrome-devtools-frontend/front_end/third_party',
32-
);
33-
});
34-
35-
for (const thirdPartyDir of thirdPartyDirectories) {
36-
const fullPath = path.join(process.cwd(), thirdPartyDir);
37-
const licenseFile = path.join(fullPath, 'LICENSE');
38-
if (!fs.existsSync(licenseFile)) {
39-
console.error('No LICENSE for', path.basename(thirdPartyDir));
40-
}
41-
42-
const destinationDir = path.join(BUILD_DIR, thirdPartyDir);
43-
const destinationFile = path.join(destinationDir, 'LICENSE');
44-
fs.copyFileSync(licenseFile, destinationFile);
45-
}
46-
}
4723

4824
function main(): void {
4925
const devtoolsThirdPartyPath =
@@ -113,22 +89,6 @@ export const experiments = {
11389
sed(clientFile, globalAssignment, '');
11490
sed(clientFile, registerCommands, '');
11591

116-
const devtoolsLicensePath = path.join(
117-
'node_modules',
118-
'chrome-devtools-frontend',
119-
'LICENSE',
120-
);
121-
const devtoolsLicenseFileSource = path.join(
122-
process.cwd(),
123-
devtoolsLicensePath,
124-
);
125-
const devtoolsLicenseFileDestination = path.join(
126-
BUILD_DIR,
127-
devtoolsLicensePath,
128-
);
129-
fs.copyFileSync(devtoolsLicenseFileSource, devtoolsLicenseFileDestination);
130-
131-
copyThirdPartyLicenseFiles();
13292
copyDevToolsDescriptionFiles();
13393
}
13494

src/DevToolsConnectionAdapter.ts

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

7-
import type {CDPConnection as devtools} from '../node_modules/chrome-devtools-frontend/mcp/mcp.js';
8-
7+
import type {CDPConnection as devtools} from './third_party/index.js';
98
import type * as puppeteer from './third_party/index.js';
109
import {CDPSessionEvent} from './third_party/index.js';
1110

src/DevtoolsUtils.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
import {PuppeteerDevToolsConnection} from './DevToolsConnectionAdapter.js';
8+
import {ISSUE_UTILS} from './issue-descriptions.js';
9+
import {logger} from './logger.js';
10+
import {Mutex} from './Mutex.js';
711
import {
812
type Issue,
913
type AggregatedIssue,
1014
type IssuesManagerEventTypes,
11-
type Target,
15+
type SDKTarget as Target,
1216
DebuggerModel,
1317
Foundation,
1418
TargetManager,
@@ -17,12 +21,7 @@ import {
1721
ProtocolClient,
1822
Common,
1923
I18n,
20-
} from '../node_modules/chrome-devtools-frontend/mcp/mcp.js';
21-
22-
import {PuppeteerDevToolsConnection} from './DevToolsConnectionAdapter.js';
23-
import {ISSUE_UTILS} from './issue-descriptions.js';
24-
import {logger} from './logger.js';
25-
import {Mutex} from './Mutex.js';
24+
} from './third_party/index.js';
2625
import type {
2726
Browser,
2827
Page,

src/McpContext.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ import fs from 'node:fs/promises';
88
import os from 'node:os';
99
import path from 'node:path';
1010

11-
import {type AggregatedIssue} from '../node_modules/chrome-devtools-frontend/mcp/mcp.js';
12-
1311
import {extractUrlLikeFromDevToolsTitle, urlsEqual} from './DevtoolsUtils.js';
1412
import type {ListenerMap} from './PageCollector.js';
1513
import {NetworkCollector, ConsoleCollector} from './PageCollector.js';
14+
import {type AggregatedIssue} from './third_party/index.js';
1615
import {Locator} from './third_party/index.js';
1716
import type {
1817
Browser,

src/McpResponse.ts

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

7-
import {AggregatedIssue} from '../node_modules/chrome-devtools-frontend/mcp/mcp.js';
8-
97
import {mapIssueToMessageObject} from './DevtoolsUtils.js';
108
import type {ConsoleMessageData} from './formatters/consoleFormatter.js';
119
import {
@@ -21,6 +19,7 @@ import {
2119
} from './formatters/networkFormatter.js';
2220
import {formatSnapshotNode} from './formatters/snapshotFormatter.js';
2321
import type {McpContext} from './McpContext.js';
22+
import {AggregatedIssue} from './third_party/index.js';
2423
import type {
2524
ConsoleMessage,
2625
ImageContent,

src/PageCollector.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,21 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import type {
8-
AggregatedIssue,
9-
Common,
10-
} from '../node_modules/chrome-devtools-frontend/mcp/mcp.js';
11-
import {
12-
IssueAggregatorEvents,
13-
IssuesManagerEvents,
14-
createIssuesFromProtocolIssue,
15-
IssueAggregator,
16-
} from '../node_modules/chrome-devtools-frontend/mcp/mcp.js';
17-
187
import {FakeIssuesManager} from './DevtoolsUtils.js';
198
import {logger} from './logger.js';
209
import type {
2110
CDPSession,
2211
ConsoleMessage,
2312
Protocol,
2413
Target,
14+
Common,
15+
} from './third_party/index.js';
16+
import {
17+
type AggregatedIssue,
18+
IssueAggregatorEvents,
19+
IssuesManagerEvents,
20+
createIssuesFromProtocolIssue,
21+
IssueAggregator,
2522
} from './third_party/index.js';
2623
import {
2724
type Browser,

src/formatters/consoleFormatter.ts

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

7-
import type {AggregatedIssue} from '../../node_modules/chrome-devtools-frontend/mcp/mcp.js';
87
import type {McpContext} from '../McpContext.js';
8+
import {type AggregatedIssue} from '../third_party/index.js';
99

1010
export interface ConsoleMessageData {
1111
consoleMessageStableId: number;

src/third_party/index.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,31 @@ export {
3535
Browser as BrowserEnum,
3636
type ChromeReleaseChannel as BrowsersChromeReleaseChannel,
3737
} from '@puppeteer/browsers';
38+
39+
export {
40+
AgentFocus,
41+
TraceEngine,
42+
PerformanceTraceFormatter,
43+
PerformanceInsightFormatter,
44+
// Issue is a type in some contexts, but let's export it as is if it's a class or if we can use export type?
45+
// Use export type for pure types if possible, or just export { ... }
46+
// The users act as if they are values (classes) mostly, except explicit type imports.
47+
// Re-exporting everything as value allows both (if they are values).
48+
AggregatedIssue,
49+
type Issue,
50+
type IssuesManagerEventTypes,
51+
type Target as SDKTarget,
52+
type CDPConnection,
53+
DebuggerModel,
54+
Foundation,
55+
TargetManager,
56+
MarkdownIssueDescription,
57+
Marked,
58+
ProtocolClient,
59+
Common,
60+
I18n,
61+
IssueAggregatorEvents,
62+
IssuesManagerEvents,
63+
createIssuesFromProtocolIssue,
64+
IssueAggregator,
65+
} from '../../node_modules/chrome-devtools-frontend/mcp/mcp.js';

0 commit comments

Comments
 (0)