From b994057d5b77dfea2f5a8e99c1779ac583d8b7a2 Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Wed, 24 Jun 2020 21:35:10 +1000 Subject: [PATCH] add stats to transpile --- cli/js/compiler.ts | 15 ++++++++------- cli/tsc.rs | 8 ++++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/cli/js/compiler.ts b/cli/js/compiler.ts index 3aaec3d188d823..a40399d3595d53 100644 --- a/cli/js/compiler.ts +++ b/cli/js/compiler.ts @@ -1139,6 +1139,7 @@ interface TranspileRequest { config?: string; configPath?: string; cwd?: string; + performance: boolean; sourceFileMap: Record; } @@ -1304,9 +1305,12 @@ function transpile({ config: configText, configPath, cwd, + performance, sourceFileMap, }: TranspileRequest): CompileResponse { - const start = performance.now(); + if (performance) { + performanceStart(); + } log(">>> transpile start"); const compilerOptions: ts.CompilerOptions = Object.assign( {}, @@ -1364,12 +1368,9 @@ function transpile({ emitMap[`${filename}.js`] = { filename, contents: outputText }; emitMap[`${filename}.map`] = { filename, contents: sourceMapText }; } - log("<<< transpile end", { - in: Object.keys(sourceFileMap).length, - out: Object.keys(emitMap).length, - duration: performance.now() - start, - }); - return { diagnostics: fromTypeScriptDiagnostic(diagnostics), emitMap }; + const stats = performance ? performanceEnd() : undefined; + log("<<< transpile end"); + return { diagnostics: fromTypeScriptDiagnostic(diagnostics), emitMap, stats }; } function bundle({ diff --git a/cli/tsc.rs b/cli/tsc.rs index 2f036e29a51487..812235514305ad 100644 --- a/cli/tsc.rs +++ b/cli/tsc.rs @@ -632,16 +632,22 @@ impl TsCompiler { serde_json::to_value(module_graph).expect("Failed to serialize data"); let compiler_config = self.config.clone(); let cwd = std::env::current_dir().unwrap(); + let performance = match global_state.flags.log_level { + Some(Level::Debug) => true, + _ => false, + }; let j = match (compiler_config.path, compiler_config.content) { (Some(config_path), Some(config_data)) => json!({ "type": msg::CompilerRequestType::Transpile, "configPath": config_path, "config": str::from_utf8(&config_data).unwrap(), "cwd": cwd, + "performance": performance, "sourceFileMap": module_graph_json, }), _ => json!({ "type": msg::CompilerRequestType::Transpile, + "performance": performance, "sourceFileMap": module_graph_json, }), }; @@ -663,6 +669,8 @@ impl TsCompiler { let transpile_response: CompileResponse = serde_json::from_str(json_str)?; + maybe_log_stats(transpile_response.stats); + if !transpile_response.diagnostics.items.is_empty() { return Err(ErrBox::from(transpile_response.diagnostics)); }