Skip to content

Single file rendering vs Project rendering: inconsistency in input path which is relative vs absolute  #12401

Open
@cderv

Description

@cderv

However, QUARTO_DOCUMENT_PATH does not output the same (using the absolute path for project and using a relative path for non-project)

I have looked into the difference between project render and singlefile render

Both start with render() which makes the input relative to Deno.cwd()

renderResultInput = relative(Deno.cwd(), walk.path) || ".";
if (renderResult) {
renderResult.context.cleanup();
}
renderResult = await render(renderResultInput, {

However, when in a project, there will be some context compute which will end up normalizing (by adding back the Deno.cwd() like the following in renderProjects

let projectRenderConfig = await computeProjectRenderConfig({
context,
projType,
projOutputDir,
projDir,
options: pOptions,
files: pFiles,
});

// file normaliation
const normalizeFiles = (targetFiles: string[]) => {
return targetFiles.map((file) => {
const target = isAbsolute(file) ? file : join(Deno.cwd(), file);
if (!existsSync(target)) {
throw new Error("Render target does not exist: " + file);
}
return normalizePath(target);
});
};
if (inputs.files) {
if (alwaysExecuteFiles) {
alwaysExecuteFiles = normalizeFiles(alwaysExecuteFiles);
inputs.files = normalizeFiles(inputs.files);
} else if (inputs.options.useFreezer) {
inputs.files = normalizeFiles(inputs.files);
}
}

So basically,

  • When this is a project, renderFiles is called with an absolute path

    const fileResults = await renderFiles(
    projectRenderConfig.filesToRender,

  • When not inside a project, so singleFile render, renderFiles() is called with a relative path

    // otherwise it's just a file render
    const result = await renderFiles(
    [{ path }],
    options,
    nbContext,
    undefined,
    undefined,
    context,
    );

This is the different we see in those environment variable from this PR, as it will be inherited by target.source

Deno.env.set("QUARTO_DOCUMENT_PATH", dirname(options.target.source));

It seems there is room for improvement to make things work the same.

Originally posted by @cderv in #12271 (comment)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions