Skip to content
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

rapier-inject - a new package for using rapier-compat without an inlined wasm file #193

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions rapier-inject/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

# Files below this line will be copied during build.
### RAPIER_COMPAT_FILES
tests
src2d/raw.ts
src3d/raw.ts
fix_raw_file.sh
gen_src.sh
tsconfig.common.json
tsconfig.json
tsconfig.pkg2d.json
tsconfig.pkg3d.json
7 changes: 7 additions & 0 deletions rapier-inject/copy_compat_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

start_line=$(($(cat .gitignore | grep "### RAPIER_COMPAT_FILES" -n | cut -d : -f 1) + 1))

tail -n +$start_line .gitignore | while read file
do
cp -r "../rapier-compat/$file" "./$file"
done
11,184 changes: 11,184 additions & 0 deletions rapier-inject/package-lock.json

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions rapier-inject/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "build-rapier-inject",
"description": "Build scripts for a rapier package which allows injecting a built wasm file.",
"private": true,
"scripts": {
"copy-files": "sh ./copy_compat_files.sh",
"build-rust-2d": "cd ../rapier2d && wasm-pack build --target web",
"build-rust-3d": "cd ../rapier3d && wasm-pack build --target web",
"build-rust": "npm run build-rust-2d && npm run build-rust-3d",
"build-genjs": "sh ./gen_src.sh",
"build-js": "rollup --config rollup.config.js --bundleConfigAsCjs",
"fix-raw-file": "sh ./fix_raw_file.sh",
"build": "npm run clean && npm run copy-files && npm run build-rust && npm run build-genjs && npm run build-js && npm run fix-raw-file",
"clean": "npx rimraf ../rapier2d/pkg ../rapier3d/pkg pkg2d pkg3d gen2d gen3d ../rapier2d/docs ../rapier3d/docs",
"test": "jest --detectOpenHandles",
"all": "npm run build"
},
"dependencies": {},
"devDependencies": {
"@rollup/plugin-commonjs": "^23.0.2",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-typescript": "^9.0.2",
"@rollup/plugin-terser": "0.1.0",
"@types/jest": "^29.2.1",
"jest": "^29.2.2",
"rimraf": "^3.0.2",
"rollup": "^3.2.5",
"rollup-plugin-base64": "^1.0.1",
"rollup-plugin-copy": "^3.4.0",
"rollup-plugin-filesize": "^9.1.2",
"ts-jest": "^29.0.3",
"tslib": "^2.4.1",
"typescript": "^4.8.4"
},
"jest": {
"roots": [
"<rootDir>/tests"
],
"preset": "ts-jest",
"collectCoverageFrom": [
"pkg2d/**/*.js",
"pkg3d/**/*.js"
],
"transformIgnorePatterns": [
"[/\\\\]node_modules[/\\\\].+\\.(js|ts)$",
"[/\\\\]pkg3d[/\\\\].+\\.(js|ts)$",
"[/\\\\]pkg2d[/\\\\].+\\.(js|ts)$"
],
"moduleFileExtensions": [
"ts",
"js"
]
}
}
68 changes: 68 additions & 0 deletions rapier-inject/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import commonjs from "@rollup/plugin-commonjs";
import {nodeResolve} from "@rollup/plugin-node-resolve";
import typescript from "@rollup/plugin-typescript";
import terser from "@rollup/plugin-terser";
import path from "path";
import {base64} from "rollup-plugin-base64";
import copy from "rollup-plugin-copy";
import filesize from "rollup-plugin-filesize";

const config = (dim) => ({
input: `./gen${dim}/rapier.ts`,
output: [
{
file: `pkg${dim}/rapier.es.js`,
format: "es",
sourcemap: true,
exports: "named",
},
{
file: `pkg${dim}/rapier.cjs.js`,
format: "cjs",
sourcemap: true,
exports: "named",
},
],
plugins: [
copy({
targets: [
{
src: `../rapier${dim}/pkg/package.json`,
dest: `./pkg${dim}/`,
transform(content) {
let config = JSON.parse(content.toString());
config.name = `@dimforge/rapier${dim}-inject`;
config.description +=
" Compatibility package that requires module injection.";
config.types = "rapier.d.ts";
config.main = "rapier.cjs.js";
config.module = "rapier.es.js";
// delete config.module;
config.files = ["*"];
return JSON.stringify(config, undefined, 2);
},
},
{
src: `../rapier${dim}/LICENSE`,
dest: `./pkg${dim}`,
},
{
src: `../rapier${dim}/README.md`,
dest: `./pkg${dim}`,
},
],
}),
base64({include: "**/*.wasm"}),
terser(),
nodeResolve(),
commonjs(),
typescript({
tsconfig: path.resolve(__dirname, `tsconfig.pkg${dim}.json`),
sourceMap: true,
inlineSources: true,
}),
filesize(),
],
});

export default [config("2d"), config("3d")];
9 changes: 9 additions & 0 deletions rapier-inject/src2d/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import wasmInit from "../pkg2d/rapier_wasm2d";

/**
* Initializes RAPIER.
* Has to be called and awaited before using any library methods.
*/
export async function init(module: WebAssembly.Module) {
await wasmInit(module);
}
9 changes: 9 additions & 0 deletions rapier-inject/src3d/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import wasmInit from "../pkg3d/rapier_wasm3d";

/**
* Initializes RAPIER.
* Has to be called and awaited before using any library methods.
*/
export async function init(module: WebAssembly.Module) {
await wasmInit(module);
}