Skip to content

Commit

Permalink
bump to v6.0.2. update changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
Birch-san committed Jul 8, 2021
1 parent 623177c commit 8193fd1
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
49 changes: 49 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,54 @@
See https://github.com/Birch-san/box2d-wasm/releases

# v6.0.1

Added a mechanism to the 'browser global' loader in the UMD entrypoint that enables you to specify the directory from which you serve Box2D.js, via the `data-box2d-dir` attribute on its `<script>` tag:

```html
<script data-box2d-dir="Box2D" src='Box2D/entry.js'></script>
```

This tells `entry.js` that `Box2D.js` can be found at `Box2D/Box2D.js`.

# v6.0.0

Simplified (i.e. flattened) directory structure introduced in v5.0.0, to make it easier to import the library and serve deferred assets.

Inlined SIMD feature detection, eliminating dependency on `wasm-feature-detect`. This simplifies the entrypoints (fewer files to locate and load in).

Eliminated "ES explicit" entrypoint (now that we are zero-dependency again, we no longer need to cater for differences in ES module resolution).

Simplified UMD entrypoint by writing bespoke loaders for each of CommonJS, AMD and Browser globals.

Tested AMD entrypoint and confirmed working. Can be used by serving a folder with the following assets:

```
entry.js
Box2D.js
Box2D.wasm
Box2D.simd.js
Box2D.simd.wasm
index.html
main.js
require.js
```

```html
<!-- load RequireJS library, import main.js -->
<script data-main="main" src="require.js"></script>
```

```js
// main.js
// import Box2D's umd/entry.js
requirejs(['./entry.js'], function (Box2DFactory) {
(async () => {
const box2D = await Box2DFactory();
console.log(box2D);
})();
});
```

# v5.0.3

Updated from Emscripten `2.0.17`->`2.0.26`.
Expand Down
14 changes: 10 additions & 4 deletions box2d-wasm/dist/umd/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,33 @@
define([asset], module => module);
} else if (typeof module === 'object' && module.exports) {
// NodeJS
/** @type {import('box2d-wasm')} */
module.exports = require(asset);
} else {
// Browser globals (root is window)
const scripts = root.document.getElementsByTagName('script')
const dirAttr = 'data-box2d-dir';
const hasDirAttribute = Array.from(scripts).find(script => script.hasAttribute(dirAttr));
const box2DDir = hasDirAttribute?.getAttribute(dirAttr) ?? '.';
const loadModule = (path) => new Promise((resolve, reject) => {
const loadModule = (path, moduleName) => new Promise((resolve, reject) => {
const tag = root.document.createElement("script");
tag.onload = () => {
resolve(root.Box2D);
resolve(root[moduleName]);
return false;
};
tag.onerror = ({ target: { src } }) => {
reject(new Error(`Failed to load '${src}'`));
reject(new Error(`Failed to load '${src}'. Check your browser console for network errors.`));
return false;
};
tag.src = path;
root.document.getElementsByTagName("head")[0].appendChild(tag);
});
const modulePromise = loadModule(`${box2DDir}/${asset}`);
/** @type {Promise<import('box2d-wasm')>} */
const modulePromise = loadModule(`${box2DDir}/${asset}`, 'Box2D');
/**
* @param {Parameters<import('box2d-wasm')>} args
* @return {ReturnType<import('box2d-wasm')>}
*/
root.Box2D = async (...args) => {
const Box2DFactory = await modulePromise;
// awaiting gives us a better stack trace (at the cost of an extra microtask)
Expand Down
2 changes: 1 addition & 1 deletion box2d-wasm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "box2d-wasm",
"version": "6.0.0",
"version": "6.0.1",
"description": "Box2D compiled to WebAssembly",
"module": "dist/es/entry.js",
"main": "dist/umd/entry.js",
Expand Down

0 comments on commit 8193fd1

Please sign in to comment.