perf(check): type check local files only when not using `--all` (#18329)

Closes #18171
This commit is contained in:
David Sherret 2023-03-21 18:19:42 -04:00 committed by GitHub
parent 7e61e8f0e0
commit 253b556e6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 6 deletions

View File

@ -102,6 +102,7 @@ pub fn check(
maybe_npm_resolver: Some(npm_resolver.clone()),
maybe_tsbuildinfo,
root_names,
check_mode: options.type_check_mode,
})?;
let diagnostics = if options.type_check_mode == TypeCheckMode::Local {

View File

@ -38066,6 +38066,7 @@ ${lanes.join("\n")}
name: "allowImportingTsExtensions",
type: "boolean",
affectsSemanticDiagnostics: true,
affectsBuildInfo: true,
category: Diagnostics.Modules,
description: Diagnostics.Allow_imports_to_include_TypeScript_file_extensions_Requires_moduleResolution_bundler_and_either_noEmit_or_emitDeclarationOnly_to_be_set,
defaultValueDescription: false
@ -120426,7 +120427,7 @@ ${lanes.join("\n")}
const { optionsNameMap } = getOptionsNameMap();
for (const name of getOwnKeys(options).sort(compareStringsCaseSensitive)) {
const optionInfo = optionsNameMap.get(name.toLowerCase());
if (optionInfo == null ? void 0 : optionInfo.affectsBuildInfo) {
if (optionInfo && (optionInfo.affectsBuildInfo || optionInfo.affectsSemanticDiagnostics)) {
(result || (result = {}))[name] = convertToReusableCompilerOptionValue(
optionInfo,
options[name],

View File

@ -328,7 +328,7 @@ delete Object.prototype.__proto__;
}
}
/** @param {ts.Diagnostic[]} diagnostics */
/** @param {readonly ts.Diagnostic[]} diagnostics */
function fromTypeScriptDiagnostic(diagnostics) {
return diagnostics.map(({ relatedInformation: ri, source, ...diag }) => {
/** @type {any} */
@ -750,6 +750,7 @@ delete Object.prototype.__proto__;
* @property {Record<string, any>} config
* @property {boolean} debug
* @property {string[]} rootNames
* @property {boolean} localOnly
*/
/**
@ -776,7 +777,7 @@ delete Object.prototype.__proto__;
/** The API that is called by Rust when executing a request.
* @param {Request} request
*/
function exec({ config, debug: debugFlag, rootNames }) {
function exec({ config, debug: debugFlag, rootNames, localOnly }) {
setLogDebug(debugFlag, "TS");
performanceStart();
if (logDebug) {
@ -800,12 +801,31 @@ delete Object.prototype.__proto__;
configFileParsingDiagnostics,
});
const checkFiles = localOnly
? rootNames
.filter((n) => !n.startsWith("http"))
.map((checkName) => {
const sourceFile = program.getSourceFile(checkName);
if (sourceFile == null) {
throw new Error("Could not find source file for: " + checkName);
}
return sourceFile;
})
: undefined;
const diagnostics = [
...program.getConfigFileParsingDiagnostics(),
...program.getSyntacticDiagnostics(),
...(checkFiles == null
? program.getSyntacticDiagnostics()
: ts.sortAndDeduplicateDiagnostics(
checkFiles.map((s) => program.getSyntacticDiagnostics(s)).flat(),
)),
...program.getOptionsDiagnostics(),
...program.getGlobalDiagnostics(),
...program.getSemanticDiagnostics(),
...(checkFiles == null
? program.getSemanticDiagnostics()
: ts.sortAndDeduplicateDiagnostics(
checkFiles.map((s) => program.getSemanticDiagnostics(s)).flat(),
)),
].filter((diagnostic) => !IGNORED_DIAGNOSTICS.includes(diagnostic.code));
// emit the tsbuildinfo file
@ -867,7 +887,7 @@ delete Object.prototype.__proto__;
allowNonTsExtensions: true,
allowImportingTsExtensions: true,
});
if (errors.length) {
if (errors.length > 0 && logDebug) {
debug(ts.formatDiagnostics(errors, host));
}
compilationSettings = options;

View File

@ -1,6 +1,7 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use crate::args::TsConfig;
use crate::args::TypeCheckMode;
use crate::node;
use crate::node::node_resolve_npm_reference;
use crate::node::NodeResolution;
@ -308,6 +309,7 @@ pub struct Request {
/// A vector of strings that represent the root/entry point modules for the
/// program.
pub root_names: Vec<(ModuleSpecifier, MediaType)>,
pub check_mode: TypeCheckMode,
}
#[derive(Debug, Clone, Eq, PartialEq)]
@ -806,6 +808,7 @@ pub fn exec(request: Request) -> Result<Response, AnyError> {
"config": request.config,
"debug": request.debug,
"rootNames": root_names,
"localOnly": request.check_mode == TypeCheckMode::Local,
});
let request_str = request_value.to_string();
let exec_source = format!("globalThis.exec({request_str})");
@ -962,6 +965,7 @@ mod tests {
maybe_npm_resolver: None,
maybe_tsbuildinfo: None,
root_names: vec![(specifier.clone(), MediaType::TypeScript)],
check_mode: TypeCheckMode::All,
};
exec(request)
}