Skip to content

Commit

Permalink
Add typescript version to the cache key
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Mar 28, 2023
1 parent f16b41b commit e133a03
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 203 deletions.
5 changes: 5 additions & 0 deletions .changeset/moody-pots-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"remark-shiki-twoslash": patch
---

Adds the TypeScript version to the cache key for twoslash
6 changes: 4 additions & 2 deletions VISION.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Things I care about which might affect scope:

### Long Term Vision

Today, early June 2021, Shiki Twoslash is bascially 1.0'd. It does everything the TypeScript website needs,
Today, early June 2021, Shiki Twoslash is basically 1.0'd. It does everything the TypeScript website needs,
and is in a good position to be used in blogs as seen on [fatihkalifa.com](https://fatihkalifa.com) and [cpojer.net](https://cpojer.net), and on serious technical documentation sites like TypeScript.

I, Orta, intend to keep maintaining Shiki Twoslash for a very long time, which means big changes will need an issue ahead of time because I can't maintain what I don't understand. Smaller things I can be flexible with.
Expand All @@ -28,4 +28,6 @@ In [the website](https://shikijs.github.io/twoslash/) I describe Shiki Twoslash

What that means is that the underlaying tokens -> HTML renderer is a complete fork from Shiki. E.g. [these files](packages/shiki-twoslash/src/renderers) won't call the original shiki renderers. I don't think I'll ever commit to re-using Shiki at at that level. Which means that there are features which Shiki may implement differently from Shiki Twoslash. For example, I copied [gatsby-remark-vscode](https://github.com/andrewbranch/gatsby-remark-vscode)'s line highlighting syntax and shiki may not.

We can take ideas (and features) from Shiki, and move them upstream too but convergence isn't a goal.
We can take ideas (and features) from Shiki, and move them upstream too but convergence isn't a goal.

(2023 edit: there may be a world in which [Shiki's plugin support](https://github.com/shikijs/shiki/pull/381) is enough for Twoslash, if that happens, I'm open to moving to that.)
4 changes: 3 additions & 1 deletion packages/remark-shiki-twoslash/src/caching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ export const cachedTwoslashCall = (
const { createHash } = require("crypto")
const { readFileSync, existsSync, mkdirSync, writeFileSync } = require("fs")
const { join } = require("path")

const shikiVersion = require('@typescript/twoslash/package.json').version
const tsVersion = require('typescript/package.json').version
const shasum = createHash("sha1")
const codeSha = shasum.update(`${code}-${shikiVersion}`).digest("hex")
const codeSha = shasum.update(`${code}-${shikiVersion}-${tsVersion}`).digest("hex")

const getNmCache = () => {
if (__dirname.includes("node_modules")) {
Expand Down
Loading

0 comments on commit e133a03

Please sign in to comment.