7
7
8
8
import { error , info , warning } from "log/mod.ts" ;
9
9
import { existsSync } from "fs/exists.ts" ;
10
+ import { basename , extname } from "path/mod.ts" ;
10
11
11
12
import * as colors from "fmt/colors.ts" ;
12
13
@@ -81,6 +82,9 @@ export const knitrEngine: ExecutionEngine = {
81
82
} ,
82
83
83
84
execute : async ( options : ExecuteOptions ) : Promise < ExecuteResult > => {
85
+ const inputBasename = basename ( options . target . input ) ;
86
+ const inputStem = basename ( inputBasename , extname ( inputBasename ) ) ;
87
+
84
88
const result = await callR < ExecuteResult > (
85
89
"execute" ,
86
90
{
@@ -92,6 +96,10 @@ export const knitrEngine: ExecutionEngine = {
92
96
options . tempDir ,
93
97
options . projectDir ,
94
98
options . quiet ,
99
+ // fixup .rmarkdown file references
100
+ ( output ) => {
101
+ return output . replaceAll ( `${ inputStem } .rmarkdown` , inputBasename ) ;
102
+ } ,
95
103
) ;
96
104
const includes = result . includes as unknown ;
97
105
// knitr appears to return [] instead of {} as the value for includes.
@@ -128,6 +136,7 @@ export const knitrEngine: ExecutionEngine = {
128
136
options . tempDir ,
129
137
options . projectDir ,
130
138
options . quiet ,
139
+ undefined ,
131
140
false ,
132
141
) . then ( ( ) => {
133
142
return Promise . resolve ( ) ;
@@ -163,6 +172,7 @@ async function callR<T>(
163
172
tempDir : string ,
164
173
projectDir ?: string ,
165
174
quiet ?: boolean ,
175
+ outputFilter ?: ( output : string ) => string ,
166
176
reportError = true ,
167
177
) : Promise < T > {
168
178
// establish cwd for execute (the current dir if there is an renv
@@ -192,7 +202,12 @@ async function callR<T>(
192
202
} ,
193
203
input ,
194
204
"stdout>stderr" ,
195
- colors . red ,
205
+ ( output ) => {
206
+ if ( outputFilter ) {
207
+ output = outputFilter ( output ) ;
208
+ }
209
+ return colors . red ( output ) ;
210
+ } ,
196
211
) ;
197
212
198
213
if ( result . success ) {
0 commit comments