From f515d282a4c963f3830aca7d530c7ac9e5daf3c6 Mon Sep 17 00:00:00 2001 From: James Marx Date: Fri, 8 Sep 2023 14:36:22 +0100 Subject: [PATCH 1/2] Ditch deasync for 11ty plugin --- .../eleventy-plugin-shiki-twoslash/index.js | 24 +++++++------------ .../package.json | 1 - 2 files changed, 8 insertions(+), 17 deletions(-) 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", From 143e1161deeaf56c663767d00138132f343581cd Mon Sep 17 00:00:00 2001 From: James Marx <47417929+Brewd3v@users.noreply.github.com> Date: Fri, 8 Sep 2023 14:43:04 +0100 Subject: [PATCH 2/2] Create witty-needles-serve.md --- .changeset/witty-needles-serve.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/witty-needles-serve.md 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