-
Notifications
You must be signed in to change notification settings - Fork 9
NPM #149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jrcain-usgs
wants to merge
3
commits into
DOI-USGS:main
Choose a base branch
from
jrcain-usgs:npm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
NPM #149
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| .DS_Store | ||
| build/ | ||
| build-wasm/ | ||
| dist/ | ||
| node_modules/ | ||
| cmake_test_discovery_*.json | ||
| test_pyspiceql* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| `<script type="module">` and use `fetch()` to get kernel bytes for `mountKernel`. | ||
| The five files (`spiceql.js`, `naifspice.js`, `spiceql_wasm.js`, | ||
| `spiceql_wasm.wasm`, `spiceql_wasm.data`) and your kernels just need to be | ||
| served over HTTP from the same folder (any static host works; opening the page from `file://` does not, | ||
| because the browser blocks `fetch()` of local files): | ||
| because the browser blocks `fetch()`): | ||
|
|
||
| ```html | ||
| <!doctype html> | ||
| <!-- index.html — served next to spiceql.js and the spiceql_wasm.* files --> | ||
| <script type="module"> | ||
| import { loadSpiceQL } from './spiceql.js'; | ||
| import { loadSpiceQL } from 'https://cdn.jsdelivr.net/npm/@usgs-astrogeology/spiceql/dist/spiceql.js'; | ||
|
|
||
| const spiceql = await loadSpiceQL(); | ||
|
|
||
| // No kernel search in WASM — fetch your own kernel and write it into the | ||
| // No kernel search in WASM — fetch the kernel and write it into the | ||
| // virtual filesystem before calling. | ||
| const bytes = new Uint8Array(await (await fetch('naif0012.tls')).arrayBuffer()); | ||
| const bytes = new Uint8Array(await (await fetch('https://cdn.jsdelivr.net/gh/DOI-USGS/SpiceQL/SpiceQL/db/kernels/naif0012.tls')).arrayBuffer()); | ||
| spiceql.mountKernel('/kernels/naif0012.tls', bytes); | ||
|
|
||
| const { result } = spiceql.utcToEt('2000-01-01T00:00:00', { | ||
| const { result, kernels } = spiceql.utcToEt('2000-01-01T00:00:00', { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might not be the best example in hindsight, UTC2et doesn't need an LSK in SpiceQL. But we can leave as is and make an issue about changing this example. |
||
| searchKernels: false, | ||
| kernelList: ['/kernels/naif0012.tls'], | ||
| }); | ||
| document.body.textContent = `ET = ${result}`; // ET seconds past J2000 | ||
|
|
||
| console.log(result); // ET seconds past J2000 | ||
| console.log(kernels); // { lsk: ['/kernels/naif0012.tls'] } | ||
| </script> | ||
| ``` | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible for this to be ran manually? Therefore, it could overwrite the existing build? Maybe we only want it to run on release?