Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: restructure types for direct import and publishing #14441

Merged
merged 54 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
271cf0c
start
adamraine Sep 22, 2022
5710d82
env
adamraine Sep 22, 2022
098806c
lhr
adamraine Sep 22, 2022
cb26da4
move more
adamraine Sep 22, 2022
44b2a63
module
adamraine Sep 22, 2022
adc7ce9
ope
adamraine Sep 22, 2022
dbc8d7d
fix
adamraine Sep 23, 2022
654d977
fix
adamraine Sep 26, 2022
36c6acb
Merge branch 'main' into expose-types
adamraine Oct 10, 2022
7832e4f
ope
adamraine Oct 11, 2022
b683d56
ope
adamraine Oct 11, 2022
5c35f7c
d.ts again
adamraine Oct 12, 2022
ddd7f46
script
adamraine Nov 11, 2022
92e9c53
Merge branch 'main' into expose-types
adamraine Nov 11, 2022
c26ad51
pipe
adamraine Nov 14, 2022
dd0843e
script
adamraine Nov 14, 2022
67dd4b8
fix uf type import
adamraine Nov 14, 2022
3f429a3
rest
adamraine Nov 14, 2022
d0de3a1
ope
adamraine Nov 14, 2022
56e89e2
back
adamraine Nov 14, 2022
01573f9
fix
adamraine Nov 14, 2022
f37ff2a
comments
adamraine Nov 15, 2022
df88711
gitignore
adamraine Nov 15, 2022
464dea0
Merge branch 'main' into expose-types
adamraine Nov 15, 2022
2231c19
Merge branch 'main' into expose-types
adamraine Nov 16, 2022
773105e
Merge branch 'main' into expose-types
adamraine Nov 16, 2022
31470cf
mv
adamraine Nov 16, 2022
1cfb63c
Merge branch 'main' into expose-types
adamraine Nov 18, 2022
db59841
Merge branch 'main' into expose-types
adamraine Nov 30, 2022
f6e5f32
Merge branch 'main' into expose-types
adamraine Dec 9, 2022
77866e0
clean types
adamraine Dec 9, 2022
3ec52ee
build all
adamraine Dec 9, 2022
d4bdee9
prepack
adamraine Dec 9, 2022
0f1e9c3
types dir
adamraine Dec 9, 2022
32ea5d2
no export
adamraine Dec 9, 2022
ca6952b
comments
adamraine Dec 9, 2022
4ea12f0
back artifacts
adamraine Dec 9, 2022
326510c
comments
adamraine Dec 9, 2022
fa54814
Merge branch 'main' into expose-types
adamraine Dec 22, 2022
687c219
fix puppeteer
adamraine Dec 22, 2022
715b4f7
license
adamraine Dec 22, 2022
c542551
Merge branch 'main' into expose-types
adamraine Jan 3, 2023
d7477a7
import all
adamraine Jan 10, 2023
cb9d884
Merge branch 'main' into expose-types
adamraine Jan 13, 2023
7955ec9
Merge branch 'main' into expose-types
adamraine Jan 17, 2023
73936ff
Merge branch 'main' into expose-types
adamraine Jan 17, 2023
efb7d5e
warning
adamraine Jan 18, 2023
14ca719
internal
adamraine Jan 18, 2023
ba3104f
add .js ext and LH to work with nodenext
adamraine Jan 18, 2023
324012a
doc recipe and test
adamraine Jan 18, 2023
9a8b537
update
adamraine Jan 18, 2023
c6761ee
Merge branch 'main' into expose-types
adamraine Jan 18, 2023
af34cd0
woah there partner
adamraine Jan 18, 2023
05e8815
comments
adamraine Jan 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ core/scripts/legacy-javascript/variants
third-party/**

# ignore d.ts files until we can properly lint them
*.d.ts
**/*.d.ts
**/*.d.cts
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module.exports = {
vars: 'all',
args: 'after-used',
argsIgnorePattern: '(^reject$|^_+$)',
varsIgnorePattern: '(^_$)',
varsIgnorePattern: '(^_$|^LH$)',
}],
'space-infix-ops': 2,
'strict': [2, 'global'],
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,8 @@ proto/scripts/*_processed.json
# require any lock file to be checked in explicitly
yarn.lock

# ignore generated d.ts files
**/*.d.ts
**/*.d.cts
!**/types/**/*.d.ts

2 changes: 2 additions & 0 deletions core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {ReportGenerator} from '../report/generator/report-generator.js';
import {startTimespanGather} from './gather/timespan-runner.js';
import {snapshotGather} from './gather/snapshot-runner.js';
import {navigationGather} from './gather/navigation-runner.js';
import * as LH from '../types/lh.js';

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

Expand Down Expand Up @@ -157,6 +158,7 @@ export {default as Gatherer} from './gather/base-gatherer.js';
export {NetworkRecords} from './computed/network-records.js';
export {default as defaultConfig} from './config/default-config.js';
export {default as desktopConfig} from './config/desktop-config.js';
export * from '../types/lh.js';
export {
legacyNavigation,
startFlow,
Expand Down
1 change: 1 addition & 0 deletions core/user-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {initializeConfig} from './config/config.js';
import {getFormatted} from '../shared/localization/format.js';
import {mergeConfigFragment, deepClone} from './config/config-helpers.js';
import * as i18n from './lib/i18n/i18n.js';
import * as LH from '../types/lh.js';

/** @typedef {WeakMap<LH.UserFlow.GatherStep, LH.Gatherer.FRGatherResult['runnerOptions']>} GatherStepRunnerOptions */

Expand Down
2 changes: 1 addition & 1 deletion flow-report/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"**/*.ts",
"**/*.tsx",
"./types",
"../types/test.d.ts",
"../types/env/test.d.ts",
"../root.js",
"../esm-utils.js",
"../core/test/test-env/fake-timers.js",
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"scripts": {
"prepack": "yarn build-report --standalone --flow --esm",
"build-all": "npm-run-posix-or-windows build-all:task",
"build-all:task": "yarn build-report && yarn build-cdt-lib && yarn build-devtools && concurrently 'yarn build-extension' 'yarn build-lr' 'yarn build-viewer' 'yarn build-treemap' 'yarn build-smokehouse-bundle' && yarn build-pack",
"build-all:task": "yarn build-report && yarn build-cdt-lib && yarn build-devtools && yarn build-types && concurrently 'yarn build-extension' 'yarn build-lr' 'yarn build-viewer' 'yarn build-treemap' 'yarn build-smokehouse-bundle' && yarn build-pack",
"build-all:task:windows": "yarn build-report && yarn build-cdt-lib && yarn build-extension && yarn build-devtools && yarn build-lr && yarn build-viewer && yarn build-treemap && yarn build-smokehouse-bundle",
"build-cdt-lib": "node ./build/build-cdt-lib.js",
"build-extension": "yarn build-extension-chrome && yarn build-extension-firefox",
Expand All @@ -29,9 +29,11 @@
"build-sample-reports": "yarn build-report && node build/build-sample-reports.js",
"build-treemap": "node ./build/build-treemap.js",
"build-viewer": "node ./build/build-viewer.js",
"build-types": "tsc --build tsconfig-all.json && rsync -a .tmp/tsbuildinfo/ ./ --include='*.d.ts' --include='*.d.cts' --exclude='*.map' --exclude='*.tsbuildinfo'",
"reset-link": "(yarn unlink || true) && yarn link && yarn link lighthouse",
"c8": "bash core/scripts/c8.sh",
"clean": "rm -r dist proto/scripts/*.json proto/scripts/*_pb2.* proto/scripts/*_pb.* proto/scripts/__pycache__ proto/scripts/*.pyc *.report.html *.report.dom.html *.report.json *.devtoolslog.json *.trace.json shared/localization/locales/*.ctc.json || true",
"clean-types": "git clean -xf '*.d.ts' '*.d.cts' -e 'node_modules/' -e 'dist/' -e '.tmp/'",
"lint": "[ \"$CI\" = true ] && eslint --quiet -f codeframe . || eslint .",
"smoke": "node cli/test/smokehouse/frontends/smokehouse-bin.js",
"debug": "node --inspect-brk ./cli/index.js",
Expand Down
2 changes: 1 addition & 1 deletion report/types/augment-dom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

// Import to augment querySelector/querySelectorAll with stricter type checking.
import '../../types/query-selector';
import '../../types/env/query-selector';

declare global {
var CompressionStream: {
Expand Down
616 changes: 310 additions & 306 deletions types/artifacts.d.ts

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions types/audit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
*/

import {ArbitraryEqualityMap} from '../core/lib/arbitrary-equality-map.js';
import {Artifacts} from './artifacts';
import AuditDetails from './lhr/audit-details';
import Config from './config';
import Gatherer from './gatherer';
import {IcuMessage} from './lhr/i18n';
import * as AuditResult from './lhr/audit-result';
import Artifacts from './artifacts.js';
import AuditDetails from './lhr/audit-details.js';
import Config from './config.js';
import Gatherer from './gatherer.js';
import {IcuMessage} from './lhr/i18n.js';
import * as AuditResult from './lhr/audit-result.js';
import Util from './utility-types.js';

declare module Audit {
Expand Down
6 changes: 3 additions & 3 deletions types/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
*/

import {Audit} from '../core/audits/audit.js';
import {SharedFlagsSettings, ConfigSettings} from './lhr/settings';
import Gatherer from './gatherer';
import {IcuMessage} from './lhr/i18n';
import {SharedFlagsSettings, ConfigSettings} from './lhr/settings.js';
import Gatherer from './gatherer.js';
import {IcuMessage} from './lhr/i18n.js';

interface ClassOf<T> {
new (): T;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions types/env/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from '../lh.js';

export as namespace LH;
Copy link
Member Author

@adamraine adamraine Oct 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this to work, we shouldn't expose LH globally at least in core. This is a temporary measure if we decide to split into multiple PRs.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there an update on this? More PRs to come?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in this PR should provide enough typings for the normal exposed api. We should still eliminate this global though.

Doing so would be done in a follow up, and probably wouldn't be a breaking change (although it would touch many files)

File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
* 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.
*/

type Locale = import('../lhr/settings.js').Locale;

declare module 'lookup-closest-locale' {
function lookupClosestLocale(locale: string[]|string|undefined, available: Record<LH.Locale, any>): LH.Locale|undefined;
function lookupClosestLocale(locale: string[]|string|undefined, available: Record<Locale, any>): Locale|undefined;

export = lookupClosestLocale;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions types/smokehouse.d.ts → types/env/smokehouse.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* 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 {Artifacts} from './artifacts';
import Config from './config';
import LHResult from './lhr/lhr';
import Artifacts from '../artifacts.js';
import Config from '../config.js';
import LHResult from '../lhr/lhr.js';

declare global {
module Smokehouse {
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions types/externs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* 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 {Artifacts} from './artifacts';
import LHResult from './lhr/lhr';
import {SharedFlagsSettings, OutputMode} from './lhr/settings';
import Artifacts from './artifacts.js';
import LHResult from './lhr/lhr.js';
import {SharedFlagsSettings, OutputMode} from './lhr/settings.js';

/**
* Extends the flags in SharedFlagsSettings with flags used to configure the
Expand Down
40 changes: 23 additions & 17 deletions types/gatherer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* 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 Crdp from 'devtools-protocol/types/protocol';
import CrdpMappings from 'devtools-protocol/types/protocol-mapping';

import {NetworkNode as _NetworkNode} from '../core/lib/dependency-graph/network-node';
import {CPUNode as _CPUNode} from '../core/lib/dependency-graph/cpu-node';
import {Simulator as _Simulator} from '../core/lib/dependency-graph/simulator/simulator';
Expand All @@ -12,24 +15,27 @@ import {ExecutionContext} from '../core/gather/driver/execution-context';
import {Fetcher} from '../core/gather/fetcher';
import {ArbitraryEqualityMap} from '../core/lib/arbitrary-equality-map';

import {Artifacts, BaseArtifacts, FRBaseArtifacts, GathererArtifacts} from './artifacts';
import Artifacts from './artifacts';
import Config from './config';
import {IcuMessage} from './lhr/i18n';
import Result from './lhr/lhr';
import Protocol from './protocol';
import {Trace, DevtoolsLog} from './artifacts';
import Puppeteer from './puppeteer';

type CrdpEvents = CrdpMappings.Events;
type CrdpCommands = CrdpMappings.Commands;

declare module Gatherer {
/** The Lighthouse wrapper around a raw CDP session. */
interface FRProtocolSession {
setTargetInfo(targetInfo: LH.Crdp.Target.TargetInfo): void;
setTargetInfo(targetInfo: Crdp.Target.TargetInfo): void;
hasNextProtocolTimeout(): boolean;
getNextProtocolTimeout(): number;
setNextProtocolTimeout(ms: number): void;
on<TEvent extends keyof LH.CrdpEvents>(event: TEvent, callback: (...args: LH.CrdpEvents[TEvent]) => void): void;
once<TEvent extends keyof LH.CrdpEvents>(event: TEvent, callback: (...args: LH.CrdpEvents[TEvent]) => void): void;
off<TEvent extends keyof LH.CrdpEvents>(event: TEvent, callback: (...args: LH.CrdpEvents[TEvent]) => void): void;
sendCommand<TMethod extends keyof LH.CrdpCommands>(method: TMethod, ...params: LH.CrdpCommands[TMethod]['paramsType']): Promise<LH.CrdpCommands[TMethod]['returnType']>;
on<TEvent extends keyof CrdpEvents>(event: TEvent, callback: (...args: CrdpEvents[TEvent]) => void): void;
once<TEvent extends keyof CrdpEvents>(event: TEvent, callback: (...args: CrdpEvents[TEvent]) => void): void;
off<TEvent extends keyof CrdpEvents>(event: TEvent, callback: (...args: CrdpEvents[TEvent]) => void): void;
sendCommand<TMethod extends keyof CrdpCommands>(method: TMethod, ...params: CrdpCommands[TMethod]['paramsType']): Promise<CrdpCommands[TMethod]['returnType']>;
dispose(): Promise<void>;
}

Expand All @@ -53,13 +59,13 @@ declare module Gatherer {
/** The connection to the page being analyzed. */
driver: FRTransitionalDriver;
/** The Puppeteer page handle. Will be undefined in legacy navigation mode. */
page?: LH.Puppeteer.Page;
page?: Puppeteer.Page;
/** The set of base artifacts that are always collected. */
baseArtifacts: FRBaseArtifacts;
baseArtifacts: Artifacts.FRBaseArtifacts;
/** The cached results of computed artifacts. */
computedCache: Map<string, ArbitraryEqualityMap>;
/** The set of available dependencies requested by the current gatherer. */
dependencies: Pick<GathererArtifacts, Exclude<TDependencies, DefaultDependenciesKey>>;
dependencies: Pick<Artifacts.GathererArtifacts, Exclude<TDependencies, DefaultDependenciesKey>>;
/** The settings used for gathering. */
settings: Config.Settings;
}
Expand All @@ -82,22 +88,22 @@ declare module Gatherer {
computedCache: Map<string, ArbitraryEqualityMap>
/** Gatherers can push to this array to add top-level warnings to the LHR. */
LighthouseRunWarnings: Array<string | IcuMessage>;
baseArtifacts: BaseArtifacts;
baseArtifacts: Artifacts.BaseArtifacts;
}

interface LoadData {
networkRecords: Array<Artifacts.NetworkRequest>;
devtoolsLog: DevtoolsLog;
trace?: Trace;
devtoolsLog: Artifacts.DevtoolsLog;
trace?: Artifacts.Trace;
}

type PhaseResultNonPromise = void | GathererArtifacts[keyof GathererArtifacts];
type PhaseResultNonPromise = void | Artifacts.GathererArtifacts[keyof Artifacts.GathererArtifacts];
type PhaseResult = PhaseResultNonPromise | Promise<PhaseResultNonPromise>

type GatherMode = Result.GatherMode;

type DefaultDependenciesKey = '__none__'
type DependencyKey = keyof GathererArtifacts | DefaultDependenciesKey
type DependencyKey = keyof Artifacts.GathererArtifacts | DefaultDependenciesKey

interface GathererMetaNoDependencies {
/**
Expand All @@ -123,7 +129,7 @@ declare module Gatherer {
GathererMetaWithDependencies<Exclude<TDependencies, DefaultDependenciesKey>>;

interface GathererInstance {
name: keyof GathererArtifacts;
name: keyof Artifacts.GathererArtifacts;
beforePass(context: Gatherer.PassContext): PhaseResult;
pass(context: Gatherer.PassContext): PhaseResult;
afterPass(context: Gatherer.PassContext, loadData: Gatherer.LoadData): PhaseResult;
Expand All @@ -132,7 +138,7 @@ declare module Gatherer {
type FRGatherPhase = keyof Omit<Gatherer.FRGathererInstance, 'name'|'meta'>

interface FRGathererInstance<TDependencies extends DependencyKey = DefaultDependenciesKey> {
name: keyof GathererArtifacts; // temporary COMPAT measure until artifact config support is available
name: keyof Artifacts.GathererArtifacts; // temporary COMPAT measure until artifact config support is available
meta: GathererMeta<TDependencies>;
startInstrumentation(context: FRTransitionalContext<DefaultDependenciesKey>): Promise<void>|void;
startSensitiveInstrumentation(context: FRTransitionalContext<DefaultDependenciesKey>): Promise<void>|void;
Expand Down
85 changes: 0 additions & 85 deletions types/global-lh.d.ts

This file was deleted.

Loading