Skip to content

Commit

Permalink
core(legacy): create legacy directory under core (#14341)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamraine committed Sep 9, 2022
1 parent 6b92590 commit f8bb5a0
Show file tree
Hide file tree
Showing 29 changed files with 131 additions and 128 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ accept your pull requests.
## Tracking Errors
We track our errors in the wild with Sentry. In general, do not worry about wrapping your audits or gatherers in try/catch blocks and reporting every error that could possibly occur; `core/runner.js` and `core/gather/gather-runner.js` already catch and report any errors that occur while running a gatherer or audit, including errors fatal to the entire run. However, there are some situations when you might want to explicitly handle an error and report it to Sentry or wrap it to avoid reporting. Generally, you can interact with Sentry simply by requiring the `core/lib/sentry.js` file and call its methods. The module exports a delegate that will correctly handle the error reporting based on the user's opt-in preference and will simply no-op if they haven't so you don't need to check.
We track our errors in the wild with Sentry. In general, do not worry about wrapping your audits or gatherers in try/catch blocks and reporting every error that could possibly occur; `core/runner.js` and `core/fraggle-rock/gather/*-runner.js` already catch and report any errors that occur while running a gatherer or audit, including errors fatal to the entire run. However, there are some situations when you might want to explicitly handle an error and report it to Sentry or wrap it to avoid reporting. Generally, you can interact with Sentry simply by requiring the `core/lib/sentry.js` file and call its methods. The module exports a delegate that will correctly handle the error reporting based on the user's opt-in preference and will simply no-op if they haven't so you don't need to check.


#### If you have an expected error that is recoverable but want to track how frequently it happens, *use Sentry.captureException*.
Expand Down
2 changes: 1 addition & 1 deletion build/build-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ async function buildBundle(entryPath, distPath, opts = {minify: true}) {

/** @type {Record<string, string>} */
const shimsObj = {
[require.resolve('../core/gather/connections/cri.js')]:
[require.resolve('../core/legacy/gather/connections/cri.js')]:
'export const CriConnection = {}',
[require.resolve('../package.json')]: `export const version = '${pkg.version}';`,
};
Expand Down
2 changes: 1 addition & 1 deletion cli/test/smokehouse/lighthouse-runners/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {once} from 'events';
import puppeteer from 'puppeteer-core';
import ChromeLauncher from 'chrome-launcher';

import {CriConnection} from '../../../../core/gather/connections/cri.js';
import {CriConnection} from '../../../../core/legacy/gather/connections/cri.js';
import {LH_ROOT} from '../../../../root.js';
import {loadArtifacts, saveArtifacts} from '../../../../core/lib/asset-saver.js';

Expand Down
6 changes: 3 additions & 3 deletions clients/devtools/devtools-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import log from 'lighthouse-logger';

import lighthouse, {legacyNavigation} from '../../core/index.js';
import {navigation, startTimespan, snapshot} from '../../core/fraggle-rock/api.js';
import {RawConnection} from '../../core/gather/connections/raw.js';
import {RawConnection} from '../../core/legacy/gather/connections/raw.js';
import {lookupLocale} from '../../core/lib/i18n/i18n.js';
import {registerLocaleData, getCanonicalLocales} from '../../shared/localization/format.js';
import * as constants from '../../core/config/constants.js';

/** @typedef {import('../../core/gather/connections/connection.js')} Connection */
/** @typedef {import('../../core/legacy/gather/connections/connection.js')} Connection */

// Rollup seems to overlook some references to `Buffer`, so it must be made explicit.
// (`parseSourceMapFromDataUrl` breaks without this)
Expand Down Expand Up @@ -58,7 +58,7 @@ function createConfig(categoryIDs, device) {
}

/**
* @param {import('../../core/gather/connections/raw.js').Port} port
* @param {import('../../core/legacy/gather/connections/raw.js').Port} port
* @return {RawConnection}
*/
function setUpWorkerConnection(port) {
Expand Down
2 changes: 1 addition & 1 deletion clients/lightrider/lightrider-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const LR_PRESETS = {
desktop: desktopConfig,
};

/** @typedef {import('../../core/gather/connections/connection.js').Connection} Connection */
/** @typedef {import('../../core/legacy/gather/connections/connection.js').Connection} Connection */

// Rollup seems to overlook some references to `Buffer`, so it must be made explicit.
// (`parseSourceMapFromDataUrl` breaks without this)
Expand Down
2 changes: 1 addition & 1 deletion core/gather/gatherers/seo/font-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const MINIMAL_LEGIBLE_FONT_SIZE_PX = 12;
// limit number of protocol calls to make sure that gatherer doesn't take more than 1-2s
const MAX_NODES_SOURCE_RULE_FETCHED = 50; // number of nodes to fetch the source font-size rule

/** @typedef {import('../../driver.js')} Driver */
/** @typedef {import('../../../legacy/gather/driver.js')} Driver */
/** @typedef {LH.Artifacts.FontSize['analyzedFailingNodesData'][0]} NodeFontData */
/** @typedef {Map<number, {fontSize: number, textLength: number}>} BackendIdsToFontData */

Expand Down
8 changes: 4 additions & 4 deletions core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import log from 'lighthouse-logger';

import {Runner} from './runner.js';
import {CriConnection} from './gather/connections/cri.js';
import {Config} from './config/config.js';
import {CriConnection} from './legacy/gather/connections/cri.js';
import {Config} from './legacy/config/config.js';
import UrlUtils from './lib/url-utils.js';
import * as fraggleRock from './fraggle-rock/api.js';
import {Driver} from './gather/driver.js';
import {Driver} from './legacy/gather/driver.js';
import {initializeConfig} from './fraggle-rock/config/config.js';

/** @typedef {import('./gather/connections/connection.js').Connection} Connection */
/** @typedef {import('./legacy/gather/connections/connection.js').Connection} Connection */

/*
* The relationship between these root modules:
Expand Down
14 changes: 7 additions & 7 deletions core/config/config.js → core/legacy/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import path from 'path';
import log from 'lighthouse-logger';

import legacyDefaultConfig from './legacy-default-config.js';
import * as constants from './constants.js';
import * as format from '../../shared/localization/format.js';
import * as validation from './../fraggle-rock/config/validation.js';
import {Runner} from '../runner.js';
import * as constants from '../../config/constants.js';
import * as format from '../../../shared/localization/format.js';
import * as validation from '../../fraggle-rock/config/validation.js';
import {Runner} from '../../runner.js';
import {
mergePlugins,
mergeConfigFragment,
Expand All @@ -21,12 +21,12 @@ import {
resolveGathererToDefn,
deepClone,
deepCloneConfigJson,
} from './config-helpers.js';
import {getModuleDirectory} from '../../esm-utils.js';
} from '../../config/config-helpers.js';
import {getModuleDirectory} from '../../../esm-utils.js';

const defaultConfigPath = './legacy-default-config.js';

/** @typedef {typeof import('../gather/gatherers/gatherer.js').Gatherer} GathererConstructor */
/** @typedef {typeof import('../../gather/gatherers/gatherer.js').Gatherer} GathererConstructor */
/** @typedef {InstanceType<GathererConstructor>} Gatherer */

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @fileoverview Construct the legacy default config from the standard default config.
*/

import defaultConfig from './default-config.js';
import defaultConfig from '../../config/default-config.js';

/** @type {LH.Config.Json} */
const legacyDefaultConfig = JSON.parse(JSON.stringify(defaultConfig));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {EventEmitter} from 'events';

import log from 'lighthouse-logger';

import {LighthouseError} from '../../lib/lh-error.js';
import {LighthouseError} from '../../../lib/lh-error.js';

// TODO(bckenny): CommandCallback properties should be tied by command type after
// https://github.com/Microsoft/TypeScript/pull/22348. See driver.js TODO.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import WebSocket from 'ws';
import log from 'lighthouse-logger';

import {Connection} from './connection.js';
import {LighthouseError} from '../../lib/lh-error.js';
import {LighthouseError} from '../../../lib/lh-error.js';

const DEFAULT_HOSTNAME = '127.0.0.1';
const CONNECT_TIMEOUT = 10000;
Expand Down
File renamed without changes.
14 changes: 7 additions & 7 deletions core/gather/driver.js → core/legacy/gather/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import {EventEmitter} from 'events';

import log from 'lighthouse-logger';

import {Fetcher} from './fetcher.js';
import {ExecutionContext} from './driver/execution-context.js';
import {LighthouseError} from '../lib/lh-error.js';
import {fetchResponseBodyFromCache} from '../gather/driver/network.js';
import {DevtoolsMessageLog} from './gatherers/devtools-log.js';
import TraceGatherer from './gatherers/trace.js';
import {getBrowserVersion} from './driver/environment.js';
import {Fetcher} from '../../gather/fetcher.js';
import {ExecutionContext} from '../../gather/driver/execution-context.js';
import {LighthouseError} from '../../lib/lh-error.js';
import {fetchResponseBodyFromCache} from '../../gather/driver/network.js';
import {DevtoolsMessageLog} from '../../gather/gatherers/devtools-log.js';
import TraceGatherer from '../../gather/gatherers/trace.js';
import {getBrowserVersion} from '../../gather/driver/environment.js';

// Controls how long to wait for a response after sending a DevTools protocol command.
const DEFAULT_PROTOCOL_TIMEOUT = 30000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@

import log from 'lighthouse-logger';

import {NetworkRecords} from '../computed/network-records.js';
import {getPageLoadError} from '../lib/navigation-error.js';
import * as emulation from '../lib/emulation.js';
import * as constants from '../config/constants.js';
import * as format from '../../shared/localization/format.js';
import {getBenchmarkIndex, getEnvironmentWarnings} from './driver/environment.js';
import * as prepare from './driver/prepare.js';
import * as storage from './driver/storage.js';
import * as navigation from './driver/navigation.js';
import * as serviceWorkers from './driver/service-workers.js';
import WebAppManifest from './gatherers/web-app-manifest.js';
import InstallabilityErrors from './gatherers/installability-errors.js';
import NetworkUserAgent from './gatherers/network-user-agent.js';
import Stacks from './gatherers/stacks.js';
import {finalizeArtifacts} from '../fraggle-rock/gather/base-artifacts.js';
import UrlUtils from '../lib/url-utils.js';

/** @typedef {import('../gather/driver.js').Driver} Driver */
/** @typedef {import('../lib/arbitrary-equality-map.js').ArbitraryEqualityMap} ArbitraryEqualityMap */
import {NetworkRecords} from '../../computed/network-records.js';
import {getPageLoadError} from '../../lib/navigation-error.js';
import * as emulation from '../../lib/emulation.js';
import * as constants from '../../config/constants.js';
import * as format from '../../../shared/localization/format.js';
import {getBenchmarkIndex, getEnvironmentWarnings} from '../../gather/driver/environment.js';
import * as prepare from '../../gather/driver/prepare.js';
import * as storage from '../../gather/driver/storage.js';
import * as navigation from '../../gather/driver/navigation.js';
import * as serviceWorkers from '../../gather/driver/service-workers.js';
import WebAppManifest from '../../gather/gatherers/web-app-manifest.js';
import InstallabilityErrors from '../../gather/gatherers/installability-errors.js';
import NetworkUserAgent from '../../gather/gatherers/network-user-agent.js';
import Stacks from '../../gather/gatherers/stacks.js';
import {finalizeArtifacts} from '../../fraggle-rock/gather/base-artifacts.js';
import UrlUtils from '../../lib/url-utils.js';

/** @typedef {import('./driver.js').Driver} Driver */
/** @typedef {import('../../lib/arbitrary-equality-map.js').ArbitraryEqualityMap} ArbitraryEqualityMap */

/**
* Each entry in each gatherer result array is the output of a gatherer phase:
Expand Down
9 changes: 5 additions & 4 deletions core/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
import fs from 'fs';
import path from 'path';

import isDeepEqual from 'lodash/isEqual.js';

import log from 'lighthouse-logger';
import isDeepEqual from 'lodash/isEqual.js';

import {Driver} from './gather/driver.js';
import {GatherRunner} from './gather/gather-runner.js';
import {Driver} from './legacy/gather/driver.js';
import {GatherRunner} from './legacy/gather/gather-runner.js';
import {ReportScoring} from './scoring.js';
import {Audit} from './audits/audit.js';
import * as format from '../shared/localization/format.js';
Expand All @@ -25,7 +26,7 @@ import {getModuleDirectory} from '../esm-utils.js';

const moduleDir = getModuleDirectory(import.meta);

/** @typedef {import('./gather/connections/connection.js').Connection} Connection */
/** @typedef {import('./legacy/gather/connections/connection.js').Connection} Connection */
/** @typedef {import('./lib/arbitrary-equality-map.js').ArbitraryEqualityMap} ArbitraryEqualityMap */
/** @typedef {LH.Config.Config} Config */

Expand Down
4 changes: 2 additions & 2 deletions core/test/gather/fetcher-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

import {Fetcher} from '../../gather/fetcher.js';
import {Driver} from '../../gather/driver.js';
import {Connection} from '../../gather/connections/connection.js';
import {Driver} from '../../legacy/gather/driver.js';
import {Connection} from '../../legacy/gather/connections/connection.js';
import {fnAny, mockCommands} from '../test-utils.js';

const {createMockSendCommandFn} = mockCommands;
Expand Down
4 changes: 2 additions & 2 deletions core/test/gather/gatherers/global-listeners-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import GlobalListenerGatherer from '../../../gather/gatherers/global-listeners.js';
import {createMockSendCommandFn} from '../mock-commands.js';
import {Connection} from '../../../gather/connections/connection.js';
import {Driver} from '../../../gather/driver.js';
import {Connection} from '../../../legacy/gather/connections/connection.js';
import {Driver} from '../../../legacy/gather/driver.js';

describe('Global Listener Gatherer', () => {
it('remove duplicate listeners from artifacts', async () => {
Expand Down
4 changes: 2 additions & 2 deletions core/test/gather/gatherers/js-usage-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* 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.
*/

import {Driver} from '../../../gather/driver.js';
import {Connection} from '../../../gather/connections/connection.js';
import {Driver} from '../../../legacy/gather/driver.js';
import {Connection} from '../../../legacy/gather/connections/connection.js';
import JsUsage from '../../../gather/gatherers/js-usage.js';
import {createMockSendCommandFn, createMockOnFn} from '../mock-commands.js';
import {createMockContext} from '../../fraggle-rock/gather/mock-driver.js';
Expand Down
4 changes: 2 additions & 2 deletions core/test/gather/gatherers/source-maps-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* 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.
*/

import {Driver} from '../../../gather/driver.js';
import {Connection} from '../../../gather/connections/connection.js';
import {Driver} from '../../../legacy/gather/driver.js';
import {Connection} from '../../../legacy/gather/connections/connection.js';
import SourceMaps from '../../../gather/gatherers/source-maps.js';
import {createMockSendCommandFn, createMockOnFn} from '../mock-commands.js';
import {flushAllTimersAndMicrotasks, fnAny, timers} from '../../test-utils.js';
Expand Down
4 changes: 2 additions & 2 deletions core/test/gather/gatherers/trace-elements-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

import TraceElementsGatherer from '../../../gather/gatherers/trace-elements.js';
import {Driver} from '../../../gather/driver.js';
import {Connection} from '../../../gather/connections/connection.js';
import {Driver} from '../../../legacy/gather/driver.js';
import {Connection} from '../../../legacy/gather/connections/connection.js';
import {createTestTrace} from '../../create-test-trace.js';
import {createMockSendCommandFn, createMockOnFn} from '../mock-commands.js';
import {flushAllTimersAndMicrotasks, fnAny, readJson, timers} from '../../test-utils.js';
Expand Down
Loading

0 comments on commit f8bb5a0

Please sign in to comment.