Skip to content

Chrome DevTools for coding agents

chore: remove allowJs from tsconfig.json and annotate URLPattern (#3290)

Nikolay Vitkov92c4a55436e1
diff --git a/rollup.config.js b/rollup.config.js
index b268dae3..76cd9dd8 100644
--- a/rollup.config.js
+++ b/rollup.config.js
@@ -75,11 +75,18 @@ const aggregatedStats = {
bundlesProcessed: 0,
totalBundles: 0,
bundledPackages: new Set(),
+ bundledDevToolsThirdParty: new Set(),
};
const projectNodeModulesPath =
path.join(process.cwd(), 'node_modules') + path.sep;
+const devtoolsThirdPartyBuildPath =
+ path.join(
+ process.cwd(),
+ 'build/third_party/devtools-frontend/front_end/third_party',
+ ) + path.sep;
+
function getPackageName(modulePath) {
// Handle rollup's virtual module paths (paths starting with 0x00)
const absolutePathStart = modulePath.indexOf(projectNodeModulesPath);
@@ -99,6 +106,45 @@ function getPackageName(modulePath) {
return segments[0];
}
+function getDevToolsThirdPartyDir(modulePath) {
+ const absolutePathStart = modulePath.indexOf(devtoolsThirdPartyBuildPath);
+ if (absolutePathStart < 0) {
+ return null;
+ }
+
+ const relativePath = modulePath.slice(
+ devtoolsThirdPartyBuildPath.length + absolutePathStart,
+ );
+ const pkg = relativePath.split(path.sep)[0];
+ // Ignore mocks generated by scripts/post-build.ts.
+ if (!pkg || pkg === 'codemirror.next') {
+ return null;
+ }
+ return path.join('third_party/devtools-frontend/front_end/third_party', pkg);
+}
+
+function parseReadmeChromium(dirPath) {
+ const readmePath = path.join(dirPath, 'README.chromium');
+ if (!fs.existsSync(readmePath)) {
+ throw new Error(`Missing README.chromium in ${dirPath}`);
+ }
+ const content = fs.readFileSync(readmePath, 'utf-8');
+ const fields = {};
+ for (const line of content.split('\n')) {
+ const trimmed = line.trim();
+ if (!trimmed || trimmed.startsWith('Description:')) {
+ break;
+ }
+ const colonIndex = trimmed.indexOf(':');
+ if (colonIndex > 0) {
+ const key = trimmed.slice(0, colonIndex).trim();
+ const value = trimmed.slice(colonIndex + 1).trim();
+ fields[key] = value;
+ }
+ }
+ return fields;
+}
+
/**
* @returns {import('rollup').Plugin}
*/
@@ -110,12 +156,21 @@ function listBundledDeps() {
for (const chunk of Object.values(bundle)) {
if (chunk.type === 'chunk' && chunk.modules) {
// chunk.modules is an object where keys are the absolute file paths
- Object.keys(chunk.modules).forEach(modulePath => {
+ for (const [modulePath, mod] of Object.entries(chunk.modules)) {
const packageName = getPackageName(modulePath);
if (packageName) {
aggregatedStats.bundledPackages.add(packageName);
}
- });
+ if (mod && !mod.isAsset && mod.renderedLength > 0) {
+ const devtoolsThirdPartyDir =
+ getDevToolsThirdPartyDir(modulePath);
+ if (devtoolsThirdPartyDir) {
+ aggregatedStats.bundledDevToolsThirdParty.add(
+ devtoolsThirdPartyDir,
+ );
+ }
+ }
+ }
}
}
aggregatedStats.bundlesProcessed++;
@@ -175,6 +230,7 @@ const bundleDependency = (
// https://github.com/microsoft/TypeScript/issues/60811.
comments: [/Copyright/i],
}),
+ listBundledDeps(),
license({
thirdParty: {
allow: {
@@ -212,17 +268,9 @@ const bundleDependency = (
});
// Manual license handling for devtools-frontend third_party
- const tsConfig = JSON.parse(
- fs.readFileSync(
- path.join(process.cwd(), 'tsconfig.json'),
- 'utf-8',
- ),
- );
- const thirdPartyDirectories = tsConfig.include.filter(location =>
- location.includes(
- 'third_party/devtools-frontend/front_end/third_party',
- ),
- );
+ const thirdPartyDirectories = Array.from(
+ aggregatedStats.bundledDevToolsThirdParty,
+ ).sort();
const manualLicenses = [];
// Add devtools-frontend main license
@@ -265,18 +313,41 @@ const bundleDependency = (
for (const thirdPartyDir of thirdPartyDirectories) {
const fullPath = path.join(process.cwd(), thirdPartyDir);
- const licenseFile = path.join(fullPath, 'LICENSE');
- if (fs.existsSync(licenseFile)) {
- const name = path.basename(thirdPartyDir);
- manualLicenses.push(
- [
- `Name: ${name}`,
- `License:`,
- '',
- fs.readFileSync(licenseFile, 'utf-8').replaceAll('\r', ''),
- ].join('\n'),
+ const metadata = parseReadmeChromium(fullPath);
+ const name =
+ metadata['Short Name'] ||
+ metadata['Name'] ||
+ path.basename(thirdPartyDir);
+ const url = metadata['URL'] || 'N/A';
+ const version = metadata['Version'] || 'N/A';
+ const licenseName = metadata['License'] || 'N/A';
+ const licenseFile = path.join(
+ fullPath,
+ metadata['License File'] || 'LICENSE',
+ );
+
+ const licenses = licenseName.split(',').map(l => l.trim());
+ if (!licenses.every(l => allowedLicenses.includes(l))) {
+ throw new Error(
+ `License violation in ${thirdPartyDir}: ${licenseName} is not in allowedLicenses`,
);
}
+ if (!fs.existsSync(licenseFile)) {
+ throw new Error(
+ `Missing license file ${licenseFile} for ${thirdPartyDir}`,
+ );
+ }
+
+ manualLicenses.push(
+ [
+ `Name: ${name}`,
+ `URL: ${url}`,
+ `Version: ${version}`,
+ `License: ${licenseName}`,
+ '',
+ fs.readFileSync(licenseFile, 'utf-8').replaceAll('\r', ''),
+ ].join('\n'),
+ );
}
if (manualLicenses.length > 0) {
@@ -290,7 +361,6 @@ const bundleDependency = (
},
},
}),
- listBundledDeps(),
commonjs(),
json(),
nodeResolve({
diff --git a/scripts/post-build.ts b/scripts/post-build.ts
index 026dad9e..90e4db17 100644
--- a/scripts/post-build.ts
+++ b/scripts/post-build.ts
@@ -6,6 +6,7 @@
import * as fs from 'node:fs';
import * as path from 'node:path';
+import ts from 'typescript';
const BUILD_DIR = path.join(process.cwd(), 'build');
@@ -18,7 +19,7 @@ function writeFile(filePath: string, content: string): void {
fs.writeFileSync(filePath, content, 'utf-8');
}
-function main(): void {
+async function main(): Promise<void> {
const devtoolsTs = path.join(
process.cwd(),
'src',
@@ -151,32 +152,38 @@ export const ExperimentName = {
`;
writeFile(runtimeFile, runtimeContent);
- // Copy missing CodeMirror .mjs files that tsc ignores due to .d.mts renames
- const codemirrorDir = path.join(
- BUILD_DIR,
- devtoolsThirdPartyPath,
- 'codemirror',
- );
- const codemirrorSrcDir = path.join(
- process.cwd(),
- 'third_party',
- 'devtools-frontend',
- 'front_end',
- 'third_party',
- 'codemirror',
- );
- const filesToCopy = [
- 'package/addon/runmode/runmode-standalone.mjs',
- 'package/mode/css/css.mjs',
- 'package/mode/javascript/javascript.mjs',
- 'package/mode/xml/xml.mjs',
+ // Temporary fix: without allowJs in tsconfig.json, tsc ignores pre-built
+ // DevTools third_party .mjs/.js files, and transpileModule formats minified
+ // single-line files so rollup-plugin-cleanup (skip-regex) does not hang on
+ // catastrophic regex backtracking during bundling.
+ const devtoolsJsFiles = [
+ 'acorn/package/dist/acorn.mjs',
+ 'codemirror/package/addon/runmode/runmode-standalone.mjs',
+ 'codemirror/package/mode/css/css.mjs',
+ 'codemirror/package/mode/javascript/javascript.mjs',
+ 'codemirror/package/mode/xml/xml.mjs',
+ 'diff/diff_match_patch.js',
+ 'intl-messageformat/package/intl-messageformat.esm.js',
+ 'legacy-javascript/lib/legacy-javascript.js',
+ 'marked/package/lib/marked.esm.js',
+ 'third-party-web/lib/nostats-subset.js',
];
- for (const file of filesToCopy) {
- const src = path.join(codemirrorSrcDir, file);
- const dest = path.join(codemirrorDir, file);
- fs.mkdirSync(path.dirname(dest), {recursive: true});
- fs.copyFileSync(src, dest);
- }
+ await Promise.all(
+ devtoolsJsFiles.map(async file => {
+ const relPath = path.join(devtoolsThirdPartyPath, file);
+ const src = path.join(process.cwd(), relPath);
+ const dest = path.join(BUILD_DIR, relPath);
+ const source = await fs.promises.readFile(src, 'utf-8');
+ const {outputText} = ts.transpileModule(source, {
+ compilerOptions: {
+ target: ts.ScriptTarget.ES2023,
+ module: ts.ModuleKind.ESNext,
+ },
+ });
+ await fs.promises.mkdir(path.dirname(dest), {recursive: true});
+ await fs.promises.writeFile(dest, outputText, 'utf-8');
+ }),
+ );
// Copy lighthouse bundle that tsc ignores due to lighthouse-devtools-mcp-bundle.d.ts
const lighthouseBundle = 'src/third_party/lighthouse-devtools-mcp-bundle.js';
@@ -203,4 +210,4 @@ function copyDevToolsDescriptionFiles(): void {
fs.cpSync(sourceDir, destDir, {recursive: true});
}
-main();
+await main();
diff --git a/src/third_party/cli.ts b/src/third_party/cli.ts
index c7e8234e..73c4bbed 100644
--- a/src/third_party/cli.ts
+++ b/src/third_party/cli.ts
@@ -33,4 +33,4 @@ export {PipeTransport} from 'puppeteer-core/internal/node/PipeTransport.js';
* Node versions. Import this instead of using the global so the import
* also installs the polyfill.
*/
-export const URLPattern = globalThis.URLPattern;
+export const URLPattern: typeof globalThis.URLPattern = globalThis.URLPattern;
diff --git a/tests/third_party_notices.test.js.snapshot b/tests/third_party_notices.test.js.snapshot
index 7e344037..7f818c1c 100644
--- a/tests/third_party_notices.test.js.snapshot
+++ b/tests/third_party_notices.test.js.snapshot
@@ -690,13 +690,6 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------- DEPENDENCY DIVIDER --------------------
-
-Name: marked
-URL: https://marked.js.org
-Version: <VERSION>
-License: MIT
-
-------------------- DEPENDENCY DIVIDER --------------------
Name: cliui
@@ -1236,8 +1229,70 @@ License: Apache-2.0
-------------------- DEPENDENCY DIVIDER --------------------
-Name: diff
-License:
+Name: acorn
+URL: https://github.com/acornjs/acorn
+Version: <VERSION>
+License: MIT
+
+MIT License
+
+Copyright (C) 2012-2022 by various contributors (see AUTHORS)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+
+-------------------- DEPENDENCY DIVIDER --------------------
+
+Name: CodeMirror
+URL: https://github.com/codemirror/CodeMirror/
+Version: <VERSION>
+License: MIT
+
+MIT License
+
+Copyright (C) 2017 by Marijn Haverbeke <[email protected]> and others
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+
+-------------------- DEPENDENCY DIVIDER --------------------
+
+Name: diff-match-patch
+URL: https://github.com/google/diff-match-patch/tree/master/javascript
+Version: <VERSION>
+License: Apache-2.0
Apache License
@@ -1445,7 +1500,9 @@ License:
-------------------- DEPENDENCY DIVIDER --------------------
Name: i18n
-License:
+URL: https://github.com/GoogleChrome/lighthouse
+Version: <VERSION>
+License: Apache-2.0
Apache License
@@ -1654,7 +1711,9 @@ License:
-------------------- DEPENDENCY DIVIDER --------------------
Name: intl-messageformat
-License:
+URL: https://github.com/formatjs/formatjs
+Version: <VERSION>
+License: BSD-3-Clause
Copyright (c) 2019, Oath Inc.
@@ -1694,7 +1753,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-------------------- DEPENDENCY DIVIDER --------------------
Name: legacy-javascript
-License:
+URL: https://github.com/GoogleChrome/lighthouse/tree/main/core/lib/legacy-javascript
+Version: <VERSION>
+License: Apache-2.0
Apache License
@@ -1903,7 +1964,9 @@ License:
-------------------- DEPENDENCY DIVIDER --------------------
Name: marked
-License:
+URL: https://github.com/markedjs/marked
+Version: <VERSION>
+License: BSD-3-Clause, MIT
## Marked
@@ -1949,7 +2012,9 @@ out of the use of this software, even if advised of the possibility of such dama
-------------------- DEPENDENCY DIVIDER --------------------
Name: source-map-scopes-codec
-License:
+URL: https://github.com/ChromeDevTools/source-map-scopes-codec
+Version: <VERSION>
+License: BSD-3-Clause
Copyright 2025 The Chromium Authors
@@ -1981,7 +2046,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-------------------- DEPENDENCY DIVIDER --------------------
Name: third-party-web
-License:
+URL: https://github.com/patrickhulce/third-party-web
+Version: <VERSION>
+License: MIT
The MIT License (MIT)
Copyright (c) 2019 Patrick Hulce
diff --git a/tsconfig.json b/tsconfig.json
index 323329b9..63afe36c 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -23,7 +23,6 @@
"noFallthroughCasesInSwitch": true,
"incremental": true,
"sourceMap": true,
- "allowJs": true,
"preserveConstEnums": true,
"useUnknownInCatchVariables": false
},
@@ -102,8 +101,5 @@
"third_party/devtools-frontend/front_end/third_party/puppeteer-legacy/**",
"third_party/devtools-frontend/front_end/panels/recorder/**",
"third_party/devtools-frontend/front_end/services/puppeteer/**"
- ],
- "files": [
- "third_party/devtools-frontend/front_end/third_party/acorn/package/dist/acorn.mjs"
]
}