mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-09-28 13:13:37 +08:00
This provides consistency of how imports are order, reducing differences in authored files. Bug: none Change-Id: I45ddd71e3e0004aca32f101cb926101544a34157 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6218490 Commit-Queue: Nikolay Vitkov <nvitkov@chromium.org> Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
67 lines
2.3 KiB
JavaScript
67 lines
2.3 KiB
JavaScript
// Copyright 2023 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';
|
|
|
|
/**
|
|
* Finds trace files in fixtures/traces with references to the provided string.
|
|
*
|
|
* Usage:
|
|
* node scripts/search-trace-files.js "v8.parse"
|
|
*/
|
|
|
|
const child_process = require('child_process');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const TRACE_FILES_DIR = path.join(__dirname, '..', 'front_end', 'panels', 'timeline', 'fixtures', 'traces');
|
|
|
|
// Get a list of all trace files (gzipped or otherwise)
|
|
const filesInDir = fs.readdirSync(TRACE_FILES_DIR, 'utf8').filter(file => file.includes('.json'));
|
|
|
|
// A set of all the *.json files that we find.
|
|
const extractedFilePaths = new Set();
|
|
|
|
for (const fileNameWithExt of filesInDir) {
|
|
// Get the name of the file with no extensions. /foo/bar/baz.json.gz => "baz"
|
|
const fileName = path.basename(fileNameWithExt).split('.')[0];
|
|
|
|
const fullPath = path.join(TRACE_FILES_DIR, `${fileName}.json.gz`);
|
|
// If we found a .json.gz without a matching .json, extract the file.
|
|
// traces/*.json are gitignored, so we can safely do this without risking
|
|
// them being committed.
|
|
if (!fs.existsSync(path.join(TRACE_FILES_DIR, `${fileName}.json`))) {
|
|
console.log('[One time operation] Extracting gzip:', fileName);
|
|
const result = child_process.spawnSync('gzip', ['--keep', '-d', `${fullPath}`]);
|
|
if (result.status !== 0) {
|
|
console.error(`Error extracting ${path.basename(fullPath)}: ${result.output}`);
|
|
}
|
|
}
|
|
extractedFilePaths.add(path.join(TRACE_FILES_DIR, `${fileName}.json`));
|
|
}
|
|
|
|
const searchTerm = process.argv[2];
|
|
console.log('Searching for', `"${searchTerm}"`);
|
|
|
|
const matches = new Set();
|
|
|
|
Array.from(extractedFilePaths).forEach(fileToCheck => {
|
|
if (!fs.existsSync(fileToCheck)) {
|
|
return null;
|
|
}
|
|
// Yes, this is pretty inefficient to read the entire file sync, but this
|
|
// is only a hacky helper script so it will do :)
|
|
const contents = fs.readFileSync(fileToCheck, 'utf8');
|
|
const hasMatch = contents.includes(searchTerm);
|
|
if (hasMatch) {
|
|
matches.add(fileToCheck);
|
|
}
|
|
});
|
|
|
|
if (matches.size) {
|
|
const matchesSorted = Array.from(matches).map(fullPath => path.relative(TRACE_FILES_DIR, fullPath)).sort();
|
|
console.log('\n=> ' + matchesSorted.join('\n=> '));
|
|
} else {
|
|
console.log('No matches found :(');
|
|
}
|