Skip to content

Commit

Permalink
misc: get LH_ROOT via new file root.js (GoogleChrome#12724)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark authored Jun 30, 2021
1 parent b877878 commit 8bb2f21
Show file tree
Hide file tree
Showing 34 changed files with 82 additions and 60 deletions.
4 changes: 2 additions & 2 deletions build/build-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ const fs = require('fs');
const path = require('path');
const assert = require('assert').strict;
const mkdir = fs.promises.mkdir;

const LighthouseRunner = require('../lighthouse-core/runner.js');
const exorcist = require('exorcist');
const browserify = require('browserify');
const terser = require('terser');
const {minifyFileTransform} = require('./build-utils.js');
const {LH_ROOT} = require('../root.js');

const COMMIT_HASH = require('child_process')
.execSync('git rev-parse HEAD')
Expand All @@ -31,7 +31,7 @@ const audits = LighthouseRunner.getAuditList()
const gatherers = LighthouseRunner.getGathererList()
.map(f => './lighthouse-core/gather/gatherers/' + f.replace(/\.js$/, ''));

const locales = fs.readdirSync(__dirname + '/../lighthouse-core/lib/i18n/locales/')
const locales = fs.readdirSync(LH_ROOT + '/lighthouse-core/lib/i18n/locales/')
.map(f => require.resolve(`../lighthouse-core/lib/i18n/locales/${f}`));

// HACK: manually include the lighthouse-plugin-publisher-ads audits.
Expand Down
3 changes: 2 additions & 1 deletion build/build-cdt-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

const fs = require('fs');
const ts = require('typescript');
const {LH_ROOT} = require('../root.js');

const outDir = `${__dirname}/../lighthouse-core/lib/cdt/generated`;
const outDir = `${LH_ROOT}/lighthouse-core/lib/cdt/generated`;
const files = {
'node_modules/chrome-devtools-frontend/front_end/sdk/SourceMap.js': 'SourceMap.js',
};
Expand Down
3 changes: 2 additions & 1 deletion build/build-dt-report-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ const browserify = require('browserify');
const fs = require('fs');
const path = require('path');
const assert = require('assert').strict;
const {LH_ROOT} = require('../root.js');

const distDir = path.join(__dirname, '..', 'dist', 'dt-report-resources');
const distDir = path.join(LH_ROOT, 'dist', 'dt-report-resources');
const bundleOutFile = `${distDir}/report-generator.js`;
const generatorFilename = `./report/report-generator.js`;
const htmlReportAssets = require('../report/report-assets.js');
Expand Down
6 changes: 3 additions & 3 deletions build/build-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@

const fs = require('fs');
const mkdir = fs.promises.mkdir;

const archiver = require('archiver');
const cpy = require('cpy');
const browserify = require('browserify');
const path = require('path');
const {LH_ROOT} = require('../root.js');

const argv = process.argv.slice(2);
const browserBrand = argv[0];

const sourceName = 'popup.js';
const distName = 'popup-bundle.js';

const sourceDir = `${__dirname}/../clients/extension`;
const distDir = `${__dirname}/../dist/extension-${browserBrand}`;
const sourceDir = `${LH_ROOT}/clients/extension`;
const distDir = `${LH_ROOT}/dist/extension-${browserBrand}`;
const packagePath = `${distDir}/../extension-${browserBrand}-package`;

const manifestVersion = require(`${sourceDir}/manifest.json`).version;
Expand Down
5 changes: 3 additions & 2 deletions build/build-lightrider-bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ const fs = require('fs');
const path = require('path');
const bundleBuilder = require('./build-bundle.js');
const {minifyFileTransform} = require('./build-utils.js');
const {LH_ROOT} = require('../root.js');

const distDir = path.join(__dirname, '..', 'dist', 'lightrider');
const sourceDir = __dirname + '/../clients/lightrider';
const distDir = path.join(LH_ROOT, 'dist', 'lightrider');
const sourceDir = path.join(LH_ROOT, 'clients', 'lightrider');

const bundleOutFile = `${distDir}/report-generator-bundle.js`;
const generatorFilename = `./report/report-generator.js`;
Expand Down
3 changes: 2 additions & 1 deletion build/build-smokehouse-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

const browserify = require('browserify');
const fs = require('fs');
const {LH_ROOT} = require('../root.js');

const distDir = `${__dirname}/../dist`;
const distDir = `${LH_ROOT}/dist`;
const bundleOutFile = `${distDir}/smokehouse-bundle.js`;
const smokehouseLibFilename = './lighthouse-cli/test/smokehouse/frontends/lib.js';

Expand Down
3 changes: 2 additions & 1 deletion build/build-treemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

const fs = require('fs');
const GhPagesApp = require('./gh-pages-app.js');
const {LH_ROOT} = require('../root.js');

/**
* Extract only the strings needed for lighthouse-treemap into
Expand Down Expand Up @@ -46,7 +47,7 @@ function buildStrings() {
async function run() {
const app = new GhPagesApp({
name: 'treemap',
appDir: `${__dirname}/../lighthouse-treemap/app`,
appDir: `${LH_ROOT}/lighthouse-treemap/app`,
html: {path: 'index.html'},
stylesheets: [
fs.readFileSync(require.resolve('tabulator-tables/dist/css/tabulator.min.css'), 'utf8'),
Expand Down
5 changes: 3 additions & 2 deletions build/build-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ const GhPagesApp = require('./gh-pages-app.js');
const {minifyFileTransform} = require('./build-utils.js');
const {concatRendererCode} = require('./build-report.js');
const htmlReportAssets = require('../report/report-assets.js');
const {LH_ROOT} = require('../root.js');

/**
* Build viewer, optionally deploying to gh-pages if `--deploy` flag was set.
*/
async function run() {
// JS bundle from browserified ReportGenerator.
const generatorFilename = `${__dirname}/../report/report-generator.js`;
const generatorFilename = `${LH_ROOT}/report/report-generator.js`;
const generatorBrowserify = browserify(generatorFilename, {standalone: 'ReportGenerator'})
.transform('@wardpeet/brfs', {
readFileSyncTransform: minifyFileTransform,
Expand All @@ -33,7 +34,7 @@ async function run() {

const app = new GhPagesApp({
name: 'viewer',
appDir: `${__dirname}/../lighthouse-viewer/app`,
appDir: `${LH_ROOT}/lighthouse-viewer/app`,
html: {path: 'index.html'},
htmlReplacements: {
'%%LIGHTHOUSE_TEMPLATES%%': htmlReportAssets.REPORT_TEMPLATES,
Expand Down
1 change: 1 addition & 0 deletions build/changelog-generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
'use strict';

const readFileSync = require('fs').readFileSync;
const resolve = require('path').resolve;
const mainTemplate = readFileSync(resolve(__dirname, 'templates/template.hbs')).toString();
Expand Down
4 changes: 2 additions & 2 deletions build/gh-pages-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

const fs = require('fs');
const path = require('path');

const cpy = require('cpy');
const ghPages = require('gh-pages');
const glob = require('glob');
const lighthousePackage = require('../package.json');
const terser = require('terser');
const {LH_ROOT} = require('../root.js');

const ghPagesDistDir = `${__dirname}/../dist/gh-pages`;
const ghPagesDistDir = `${LH_ROOT}/dist/gh-pages`;

const license = `/*
* @license Copyright 2020 The Lighthouse Authors. All Rights Reserved.
Expand Down
3 changes: 2 additions & 1 deletion clients/test/extension/popup-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ const path = require('path');
const puppeteer = require('puppeteer');
const {DEFAULT_CATEGORIES, STORAGE_KEYS} =
require('../../extension/scripts/settings-controller.js');
const {LH_ROOT} = require('../../../root.js');

const lighthouseExtensionPath = path.resolve(__dirname, '../../../dist/extension-chrome');
const lighthouseExtensionPath = path.resolve(LH_ROOT, 'dist/extension-chrome');

const mockStorage = {
[STORAGE_KEYS.Categories]: {
Expand Down
14 changes: 6 additions & 8 deletions lighthouse-cli/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
*/
'use strict';

const fs = require('fs');
const path = require('path');

/*
* The relationship between these CLI modules:
/**
* @fileoverview The relationship between these CLI modules:
*
* index.js : only calls bin.js's begin()
* cli-flags.js : leverages yargs to read argv, outputs LH.CliFlags
Expand All @@ -21,24 +18,25 @@ const path = require('path');
* cli-flags lh-core/index
*/

const fs = require('fs');
const path = require('path');
const commands = require('./commands/commands.js');
const printer = require('./printer.js');
const {getFlags} = require('./cli-flags.js');
const {runLighthouse} = require('./run.js');
const {generateConfig} = require('../lighthouse-core/index.js');

const log = require('lighthouse-logger');
const pkg = require('../package.json');
const Sentry = require('../lighthouse-core/lib/sentry.js');

const updateNotifier = require('update-notifier');
const {askPermission} = require('./sentry-prompt.js');
const {LH_ROOT} = require('../root.js');

/**
* @return {boolean}
*/
function isDev() {
return fs.existsSync(path.join(__dirname, '../.git'));
return fs.existsSync(path.join(LH_ROOT, '/.git'));
}

/**
Expand Down
5 changes: 3 additions & 2 deletions lighthouse-cli/test/cli/run-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
const assert = require('assert').strict;
const path = require('path');
const fs = require('fs');

const run = require('../../run.js');
const parseChromeFlags = require('../../run.js').parseChromeFlags;
const {LH_ROOT} = require('../../../root.js');

/** @type {LH.Config.Json} */
const testConfig = {
'extends': 'lighthouse:default',
Expand Down Expand Up @@ -39,7 +40,7 @@ describe('CLI run', function() {
beforeAll(async () => {
const url = 'http://localhost:10200/dobetterweb/dbw_tester.html';
// eslint-disable-next-line max-len
const samplev2ArtifactsPath = __dirname + '/../../../lighthouse-core/test/results/artifacts/';
const samplev2ArtifactsPath = LH_ROOT + '/lighthouse-core/test/results/artifacts/';

// eslint-disable-next-line max-len
const flags = getFlags([
Expand Down
6 changes: 3 additions & 3 deletions lighthouse-cli/test/fixtures/static-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ const mime = require('mime-types');
const parseQueryString = require('querystring').parse;
const parseURL = require('url').parse;
const URLSearchParams = require('url').URLSearchParams;
const HEADER_SAFELIST = new Set(['x-robots-tag', 'link', 'content-security-policy']);
const {LH_ROOT} = require('../../../root.js');

const lhRootDirPath = path.join(__dirname, '../../../');
const HEADER_SAFELIST = new Set(['x-robots-tag', 'link', 'content-security-policy']);

class Server {
baseDir = __dirname;
Expand Down Expand Up @@ -192,7 +192,7 @@ class Server {

// Disallow file requests outside of LH folder
const filePathDir = path.parse(absoluteFilePath).dir;
if (!filePathDir.startsWith(lhRootDirPath)) {
if (!filePathDir.startsWith(LH_ROOT)) {
return readFileCallback(new Error('Disallowed path'));
}

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/lib/i18n/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ const lookupClosestLocale = require('lookup-closest-locale');
const LOCALES = require('./locales.js');
const {isObjectOfUnknownValues, isObjectOrArrayOfUnknownValues} = require('../type-verifiers.js');
const log = require('lighthouse-logger');
const {LH_ROOT} = require('../../../root.js');

const DEFAULT_LOCALE = 'en';

/** @typedef {import('intl-messageformat-parser').Element} MessageElement */
/** @typedef {import('intl-messageformat-parser').ArgumentElement} ArgumentElement */

const LH_ROOT = path.join(__dirname, '../../../');
const MESSAGE_I18N_ID_REGEX = / | [^\s]+$/;

const UIStrings = {
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/scripts/build-report-for-autodeployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
const fs = require('fs');
const path = require('path');
const swapLocale = require('../lib/i18n/swap-locale.js');

const ReportGenerator = require('../../report/report-generator.js');
const {defaultSettings} = require('../config/constants.js');
const lighthouse = require('../index.js');
const lhr = /** @type {LH.Result} */ (require('../../lighthouse-core/test/results/sample_v2.json'));
const {LH_ROOT} = require('../../root.js');

const DIST = path.join(__dirname, `../../dist/now`);
const DIST = path.join(LH_ROOT, `dist/now`);

(async function() {
addPluginCategory(lhr);
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/scripts/compare-runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ const glob = require('glob');
const util = require('util');
const execFile = util.promisify(require('child_process').execFile);
const yargs = require('yargs');
const {LH_ROOT} = require('../../root.js');

const {ProgressLogger} = require('./lantern/collect/common.js');

const LH_ROOT = `${__dirname}/../..`;
const ROOT_OUTPUT_DIR = `${LH_ROOT}/timings-data`;

const rawArgv = yargs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

const fs = require('fs');
const path = require('path');
const {LH_ROOT} = require('../../../root.js');

const LH_ROOT = path.join(__dirname, '../../../');
const TMP_DIR = path.join(LH_ROOT, '.tmp/gcp-instances');
const URLS_LIST = process.argv[2]
? path.resolve(process.cwd(), process.argv[2])
Expand Down
3 changes: 1 addition & 2 deletions lighthouse-core/scripts/i18n/bake-ctc-to-lhl.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

const fs = require('fs');
const path = require('path');

const LH_ROOT = path.join(__dirname, '../../../');
const {LH_ROOT} = require('../../../root.js');

/**
* @typedef CtcMessage
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/scripts/i18n/collect-strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const Util = require('../../../report/renderer/util.js');
const {collectAndBakeCtcStrings} = require('./bake-ctc-to-lhl.js');
const {pruneObsoleteLhlMessages} = require('./prune-obsolete-lhl-messages.js');
const {countTranslatedMessages} = require('./count-translated.js');
const {LH_ROOT} = require('../../../root.js');

const LH_ROOT = path.join(__dirname, '../../../');
const UISTRINGS_REGEX = /UIStrings = .*?\};\n/s;

/** @typedef {import('./bake-ctc-to-lhl.js').CtcMessage} CtcMessage */
Expand Down
9 changes: 5 additions & 4 deletions lighthouse-core/scripts/i18n/count-translated.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

const fs = require('fs');
const glob = require('glob');
const path = require('path');
const {LH_ROOT} = require('../../../root.js');

const lhRoot = `${__dirname}/../../../`;
const enUsLhlFilename = lhRoot + 'lighthouse-core/lib/i18n/locales/en-US.json';
const enUsLhlFilename = LH_ROOT + '/lighthouse-core/lib/i18n/locales/en-US.json';
/** @type {LhlMessages} */
const enUsLhl = JSON.parse(fs.readFileSync(enUsLhlFilename, 'utf8'));

Expand All @@ -30,7 +31,7 @@ function countTranslatedMessages() {
const globPattern = 'lighthouse-core/lib/i18n/locales/**/+([-a-zA-Z0-9]).json';
const localeFilenames = glob.sync(globPattern, {
ignore,
cwd: lhRoot,
cwd: LH_ROOT,
});

/** @type {Array<[string, number]>} */
Expand All @@ -40,7 +41,7 @@ function countTranslatedMessages() {
for (const localeFilename of localeFilenames) {
// Use readFileSync in case other code in this process has altered the require()d form.
/** @type {LhlMessages} */
const localeLhl = JSON.parse(fs.readFileSync(lhRoot + localeFilename, 'utf-8'));
const localeLhl = JSON.parse(fs.readFileSync(path.join(LH_ROOT, localeFilename), 'utf-8'));

for (const localeKey of Object.keys(localeLhl)) {
const messageCount = countPerMessage.get(localeKey);
Expand Down
7 changes: 3 additions & 4 deletions lighthouse-core/scripts/i18n/prune-obsolete-lhl-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const fs = require('fs');
const path = require('path');
const glob = require('glob');
const MessageParser = require('intl-messageformat-parser').default;

const {collectAllCustomElementsFromICU} = require('../../lib/i18n/i18n.js');
const {LH_ROOT} = require('../../../root.js');

/** @typedef {Record<string, {message: string}>} LhlMessages */

Expand Down Expand Up @@ -125,16 +125,15 @@ function pruneObsoleteLhlMessages() {
'**/en-XL.json',
];
const globPattern = 'lighthouse-core/lib/i18n/locales/**/+([-a-zA-Z0-9]).json';
const lhRoot = `${__dirname}/../../../`;
const localePaths = glob.sync(globPattern, {
ignore,
cwd: lhRoot,
cwd: LH_ROOT,
});

/** @type {Set<string>} */
const alreadyLoggedPrunes = new Set();
for (const localePath of localePaths) {
const absoluteLocalePath = path.join(lhRoot, localePath);
const absoluteLocalePath = path.join(LH_ROOT, localePath);
// readFileSync so that the file is pulled again once updated by a collect-strings run
const localeLhl = JSON.parse(fs.readFileSync(absoluteLocalePath, 'utf-8'));
const prunedLocale = pruneLocale(goldenLocaleArgumentIds, localeLhl, alreadyLoggedPrunes);
Expand Down
Loading

0 comments on commit 8bb2f21

Please sign in to comment.