Skip to content

Commit

Permalink
add stats to transpile
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed Jun 24, 2020
1 parent e52ce06 commit b994057
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
15 changes: 8 additions & 7 deletions cli/js/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,7 @@ interface TranspileRequest {
config?: string;
configPath?: string;
cwd?: string;
performance: boolean;
sourceFileMap: Record<string, SourceFileMapEntry>;
}

Expand Down Expand Up @@ -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(
{},
Expand Down Expand Up @@ -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({
Expand Down
8 changes: 8 additions & 0 deletions cli/tsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
};
Expand All @@ -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));
}
Expand Down

0 comments on commit b994057

Please sign in to comment.