@@ -25,7 +25,7 @@ import { fromJS, List, Map } from "immutable";
25
25
import { debounce , union } from "lodash" ;
26
26
import { normalize as path_normalize } from "path" ;
27
27
28
- import { Store } from "@cocalc/frontend/app-framework" ;
28
+ import { Store , TypedMap } from "@cocalc/frontend/app-framework" ;
29
29
import {
30
30
TableOfContentsEntry ,
31
31
TableOfContentsEntryList ,
@@ -53,8 +53,9 @@ import {
53
53
} from "@cocalc/util/misc" ;
54
54
import { reuseInFlight } from "@cocalc/util/reuse-in-flight" ;
55
55
56
+ import { ExecOutput } from "@cocalc/util/db-schema/projects" ;
57
+ import { ExecuteCodeOutputAsync } from "@cocalc/util/types/execute-code" ;
56
58
import { bibtex } from "./bibtex" ;
57
- import { IBuildSpecs } from "./build" ;
58
59
import { clean } from "./clean" ;
59
60
import { KNITR_EXTS } from "./constants" ;
60
61
import { count_words } from "./count_words" ;
@@ -75,6 +76,8 @@ import { parseTableOfContents } from "./table-of-contents";
75
76
import {
76
77
BuildLog ,
77
78
BuildLogs ,
79
+ IBuildSpecs ,
80
+ ProcessInfos ,
78
81
ScrollIntoViewMap ,
79
82
ScrollIntoViewRecord ,
80
83
} from "./types" ;
@@ -94,6 +97,7 @@ interface LatexEditorState extends CodeEditorState {
94
97
includeError ?: string ;
95
98
build_command_hardcoded ?: boolean ; // if true, an % !TeX cocalc = ... directive sets the command via the document itself
96
99
contents ?: TableOfContentsEntryList ; // table of contents data.
100
+ proc_infos : ProcessInfos ;
97
101
}
98
102
99
103
export class Actions extends BaseActions < LatexEditorState > {
@@ -694,7 +698,8 @@ export class Actions extends BaseActions<LatexEditorState> {
694
698
}
695
699
696
700
async run_build ( time : number , force : boolean ) : Promise < void > {
697
- ( this as unknown as any ) . setState ( { build_logs : Map ( ) } ) ;
701
+ this . setState ( { build_logs : Map ( ) } ) ;
702
+ this . setState ( { proc_infos : Map ( ) } ) ;
698
703
699
704
if ( this . bad_filename ) {
700
705
const err = `ERROR: It is not possible to compile this LaTeX file with the name '${ this . path } '.
@@ -846,6 +851,7 @@ export class Actions extends BaseActions<LatexEditorState> {
846
851
}
847
852
this . set_error ( "" ) ;
848
853
this . set_build_logs ( { latex : undefined } ) ;
854
+ this . set_proc_infos ( { latex : undefined } ) ;
849
855
if ( typeof s == "string" ) {
850
856
build_command = s ;
851
857
} else {
@@ -854,14 +860,18 @@ export class Actions extends BaseActions<LatexEditorState> {
854
860
const status = ( s ) => this . set_status ( `Running Latex... ${ s } ` ) ;
855
861
status ( "" ) ;
856
862
try {
857
- output = await latexmk (
863
+ const [ info , job ] = await latexmk (
858
864
this . project_id ,
859
865
this . path ,
860
866
build_command ,
861
867
timestamp ,
862
868
status ,
863
869
this . get_output_directory ( ) ,
864
870
) ;
871
+ this . set_proc_infos ( { latex : info } ) ;
872
+ output = await job ;
873
+ if ( output . type !== "async" ) throw new Error ( "not an asnyc job" ) ;
874
+ this . set_proc_infos ( { latex : output } ) ;
865
875
} catch ( err ) {
866
876
this . set_error ( err ) ;
867
877
return ;
@@ -1080,6 +1090,7 @@ export class Actions extends BaseActions<LatexEditorState> {
1080
1090
status ,
1081
1091
this . get_output_directory ( ) ,
1082
1092
) ;
1093
+ if ( ! output ) throw new Error ( "Unable to run SageTeX." ) ;
1083
1094
if ( output . stderr . indexOf ( "sagetex.VersionError" ) != - 1 ) {
1084
1095
// See https://github.com/sagemathinc/cocalc/issues/4432
1085
1096
throw Error (
@@ -1274,16 +1285,34 @@ export class Actions extends BaseActions<LatexEditorState> {
1274
1285
} ) ;
1275
1286
}
1276
1287
1288
+ set_proc_infos ( obj : {
1289
+ [ K in keyof IBuildSpecs ] ?: ExecuteCodeOutputAsync ;
1290
+ } ) : void {
1291
+ let proc_infos : ProcessInfos = this . store . get ( "proc_infos" ) ;
1292
+ if ( ! proc_infos ) {
1293
+ return ;
1294
+ }
1295
+ for ( const k in obj ) {
1296
+ const v : ExecuteCodeOutputAsync = obj [ k ] ;
1297
+ if ( ! v ) continue ;
1298
+ proc_infos = proc_infos . set (
1299
+ k as any ,
1300
+ fromJS ( v ) as any as TypedMap < ExecOutput > ,
1301
+ ) ;
1302
+ }
1303
+ this . setState ( { proc_infos } ) ;
1304
+ }
1305
+
1277
1306
set_build_logs ( obj : { [ K in keyof IBuildSpecs ] ?: BuildLog } ) : void {
1278
1307
let build_logs : BuildLogs = this . store . get ( "build_logs" ) ;
1279
1308
if ( ! build_logs ) {
1280
1309
// may have already been closed.
1281
1310
return ;
1282
1311
}
1283
- let k : string ;
1284
- for ( k in obj ) {
1312
+ for ( const k in obj ) {
1285
1313
const v : BuildLog = obj [ k ] ;
1286
- build_logs = build_logs . set ( k , fromJS ( v ) ) ;
1314
+ if ( ! v ) continue ;
1315
+ build_logs = build_logs . set ( k , fromJS ( v ) as any as TypedMap < BuildLog > ) ;
1287
1316
}
1288
1317
this . setState ( { build_logs } ) ;
1289
1318
}
@@ -1296,7 +1325,10 @@ export class Actions extends BaseActions<LatexEditorState> {
1296
1325
log += s + "\n" ;
1297
1326
const build_logs : BuildLogs = this . store . get ( "build_logs" ) ;
1298
1327
this . setState ( {
1299
- build_logs : build_logs . set ( "clean" , fromJS ( { output : log } ) ) ,
1328
+ build_logs : build_logs . set (
1329
+ "clean" ,
1330
+ fromJS ( { output : log } ) as any as TypedMap < BuildLog > ,
1331
+ ) ,
1300
1332
} ) ;
1301
1333
} ;
1302
1334
0 commit comments