mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-02 18:11:04 +08:00
This reverts commit862107080d. Reason for revert: Chromium build issue fixed. Original change's description: > Revert "Reland "Remove support for remote modules"" > > This reverts commitb3859e8d65. > > Reason for revert: Breaking roll (https://ci.chromium.org/p/chromium/builders/ci/win-archive-rel/17700) > > Original change's description: > > Reland "Remove support for remote modules" > > > > This reverts commitd5044ddf05. > > > > Reason for revert: Fixed Chromium debug issue. > > > > Original change's description: > > > Revert "Remove support for remote modules" > > > > > > This reverts commit419c91eff6. > > > > > > Reason for revert: Breaks roll https://chromium-review.googlesource.com/c/chromium/src/+/2416805 > > > > > > Original change's description: > > > > Remove support for remote modules > > > > > > > > LightHouse is currently broken in Canary, because of problems with > > > > the appspot server. This isn't the first occurrence of this problem > > > > and it becomes increasingly more difficult to figure out why the > > > > server keeps on breaking. This is combined with a large infrastructure > > > > cost of supporting remote modules and a confusing debugging experience > > > > when working with it locally. > > > > > > > > The reason we had remote modules was the fact that these modules are > > > > too large to be included in the Chromium bundle. In the last months, > > > > we have made numerous remote modules bundled, by applying minifications > > > > and optimizations to each module. > > > > > > > > The remaining remote module that we are currently shipping is LightHouse. > > > > Since the remote appspot server is broken and unlikely to be fixed > > > > anytime soon, now is the best time to finally resolve the remote > > > > modules question. > > > > > > > > Therefore, we remove support for remote modules from the `module.json` > > > > files and `Runtime.js`. Additionally, we update the build system > > > > to properly generate the required files and load them via ES modules. > > > > > > > > We will be able to perform subsequent cleanups in the Runtime to remove > > > > more infrastructure related to scripts/remote modules, but given that > > > > this CL is already quite large we are doing that in a follow-up CL. > > > > > > > > Follow-up action items for the LightHouse folks are to further decrease > > > > the bundle size for LightHouse. Since we are now loading it via ES > > > > modules, we can now use ES imports in the `devtools-dt-bundle.js` as > > > > well. This allows us to remove the copy of the SDK files, as well as > > > > make use of proper ES exports, rather than the browserified requires. > > > > > > > > R=aerotwist@chromium.org,yangguo@chromium.org,paulirish@chromium.org > > > > > > > > Fixed: 1128890 > > > > Change-Id: Ib4271a8064b18d31b75d9e28dbe5e3cb3c77d7ff > > > > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2416511 > > > > Reviewed-by: Paul Lewis <aerotwist@chromium.org> > > > > Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> > > > > > > TBR=yangguo@chromium.org,paulirish@chromium.org,aerotwist@chromium.org,tvanderlippe@chromium.org > > > > > > Change-Id: I9d3da08108a35d7dadeefd526ea9dbd562ad3432 > > > No-Presubmit: true > > > No-Tree-Checks: true > > > No-Try: true > > > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2416519 > > > Reviewed-by: Alex Rudenko <alexrudenko@chromium.org> > > > Commit-Queue: Alex Rudenko <alexrudenko@chromium.org> > > > > Change-Id: I26bf0565297c8e167039362b30109d7020bbca56 > > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2418431 > > Commit-Queue: Paul Lewis <aerotwist@chromium.org> > > Reviewed-by: Paul Lewis <aerotwist@chromium.org> > > TBR=yangguo@chromium.org,paulirish@chromium.org,aerotwist@chromium.org,tvanderlippe@chromium.org,alexrudenko@chromium.org > > Change-Id: I0ed24d32c9b68bc4cb8026f6fc362540800beeb0 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2418408 > Reviewed-by: Paul Lewis <aerotwist@chromium.org> > Commit-Queue: Paul Lewis <aerotwist@chromium.org> Change-Id: I8718e9d94c384a13fd18261f8f497d32418658fb Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2421690 Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Paul Lewis <aerotwist@chromium.org>
173 lines
5.8 KiB
JavaScript
173 lines
5.8 KiB
JavaScript
// Copyright 2017 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
'use strict';
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const FRONTEND_PATH = path.resolve(__dirname, '..', 'front_end');
|
|
|
|
const manifestModules = [];
|
|
for (const config
|
|
of ['inspector.json', 'devtools_app.json', 'js_app.json', 'node_app.json', 'shell.json', 'worker_app.json']) {
|
|
manifestModules.push(...require(path.resolve(FRONTEND_PATH, config)).modules);
|
|
}
|
|
|
|
const gnPath = path.resolve(__dirname, '..', 'BUILD.gn');
|
|
const gnFile = fs.readFileSync(gnPath, 'utf-8');
|
|
const gnLines = gnFile.split('\n');
|
|
|
|
/**
|
|
* Ensures that generated module files are in the right list in BUILD.gn.
|
|
* This is primarily to avoid remote modules from accidentally getting
|
|
* bundled with the main Chrome binary.
|
|
*/
|
|
function checkNonAutostartNonRemoteModules() {
|
|
const errors = [];
|
|
const gnVariable = 'generated_non_autostart_non_remote_modules';
|
|
const lines = selectGNLines(`${gnVariable} = [`, ']');
|
|
if (!lines.length) {
|
|
return [
|
|
'Could not identify non-autostart non-remote modules in gn file',
|
|
'Please look at: ' + __filename,
|
|
];
|
|
}
|
|
const text = lines.join('\n');
|
|
const modules = manifestModules.filter(m => m.type !== 'autostart').map(m => m.name);
|
|
|
|
const missingModules = modules.filter(m => !text.includes(`${m}/${m}_module.js`));
|
|
if (missingModules.length) {
|
|
errors.push(`Check that you've included [${missingModules.join(', ')}] modules in: ` + gnVariable);
|
|
}
|
|
|
|
// e.g. "$resources_out_dir/lighthouse/lighthouse_module.js" => "lighthouse"
|
|
const mapLineToModuleName = line => line.split('/')[2].split('_module')[0];
|
|
|
|
const extraneousModules = lines.map(mapLineToModuleName).filter(module => !modules.includes(module));
|
|
if (extraneousModules.length) {
|
|
errors.push(`Found extraneous modules [${extraneousModules.join(', ')}] in: ` + gnVariable);
|
|
}
|
|
|
|
return errors;
|
|
}
|
|
|
|
/**
|
|
* Ensures that all source files (according to the various module.json files) are
|
|
* listed in BUILD.gn.
|
|
*/
|
|
function checkAllDevToolsFiles() {
|
|
return checkGNVariable('all_devtools_files', 'all_devtools_files', moduleJSON => {
|
|
const scripts = moduleJSON.scripts || [];
|
|
const resources = moduleJSON.resources || [];
|
|
return [
|
|
'module.json',
|
|
...scripts,
|
|
...resources,
|
|
];
|
|
});
|
|
}
|
|
|
|
function checkDevtoolsModuleEntrypoints() {
|
|
return checkGNVariable(
|
|
'devtools_module_entrypoints', 'devtools_module_entrypoint_sources',
|
|
(moduleJSON, folderName) => {
|
|
return (moduleJSON.modules || []).filter(fileName => {
|
|
return fileName === `${folderName}-legacy.js`;
|
|
});
|
|
},
|
|
buildGNPath => filename => {
|
|
const relativePath = path.normalize(`${buildGNPath}/${filename}`);
|
|
return `"${relativePath}",`;
|
|
});
|
|
}
|
|
|
|
function checkGNVariable(fileName, gnVariable, obtainFiles, obtainRelativePath) {
|
|
const filePath = path.resolve(__dirname, '..', `${fileName}.gni`);
|
|
const fileContent = fs.readFileSync(filePath, 'utf-8');
|
|
const linesToCheck = fileContent.split('\n');
|
|
|
|
const errors = [];
|
|
const excludedFiles =
|
|
['axe.js', 'formatter_worker/', 'third_party/lighthouse/', 'third_party/i18n/'].map(path.normalize);
|
|
const lines = selectGNLines(`${gnVariable} = [`, ']', linesToCheck).map(path.normalize);
|
|
if (!lines.length) {
|
|
return [
|
|
`Could not identify ${gnVariable} list in gn file`,
|
|
'Please look at: ' + __filename,
|
|
];
|
|
}
|
|
const gnFiles = new Set(lines);
|
|
let moduleFiles = [];
|
|
|
|
function addModuleFilesForDirectory(moduleJSONPath, buildGNPath, folderName) {
|
|
const moduleJSON = require(moduleJSONPath);
|
|
const files = obtainFiles(moduleJSON, folderName)
|
|
.map(obtainRelativePath && obtainRelativePath(buildGNPath) || relativePathFromBuildGN)
|
|
.filter(file => excludedFiles.every(excludedFile => !file.includes(excludedFile)));
|
|
moduleFiles = moduleFiles.concat(files);
|
|
|
|
function relativePathFromBuildGN(filename) {
|
|
const relativePath = path.normalize(`front_end/${buildGNPath}/${filename}`);
|
|
return `"${relativePath}",`;
|
|
}
|
|
}
|
|
|
|
function traverseDirectoriesForModuleJSONFiles(folderName, buildGNPath) {
|
|
if (!fs.lstatSync(folderName).isDirectory()) {
|
|
return;
|
|
}
|
|
const moduleJSONPath = path.join(folderName, 'module.json');
|
|
if (fs.existsSync(moduleJSONPath)) {
|
|
addModuleFilesForDirectory(moduleJSONPath, buildGNPath, path.basename(folderName));
|
|
}
|
|
|
|
fs.readdirSync(folderName).forEach(nestedModuleName => {
|
|
traverseDirectoriesForModuleJSONFiles(
|
|
path.join(folderName, nestedModuleName), `${buildGNPath}/${nestedModuleName}`);
|
|
});
|
|
}
|
|
|
|
fs.readdirSync(FRONTEND_PATH).forEach(moduleName => {
|
|
traverseDirectoriesForModuleJSONFiles(path.join(FRONTEND_PATH, moduleName), moduleName);
|
|
});
|
|
|
|
for (const file of moduleFiles) {
|
|
if (!gnFiles.has(file)) {
|
|
errors.push(`Missing file in BUILD.gn for ${gnVariable}: ` + file);
|
|
}
|
|
}
|
|
|
|
return errors;
|
|
}
|
|
|
|
function selectGNLines(startLine, endLine, linesToCheck = gnLines) {
|
|
const lines = linesToCheck.map(line => line.trim());
|
|
const startIndex = lines.indexOf(startLine);
|
|
if (startIndex === -1) {
|
|
return [];
|
|
}
|
|
const endIndex = lines.indexOf(endLine, startIndex);
|
|
if (endIndex === -1) {
|
|
return [];
|
|
}
|
|
return lines.slice(startIndex + 1, endIndex);
|
|
}
|
|
|
|
function main() {
|
|
const errors = [
|
|
...checkNonAutostartNonRemoteModules(),
|
|
...checkAllDevToolsFiles(),
|
|
...checkDevtoolsModuleEntrypoints(),
|
|
];
|
|
if (errors.length) {
|
|
console.log('DevTools BUILD.gn checker detected errors!');
|
|
console.log(`There's an issue with: ${gnPath}`);
|
|
console.log(errors.join('\n'));
|
|
process.exit(1);
|
|
}
|
|
console.log('DevTools BUILD.gn checker passed');
|
|
}
|
|
|
|
main();
|