@@ -22,6 +22,7 @@ import { kSourceMappingRegexes } from "../config/constants.ts";
2222import { quartoConfig } from "../core/quarto.ts" ;
2323import { safeModeFromFile } from "../deno_ral/fs.ts" ;
2424import { ProjectContext } from "../project/types.ts" ;
25+ import { memoizeStringFunction } from "./cache/cache.ts" ;
2526
2627export interface SassVariable {
2728 name : string ;
@@ -50,10 +51,9 @@ export function outputVariable(
5051let counter : number = 1 ;
5152export async function compileSass (
5253 bundles : SassBundleLayers [ ] ,
53- projectContext : ProjectContext ,
54+ project : ProjectContext ,
5455 minified = true ,
5556) {
56- const { temp } = projectContext ;
5757 // Gather the inputs for the framework
5858 const frameWorkUses = bundles . map (
5959 ( bundle ) => bundle . framework ?. uses || "" ,
@@ -161,7 +161,7 @@ export async function compileSass(
161161 const result = await compileWithCache (
162162 scssInput ,
163163 loadPaths ,
164- temp ,
164+ project ,
165165 {
166166 compressed : minified ,
167167 cacheIdentifier : await md5HashBytes ( new TextEncoder ( ) . encode ( scssInput ) ) ,
@@ -357,24 +357,37 @@ type CompileWithCacheOptions = {
357357 addVarsBlock ?: boolean ;
358358} ;
359359
360+ const memoizedGetVarsBlock = memoizeStringFunction ( [
361+ "core" ,
362+ "sass" ,
363+ "cssVarsBlock" ,
364+ ] , ( input : string ) => Promise . resolve ( cssVarsBlock ( input ) ) ) ;
365+
360366export async function compileWithCache (
361367 input : string ,
362368 loadPaths : string [ ] ,
363- temp : TempContext ,
369+ project : ProjectContext ,
364370 options ?: CompileWithCacheOptions ,
365371) {
372+ const { temp } = project ;
366373 const {
367374 compressed,
368375 cacheIdentifier,
369376 addVarsBlock,
370377 } = options || { } ;
371378
372- const handleVarsBlock = ( input : string ) => {
379+ const handleVarsBlock = async ( input : string ) => {
373380 if ( ! addVarsBlock ) {
374381 return input ;
375382 }
376383 try {
377- input += "\n" + cssVarsBlock ( input ) ;
384+ const result = await memoizedGetVarsBlock ( project , input ) ;
385+ console . log ( "<<<<" ) ;
386+ console . log ( input ) ;
387+ console . log ( "----" ) ;
388+ console . log ( result ) ;
389+ console . log ( ">>>>" ) ;
390+ return input + result ;
378391 } catch ( e ) {
379392 console . warn ( "Error adding css vars block" , e ) ;
380393 console . warn (
@@ -404,12 +417,12 @@ export async function compileWithCache(
404417 input ,
405418 cacheIdentifier ,
406419 async ( outputFilePath : string ) => {
407- input = handleVarsBlock ( input ) ;
420+ input = await handleVarsBlock ( input ) ;
408421 await dartCompile ( input , outputFilePath , temp , loadPaths , compressed ) ;
409422 } ,
410423 ) ;
411424 } else {
412- input = handleVarsBlock ( input ) ;
425+ input = await handleVarsBlock ( input ) ;
413426 const outputFilePath = temp . createFile ( { suffix : ".css" } ) ;
414427 // Skip the cache and just compile
415428 await dartCompile (
0 commit comments