Skip to content

Commit

Permalink
only restrict output dir for knitr
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Nov 3, 2023
1 parent b5958fd commit a2bfab3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/command/render/render-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ import { error, info } from "log/mod.ts";
import * as ld from "../../core/lodash.ts";
import { basename, dirname, join, relative } from "path/mod.ts";
import { Format } from "../../config/types.ts";
import { figuresDir, inputFilesDir, isServerShiny } from "../../core/render.ts";
import {
figuresDir,
inputFilesDir,
isServerShiny,
isServerShinyKnitr,
} from "../../core/render.ts";
import {
normalizePath,
removeIfEmptyDir,
Expand Down Expand Up @@ -495,10 +500,12 @@ async function renderFileInternal(
);
throw new Error();
} else if (
projectOutputDir(context.project) !== normalizePath(context.project.dir)
(projectOutputDir(context.project) !==
normalizePath(context.project.dir)) &&
isServerShinyKnitr(context.format, context.engine.name)
) {
error(
`${src} uses server: shiny so cannot be included in a project with an output-dir ` +
`${src} is a knitr engine document that uses server: shiny so cannot be included in a project with an output-dir ` +
`(shiny document output must be rendered alongside its source document).`,
);
throw new Error();
Expand Down
9 changes: 8 additions & 1 deletion src/core/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { kOutputExt, kOutputFile, kServer } from "../config/constants.ts";
import { Format, Metadata } from "../config/types.ts";
import { kJupyterEngine } from "../execute/types.ts";
import { kJupyterEngine, kKnitrEngine } from "../execute/types.ts";
import { dirAndStem } from "./path.ts";
import { extname } from "path/mod.ts";

Expand Down Expand Up @@ -37,6 +37,13 @@ export function isServerShinyPython(
return isServerShiny(format) && engine === kJupyterEngine;
}

export function isServerShinyKnitr(
format: Format,
engine: string | undefined,
) {
return isServerShiny(format) && engine === kKnitrEngine;
}

export function formatOutputFile(format: Format) {
let outputFile = format.pandoc[kOutputFile];
if (outputFile) {
Expand Down

0 comments on commit a2bfab3

Please sign in to comment.