1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 21:50:00 -05:00

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_npm_resolver: Some(npm_resolver.clone()),
maybe_tsbuildinfo, maybe_tsbuildinfo,
root_names, root_names,
check_mode: options.type_check_mode,
})?; })?;
let diagnostics = if options.type_check_mode == TypeCheckMode::Local { let diagnostics = if options.type_check_mode == TypeCheckMode::Local {

View file

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

View file

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

View file

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