| 57 | ].join(' '); |
| 58 | |
| 59 | function ensureSubmodule(): void { |
| 60 | const devtoolsFrontendDir = resolve( |
| 61 | projectRoot, |
| 62 | 'third_party', |
| 63 | 'devtools-frontend', |
| 64 | ); |
| 65 | const mcpEntry = resolve(devtoolsFrontendDir, 'mcp', 'mcp.ts'); |
| 66 | // The newest path that SPARSE_CHECKOUT_PATTERNS added: a checkout that |
| 67 | // has mcp.ts but not this file predates the current patterns. |
| 68 | const sparseMarker = resolve( |
| 69 | devtoolsFrontendDir, |
| 70 | 'v8', |
| 71 | 'include', |
| 72 | 'js_protocol.pdl', |
| 73 | ); |
| 74 | |
| 75 | if (existsSync(mcpEntry) && existsSync(sparseMarker)) { |
| 76 | console.log('devtools-frontend submodule is ready.'); |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | if (existsSync(mcpEntry) && !existsSync(sparseMarker)) { |
| 81 | console.log('Updating devtools-frontend sparse checkout patterns...'); |
| 82 | try { |
| 83 | execSync( |
| 84 | `git sparse-checkout set --no-cone ${SPARSE_CHECKOUT_PATTERNS}`, |
| 85 | { |
| 86 | cwd: devtoolsFrontendDir, |
| 87 | stdio: 'inherit', |
| 88 | }, |
| 89 | ); |
| 90 | return; |
| 91 | } catch (error) { |
| 92 | console.warn( |
| 93 | 'Failed to update sparse checkout in place, re-initializing:', |
| 94 | error, |
| 95 | ); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | console.log( |
| 100 | 'Initializing devtools-frontend submodule with sparse checkout...', |
| 101 | ); |
| 102 | try { |
| 103 | const gitModuleDir = resolve( |
| 104 | projectRoot, |
| 105 | '.git', |
| 106 | 'modules', |
| 107 | 'devtools-frontend', |
| 108 | ); |
| 109 | // If the submodule was previously initialized (e.g. as a full checkout), |
| 110 | // the existing directories will cause `git clone` or `absorbgitdirs` to fail. |
| 111 | // We clean them up here to ensure the sparse checkout initialization succeeds. |
| 112 | if (existsSync(devtoolsFrontendDir)) { |
| 113 | rmSync(devtoolsFrontendDir, {recursive: true, force: true}); |
| 114 | } |
| 115 | if (existsSync(gitModuleDir)) { |
| 116 | rmSync(gitModuleDir, {recursive: true, force: true}); |