Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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`.
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
67 changes: 67 additions & 0 deletions scripts/expose-cljs-main-exports.mjs
Original file line number Diff line number Diff line change
@@ -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`,
);
2 changes: 1 addition & 1 deletion scripts/smoke-cljs-azure-parity.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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, '..');
Expand Down
2 changes: 1 addition & 1 deletion scripts/smoke-cljs-blink.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down