Skip to content

Chrome DevTools for coding agents

chore: use sparse checkout for devtools-frontend (#2835)

Nikolay Vitkovedd8b2c2b947
diff --git a/.gitmodules b/.gitmodules
index 51754944..00de42e7 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -3,3 +3,4 @@
url = https://github.com/ChromeDevTools/devtools-frontend.git
branch = main
shallow = true
+ fetchRecurseSubmodules = false
diff --git a/package.json b/package.json
index 82b0a8d3..5ba52d17 100644
--- a/package.json
+++ b/package.json
@@ -11,6 +11,7 @@
"scripts": {
"cli:generate": "node scripts/generate-cli.ts",
"clean": "node -e \"require('fs').rmSync('build', {recursive: true, force: true})\"",
+ "clean:submodules": "node scripts/clean-submodules.ts",
"bundle": "npm run clean && npm run build && rollup -c rollup.config.js && node -e \"require('fs').rmSync('build/node_modules', {recursive: true, force: true})\" && node scripts/append-lighthouse-notices.ts",
"build": "tsc && node scripts/post-build.ts",
"typecheck": "tsc --noEmit",
diff --git a/scripts/clean-submodules.ts b/scripts/clean-submodules.ts
new file mode 100644
index 00000000..fdea495a
--- /dev/null
+++ b/scripts/clean-submodules.ts
@@ -0,0 +1,32 @@
+/**
+ * @license
+ * Copyright 2026 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import {rmSync, existsSync} from 'node:fs';
+import {resolve} from 'node:path';
+
+const projectRoot = process.cwd();
+
+console.log('Cleaning submodules...');
+
+const directoriesToRemove = [
+ resolve(projectRoot, 'third_party', 'devtools-frontend'),
+ resolve(projectRoot, '.git', 'modules', 'devtools-frontend'),
+];
+
+for (const dir of directoriesToRemove) {
+ try {
+ if (existsSync(dir)) {
+ rmSync(dir, {recursive: true, force: true});
+ console.log(`Removed ${dir}`);
+ }
+ } catch (error) {
+ console.error(`Failed to remove ${dir}:`, error);
+ }
+}
+
+console.log(
+ 'Submodules cleaned. You can now run `npm run prepare` to re-initialize them.',
+);
diff --git a/scripts/prepare.ts b/scripts/prepare.ts
index 27a054f6..fd4214f1 100644
--- a/scripts/prepare.ts
+++ b/scripts/prepare.ts
@@ -5,7 +5,7 @@
*/
import {execSync} from 'node:child_process';
-import {existsSync, readFileSync, writeFileSync} from 'node:fs';
+import {existsSync, readFileSync, writeFileSync, rmSync} from 'node:fs';
import {resolve} from 'node:path';
const projectRoot = process.cwd();
@@ -51,29 +51,60 @@ function ensureSubmodule(): void {
return;
}
- console.log('Initializing devtools-frontend submodule...');
+ console.log(
+ 'Initializing devtools-frontend submodule with sparse checkout...',
+ );
try {
- execSync('git submodule update --init --depth 1', {
+ const gitModuleDir = resolve(
+ projectRoot,
+ '.git',
+ 'modules',
+ 'devtools-frontend',
+ );
+ // If the submodule was previously initialized (e.g. as a full checkout),
+ // the existing directories will cause `git clone` or `absorbgitdirs` to fail.
+ // We clean them up here to ensure the sparse checkout initialization succeeds.
+ if (existsSync(devtoolsFrontendDir)) {
+ rmSync(devtoolsFrontendDir, {recursive: true, force: true});
+ }
+ if (existsSync(gitModuleDir)) {
+ rmSync(gitModuleDir, {recursive: true, force: true});
+ }
+
+ // 1. Clone only the tree structure of the default branch (no blobs)
+ execSync(
+ 'git clone --no-checkout --depth 1 --filter=blob:none https://github.com/ChromeDevTools/devtools-frontend.git third_party/devtools-frontend',
+ {
+ cwd: projectRoot,
+ stdio: 'inherit',
+ },
+ );
+
+ // 2. Set the sparse checkout configuration
+ execSync(
+ 'git sparse-checkout set --no-cone "/*" "!/*/" "/front_end/" "!/front_end/panels/" "!/front_end/ui/" "/mcp/" "/extension-api/"',
+ {
+ cwd: devtoolsFrontendDir,
+ stdio: 'inherit',
+ },
+ );
+
+ // 3. Move the submodule's .git directory to the superproject's .git/modules
+ execSync('git submodule absorbgitdirs third_party/devtools-frontend', {
cwd: projectRoot,
stdio: 'inherit',
});
- } catch (submoduleError) {
- console.warn('git submodule update failed:', submoduleError);
- }
- if (!existsSync(mcpEntry)) {
- console.log('Fetching devtools-frontend...');
- try {
- execSync(
- 'git clone --depth 1 https://github.com/ChromeDevTools/devtools-frontend.git third_party/devtools-frontend',
- {
- cwd: projectRoot,
- stdio: 'inherit',
- },
- );
- } catch (cloneError) {
- console.error('Failed to clone devtools-frontend:', cloneError);
- }
+ // 4. Update the submodule to the correct commit (this fetches the commit and only downloads the blobs for the sparse checkout)
+ execSync(
+ 'git submodule update --force --checkout third_party/devtools-frontend',
+ {
+ cwd: projectRoot,
+ stdio: 'inherit',
+ },
+ );
+ } catch (error) {
+ console.error('Failed to initialize devtools-frontend:', error);
}
}