From 353e21478c01561fa698d5219fe4851ea178f8e5 Mon Sep 17 00:00:00 2001 From: Sean Rennie Date: Fri, 22 Sep 2023 10:58:37 +0100 Subject: [PATCH 1/2] build for esm --- Cargo.toml | 2 +- scripts/build.sh | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a76519e..c653c06 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "geodesy-wasm" -version = "0.2.0--alpha1" +version = "0.2.0-beta2" keywords = ["geospatial", "geodesy", "cartography", "geography"] categories = ["science"] authors = ["Sean Rennie "] diff --git a/scripts/build.sh b/scripts/build.sh index dd547f4..587e475 100644 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -42,6 +42,19 @@ else echo "Skipping bundler target" fi +# Build esm version into tmp_build/esm +if [ -z "${TARGET+x}" ] || [ "$TARGET" == "esm" ]; then + echo "Building esm target" + wasm-pack build \ + $BUILD \ + --out-dir tmp_build/esm \ + --out-name geodesy-wasm \ + --target web \ + $FLAGS +else + echo "Skipping esm target" +fi + # Compile JS Wrapper # Compile geodesy.ts for bundler @@ -62,17 +75,32 @@ else echo "Skipping node target TS compilation" fi +# Compile geodesy.ts for Node +if [ -z "${TARGET+x}" ] || [ "$TARGET" == "esm" ]; then + sed 's/@geodesy-wasm/\.\/geodesy-wasm.js/g' js/geodesy.ts > tmp_build/esm/index.ts + bun tsc tmp_build/esm/index.ts --outDir tmp_build/esm --declaration --declarationDir tmp_build/esm --target es2020 --module ESNEXT + rm tmp_build/esm/index.ts +else + echo "Skipping esm target TS compilation" +fi + # Copy files into pkg/ -mkdir -p pkg/{node,bundler} +mkdir -p pkg/{node,bundler,esm} cp tmp_build/bundler/geodesy-wasm* pkg/bundler/ cp tmp_build/bundler/index* pkg/bundler/ -cp tmp_build/node/geodesy-wasm* pkg/node +cp tmp_build/node/geodesy-wasm* pkg/node/ cp tmp_build/node/index* pkg/node/ +cp tmp_build/esm/geodesy-wasm* pkg/esm/ +cp tmp_build/esm/index* pkg/esm/ + cp tmp_build/bundler/{package.json,README.md} pkg/ cp {LICENSE-MIT,LICENSE-APACHE} pkg/ +# Create minimal package.json in esm/ folder with type: module +echo '{"type": "module"}' > pkg/esm/package.json + # Update files array in package.json using JQ # Set module field to bundler/geodesy-wasm.js # Set types field to bundler/geodesy-wasm.d.ts From ad3c8cda5446a29615ba11b662ee5a2f7c2e5397 Mon Sep 17 00:00:00 2001 From: Sean Rennie Date: Fri, 22 Sep 2023 10:58:46 +0100 Subject: [PATCH 2/2] update change log and read me --- CHANGELOG.md | 11 +++++++++-- README.md | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 211e5cc..75cb102 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.2.0-beta2] - 2021-10-20 + +### Added + +- ESM Build [#16](https://github.com/Rennzie/geodesy-wasm/issues/16) +- Example usage in ObservableHQ + +## [0.2.0-beta1] - 2021-10-20 + ### Added - This CHANGELOG file @@ -26,5 +35,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Update the README with usage examples and better documentation [#9](https://github.com/Rennzie/geodesy-wasm/issues/9) - Add tests for the wrapper [#10](https://github.com/Rennzie/geodesy-wasm/issues/10) - Replaced yarn with [bun](https://bun.sh/docs/cli/test) in the process - -[unreleased]: diff --git a/README.md b/README.md index bd83245..5b93135 100644 --- a/README.md +++ b/README.md @@ -168,6 +168,10 @@ console.log(resultFwd); // [[ 13004.309008754391 6837202.757094237 9.61 ], [ 13007.829360281388 6837191.955741842 9.61 ]] ``` +#### Using ESM Modules in ObservableHQ + +See [this notebook](https://observablehq.com/d/3ff9d9b8f0b5168a) for an example of using Geodesy-Wasm in ObservableHQ. + ## Development For convenience all scripts can be run with `bun