Skip to content

Commit

Permalink
Merge pull request #17 from Rennzie/16-deployed-package-works-in-all-…
Browse files Browse the repository at this point in the history
…environments

16 deployed package works in all environments
  • Loading branch information
Rennzie authored Sep 22, 2023
2 parents 178a3e9 + ad3c8cd commit aff842f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]:
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <script>`. Make sure all the javascript related dependencies are installed with `bun install`. Rust dependencies are managed by [cargo](https://doc.rust-lang.org/cargo/) and don't require and explicit install step.
Expand Down
32 changes: 30 additions & 2 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit aff842f

Please sign in to comment.