Skip to content

Chrome DevTools for coding agents

build: update pre-release workflow and package files for GN build (#3416)

Nikolay Vitkov0b37364dc0a8
diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml
index c145d343..66aa03dc 100644
--- a/.github/workflows/pre-release.yml
+++ b/.github/workflows/pre-release.yml
@@ -63,12 +63,12 @@ jobs:
shell: bash
run: npm run verify-npm-package
- - name: Remove node_modules
+ - name: Remove unbundled dependencies
shell: bash
- run: rm -rf node_modules
+ run: rm -rf node_modules out/Default/gen/third_party
- name: Smoke test bundled binaries
shell: bash
run: |
- node ./build/src/bin/chrome-devtools-mcp.js --version
- node ./build/src/bin/chrome-devtools.js --version
+ node ./out/Default/gen/src/bin/chrome-devtools-mcp.js --version
+ node ./out/Default/gen/src/bin/chrome-devtools.js --version
diff --git a/AGENTS.md b/AGENTS.md
index f06c55cf..082f4ffd 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -3,7 +3,8 @@ This repository contains an MCP server and CLI for Chrome DevTools.
# Instructions
- Use only scripts from `package.json` to run commands.
-- Use `npm run build` to run tsc and test build.
+- Use `npm run build` to compile the project and tests with GN and Ninja.
+- Update `src/BUILD.gn` or `tests/BUILD.gn` whenever adding, renaming, or removing `.ts` files in `src/` or `tests/`.
- Use `npm run test` to build and run tests, run all tests to verify correctness.
- Use `npm run test path-to-test.ts` to build and run a single test file, for example, `npm run test tests/McpContext.test.ts`.
- Use `npm run format` to fix formatting and get linting errors.
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index c396ce31..0fb29a32 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -75,13 +75,14 @@ Check that you are using node version specified in .nvmrc, then run following co
git clone https://github.com/ChromeDevTools/chrome-devtools-mcp.git
cd chrome-devtools-mcp
npm ci
+npm run gclient-sync
npm run build
```
### Testing with @modelcontextprotocol/inspector
```sh
-npx @modelcontextprotocol/inspector node ./build/src/bin/chrome-devtools-mcp.js
+npx @modelcontextprotocol/inspector node ./out/Default/gen/src/bin/chrome-devtools-mcp.js
```
### Testing with an MCP client
@@ -94,7 +95,7 @@ Add the MCP server to your client's config.
"chrome-devtools": {
"command": "node",
"args": [
- "/<path-to-chrome-devtools-mcp>/build/src/bin/chrome-devtools-mcp.js"
+ "/<path-to-chrome-devtools-mcp>/out/Default/gen/src/bin/chrome-devtools-mcp.js"
]
}
}
@@ -111,7 +112,7 @@ Usually VS Code automatically detects and forwards `6274` but fails to detect `6
To write debug logs to `log.txt` in the working directory, run with the following commands:
```sh
-npx @modelcontextprotocol/inspector node ./build/src/bin/chrome-devtools-mcp.js --log-file=/your/desired/path/log.txt
+npx @modelcontextprotocol/inspector node ./out/Default/gen/src/bin/chrome-devtools-mcp.js --log-file=/your/desired/path/log.txt
```
You can use the `NODE_DEBUG` environment variable as usual to control categories that are logged.
diff --git a/package.json b/package.json
index dcf17da1..da8110ce 100644
--- a/package.json
+++ b/package.json
@@ -44,9 +44,11 @@
"out/Default/gen/src",
"LICENSE",
"skills",
- "!*.tsbuildinfo",
+ "!**/*.tsbuildinfo",
"!**/*.js.map",
- "!**/*.d.ts"
+ "!**/*.d.ts",
+ "!**/*-tsconfig*.json",
+ "!**/*.stamp"
],
"repository": "ChromeDevTools/chrome-devtools-mcp",
"author": "Google LLC",
diff --git a/scripts/clean.ts b/scripts/clean.ts
index f630a8c3..f80f1591 100644
--- a/scripts/clean.ts
+++ b/scripts/clean.ts
@@ -4,16 +4,20 @@
* SPDX-License-Identifier: Apache-2.0
*/
-import {rmSync} from 'node:fs';
+import {execFileSync} from 'node:child_process';
+import {existsSync} from 'node:fs';
import {resolve} from 'node:path';
-import {runGnGen} from './gn-gen.ts';
+import {getGnBinaryPath, runGnGen} from './gn-gen.ts';
const projectRoot = process.cwd();
-const pathsToRemove = ['out/Default/gen/src', 'out/Default/gen/tests'];
+const outDir = resolve(projectRoot, 'out', 'Default');
-for (const relPath of pathsToRemove) {
- rmSync(resolve(projectRoot, relPath), {recursive: true, force: true});
+if (existsSync(resolve(outDir, 'build.ninja'))) {
+ execFileSync(getGnBinaryPath(), ['clean', 'out/Default'], {
+ cwd: projectRoot,
+ stdio: 'inherit',
+ });
}
runGnGen();
diff --git a/scripts/gn-gen.ts b/scripts/gn-gen.ts
index 304aa968..3b2d270f 100644
--- a/scripts/gn-gen.ts
+++ b/scripts/gn-gen.ts
@@ -5,14 +5,14 @@
*/
import {execFileSync} from 'node:child_process';
-import {rmSync} from 'node:fs';
+import {writeFileSync} from 'node:fs';
import {resolve} from 'node:path';
import {linkDevToolsDeps} from './link-devtools-deps.ts';
const projectRoot = process.cwd();
-function getGnBinaryPath(): string {
+export function getGnBinaryPath(): string {
switch (process.platform) {
case 'win32':
return resolve(projectRoot, 'buildtools', 'win', 'gn.exe');
@@ -30,8 +30,8 @@ export function runGnGen(): void {
stdio: 'inherit',
});
- // Remove the generated .gitignore so npm pack / publish includes out/Default/gen.
- rmSync(resolve(projectRoot, 'out', 'Default', '.gitignore'), {force: true});
+ // Empty .gitignore so npm pack includes gen/ and GN regeneration keeps it.
+ writeFileSync(resolve(projectRoot, 'out', 'Default', '.gitignore'), '');
}
if (import.meta.main) {
diff --git a/scripts/verify-npm-package.js b/scripts/verify-npm-package.js
index 8093940f..59ac66a4 100644
--- a/scripts/verify-npm-package.js
+++ b/scripts/verify-npm-package.js
@@ -6,20 +6,29 @@
import {execSync} from 'node:child_process';
-// Checks that the select build files are present using `npm publish --dry-run`.
+// Checks that the select build files are present using `npm pack --dry-run`.
function verifyPackageContents() {
try {
- const output = execSync('npm publish --dry-run --json --silent', {
+ const output = execSync('npm pack --dry-run --json --silent', {
encoding: 'utf8',
});
// skip non-JSON output from prepare.
- const data = JSON.parse(output.substring(output.indexOf('{')));
- const files = data['chrome-devtools-mcp'].files.map(f => f.path);
+ const jsonStart = output.search(/[{[]/);
+ const data = JSON.parse(output.substring(jsonStart));
+ const pkgData = Array.isArray(data) ? data[0] : data['chrome-devtools-mcp'];
+ const files = pkgData.files.map(f => f.path);
// Check some important files.
const requiredPaths = [
'out/Default/gen/src/index.js',
+ 'out/Default/gen/src/bin/chrome-devtools-mcp.js',
+ 'out/Default/gen/src/bin/chrome-devtools.js',
'out/Default/gen/src/third_party/index.js',
'out/Default/gen/src/third_party/cli.js',
+ 'out/Default/gen/src/third_party/devtools-formatter-worker.js',
+ 'out/Default/gen/src/third_party/devtools-heap-snapshot-worker.js',
+ 'out/Default/gen/src/third_party/lighthouse-devtools-mcp-bundle.js',
+ 'out/Default/gen/src/third_party/THIRD_PARTY_NOTICES',
+ 'out/Default/gen/src/third_party/issue-descriptions/',
];
for (const requiredPath of requiredPaths) {
const hasBuildFolder = files.some(path => path.startsWith(requiredPath));
@@ -30,11 +39,27 @@ function verifyPackageContents() {
process.exit(1);
}
}
+ const forbiddenSuffixes = [
+ '.d.ts',
+ '.js.map',
+ '.tsbuildinfo',
+ '-tsconfig.json',
+ '-tsconfig.ref.json',
+ '.stamp',
+ ];
+ for (const file of files) {
+ if (forbiddenSuffixes.some(suffix => file.endsWith(suffix))) {
+ console.error(
+ `Assertion Failed: build artifact "${file}" should not be in tarball.`,
+ );
+ process.exit(1);
+ }
+ }
console.log(
- `npm publish --dry-run contained ${JSON.stringify(requiredPaths)}`,
+ `npm pack --dry-run contained ${JSON.stringify(requiredPaths)}`,
);
} catch (err) {
- console.error('failed to parse npm publish output', err);
+ console.error('failed to parse npm pack output', err);
process.exit(1);
}
}