chromedevtools--chrome-devtools-mcp
79ab800b1e
The `self.Protocol` assignment and register call have moved to the InspectorBackend constructor. The `self.Protocol` assignment now use `globalThis`. The register call is necessary to make DevTools foundation work.
91 行
2.4 KiB
TypeScript
91 行
2.4 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2025 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import * as fs from 'node:fs';
|
|
import * as path from 'node:path';
|
|
|
|
const BUILD_DIR = path.join(process.cwd(), 'build');
|
|
|
|
/**
|
|
* Writes content to a file.
|
|
* @param filePath The path to the file.
|
|
* @param content The content to write.
|
|
*/
|
|
function writeFile(filePath: string, content: string): void {
|
|
fs.writeFileSync(filePath, content, 'utf-8');
|
|
}
|
|
|
|
function main(): void {
|
|
const devtoolsThirdPartyPath =
|
|
'node_modules/chrome-devtools-frontend/front_end/third_party';
|
|
const devtoolsFrontEndCorePath =
|
|
'node_modules/chrome-devtools-frontend/front_end/core';
|
|
|
|
// Create i18n mock
|
|
const i18nDir = path.join(BUILD_DIR, devtoolsFrontEndCorePath, 'i18n');
|
|
const localesFile = path.join(i18nDir, 'locales.js');
|
|
const localesContent = `
|
|
export const LOCALES = [
|
|
'en-US',
|
|
];
|
|
|
|
export const BUNDLED_LOCALES = [
|
|
'en-US',
|
|
];
|
|
|
|
export const DEFAULT_LOCALE = 'en-US';
|
|
|
|
export const REMOTE_FETCH_PATTERN = '@HOST@/remote/serve_file/@VERSION@/core/i18n/locales/@LOCALE@.json';
|
|
|
|
export const LOCAL_FETCH_PATTERN = './locales/@LOCALE@.json';`;
|
|
writeFile(localesFile, localesContent);
|
|
|
|
// Create codemirror.next mock.
|
|
const codeMirrorDir = path.join(
|
|
BUILD_DIR,
|
|
devtoolsThirdPartyPath,
|
|
'codemirror.next',
|
|
);
|
|
fs.mkdirSync(codeMirrorDir, {recursive: true});
|
|
const codeMirrorFile = path.join(codeMirrorDir, 'codemirror.next.js');
|
|
const codeMirrorContent = `export default {}`;
|
|
writeFile(codeMirrorFile, codeMirrorContent);
|
|
|
|
// Create root mock
|
|
const rootDir = path.join(BUILD_DIR, devtoolsFrontEndCorePath, 'root');
|
|
fs.mkdirSync(rootDir, {recursive: true});
|
|
const runtimeFile = path.join(rootDir, 'Runtime.js');
|
|
const runtimeContent = `
|
|
export function getChromeVersion() { return ''; };
|
|
export const hostConfig = {};
|
|
export const Runtime = {
|
|
isDescriptorEnabled: () => true,
|
|
queryParam: () => null,
|
|
}
|
|
export const experiments = {
|
|
isEnabled: () => false,
|
|
}
|
|
`;
|
|
writeFile(runtimeFile, runtimeContent);
|
|
|
|
copyDevToolsDescriptionFiles();
|
|
}
|
|
|
|
function copyDevToolsDescriptionFiles() {
|
|
const devtoolsIssuesDescriptionPath =
|
|
'node_modules/chrome-devtools-frontend/front_end/models/issues_manager/descriptions';
|
|
const sourceDir = path.join(process.cwd(), devtoolsIssuesDescriptionPath);
|
|
const destDir = path.join(
|
|
BUILD_DIR,
|
|
'src',
|
|
'third_party',
|
|
'issue-descriptions',
|
|
);
|
|
fs.cpSync(sourceDir, destDir, {recursive: true});
|
|
}
|
|
|
|
main();
|