From 05cdf97ccbdd94d99370221a79ce42355d8981b9 Mon Sep 17 00:00:00 2001 From: Ian Kerins Date: Sun, 14 Jan 2024 19:17:50 -0500 Subject: [PATCH] Abandon the Shikiji patch approach `npm` does not support the `patch` protocol, so we lost the ability to `npm install -g neogrok`. Just do the aforementioned janky integration with the shikiji APIs as they exist today. --- .changeset/spicy-bulldogs-breathe.md | 5 ++ .../shikiji-core-npm-0.9.18-826293a3df.patch | 49 ------------------- .../shikiji-npm-0.9.18-945ea5efcb.patch | 13 ----- package.json | 5 +- src/routes/(search-page)/line-group.svelte | 4 +- .../(search-page)/rendered-content.svelte | 7 ++- yarn.lock | 18 +------ 7 files changed, 17 insertions(+), 84 deletions(-) create mode 100644 .changeset/spicy-bulldogs-breathe.md delete mode 100644 .yarn/patches/shikiji-core-npm-0.9.18-826293a3df.patch delete mode 100644 .yarn/patches/shikiji-npm-0.9.18-945ea5efcb.patch diff --git a/.changeset/spicy-bulldogs-breathe.md b/.changeset/spicy-bulldogs-breathe.md new file mode 100644 index 0000000..7d67b41 --- /dev/null +++ b/.changeset/spicy-bulldogs-breathe.md @@ -0,0 +1,5 @@ +--- +"neogrok": patch +--- + +Fix ability to `npm install -g neogrok` diff --git a/.yarn/patches/shikiji-core-npm-0.9.18-826293a3df.patch b/.yarn/patches/shikiji-core-npm-0.9.18-826293a3df.patch deleted file mode 100644 index e7e630d..0000000 --- a/.yarn/patches/shikiji-core-npm-0.9.18-826293a3df.patch +++ /dev/null @@ -1,49 +0,0 @@ -diff --git a/dist/chunk-types.d.mts b/dist/chunk-types.d.mts -index 2992357a1d0e670afce9ec11133a58a4e17593da..788cab9adb4134796ab6cd91fa9fd25b3a971dc5 100644 ---- a/dist/chunk-types.d.mts -+++ b/dist/chunk-types.d.mts -@@ -1124,10 +1124,8 @@ interface ThemedTokenExplanation { - interface ThemedToken extends TokenStyles, TokenBase { - } - interface TokenBase { -- /** -- * The content of the token -- */ -- content: string; -+ start: number; -+ end: number; - /** - * Explanation of - * -diff --git a/dist/index.mjs b/dist/index.mjs -index 6f891f5e37470cb673f8bcb8914c44634ca47091..1b52e8c87fa19d739e66f824715a18f37ae05fc6 100644 ---- a/dist/index.mjs -+++ b/dist/index.mjs -@@ -3709,7 +3709,7 @@ function dimColor(color) { - function codeToThemedTokens(internal, code, options = {}) { - const { lang = 'text', theme: themeName = internal.getLoadedThemes()[0], } = options; - if (isPlaintext(lang)) { -- const lines = code.split(/\r\n|\r|\n/); -+ const lines = code; - return [...lines.map(line => [{ content: line }])]; - } - const { theme, colorMap } = internal.setTheme(themeName); -@@ -3723,7 +3723,7 @@ function tokenizeWithTheme(code, grammar, theme, colorMap, options) { - ...theme.colorReplacements, - ...options?.colorReplacements, - }; -- const lines = code.split(/\r\n|\r|\n/); -+ const lines = code; - let ruleStack = INITIAL; - let actual = []; - const final = []; -@@ -3754,7 +3754,8 @@ function tokenizeWithTheme(code, grammar, theme, colorMap, options) { - const foregroundColor = applyColorReplacements(colorMap[foreground], colorReplacements); - const fontStyle = StackElementMetadata.getFontStyle(metadata); - const token = { -- content: line.substring(startIndex, nextStartIndex), -+ start: startIndex, -+ end: nextStartIndex, - color: foregroundColor, - fontStyle, - }; diff --git a/.yarn/patches/shikiji-npm-0.9.18-945ea5efcb.patch b/.yarn/patches/shikiji-npm-0.9.18-945ea5efcb.patch deleted file mode 100644 index be31b91..0000000 --- a/.yarn/patches/shikiji-npm-0.9.18-945ea5efcb.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/dist/bundle-full.d.mts b/dist/bundle-full.d.mts -index b8e655052e4a1b6e10e617eb06008a0782ff3a70..db1121f519c64bcada055f10f07500c27afca436 100644 ---- a/dist/bundle-full.d.mts -+++ b/dist/bundle-full.d.mts -@@ -12,7 +12,7 @@ type Highlighter = HighlighterGeneric; - declare const getHighlighter: shikiji_core.GetHighlighterFactory; - declare const codeToHtml: (code: string, options: shikiji_core.CodeToHastOptions) => Promise; - declare const codeToHast: (code: string, options: shikiji_core.CodeToHastOptions) => Promise; --declare const codeToThemedTokens: (code: string, options: shikiji_core.RequireKeys, "lang" | "theme">) => Promise; -+declare const codeToThemedTokens: (code: string[], options: shikiji_core.RequireKeys, "lang" | "theme">) => Promise; - declare const codeToTokensWithThemes: (code: string, options: shikiji_core.RequireKeys, "lang" | "themes">) => Promise; - declare const getSingletonHighlighter: () => Promise>; - diff --git a/package.json b/package.json index a0b2001..b5dc3c7 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "lucide-svelte": "0.303.0", "pretty-bytes": "6.1.1", "prom-client": "15.0.0", - "shikiji": "patch:shikiji@npm%3A0.9.18#~/.yarn/patches/shikiji-npm-0.9.18-945ea5efcb.patch" + "shikiji": "0.9.18" }, "engines": { "node": ">=20" @@ -107,7 +107,6 @@ "typed-array-length": "npm:@nolyfill/typed-array-length@latest", "unbox-primitive": "npm:@nolyfill/unbox-primitive@latest", "which-boxed-primitive": "npm:@nolyfill/which-boxed-primitive@latest", - "which-typed-array": "npm:@nolyfill/which-typed-array@latest", - "shikiji-core@npm:0.9.18": "patch:shikiji-core@npm%3A0.9.18#~/.yarn/patches/shikiji-core-npm-0.9.18-826293a3df.patch" + "which-typed-array": "npm:@nolyfill/which-typed-array@latest" } } diff --git a/src/routes/(search-page)/line-group.svelte b/src/routes/(search-page)/line-group.svelte index 6b113aa..71e641b 100644 --- a/src/routes/(search-page)/line-group.svelte +++ b/src/routes/(search-page)/line-group.svelte @@ -56,7 +56,9 @@ if (!canceled) { highlights.set( await codeToThemedTokens( - lines.map(({ line: { text } }) => text), + // Shikiji only accepts a single string even though it goes right + // ahead and splits it :(. + lines.map(({ line: { text } }) => text).join("\n"), { theme: "github-light", lang, diff --git a/src/routes/(search-page)/rendered-content.svelte b/src/routes/(search-page)/rendered-content.svelte index 0ebf604..60d6344 100644 --- a/src/routes/(search-page)/rendered-content.svelte +++ b/src/routes/(search-page)/rendered-content.svelte @@ -44,7 +44,10 @@ const matchRangeIterator = content.matchRanges[Symbol.iterator](); let currentMatchRange: Range | undefined = matchRangeIterator.next().value; - for (const { start, end, fontStyle, color } of highlights) { + + let start = 0; + for (const { content: highlightText, fontStyle, color } of highlights) { + const end = start + highlightText.length; const fontClass = toFontClass(fontStyle); let base = start; @@ -94,6 +97,8 @@ color, }); } + + start = end; } } else { let base = 0; diff --git a/yarn.lock b/yarn.lock index bc3cd5c..ef87372 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3580,7 +3580,7 @@ __metadata: prettier-plugin-svelte: "npm:3.0.3" pretty-bytes: "npm:6.1.1" prom-client: "npm:15.0.0" - shikiji: "patch:shikiji@npm%3A0.9.18#~/.yarn/patches/shikiji-npm-0.9.18-945ea5efcb.patch" + shikiji: "npm:0.9.18" svelte: "npm:4.2.1" svelte-check: "npm:3.5.2" tailwindcss: "npm:3.3.3" @@ -4510,13 +4510,6 @@ __metadata: languageName: node linkType: hard -"shikiji-core@patch:shikiji-core@npm%3A0.9.18#~/.yarn/patches/shikiji-core-npm-0.9.18-826293a3df.patch": - version: 0.9.18 - resolution: "shikiji-core@patch:shikiji-core@npm%3A0.9.18#~/.yarn/patches/shikiji-core-npm-0.9.18-826293a3df.patch::version=0.9.18&hash=6968ed" - checksum: ace21e92feb3bfe58d126d95fd876b729184dbf57bf1e0cf3f96f7c71840754ed227649328e2301bcb47730e6875c4915e109599db5ed5d7f28557a3bd82b4c5 - languageName: node - linkType: hard - "shikiji@npm:0.9.18": version: 0.9.18 resolution: "shikiji@npm:0.9.18" @@ -4526,15 +4519,6 @@ __metadata: languageName: node linkType: hard -"shikiji@patch:shikiji@npm%3A0.9.18#~/.yarn/patches/shikiji-npm-0.9.18-945ea5efcb.patch": - version: 0.9.18 - resolution: "shikiji@patch:shikiji@npm%3A0.9.18#~/.yarn/patches/shikiji-npm-0.9.18-945ea5efcb.patch::version=0.9.18&hash=43ddf9" - dependencies: - shikiji-core: "npm:0.9.18" - checksum: b397c3bef535e66c64c73785143e4ce9e6faca083966b0ade618063e88fa27ed025531e78aaa7712ad5c776a97130a0e6603c77fadeeebde5ba078dfb7d9cfc3 - languageName: node - linkType: hard - "siginfo@npm:^2.0.0": version: 2.0.0 resolution: "siginfo@npm:2.0.0"