Skip to content

Turn one illustration into an animated 2D mesh avatar with a coding agent and a local editor

Build packages in order before publishing

shinshin86f1cd0291b560
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index c25a0f4..16dd657 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -38,6 +38,11 @@ jobs:
- name: Build embed element
run: npm run build:element
+ # Built in dependency order here; prepack then skips rebuilding (MESH_AVATAR_PREBUILT)
+ # because changesets publishes the packages in parallel.
+ - name: Build React wrapper
+ run: npm run build:react
+
- name: Run unit tests
run: npm test
@@ -50,3 +55,4 @@ jobs:
title: 'chore: version packages'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ MESH_AVATAR_PREBUILT: '1'
diff --git a/packages/element/package.json b/packages/element/package.json
index cf3929c..03ac107 100644
--- a/packages/element/package.json
+++ b/packages/element/package.json
@@ -36,7 +36,7 @@
},
"scripts": {
"build": "vite build && vite build --mode standalone && tsc -p tsconfig.build.json",
- "prepack": "npm run build"
+ "prepack": "node ../../tools/prepack.mjs"
},
"exports": {
".": {
diff --git a/packages/react/package.json b/packages/react/package.json
index 8422b6f..f4b46f8 100644
--- a/packages/react/package.json
+++ b/packages/react/package.json
@@ -34,7 +34,7 @@
},
"scripts": {
"build": "vite build && tsc -p tsconfig.build.json",
- "prepack": "npm run build"
+ "prepack": "node ../../tools/prepack.mjs"
},
"exports": {
".": {
diff --git a/packages/runtime/package.json b/packages/runtime/package.json
index 747ba03..b21d9c8 100644
--- a/packages/runtime/package.json
+++ b/packages/runtime/package.json
@@ -31,7 +31,7 @@
},
"scripts": {
"build": "vite build && tsc -p tsconfig.build.json && node fix-declarations.mjs",
- "prepack": "npm run build"
+ "prepack": "node ../../tools/prepack.mjs"
},
"exports": {
".": {
diff --git a/tools/prepack.mjs b/tools/prepack.mjs
new file mode 100644
index 0000000..8558868
--- /dev/null
+++ b/tools/prepack.mjs
@@ -0,0 +1,13 @@
+// Runs a package's build before `npm pack` / `npm publish`, except in the release workflow:
+// changesets publishes the packages in parallel and they read each other's dist, so a rebuild
+// there empties a dependency's dist while another package compiles against it. The workflow
+// builds runtime, element and React in order first and sets MESH_AVATAR_PREBUILT=1.
+import { spawnSync } from 'node:child_process';
+
+if (process.env.MESH_AVATAR_PREBUILT === '1') {
+ console.log('prepack: using the build from the release workflow');
+} else {
+ const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
+ const result = spawnSync(npm, ['run', 'build'], { stdio: 'inherit', shell: process.platform === 'win32' });
+ process.exitCode = result.status ?? 1;
+}