8000 feat: publish @minigraf/browser to npm, rename pkg/ and swift/ for naming consistency by adityamukho · Pull Request #179 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content
Merged
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
8000
26 changes: 13 additions & 13 deletions .github/workflows/mobile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,26 +89,26 @@ jobs:

- name: Generate Swift bindings
run: |
mkdir -p swift/Sources/MinigrafKit
mkdir -p minigraf-swift/Sources/MinigrafKit
cargo run -p minigraf-ffi --bin uniffi-bindgen -- generate \
--library target/aarch64-apple-ios/release/libminigraf_ffi.a \
--language swift \
--out-dir swift/Sources/MinigrafKit/
--out-dir minigraf-swift/Sources/MinigrafKit/

- name: Prepare headers for xcframework
run: |
mkdir -p swift/includes
cp swift/Sources/MinigrafKit/*.h swift/includes/ 2>/dev/null || true
cp swift/Sources/MinigrafKit/*.modulemap swift/includes/ 2>/dev/null || true
mkdir -p minigraf-swift/includes
cp minigraf-swift/Sources/MinigrafKit/*.h minigraf-swift/includes/ 2>/dev/null || true
cp minigraf-swift/Sources/MinigrafKit/*.modulemap minigraf-swift/includes/ 2>/dev/null || true

- name: Assemble xcframework
run: |
TAG="${{ inputs.tag || github.ref_name }}"
xcodebuild -create-xcframework \
-library target/aarch64-apple-ios/release/libminigraf_ffi.a \
-headers swift/includes/ \
-headers minigraf-swift/includes/ \
-library target/aarch64-apple-ios-sim/release/libminigraf_ffi.a \
-headers swift/includes/ \
-headers minigraf-swift/includes/ \
-output "MinigrafKit.xcframework"
zip -r "MinigrafKit-${TAG}.xcframework.zip" MinigrafKit.xcframework

Expand All @@ -120,7 +120,7 @@ jobs:
- uses: actions/upload-artifact@v4
with:
name: swift-sources
path: swift/Sources/MinigrafKit/
path: minigraf-swift/Sources/MinigrafKit/

# ── Upload to release + GitHub Packages ──────────────────────────────────────

Expand All @@ -146,7 +146,7 @@ jobs:
- uses: actions/download-artifact@v4
with:
name: swift-sources
path: swift/Sources/MinigrafKit/
path: minigraf-swift/Sources/MinigrafKit/

- name: Set up JDK 17
uses: actions/setup-java@v4
Expand Down Expand Up @@ -222,7 +222,7 @@ jobs:
# swift sources already downloaded by actions/download-artifact above).
TMPDIR_SWIFT=$(mktemp -d)
cp Package.swift "$TMPDIR_SWIFT/Package.swift"
cp -r swift/Sources/MinigrafKit/ "$TMPDIR_SWIFT/MinigrafKit"
cp -r minigraf-swift/Sources/MinigrafKit/ "$TMPDIR_SWIFT/MinigrafKit"

# Switch to swift-releases branch so we only push Package.swift and Swift
# sources — not the full main HEAD (which includes workflow files, requiring
Expand All @@ -239,11 +239,11 @@ jobs:

# Apply only the intended changes.
cp "$TMPDIR_SWIFT/Package.swift" Package.swift
mkdir -p swift/Sources/MinigrafKit/
cp -r "$TMPDIR_SWIFT/MinigrafKit/." swift/Sources/MinigrafKit/
mkdir -p minigraf-swift/Sources/MinigrafKit/
cp -r "$TMPDIR_SWIFT/MinigrafKit/." minigraf-swift/Sources/MinigrafKit/
rm -rf "$TMPDIR_SWIFT"

git add Package.swift swift/Sources/MinigrafKit/
git add Package.swift minigraf-swift/Sources/MinigrafKit/
git commit -m "chore(release): update Package.swift and Swift bindings for ${TAG}" \
|| echo "Nothing to commit"
# Push to the unprotected swift-releases branch instead of main.
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/wasm-browser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ jobs:
- name: Build (release)
run: wasm-pack build --target web --features browser

- name: Rename pkg/ → minigraf-wasm/
run: mv pkg minigraf-wasm

- name: Check gzipped binary size
run: |
SIZE=$(gzip -c pkg/minigraf_bg.wasm | wc -c)
SIZE=$(gzip -c minigraf-wasm/minigraf_bg.wasm | wc -c)
echo "Gzipped WASM size: ${SIZE} bytes"
if [ "$SIZE" -gt 1048576 ]; then
echo "WARNING: exceeds 1 MB gzipped budget (${SIZE} bytes)"
Expand All @@ -40,7 +43,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: wasm-pkg
path: pkg/
path: minigraf-wasm/

test:
needs: build
Expand Down
53 changes: 51 additions & 2 deletions .github/workflows/wasm-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ jobs:
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Build browser WASM
run: wasm-pack build --target web --features browser
- name: Package pkg/ directory
- name: Rename pkg/ → minigraf-wasm/
run: mv pkg minigraf-wasm
- name: Package minigraf-wasm/ directory
run: |
mkdir -p target/wasm-artifacts
tar -czf target/wasm-artifacts/minigraf-browser-wasm.tar.gz -C . pkg/
tar -czf target/wasm-artifacts/minigraf-browser-wasm.tar.gz -C . minigraf-wasm/
- uses: actions/upload-artifact@v6
with:
name: artifacts-wasm-browser
Expand Down Expand Up @@ -86,3 +88,50 @@ jobs:
gh release upload "$TAG" wasm-artifacts/* \
--repo "$GITHUB_REPOSITORY" \
--clobber

publish-npm:
name: Publish @minigraf/browser to npm
needs: [build-wasm-browser]
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v6
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Build browser WASM
run: wasm-pack build --target web --features browser
- name: Rename pkg/ → minigraf-wasm/
run: mv pkg minigraf-wasm
- name: Stamp package name and version
env:
TAG: ${{ inputs.tag || github.ref_name }}
run: |
VERSION="${TAG#v}"
# Only publish stable releases; pre-release tags (e.g. v1.0.0-rc.1) are rejected here intentionally.
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "ERROR: VERSION '$VERSION' does not look like a semver string. Aborting."
exit 1
fi
export VERSION
node -e "
const fs = require('fs');
const p = 'minigraf-wasm/package.json';
const pkg = JSON.parse(fs.readFileSync(p, 'utf8'));
pkg.name = '@minigraf/browser';
pkg.version = process.env.VERSION;
fs.writeFileSync(p, JSON.stringify(pkg, null, 2) + '\n');
"
- name: Publish to npm
working-directory: minigraf-wasm
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish --access public
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `BrowserDb` public API: `open_in_memory()`, `execute()`, `checkpoint()`, `export_graph()`, `import_graph()`
- `BrowserBufferBackend` — in-memory `StorageBackend` over a flat page buffer, identical byte layout to the native `.graph` format
- `IndexedDbBackend` — page-granular IndexedDB storage (one 4 KB entry per page); only dirty pages written on checkpoint
- `wasm-pack` build workflow (`wasm32-unknown-unknown --features browser`) generating `pkg/` with JS glue and TypeScript definitions
- `wasm-pack` build workflow (`wasm32-unknown-unknown --features browser`) generating `minigraf-wasm/` with JS glue and TypeScript definitions
- `wasm-bindgen-test` browser integration tests (Chrome + Firefox via `wasm-pack test`)
- **Phase 8.1b** — Server-side WASM (`wasm32-wasip1` / WASI):
- `FileBackend` verified under WASI's capability-based filesystem (no backend changes needed)
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let package = Package(
.target(
name: "MinigrafKit",
dependencies: [.target(name: "minigrafFFI")],
path: "swift/Sources/MinigrafKit"
path: "minigraf-swift/Sources/MinigrafKit"
),
]
)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ See the [Mobile Integration](https://github.com/project-minigraf/minigraf/wiki/U

### For WASM / Browser

Phase 8.1a complete: IndexedDB backend, `wasm-pack` packaging. Phase 8.1b complete: server-side WASM via `wasm32-wasip1` / WASI (Wasmtime, Wasmer). npm release as `@minigraf/core` planned for Phase 8.2.
Phase 8.1a complete: IndexedDB backend, `wasm-pack` packaging. Phase 8.1b complete: server-side WASM via `wasm32-wasip1` / WASI (Wasmtime, Wasmer). npm release as `@minigraf/browser` planned for Phase 8.2.

See the [Use Cases](https://github.com/project-minigraf/minigraf/wiki/Use-Cases) wiki page for detailed guides on all three targets.

Expand Down
4 changes: 2 additions & 2 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ There are two separate compilation targets with different requirements:
**Features**:
- ✅ `IndexedDbBackend`: page-granular IndexedDB storage using `web-sys` + `wasm-bindgen`
- ✅ `BrowserDb` public API annotated with `#[wasm_bindgen]` (execute, checkpoint, export_graph, import_graph)
- ✅ Built with `wasm-pack` — generates `pkg/` with JS glue and TypeScript `.d.ts`
- ✅ Built with `wasm-pack` — generates `minigraf-wasm/` with JS glue and TypeScript `.d.ts`
- ✅ TypeScript definitions auto-generated by `wasm-pack`
- ✅ npm publish deferred to Phase 8.3 (bindings complete; package story not yet finalized)
- ✅ Export/import API for portable `.graph` blob (same binary format as native)
Expand Down Expand Up @@ -1173,7 +1173,7 @@ This is a deliberate operation (a button or API call), not transparent — which
# Install wasm-pack
cargo install wasm-pack

# Build for browser (generates pkg/ with .js, .d.ts, .wasm)
# Build for browser (generates minigraf-wasm/ with .js, .d.ts, .wasm)
wasm-pack build --target web

# Publish to npm
Expand Down
2 changes: 1 addition & 1 deletion TEST_COVERAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
- ✅ `BrowserDb` public API: `open_in_memory`, `execute`, `checkpoint`, `export_graph`, `import_graph`
- ✅ `BrowserBufferBackend` — in-memory `StorageBackend` over a flat page buffer, byte-identical to native `.graph` format
- ✅ `IndexedDbBackend` — page-granular IndexedDB storage via `web-sys` + `wasm-bindgen`
- ✅ `wasm-pack` build generating `pkg/` with JS glue and TypeScript `.d.ts`
- ✅ `wasm-pack` build generating `minigraf-wasm/` with JS glue and TypeScript `.d.ts`
- ✅ `wasm-bindgen-test` suite: 6 browser integration tests (Chrome + Firefox in CI)

**Phase 8.1b Features** (WASI, complete):
Expand Down
Loading
Loading
0