diff --git a/.changeset/witty-needles-serve.md b/.changeset/witty-needles-serve.md new file mode 100644 index 0000000..d273ab4 --- /dev/null +++ b/.changeset/witty-needles-serve.md @@ -0,0 +1,5 @@ +--- +"eleventy-plugin-shiki-twoslash": patch +--- + +Ditch deasync in 11ty plugin diff --git a/packages/eleventy-plugin-shiki-twoslash/index.js b/packages/eleventy-plugin-shiki-twoslash/index.js index 38fd427..8ed022f 100644 --- a/packages/eleventy-plugin-shiki-twoslash/index.js +++ b/packages/eleventy-plugin-shiki-twoslash/index.js @@ -1,30 +1,22 @@ // @ts-check const { setupForFile, transformAttributesToHTML } = require("remark-shiki-twoslash") -const { sleep } = require("deasync") /** * @param {*} eleventyConfig * @param {import("shiki-twoslash").UserConfigSettings} options */ + +let highlighters = undefined + module.exports = function (eleventyConfig, options = {}) { /** @type {import("shiki").Highlighter[]} */ - let highlighters = undefined - setupForFile(options).then(h => (highlighters = h.highlighters)) - - if (!highlighters) { - let count = 10000 / 200 - while (!highlighters) { - sleep(200) - count -= 1 - if (count <= 0) - throw new Error( - "Could not get Shiki loaded async via 'deasync'. 11ty doesn't have an API for async plugins, and Shiki needs this for the WASM syntax highlighter. You can try using a different version of node, or requesting APIs at https://github.com/11ty/eleventy" - ) - } - } + eleventyConfig.on("eleventy.before", async () => { + const h = await setupForFile(options) + highlighters = await h.highlighters; + }); eleventyConfig.addMarkdownHighlighter((code, lang, fence) => { code = code.replace(/\r?\n$/, "") // strip trailing newline fed during code block parsing return transformAttributesToHTML(code, [lang, fence].join(" "), highlighters, options) }) -} +} \ No newline at end of file diff --git a/packages/eleventy-plugin-shiki-twoslash/package.json b/packages/eleventy-plugin-shiki-twoslash/package.json index 817d7ca..ec48985 100644 --- a/packages/eleventy-plugin-shiki-twoslash/package.json +++ b/packages/eleventy-plugin-shiki-twoslash/package.json @@ -20,7 +20,6 @@ "build": "pnpm exec tsc index.js --declaration --allowJs --emitDeclarationOnly --target es2018 -moduleResolution node" }, "dependencies": { - "deasync": "^0.1.21", "remark-shiki-twoslash": "3.1.7", "typescript": ">3", "@typescript/vfs": "1.4.0",