diff --git a/packages/site-kit/src/lib/markdown/renderer.ts b/packages/site-kit/src/lib/markdown/renderer.ts index ace7b0398..0072d3801 100644 --- a/packages/site-kit/src/lib/markdown/renderer.ts +++ b/packages/site-kit/src/lib/markdown/renderer.ts @@ -1,6 +1,7 @@ import MagicString from 'magic-string'; import { createHash, Hash } from 'node:crypto'; import fs from 'node:fs'; +import process from 'node:process'; import path from 'node:path'; import ts from 'typescript'; import * as marked from 'marked'; @@ -28,9 +29,21 @@ const theme = createCssVariablesTheme({ fontStyle: true }); +// Hash the contents of this file and its dependencies so that we get a new cache in case we have changed +// how the markdown is rendered (whose logic live here). This is to avoid serving stale code snippets. const hash = createHash('sha256'); hash.update(fs.readFileSync('../../pnpm-lock.yaml', 'utf-8')); -hash_graph(hash, fileURLToPath(import.meta.url)); +// CAREFUL: update this URL in case you ever move this file or start the dev/build process from another directory +const original_file = '../../packages/site-kit/src/lib/markdown/renderer.ts'; +if (!fs.existsSync(original_file)) { + throw new Error( + 'Update the path to the markdown renderer code. Current value: ' + + original_file + + ' | Current cwd: ' + + process.cwd() + ); +} +hash_graph(hash, original_file); const digest = hash.digest().toString('base64').replace(/\//g, '-'); /**