From 4674258e92f109df536d6da2d777d120377d4095 Mon Sep 17 00:00:00 2001 From: noClaps <04plugs-bios@icloud.com> Date: Fri, 3 Jan 2025 22:18:09 +0000 Subject: [PATCH] Update types and exports --- .github/workflows/build-wasm.yml | 1 - highlight.test.ts | 2 +- index.ts | 69 ++++++++++++++++++++++++++++++++ main.ts | 2 - package.json | 5 ++- src/lib.rs | 8 ++-- 6 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 index.ts delete mode 100644 main.ts diff --git a/.github/workflows/build-wasm.yml b/.github/workflows/build-wasm.yml index dd5df3d..fbf567e 100644 --- a/.github/workflows/build-wasm.yml +++ b/.github/workflows/build-wasm.yml @@ -18,7 +18,6 @@ jobs: - run: | mkdir dist bun run build --target wasm32-wasip1-threads - echo "/** The type of bundled language used by the Highlight package */\nexport type BundledLanguage = string;" >> dist/index.d.ts - uses: actions/upload-artifact@v4 with: path: dist diff --git a/highlight.test.ts b/highlight.test.ts index 399ac9b..aa7b021 100644 --- a/highlight.test.ts +++ b/highlight.test.ts @@ -1,4 +1,4 @@ -import { highlight, type BundledLanguage, type Theme } from "./main.ts"; +import { highlight, type BundledLanguage, type Theme } from "./index.ts"; const theme: Theme = { fg: "#fff", diff --git a/index.ts b/index.ts new file mode 100644 index 0000000..26c6314 --- /dev/null +++ b/index.ts @@ -0,0 +1,69 @@ +export { highlight, type Theme } from "./dist/index.js"; + +/** A list of the languages supported by Highlight. */ +export const bundledLanguages = [ + // Agda + "agda", + // C + "c", + // C++ + "cpp", + "c++", + // CSS + "css", + // Go + "go", + "golang", + // Haskell + "haskell", + "hs", + // HTML + "html", + // Java + "java", + // JavaScript + "javascript", + "js", + "jsx", + // JSDoc + "jsdoc", + // JSON + "json", + // OCaml + "ocaml", + "ml", + "ocaml_interface", + "ocaml_type", + // PHP + "php", + "php_only", + // Python + "python", + "py", + // Ruby + "ruby", + "rb", + // Rust + "rust", + "rs", + // Scala + "scala", + // Shell + "shellscript", + "shell", + "bash", + "zsh", + "sh", + // TypeScript + "typescript", + "ts", + "tsx", + // Plain + "plaintext", + "plain", + "text", + "txt", +] as const; + +/** The type of bundled language used by the Highlight package */ +export type BundledLanguage = (typeof bundledLanguages)[number]; diff --git a/main.ts b/main.ts deleted file mode 100644 index 20f136b..0000000 --- a/main.ts +++ /dev/null @@ -1,2 +0,0 @@ -/** The type of bundled language used by the Highlight package */ -export type BundledLanguage = string; diff --git a/package.json b/package.json index c4ffb93..533bbd1 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,10 @@ "@napi-rs/wasm-runtime": "^0.2.6", "@types/bun": "^1.1.14" }, - "exports": "./main.ts", + "exports": "./index.ts", "files": [ - "main.ts", + "index.ts", + "dist", "LICENSE", "README.md", "package.json" diff --git a/src/lib.rs b/src/lib.rs index abdc81d..52bf2e3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -126,8 +126,6 @@ fn escape_html(input: String) -> String { .replace('>', ">") } -/// A list of the languages supported by Highlight. -#[napi(js_name = "bundledLanguages")] pub const BUNDLED_LANGUAGES: [&str; 41] = [ // Agda "agda", @@ -238,7 +236,11 @@ const htmlOutput = highlight(code, "ts", theme); ``` */ #[napi] -pub fn highlight(code: String, language: String, theme: Option) -> String { +pub fn highlight( + code: String, + #[napi(ts_arg_type = "BundledLanguage")] language: String, + theme: Option, +) -> String { if !BUNDLED_LANGUAGES.contains(&language.as_str()) { panic!("Language {} is not supported by Highlight", language); }