Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions news/changelog-1.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ All changes included in 1.7:

- ([#12042](https://github.com/quarto-dev/quarto-cli/issues/12042)): Preserve Markdown content that follows YAML metadata in a `raw` .ipynb cell.

## `quarto inspect`

- ([#12336](https://github.com/quarto-dev/quarto-cli/issues/12336)): Clean up transient files created by `quarto inspect`.

## `html` format

- ([#12277](https://github.com/quarto-dev/quarto-cli/pull/12277)): Provide light and dark plot and table renderings with `renderings: [light,dark]`
Expand Down
13 changes: 10 additions & 3 deletions src/project/project-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import { ExecutionEngine, kMarkdownEngine } from "../execute/types.ts";
import { projectResourceFiles } from "./project-resources.ts";

import {
cleanupFileInformationCache,
ignoreFieldsForProjectType,
normalizeFormatYaml,
projectConfigFile,
Expand Down Expand Up @@ -267,6 +268,7 @@ export async function projectContext(
const temp = createTempContext({
dir: join(dir, ".quarto", "temp"),
});
const fileInformationCache = new Map();
const result: ProjectContext = {
resolveBrand: async (fileName?: string) =>
projectResolveBrand(result, fileName),
Expand All @@ -286,7 +288,7 @@ export async function projectContext(
},
dir,
engines: [],
fileInformationCache: new Map(),
fileInformationCache,
files: {
input: [],
},
Expand All @@ -312,6 +314,7 @@ export async function projectContext(
diskCache: await createProjectCache(join(dir, ".quarto")),
temp,
cleanup: () => {
cleanupFileInformationCache(result);
result.diskCache.close();
},
};
Expand Down Expand Up @@ -359,6 +362,7 @@ export async function projectContext(
const temp = createTempContext({
dir: join(dir, ".quarto", "temp"),
});
const fileInformationCache = new Map();
const result: ProjectContext = {
resolveBrand: async (fileName?: string) =>
projectResolveBrand(result, fileName),
Expand All @@ -379,7 +383,7 @@ export async function projectContext(
dir,
config: projectConfig,
engines: [],
fileInformationCache: new Map(),
fileInformationCache,
files: {
input: [],
},
Expand All @@ -402,6 +406,7 @@ export async function projectContext(
diskCache: await createProjectCache(join(dir, ".quarto")),
temp,
cleanup: () => {
cleanupFileInformationCache(result);
result.diskCache.close();
},
};
Expand All @@ -427,6 +432,7 @@ export async function projectContext(
configResolvers.shift();
} else if (force) {
const temp = globalTempContext();
const fileInformationCache = new Map();
const context: ProjectContext = {
resolveBrand: async (fileName?: string) =>
projectResolveBrand(context, fileName),
Expand All @@ -451,7 +457,7 @@ export async function projectContext(
[kProjectOutputDir]: flags?.outputDir,
},
},
fileInformationCache: new Map(),
fileInformationCache,
files: {
input: [],
},
Expand All @@ -474,6 +480,7 @@ export async function projectContext(
diskCache: await createProjectCache(join(temp.baseDir, ".quarto")),
temp,
cleanup: () => {
cleanupFileInformationCache(context);
context.diskCache.close();
},
};
Expand Down
26 changes: 25 additions & 1 deletion src/project/project-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright (C) 2020-2022 Posit Software, PBC
*/

import { existsSync } from "../deno_ral/fs.ts";
import { existsSync, safeRemoveSync } from "../deno_ral/fs.ts";
import {
dirname,
isAbsolute,
Expand Down Expand Up @@ -582,3 +582,27 @@ export async function projectResolveBrand(
}
}
}

export function cleanupFileInformationCache(project: ProjectContext) {
project.fileInformationCache.forEach((entry) => {
if (entry?.target?.data) {
const data = entry.target.data as {
transient?: boolean;
};
if (data.transient && entry.target?.input) {
safeRemoveSync(entry.target?.input);
}
}
});
}

export async function withProjectCleanup<T>(
project: ProjectContext,
fn: (project: ProjectContext) => Promise<T>,
): Promise<T> {
try {
return await fn(project);
} finally {
project.cleanup();
}
}
Loading
Loading