From 57e8e3b35363d1c2e844c105bd9443ac665ba85e Mon Sep 17 00:00:00 2001 From: Lucas Garron Date: Thu, 23 Jan 2025 11:36:15 -0800 Subject: [PATCH] Add a `@cubing/icons/js` entry point, transpiled via TypeScript. For a discussion of tradeoffs, see: https://github.com/cubing/icons/issues/146 --- js/index.d.ts | 1 + js/index.js | 1 + package.json | 7 ++++++- script/build-lib.ts | 11 +++++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 js/index.d.ts create mode 100644 js/index.js diff --git a/js/index.d.ts b/js/index.d.ts new file mode 100644 index 0000000..5bfe26d --- /dev/null +++ b/js/index.d.ts @@ -0,0 +1 @@ +import "../dist/lib/@cubing/icons/js/ts/index.d.ts"; diff --git a/js/index.js b/js/index.js new file mode 100644 index 0000000..377775e --- /dev/null +++ b/js/index.js @@ -0,0 +1 @@ +import "../dist/lib/@cubing/icons/js/ts/index.js"; diff --git a/package.json b/package.json index 754d7d5..e3bba0a 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "@types/bun": "^1.1.14", "@types/jsdom": "^21.1.7", "fantasticon": "^3.0.0", - "jsdom": "^25.0.1" + "jsdom": "^25.0.1", + "typescript": "^5.7.3" }, "exports": { ".": { @@ -28,6 +29,10 @@ "./css": { "default": "./dist/lib/@cubing/icons/cubing-icons.css" }, + "./js": { + "types": "./dist/lib/@cubing/icons/js/ts/index.d.ts", + "default": "./dist/lib/@cubing/icons/js/ts/index.js" + }, "./ts": { "default": "./ts/index.ts" } diff --git a/script/build-lib.ts b/script/build-lib.ts index 623e24d..468ec19 100644 --- a/script/build-lib.ts +++ b/script/build-lib.ts @@ -1,5 +1,6 @@ import { mkdir, readFile, writeFile } from "node:fs/promises"; import { join } from "node:path"; +import { $ } from "bun"; import { FontAssetType, OtherAssetType, generateFonts } from "fantasticon"; const LIB_OUTPUT_DIR = "dist/lib/@cubing/icons"; @@ -29,4 +30,14 @@ await writeFile( ), ); +// This places output files in an awkward directory structure, but it keeps our +// transpilation setup as simple as possible. The alternatives come with +// potentially heavy tradeoffs: https://github.com/cubing/icons/issues/146 +await $`bun x tsc \ + --skipLibCheck \ + --declaration \ + --target es2022 \ + --outdir ./dist/lib/@cubing/icons/js \ + ./ts/index.ts`; + console.log(`The library has been built at: ${LIB_OUTPUT_DIR}`);