Skip to content
Merged
Changes from 1 commit
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
52 changes: 30 additions & 22 deletions src/core/sass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ export async function compileSass(
'// quarto-scss-analysis-annotation { "origin": null }',
].join("\n\n");

const save_scss_prefix = Deno.env.get("QUARTO_SAVE_SCSS")
if (save_scss_prefix) {
// Save the SCSS before compilation
const counterValue = counter++;
Deno.writeTextFileSync(
`${save_scss_prefix}-${counterValue}.scss`,
scssInput,
);
}

// Compile the scss
const result = await compileWithCache(
scssInput,
Expand All @@ -157,29 +167,27 @@ export async function compileSass(
},
);

if (!Deno.env.get("QUARTO_SAVE_SCSS")) {
return result;
if (save_scss_prefix) {
// The compilation succeeded, we can update the file with additional info
const partialOutput = Deno.readTextFileSync(result);
// now we attempt to find the SCSS variables in the output
// and inject them back in the SCSS file so that our debug tooling can use them.
const scssToWrite = [scssInput];
const internalVars = Array.from(
partialOutput.matchAll(/(--quarto-scss-export-[^;}]+;?)/g),
).map((m) => m[0]);
const annotation = {
"css-vars": internalVars,
};
scssToWrite.push(
`// quarto-scss-analysis-annotation ${JSON.stringify(annotation)}`,
);
scssInput = scssToWrite.join("\n");
Deno.writeTextFileSync(
`${save_scss_prefix}-${counter}.scss`,
scssInput,
);
}
const partialOutput = Deno.readTextFileSync(result);
// now we attempt to find the SCSS variables in the output
// and inject them back in the SCSS file so that our debug tooling can use them.
const scssToWrite = [scssInput];
const internalVars = Array.from(
partialOutput.matchAll(/(--quarto-scss-export-[^;}]+;?)/g),
).map((m) => m[0]);
const annotation = {
"css-vars": internalVars,
};
scssToWrite.push(
`// quarto-scss-analysis-annotation ${JSON.stringify(annotation)}`,
);
scssInput = scssToWrite.join("\n");
const prefix = Deno.env.get("QUARTO_SAVE_SCSS");
const counterValue = counter++;
Deno.writeTextFileSync(
`${prefix}-${counterValue}.scss`,
scssInput,
);

return result;
}
Expand Down
Loading