-
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
cli: compile out remaining typescript; add tsc type checking via jsdocs #3747
Changes from 7 commits
45c885a
856c70c
57841e6
3eef710
531e789
c630213
5ff3e61
d2e4c26
f381c6c
e61c1cf
289c9e7
448a6e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,51 +5,57 @@ | |
*/ | ||
'use strict'; | ||
|
||
import {existsSync} from 'fs'; | ||
import * as path from 'path'; | ||
const existsSync = require('fs').existsSync; | ||
const path = require('path'); | ||
|
||
import * as Commands from './commands/commands'; | ||
import * as Printer from './printer'; | ||
import {getFlags} from './cli-flags'; | ||
import {runLighthouse} from './run'; | ||
const commands = require('./commands/commands.js'); | ||
const printer = require('./printer.js'); | ||
const getFlags = require('./cli-flags.js').getFlags; | ||
const runLighthouse = require('./run').runLighthouse; | ||
|
||
const log = require('lighthouse-logger'); | ||
// @ts-ignore | ||
const perfOnlyConfig = require('../lighthouse-core/config/perf.json'); | ||
// @ts-ignore | ||
const pkg = require('../package.json'); | ||
const Sentry = require('../lighthouse-core/lib/sentry'); | ||
|
||
// accept noop modules for these, so the real dependency is optional. | ||
import {updateNotifier} from './shim-modules'; | ||
import {askPermission} from './sentry-prompt'; | ||
const updateNotifier = require('update-notifier'); | ||
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. intentionally not shimming anymore? 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, I think(?) it only added value to users not installing 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 that seems fine, better to be clear about our non users than half support :) |
||
const askPermission = require('./sentry-prompt').askPermission; | ||
|
||
/** | ||
* @return {boolean} | ||
*/ | ||
function isDev() { | ||
return existsSync(path.join(__dirname, '../.git')); | ||
} | ||
|
||
// Tell user if there's a newer version of LH. | ||
updateNotifier({pkg}).notify(); | ||
|
||
const cliFlags = getFlags(); | ||
const /** @type {!LH.Flags} */ cliFlags = getFlags(); | ||
|
||
// Process terminating command | ||
if (cliFlags.listAllAudits) { | ||
Commands.ListAudits(); | ||
commands.listAudits(); | ||
} | ||
|
||
// Process terminating command | ||
if (cliFlags.listTraceCategories) { | ||
Commands.ListTraceCategories(); | ||
commands.listTraceCategories(); | ||
} | ||
|
||
/** @type {string} */ | ||
const url = cliFlags._[0]; | ||
|
||
let config: Object|null = null; | ||
/** @type {!LH.Config|undefined} */ | ||
let config; | ||
if (cliFlags.configPath) { | ||
// Resolve the config file path relative to where cli was called. | ||
cliFlags.configPath = path.resolve(process.cwd(), cliFlags.configPath); | ||
config = require(cliFlags.configPath); | ||
config = /** @type {!LH.Config} */ (require(cliFlags.configPath)); | ||
} else if (cliFlags.perf) { | ||
config = perfOnlyConfig; | ||
config = /** @type {!LH.Config} */ (perfOnlyConfig); | ||
} | ||
|
||
// set logging preferences | ||
|
@@ -61,27 +67,39 @@ if (cliFlags.verbose) { | |
} | ||
log.setLevel(cliFlags.logLevel); | ||
|
||
if (cliFlags.output === Printer.OutputMode[Printer.OutputMode.json] && !cliFlags.outputPath) { | ||
if (cliFlags.output === printer.OutputMode.json && !cliFlags.outputPath) { | ||
cliFlags.outputPath = 'stdout'; | ||
} | ||
|
||
export async function run() { | ||
if (typeof cliFlags.enableErrorReporting === 'undefined') { | ||
cliFlags.enableErrorReporting = await askPermission(); | ||
} | ||
|
||
Sentry.init({ | ||
url, | ||
flags: cliFlags, | ||
environmentData: { | ||
name: 'redacted', // prevent sentry from using hostname | ||
environment: isDev() ? 'development' : 'production', | ||
release: pkg.version, | ||
tags: { | ||
channel: 'cli', | ||
}, | ||
}, | ||
}); | ||
|
||
return runLighthouse(url, cliFlags, config); | ||
/** | ||
* @return {!Promise<(void|!LH.Results)>} | ||
*/ | ||
function run() { | ||
return Promise.resolve() | ||
.then(_ => { | ||
if (typeof cliFlags.enableErrorReporting === 'undefined') { | ||
return askPermission().then(answer => { | ||
cliFlags.enableErrorReporting = answer; | ||
}); | ||
} | ||
}) | ||
.then(_ => { | ||
Sentry.init({ | ||
url, | ||
flags: cliFlags, | ||
environmentData: { | ||
name: 'redacted', // prevent sentry from using hostname | ||
environment: isDev() ? 'development' : 'production', | ||
release: pkg.version, | ||
tags: { | ||
channel: 'cli', | ||
}, | ||
}, | ||
}); | ||
|
||
return runLighthouse(url, cliFlags, config); | ||
}); | ||
} | ||
|
||
module.exports = { | ||
run, | ||
}; |
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.
for some reason typescript won't resolve
json
files as part ofrequire()
(you get a"Cannot find module '../lighthouse-core/config/perf.json'"
here). Searching didn't find a better solution, and @JoelEinbinder did this in puppeteer, so I'm going with that unless anyone has a better fix :)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.
did some searching as well, there is no support.