Skip to content

Commit 3ebe230

Browse files
committed
projectcontext - add tempcontext as a field
1 parent 28e0316 commit 3ebe230

File tree

8 files changed

+32
-17
lines changed

8 files changed

+32
-17
lines changed

src/command/render/pandoc-html.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ export async function resolveSassBundles(
5353
inputDir: string,
5454
extras: FormatExtras,
5555
format: Format,
56-
temp: TempContext,
5756
project: ProjectContext,
5857
) {
58+
const { temp } = project;
5959
extras = cloneDeep(extras);
6060

6161
const mergedBundles: Record<string, SassBundleWithBrand[]> = {};
@@ -159,11 +159,11 @@ export async function resolveSassBundles(
159159

160160
for (const target of targets) {
161161
let cssPath: string | undefined;
162-
cssPath = await compileSass(target.bundles, temp);
162+
cssPath = await compileSass(target.bundles, project);
163163
// First, Clean CSS
164164
cleanSourceMappingUrl(cssPath);
165165
// look for a sentinel 'dark' value, extract variables
166-
const cssResult = await processCssIntoExtras(cssPath, extras, temp);
166+
const cssResult = await processCssIntoExtras(cssPath, extras, project);
167167
cssPath = cssResult.path;
168168

169169
// it can happen that processing generate an empty css file (e.g quarto-html deps with Quarto CSS variables)
@@ -261,7 +261,7 @@ export async function resolveSassBundles(
261261
inputDir,
262262
extras,
263263
format,
264-
temp,
264+
project,
265265
hasDarkStyles ? "light" : "default",
266266
defaultStyle,
267267
);
@@ -272,7 +272,7 @@ export async function resolveSassBundles(
272272
inputDir,
273273
extras,
274274
format,
275-
temp,
275+
project,
276276
"dark",
277277
defaultStyle,
278278
);
@@ -291,7 +291,7 @@ async function resolveQuartoSyntaxHighlighting(
291291
inputDir: string,
292292
extras: FormatExtras,
293293
format: Format,
294-
temp: TempContext,
294+
project: ProjectContext,
295295
style: "dark" | "light" | "default",
296296
defaultStyle?: "dark" | "light",
297297
) {
@@ -381,7 +381,7 @@ async function resolveQuartoSyntaxHighlighting(
381381
rules: rules.join("\n"),
382382
},
383383
}],
384-
temp,
384+
project,
385385
false,
386386
);
387387

@@ -500,8 +500,9 @@ interface CSSResult {
500500
async function processCssIntoExtras(
501501
cssPath: string,
502502
extras: FormatExtras,
503-
temp: TempContext,
503+
project: ProjectContext,
504504
): Promise<CSSResult> {
505+
const { temp } = project;
505506
extras.html = extras.html || {};
506507

507508
const css = Deno.readTextFileSync(cssPath);

src/command/render/pandoc.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,6 @@ async function resolveExtras(
14151415
inputDir,
14161416
extras,
14171417
format,
1418-
temp,
14191418
project,
14201419
);
14211420

src/core/sass.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { md5HashBytes } from "./hash.ts";
2121
import { kSourceMappingRegexes } from "../config/constants.ts";
2222
import { quartoConfig } from "../core/quarto.ts";
2323
import { safeModeFromFile } from "../deno_ral/fs.ts";
24+
import { ProjectContext } from "../project/types.ts";
2425

2526
export interface SassVariable {
2627
name: string;
@@ -49,9 +50,10 @@ export function outputVariable(
4950
let counter: number = 1;
5051
export async function compileSass(
5152
bundles: SassBundleLayers[],
52-
temp: TempContext,
53+
projectContext: ProjectContext,
5354
minified = true,
5455
) {
56+
const { temp } = projectContext;
5557
// Gather the inputs for the framework
5658
const frameWorkUses = bundles.map(
5759
(bundle) => bundle.framework?.uses || "",

src/format/reveal/format-reveal-theme.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ export async function revealTheme(
6868
format: Format,
6969
input: string,
7070
libDir: string,
71-
temp: TempContext,
7271
project: ProjectContext,
7372
) {
73+
const { temp } = project;
7474
// metadata override to return
7575
const metadata: Metadata = {};
7676

@@ -196,7 +196,7 @@ export async function revealTheme(
196196
};
197197

198198
// compile sass
199-
const css = await compileSass([bundleLayers], temp);
199+
const css = await compileSass([bundleLayers], project);
200200
// Remove sourcemap information
201201
cleanSourceMappingUrl(css);
202202
// convert from string to bytes

src/format/reveal/format-reveal.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ export function revealjsFormat() {
212212
format,
213213
input,
214214
libDir,
215-
services.temp,
216215
project,
217216
);
218217

src/project/project-context.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,8 @@ import { computeProjectEnvironment } from "./project-environment.ts";
9999
import { ProjectEnvironment } from "./project-environment-types.ts";
100100
import { NotebookContext } from "../render/notebook/notebook-types.ts";
101101
import { MappedString } from "../core/mapped-text.ts";
102-
import { timeCall } from "../core/performance/function-times.ts";
103-
import { assertEquals } from "testing/asserts";
104102
import { createProjectCache } from "../core/cache/cache.ts";
103+
import { createTempContext } from "../core/temp.ts";
105104

106105
export async function projectContext(
107106
path: string,
@@ -264,6 +263,9 @@ export async function projectContext(
264263
);
265264
}
266265

266+
const temp = createTempContext({
267+
dir: join(dir, ".quarto", "temp"),
268+
});
267269
const result: ProjectContext = {
268270
resolveBrand: async (fileName?: string) =>
269271
projectResolveBrand(result, fileName),
@@ -307,6 +309,7 @@ export async function projectContext(
307309
},
308310
isSingleFile: false,
309311
diskCache: await createProjectCache(join(dir, ".quarto")),
312+
temp,
310313
};
311314

312315
// see if the project [kProjectType] wants to filter the project config
@@ -349,6 +352,9 @@ export async function projectContext(
349352
return result;
350353
} else {
351354
debug(`projectContext: Found Quarto project in ${dir}`);
355+
const temp = createTempContext({
356+
dir: join(dir, ".quarto", "temp"),
357+
});
352358
const result: ProjectContext = {
353359
resolveBrand: async (fileName?: string) =>
354360
projectResolveBrand(result, fileName),
@@ -390,6 +396,7 @@ export async function projectContext(
390396
notebookContext,
391397
isSingleFile: false,
392398
diskCache: await createProjectCache(join(dir, ".quarto")),
399+
temp,
393400
};
394401
const { files, engines } = await projectInputFiles(
395402
result,
@@ -412,6 +419,9 @@ export async function projectContext(
412419
dir = originalDir;
413420
configResolvers.shift();
414421
} else if (force) {
422+
const temp = createTempContext({
423+
dir: join(dir, ".quarto", "temp"),
424+
});
415425
const context: ProjectContext = {
416426
resolveBrand: async (fileName?: string) =>
417427
projectResolveBrand(context, fileName),
@@ -457,6 +467,7 @@ export async function projectContext(
457467
},
458468
isSingleFile: false,
459469
diskCache: await createProjectCache(join(dir, ".quarto")),
470+
temp,
460471
};
461472
if (Deno.statSync(path).isDirectory) {
462473
const { files, engines } = await projectInputFiles(context);

src/project/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
} from "../resources/types/schema-types.ts";
2323
import { ProjectEnvironment } from "./project-environment-types.ts";
2424
import { ProjectCache } from "../core/cache/cache-types.ts";
25+
import { TempContext } from "../core/temp-types.ts";
2526

2627
export {
2728
type NavigationItem as NavItem,
@@ -114,6 +115,7 @@ export interface ProjectContext {
114115
isSingleFile: boolean;
115116

116117
diskCache: ProjectCache;
118+
temp: TempContext;
117119
}
118120

119121
export interface ProjectFiles {

src/project/types/single-file/single-file.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ export async function singleFileProjectContext(
3434
flags?: RenderFlags,
3535
): Promise<ProjectContext> {
3636
const environmentMemoizer = makeProjectEnvironmentMemoizer(notebookContext);
37-
const tempContext = globalTempContext();
38-
const projectCacheBaseDir = tempContext.createDir();
37+
const temp = globalTempContext();
38+
const projectCacheBaseDir = temp.createDir();
3939

4040
const result: ProjectContext = {
4141
resolveBrand: (fileName?: string) => projectResolveBrand(result, fileName),
@@ -76,6 +76,7 @@ export async function singleFileProjectContext(
7676
},
7777
isSingleFile: true,
7878
diskCache: await createProjectCache(projectCacheBaseDir),
79+
temp,
7980
};
8081
return result;
8182
}

0 commit comments

Comments
 (0)