diff --git a/README.md b/README.md index 732c6cb..c49f380 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,9 @@ npm install three ## Runtime Exports -The CLJS npm bundle is exposed through `./cljs`. +The CLJS npm bundle is compiled into the package and exposed from the normal +root entrypoint. Consumers should import it like any other JavaScript library and +should not need Java, Clojure, or `shadow-cljs` during app install/build. ```ts import { @@ -46,7 +48,14 @@ import { createTTSAgency, createConversationAgency, createVocalAgency, -} from '@lovelace_lol/polyester/cljs'; +} from '@lovelace_lol/polyester'; +``` + +Backwards-compatible `./cljs` imports are still available for existing +experiments, but new LoomLarge integration should use the root entrypoint. + +```ts +import { createBlinkAgency } from '@lovelace_lol/polyester'; ``` The CLJS worker bundle is exposed through `./cljs-worker`. @@ -58,10 +67,11 @@ const worker = new Worker( ); ``` -The current root export still mirrors the inherited Latticework TypeScript -surface while the split is being validated. The long-term direction is for -Polyester to become the CLJS-first agency package and for Latticework to remain -the stable TypeScript package until the migration is complete. +The root export still mirrors the inherited Latticework TypeScript surface while +the split is being validated, and it now also re-exports the compiled CLJS agency +constructors needed by LoomLarge. The long-term direction is for Polyester to +become the CLJS-first agency package and for Latticework to remain the stable +TypeScript package until the migration is complete. ## Current CLJS Agency Coverage diff --git a/package.json b/package.json index e4185ce..6b3f784 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "access": "public" }, "scripts": { - "build": "tsup && npm run build:cljs && node scripts/copy-snippets.mjs", + "build": "tsup && npm run build:cljs && node scripts/expose-cljs-main-exports.mjs && node scripts/copy-snippets.mjs", "build:cljs": "shadow-cljs release npm worker", "dev": "tsup --watch", "dev:cljs": "shadow-cljs watch npm worker", diff --git a/scripts/expose-cljs-main-exports.mjs b/scripts/expose-cljs-main-exports.mjs new file mode 100644 index 0000000..258e44b --- /dev/null +++ b/scripts/expose-cljs-main-exports.mjs @@ -0,0 +1,67 @@ +import { appendFile, readFile } from 'node:fs/promises'; + +const exportNames = [ + 'createAnimationAgency', + 'createBlinkAgency', + 'createConversationAgency', + 'createEyeHeadTrackingAgency', + 'createGazeAgency', + 'createHairAgency', + 'createLipSyncAgency', + 'createProsodicAgency', + 'createTranscriptionAgency', + 'createTTSAgency', + 'createVocalAgency', + 'createAgencyWorkerClient', + 'createAnimationWorkerClient', + 'createBlinkWorkerClient', + 'createConversationWorkerClient', + 'createEyeHeadTrackingWorkerClient', + 'createGazeWorkerClient', + 'createHairWorkerClient', + 'createLipSyncWorkerClient', + 'createProsodicWorkerClient', + 'createTranscriptionWorkerClient', + 'createTTSWorkerClient', + 'createVocalWorkerClient', + 'installLatticework', +]; + +async function appendOnce(file, marker, text) { + const content = await readFile(file, 'utf8'); + if (!content.includes(marker)) { + await appendFile(file, text); + } +} + +const exportBlock = exportNames.map((name) => ` ${name},`).join('\n'); + +await appendOnce( + 'dist/index.js', + "from './cljs/index.js'", + `\nexport {\n${exportBlock}\n} from './cljs/index.js';\n`, +); + +await appendOnce( + 'dist/index.d.ts', + "from '../types/cljs'", + `\nexport {\n${exportBlock}\n} from '../types/cljs';\n`, +); + +await appendOnce( + 'dist/index.d.cts', + "from '../types/cljs'", + `\nexport {\n${exportBlock}\n} from '../types/cljs';\n`, +); + +const cjsBlock = exportNames.map((name) => ( + `exports.${name} = function ${name}() {\n` + + ` throw new Error('${name} is only available from the ESM package entrypoint.');\n` + + '};' +)).join('\n'); + +await appendOnce( + 'dist/index.cjs', + 'createBlinkAgency is only available from the ESM package entrypoint', + `\n${cjsBlock}\n`, +); diff --git a/scripts/smoke-cljs-azure-parity.mjs b/scripts/smoke-cljs-azure-parity.mjs index dd6e9f1..7746f2f 100644 --- a/scripts/smoke-cljs-azure-parity.mjs +++ b/scripts/smoke-cljs-azure-parity.mjs @@ -3,7 +3,7 @@ import { mkdtemp, rm } from 'node:fs/promises'; import { tmpdir } from 'node:os'; import path from 'node:path'; import { fileURLToPath, pathToFileURL } from 'node:url'; -import { createTTSAgency } from '../dist/cljs/index.js'; +import { createTTSAgency } from '../dist/index.js'; const scriptDir = path.dirname(fileURLToPath(import.meta.url)); const repoRoot = path.resolve(scriptDir, '..'); diff --git a/scripts/smoke-cljs-blink.mjs b/scripts/smoke-cljs-blink.mjs index 156070a..b5311dc 100644 --- a/scripts/smoke-cljs-blink.mjs +++ b/scripts/smoke-cljs-blink.mjs @@ -10,7 +10,7 @@ import { createTranscriptionAgency, createTTSAgency, createVocalAgency, -} from '../dist/cljs/index.js'; +} from '../dist/index.js'; const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));