diff --git a/.github/workflows/release_wasm.yml b/.github/workflows/release_wasm.yml index 44a550f..8167dba 100644 --- a/.github/workflows/release_wasm.yml +++ b/.github/workflows/release_wasm.yml @@ -15,6 +15,7 @@ on: permissions: contents: write # required to upload release assets + id-token: write # Required for OIDC trusted publishing jobs: build-and-upload: @@ -103,3 +104,15 @@ jobs: run: | gh release upload "${{ steps.package.outputs.tag }}" \ "${{ steps.package.outputs.asset }}" --clobber + + - uses: actions/setup-node@v6 + with: + node-version: '24' + registry-url: 'https://registry.npmjs.org' + package-manager-cache: false + + - name: Publish to NPM + run: | + npm install -g npm@latest # ensure OIDC-capable npm (>= 11.5.1) + npm install + npm publish diff --git a/.gitignore b/.gitignore index b6f73c8..6a86cee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .DS_Store build/ build-wasm/ +dist/ node_modules/ cmake_test_discovery_*.json test_pyspiceql* \ No newline at end of file diff --git a/README.md b/README.md index f94f2fa..c6a716e 100644 --- a/README.md +++ b/README.md @@ -75,9 +75,32 @@ The SpiceQL API is available via Python bindings in the module `pyspiceql`. The ## WebAssembly / JavaScript -SpiceQL can be compiled to WebAssembly with [Emscripten](https://emscripten.org/), exposing the `api.h` surface to JavaScript so it runs in the browser or Node. This is a separate build from the native library and its Python bindings. +### Setup/Installation Options + +#### [GitHub Releases (Manual Download) ↗](https://github.com/DOI-USGS/SpiceQL/releases) + +#### NPM Installation + +```sh +# In your terminal in your project directory: +npm install @usgs-astrogeology/spiceql +``` + +```js +// In your javascript: +import { loadSpiceQL } from '@usgs-astrogeology/spiceql' +``` + +*A Module Bundler, like Vite, is required for this kind of import.* + + +#### Import from CDN (jsDelivr) + +```js +// In your javascript: +import { loadSpiceQL } from 'https://cdn.jsdelivr.net/npm/@usgs-astrogeology/spiceql/dist/spiceql.js'; +``` -> **NOTE**: There is no CDN/npm package yet. You must either build the module locally or download the prebuilt artifact from the [GitHub Releases](https://github.com/DOI-USGS/SpiceQL/releases) page. ### Building locally @@ -100,8 +123,9 @@ emcmake cmake -S . -B build-wasm \ cmake --build build-wasm -j"$(getconf _NPROCESSORS_ONLN)" ``` +*If you get a permission denied error, use a lower number of cores in the last command: `-j4` or `-j1` instead of `-j"$(getconf _NPROCESSORS_ONLN)"`* -The CMake options are: +#### CMake Options: | Option | Value | Why | | --- | --- | --- | @@ -126,6 +150,7 @@ Copy the three `spiceql_wasm.*` artifacts and both wrappers (`bindings/wasm/spic ```js // example.mjs — run with: node example.mjs + import { loadSpiceQL } from './spiceql.js'; const spiceql = await loadSpiceQL(); @@ -144,31 +169,32 @@ console.log(result); // ET seconds past J2000 console.log(kernels); // { lsk: ['/kernels/naif0012.tls'] } ``` -In a browser it works the same way — `import` `spiceql.js` locally from a +In a browser it works the same way — `import` `spiceql.js` in a ` ``` diff --git a/package.json b/package.json index 8e59124..00d8e7a 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,22 @@ { - "name": "spiceql-wasm", + "name": "@usgs-astrogeology/spiceql", "version": "1.7.0", "description": "WebAssembly/JS bindings for SpiceQL (Emscripten). See bindings/wasm.", "type": "module", - "private": true, "exports": { - ".": "./bindings/wasm/spiceql.js" + ".": "./dist/spiceql.js" }, "files": [ - "bindings/wasm/spiceql.js" + "dist/spiceql.js", + "dist/naifspice.js", + "dist/spiceql_wasm.data", + "dist/spiceql_wasm.js", + "dist/spiceql_wasm.wasm", + "README.md", + "LICENSE.md" ], "scripts": { + "prepack": "rm -rf dist && mkdir -p dist && cp bindings/wasm/spiceql.js bindings/wasm/naifspice.js build-wasm/bindings/wasm/spiceql_wasm.js build-wasm/bindings/wasm/spiceql_wasm.data build-wasm/bindings/wasm/spiceql_wasm.wasm dist/", "test": "node --test \"bindings/wasm/tests/*.test.mjs\"" }, "engines": { @@ -20,5 +26,30 @@ "repository": { "type": "git", "url": "https://github.com/DOI-USGS/SpiceQL.git" + }, + "homepage": "https://github.com/DOI-USGS/SpiceQL#readme", + "bugs": { + "url": "https://github.com/DOI-USGS/SpiceQL/issues" + }, + "keywords": [ + "spice-query-language", + "spiceql", + "planetary", + "webassembly", + "wasm", + "astrogeology", + "kernels", + "remote-sensing", + "mars", + "moon", + "planetary-science", + "spice-kernels", + "spice", + "naif", + "naif-spice" + ], + "author": "USGS Astrogeology Science Center", + "publishConfig": { + "access": "public" } }