You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/js-host-api/README.md
+50Lines changed: 50 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -630,3 +630,53 @@ just test-js-host-api release
630
630
just build-all
631
631
just test-all release
632
632
```
633
+
634
+
## Publishing to npm
635
+
636
+
The package is published to npmjs.com as `@hyperlight/js-host-api` with platform-specific binary packages.
637
+
638
+
### Automated Release
639
+
640
+
Publishing happens automatically when a release is created via the `CreateRelease` workflow on a `release/vX.Y.Z` branch.
641
+
642
+
### Manual Publishing
643
+
644
+
You can also trigger the npm publish workflow manually:
645
+
646
+
1. Go to **Actions** → **Publish npm packages**
647
+
2. Click **Run workflow**
648
+
3. Enter the version (e.g., `0.2.0`)
649
+
4. Optionally enable **dry-run** to test without publishing
650
+
651
+
### Setup Requirements
652
+
653
+
The following secret must be configured in the repository:
654
+
655
+
| Secret | Description |
656
+
|--------|-------------|
657
+
|`NPM_TOKEN`| npm access token with publish permissions for the `@hyperlight` scope |
658
+
659
+
To create an npm token:
660
+
1. Log in to [npmjs.com](https://www.npmjs.com/)
661
+
2. Go to **Access Tokens** → **Generate New Token**
662
+
3. Select **Automation** token type (for CI/CD)
663
+
4. Add the token as a repository secret named `NPM_TOKEN`
664
+
665
+
### Package Structure
666
+
667
+
The npm release consists of the following packages:
668
+
669
+
| Package | Description |
670
+
|---------|-------------|
671
+
|`@hyperlight/js-host-api`| Main package (installs correct binary automatically) |
672
+
|`@hyperlight/js-host-api-linux-x64-gnu`| Linux x86_64 (glibc) native binary |
673
+
|`@hyperlight/js-host-api-linux-x64-musl`| Linux x86_64 (musl/Alpine) native binary |
674
+
|`@hyperlight/js-host-api-win32-x64-msvc`| Windows x86_64 native binary |
675
+
676
+
### How Platform Selection Works
677
+
678
+
This project uses the [napi-rs](https://napi.rs/docs/deep-dive/release#3-the-native-addon-for-different-platforms-is-distributed-through-different-npm-packages) approach for distributing native addons across platforms. Each platform-specific binary is published as a separate npm package and listed as an `optionalDependency` of the main package.
679
+
680
+
**At install time:** npm uses the `os`, `cpu`, and `libc` fields in each platform sub-package's `package.json` to determine which optional dependency to install. Packages that don't match the user's platform are silently skipped. The main package itself does **not** have `os`/`cpu` fields because it contains only JavaScript — restricting it would prevent installation on unsupported platforms even for type-checking or development purposes.
681
+
682
+
**At runtime:** The napi-rs generated `index.js` detects the platform (including glibc vs musl on Linux) and loads the correct `.node` binary.
0 commit comments