-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
report: extract independent report types #12946
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
'use strict'; | ||
|
||
module.exports = { | ||
extends: '../.eslintrc.js', | ||
env: { | ||
browser: true, | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
'use strict'; | ||
|
||
module.exports = { | ||
extends: '../.eslintrc.js', | ||
env: { | ||
browser: true, | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,16 +5,13 @@ | |
*/ | ||
|
||
import _ReportGenerator = require('../../report/generator/report-generator.js'); | ||
import {DOM as _DOM} from '../../report/renderer/dom.js'; | ||
import {ReportRenderer as _ReportRenderer} from '../../report/renderer/report-renderer.js'; | ||
import {ReportUIFeatures as _ReportUIFeatures} from '../../report/renderer/report-ui-features.js'; | ||
import {Logger as _Logger} from '../../report/renderer/logger.js'; | ||
import {TextEncoding as _TextEncoding} from '../../report/renderer/text-encoding.js'; | ||
import {LighthouseReportViewer as _LighthouseReportViewer} from '../app/src/lighthouse-report-viewer.js'; | ||
import 'google.analytics'; | ||
import {FirebaseNamespace} from '@firebase/app-types'; | ||
import '@firebase/auth-types'; | ||
import _ReportResult from '../../report/types/report-result'; | ||
|
||
// Import for needed DOM type augmentation. | ||
import '../../report/types/augment-dom'; | ||
|
||
declare global { | ||
var ReportGenerator: typeof _ReportGenerator; | ||
|
@@ -29,7 +26,9 @@ declare global { | |
// Inserted by viewer build. | ||
LH_CURRENT_VERSION: string; | ||
} | ||
|
||
// Expose global types in LH namespace. | ||
module LH { | ||
export import ReportResult = _ReportResult; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh interesting I wouldn't have expected does this differ from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yeah, you get the interface but not the module, so e.g. |
||
} | ||
} | ||
|
||
// empty export to keep file a module | ||
export {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added a new Also, turns out eslintrc files automatically extend any other eslintrc files up through to the root directory, though I added a |
||
* @license Copyright 2021 The Lighthouse Authors. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* 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'; | ||
|
||
/** | ||
* eslint does not support ESM rc files, so this must be a .cjs file. | ||
* @see https://eslint.org/docs/user-guide/configuring/configuration-files#configuration-file-formats | ||
* @see https://github.com/eslint/eslint/issues/13481 | ||
*/ | ||
|
||
module.exports = { | ||
env: { | ||
browser: true, | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ const URL_PREFIXES = ['http://', 'https://', 'data:']; | |
export class DetailsRenderer { | ||
/** | ||
* @param {DOM} dom | ||
* @param {{fullPageScreenshot?: LH.Artifacts.FullPageScreenshot}} [options] | ||
* @param {{fullPageScreenshot?: LH.Audit.Details.FullPageScreenshot}} [options] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this starts to illustrate how the boundaries are hard to see here (glancing at this without context, I wouldn't expect Long-term do you plan to renamespace the report to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, it's a really good question. I'm not sure. I defaulted to maintaining the familiar module LH {
module Audit {
export import Details = AuditDetails;
}
} so seems doubly weird to maintain it? Not that useful in the report if considered in isolation, and if the goal is consistency across files, it's actually misleading because you might think e.g. So long term it may make sense to re work the names, but then it's asking everyone to keep track of multiple names for the same thing... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe if microsoft/TypeScript#41825 is fixed, core could keep the global types and the other areas with fewer files and fewer type needs could just do /** @typedef {import('../../lhr/audit-details')} AuditDetails */
export class DetailsRenderer {
/**
* @param {DOM} dom
* @param {{fullPageScreenshot?: AuditDetails.FullPageScreenshot}} [options]
*/
constructor(dom, options = {}) {
this._dom = dom;
this._fullPageScreenshot = options.fullPageScreenshot;
}
} Without that issue fixed, though, we'd be stuck with /** @typedef {import('../../lhr/audit-details').FullPageScreenshot} FullPageScreenshot */
/** @typedef {import('../../lhr/audit-details').OpportunityColumnHeading} OpportunityColumnHeading */
/** @typedef {import('../../lhr/audit-details').TableColumnHeading} TableColumnHeading */
/** @typedef {import('../../lhr/audit-details').List} List */
/** @typedef {import('../../lhr/audit-details').NodeValue} NodeValue */
// ... :( |
||
*/ | ||
constructor(dom, options = {}) { | ||
this._dom = dom; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"compilerOptions": { | ||
"composite": true, | ||
"outDir": "../.tmp/tsbuildinfo/report", | ||
"emitDeclarationOnly": true, | ||
"declarationMap": true, | ||
|
||
// Limit to base JS and DOM defs. | ||
"lib": ["es2020", "dom", "dom.iterable"], | ||
// Don't include any node_module types. | ||
"types": [], | ||
"target": "es2020", | ||
"module": "es2020", | ||
"moduleResolution": "node", | ||
|
||
"allowJs": true, | ||
"checkJs": true, | ||
"strict": true, | ||
// TODO: remove the next line to be fully `strict`. | ||
"useUnknownInCatchVariables": false, | ||
|
||
// "listFiles": true, | ||
// "noErrorTruncation": true, | ||
"extendedDiagnostics": true, | ||
}, | ||
"include": [ | ||
"**/*.js", | ||
"types/**/*.d.ts", | ||
], | ||
"references": [ | ||
{"path": "../types/lhr/"}, | ||
{"path": "./generator/"} | ||
], | ||
"exclude": [ | ||
"generator/**/*.js", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't realize |
||
// These test files require further changes before they can be type checked. | ||
"test/**/*.js", | ||
], | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* @license Copyright 2021 The Lighthouse Authors. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* @fileoverview Augment global scope with needed DOM APIs that are newer or not | ||
* widely supported enough to be in tsc's lib `dom`. | ||
*/ | ||
|
||
// Import to augment querySelector/querySelectorAll with stricter type checking. | ||
import '../../types/query-selector'; | ||
|
||
declare global { | ||
var CompressionStream: { | ||
prototype: CompressionStream, | ||
new (format: string): CompressionStream, | ||
}; | ||
|
||
interface CompressionStream extends GenericTransformStream { | ||
readonly format: string; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* @license Copyright 2021 The Lighthouse Authors. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* A minimal type for Node's `Buffer` to avoid importing all Node types for | ||
* atob/btoa fallback for testing `text-encoding.js`. | ||
*/ | ||
|
||
declare global { | ||
class Buffer { | ||
static from(str: string, encoding?: string): Buffer; | ||
toString(encoding?: string): string; | ||
} | ||
} | ||
|
||
export {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the force module situation these days such that this isn't necessary? I feel like I remember reading a PR description or comment about this recently, but couldn't find it quickly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's kind of dumb: if there's any
import
orexport
statements, the file is a module (which is why we had the empty ones in there before when everything was in one or two files and we didn't have any imports), and if you want an explicitdeclare global {}
block in there it has to be a module, otherwise it's ambient and everything is a global type.Fortunately(?) we almost always have
import
statements these days, and the error message is a lot better, basically saying you can'tdeclare global
unless this file is a module.I vaguely recall a few years back in the es modules transition wars the idea of using that same heuristic to automatically detect if a file was an
.mjs
vs.cjs
file without a file extension/package.jsontype
entry, and then everyone realized that would be super fragile and annoying and decided not to go that way. But here it is anyways :)