豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 94b899c

Browse files
authored
build: bundle devtools frontend (#656)
1 parent 7a3b4e7 commit 94b899c

File tree

18 files changed

+120
-87
lines changed

18 files changed

+120
-87
lines changed

.github/workflows/run-tests.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ jobs:
4242

4343
- name: Build
4444
run: npm run bundle
45+
env:
46+
NODE_OPTIONS: '--max_old_space_size=4096'
4547

4648
- name: Set up Node.js
4749
uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
@@ -62,7 +64,7 @@ jobs:
6264
- name: Run tests
6365
shell: bash
6466
if: ${{ matrix.node != '20' }}
65-
run: npm run test
67+
run: npm run test:no-build
6668

6769
# Gating job for branch protection.
6870
test-success:

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"main": "index.js",
88
"scripts": {
99
"clean": "node -e \"require('fs').rmSync('build', {recursive: true, force: true})\"",
10-
"bundle": "npm run clean && npm run build && rollup -c rollup.config.mjs",
10+
"bundle": "npm run clean && npm run build && rollup -c rollup.config.mjs && node -e \"require('fs').rmSync('build/node_modules', {recursive: true, force: true})\"",
1111
"build": "tsc && node --experimental-strip-types --no-warnings=ExperimentalWarning scripts/post-build.ts",
1212
"typecheck": "tsc --noEmit",
1313
"format": "eslint --cache --fix . && prettier --write --cache .",
@@ -16,11 +16,12 @@
1616
"docs:generate": "node --experimental-strip-types scripts/generate-docs.ts",
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",
19-
"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\"",
21-
"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\"",
22-
"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\"",
23-
"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\"",
19+
"test:node20": "node --import ./build/tests/setup.js --test-reporter spec --test-force-exit --test build/tests",
20+
"test:no-build": "node --import ./build/tests/setup.js --no-warnings=ExperimentalWarning --experimental-print-required-tla --test-reporter spec --test-force-exit --test \"build/tests/**/*.test.js\"",
21+
"test": "npm run build && npm run test:no-build",
22+
"test:only": "npm run build && node --import ./build/tests/setup.js --no-warnings=ExperimentalWarning --test-reporter spec --test-force-exit --test --test-only \"build/tests/**/*.test.js\"",
23+
"test:only:no-build": "node --import ./build/tests/setup.js --no-warnings=ExperimentalWarning --test-reporter spec --test-force-exit --test --test-only \"build/tests/**/*.test.js\"",
24+
"test:update-snapshots": "npm run build && node --import ./build/tests/setup.js --no-warnings=ExperimentalWarning --test-force-exit --test --test-update-snapshots \"build/tests/**/*.test.js\"",
2425
"prepare": "node --experimental-strip-types scripts/prepare.ts",
2526
"verify-server-json-version": "node --experimental-strip-types scripts/verify-server-json-version.ts"
2627
},

rollup.config.mjs

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* and modified to specific requirement.
2020
*/
2121

22+
import fs from 'node:fs';
2223
import path from 'node:path';
2324

2425
import commonjs from '@rollup/plugin-commonjs';
@@ -79,7 +80,7 @@ const bundleDependency = (
7980
'THIRD_PARTY_NOTICES',
8081
),
8182
template(dependencies) {
82-
const stringified_dependencies = dependencies.map(dependency => {
83+
const stringifiedDependencies = dependencies.map(dependency => {
8384
let arr = [];
8485
arr.push(`Name: ${dependency.name ?? 'N/A'}`);
8586
let url = dependency.homepage ?? dependency.repository;
@@ -95,9 +96,60 @@ 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(
102+
fs.readFileSync(
103+
path.join(process.cwd(), 'tsconfig.json'),
104+
'utf-8',
105+
),
106+
);
107+
const thirdPartyDirectories = tsConfig.include.filter(location =>
108+
location.includes(
109+
'node_modules/chrome-devtools-frontend/front_end/third_party',
110+
),
111+
);
112+
113+
const manualLicenses = [];
114+
// Add chrome-devtools-frontend main license
115+
const cdtfLicensePath = path.join(
116+
process.cwd(),
117+
'node_modules/chrome-devtools-frontend/LICENSE',
118+
);
119+
if (fs.existsSync(cdtfLicensePath)) {
120+
manualLicenses.push(
121+
[
122+
'Name: chrome-devtools-frontend',
123+
'License: Apache-2.0',
124+
'',
125+
fs.readFileSync(cdtfLicensePath, 'utf-8'),
126+
].join('\n'),
127+
);
128+
}
129+
130+
for (const thirdPartyDir of thirdPartyDirectories) {
131+
const fullPath = path.join(process.cwd(), thirdPartyDir);
132+
const licenseFile = path.join(fullPath, 'LICENSE');
133+
if (fs.existsSync(licenseFile)) {
134+
const name = path.basename(thirdPartyDir);
135+
manualLicenses.push(
136+
[
137+
`Name: ${name}`,
138+
`License:`,
139+
'',
140+
fs.readFileSync(licenseFile, 'utf-8').replaceAll('\r', ''),
141+
].join('\n'),
142+
);
143+
}
144+
}
145+
146+
if (manualLicenses.length > 0) {
147+
stringifiedDependencies.push(...manualLicenses);
148+
}
149+
98150
const divider =
99151
'\n\n-------------------- DEPENDENCY DIVIDER --------------------\n\n';
100-
return stringified_dependencies.join(divider);
152+
return stringifiedDependencies.join(divider);
101153
},
102154
},
103155
},

scripts/post-build.ts

Lines changed: 6 additions & 42 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,29 +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-
}
47-
4823
function main(): void {
4924
const devtoolsThirdPartyPath =
5025
'node_modules/chrome-devtools-frontend/front_end/third_party';
@@ -113,30 +88,19 @@ export const experiments = {
11388
sed(clientFile, globalAssignment, '');
11489
sed(clientFile, registerCommands, '');
11590

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();
13291
copyDevToolsDescriptionFiles();
13392
}
13493

13594
function copyDevToolsDescriptionFiles() {
13695
const devtoolsIssuesDescriptionPath =
13796
'node_modules/chrome-devtools-frontend/front_end/models/issues_manager/descriptions';
13897
const sourceDir = path.join(process.cwd(), devtoolsIssuesDescriptionPath);
139-
const destDir = path.join(BUILD_DIR, devtoolsIssuesDescriptionPath);
98+
const destDir = path.join(
99+
BUILD_DIR,
100+
'src',
101+
'third_party',
102+
'issue-descriptions',
103+
);
140104
fs.cpSync(sourceDir, destDir, {recursive: true});
141105
}
142106

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;

0 commit comments

Comments
 (0)