Files
react-native-devtools-frontend/scripts/visualize_deps/run_visualize.js
T
Connor Clark 2bc3be29be Reland "[Lighthouse] Rename Audits panel to Lighthouse"
This reverts commit 0651468562.

Reason for revert: Cause of failure has been remedied. See: https://chromium-review.googlesource.com/c/chromium/src/+/2055398

Original change's description:
> Revert "[Lighthouse] Rename Audits panel to Lighthouse"
>
> This reverts commit 2ae53ef04d.
>
> Reason for revert: This CL breaks CI: https://ci.chromium.org/p/devtools-frontend/builders/ci/DevTools%20Linux/453. It looks like the layout test expects audits not lighthouse in the name, so it's probably in need of a 3-way merge.
>
> Original change's description:
> > [Lighthouse] Rename Audits panel to Lighthouse
> >
> > Change-Id: Ia2ab175d2a3b6c8ded73aff8ff0f5582f5a8fa0c
> > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2044605
> > Commit-Queue: Connor Clark <cjamcl@chromium.org>
> > Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
> > Reviewed-by: Paul Irish <paulirish@chromium.org>
>
> TBR=paulirish@chromium.org,aerotwist@chromium.org,tvanderlippe@chromium.org,cjamcl@chromium.org
>
> Change-Id: Ia6d5f42a0e6ece4352696c51bf0de5754774cb0a
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2051983
> Reviewed-by: Paul Lewis <aerotwist@chromium.org>
> Commit-Queue: Paul Lewis <aerotwist@chromium.org>

TBR=paulirish@chromium.org,aerotwist@chromium.org,tvanderlippe@chromium.org,cjamcl@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 1052111
Change-Id: I638ca9bd5cd94e02fb7318f2a7d7c66fca40e6c8
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2056866
Reviewed-by: Connor Clark <cjamcl@chromium.org>
Reviewed-by: Paul Irish <paulirish@chromium.org>
Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org>
Commit-Queue: Connor Clark <cjamcl@chromium.org>
2020-02-18 01:56:25 +00:00

114 lines
3.7 KiB
JavaScript

// Copyright 2016 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';
var childProcess = require('child_process');
const fs = require('fs');
var http = require('http');
const path = require('path');
var parseURL = require('url').parse;
const utils = require('../utils');
const FRONTEND_PATH = path.resolve(__dirname, '..', '..', 'front_end');
const OUT_DIR_PATH = path.resolve(__dirname, 'out');
const OUT_FILE_PATH = path.resolve(OUT_DIR_PATH, 'dependencies.dot');
const SERVER_PORT = parseInt(process.env.PORT, 10) || 8001;
function main() {
generateDot();
try {
childProcess.execSync(`dot -O -Tsvg ${OUT_FILE_PATH}`);
} catch (err) {
console.log(`Could not generate dot svg because: ${err}`);
console.log('Make sure you have graphviz installed (e.g. sudo apt install graphviz)');
return;
}
console.log('Generated dot file & svg');
startServer();
console.log(`Go to: http://localhost:${SERVER_PORT}/jquery_svg.html`);
}
function generateDot() {
if (!utils.isDir(OUT_DIR_PATH))
fs.mkdirSync(OUT_DIR_PATH);
const modules = new Set();
const moduleToDependencyList = ['digraph dependencies {'];
moduleToDependencyList.push('fixedsize = true;');
fs.readdirSync(FRONTEND_PATH).forEach(function(file) {
const moduleJSONPath = path.join(FRONTEND_PATH, file, 'module.json');
if (fs.statSync(path.join(FRONTEND_PATH, file)).isDirectory() && utils.isFile(moduleJSONPath)) {
const module = file;
if (module === 'lighthouse_worker')
return;
modules.add(module);
const moduleJSON = require(moduleJSONPath);
let moduleSize = 0;
let resources = (moduleJSON.scripts || []).concat((moduleJSON.resources || []));
for (let script of resources) {
if (fs.existsSync(path.join(FRONTEND_PATH, module, script)))
moduleSize += fs.statSync(path.join(FRONTEND_PATH, module, script)).size;
}
moduleSize /= 200000;
moduleSize = Math.max(0.5, moduleSize);
let fontSize = Math.max(moduleSize * 14, 14);
moduleToDependencyList.push(`${module} [width=${moduleSize}, height=${moduleSize} fontsize=${fontSize}];`);
if (moduleJSON.dependencies) {
for (let d of moduleJSON.dependencies)
moduleToDependencyList.push(` ${module} -> ${d}`);
}
}
});
moduleToDependencyList.push('}');
const content = moduleToDependencyList.join('\n');
fs.writeFileSync(OUT_FILE_PATH, content);
}
function startServer() {
http.createServer(requestHandler).listen(SERVER_PORT);
function requestHandler(request, response) {
var filePath = parseURL(request.url).pathname;
var absoluteFilePath = path.join(__dirname, filePath);
if (!path.resolve(absoluteFilePath).startsWith(__dirname)) {
console.log(`File requested is outside of folder: ${__dirname}`);
sendResponse(403, `403 - Access denied. File requested is outside of folder: ${__dirname}`);
return;
}
fs.exists(absoluteFilePath, fsExistsCallback);
function fsExistsCallback(fileExists) {
if (!fileExists) {
console.log(`Cannot find file ${absoluteFilePath}`);
sendResponse(404, '404 - File not found');
return;
}
fs.readFile(absoluteFilePath, 'binary', readFileCallback);
}
function readFileCallback(err, file) {
if (err) {
console.log(`Unable to read local file ${absoluteFilePath}:`, err);
sendResponse(500, '500 - Internal Server Error');
return;
}
sendResponse(200, file);
}
function sendResponse(statusCode, data) {
response.writeHead(statusCode);
response.write(data, 'binary');
response.end();
}
}
}
if (require.main === module)
main();