Skip to content

Commit

Permalink
release
Browse files Browse the repository at this point in the history
  • Loading branch information
leokun authored and leokun committed Nov 2, 2024
1 parent 94df220 commit 175a5ca
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 116 deletions.
34 changes: 0 additions & 34 deletions .github/workflows/main.yml

This file was deleted.

7 changes: 1 addition & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ jobs:
registry-url: 'https://registry.npmjs.org'
- name: Default
run: |
npm install
npx playwright install-deps
npx playwright install
sh setup.sh
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
Expand All @@ -27,12 +24,10 @@ jobs:
cd ..
source ./emsdk/emsdk_env.sh
cd emscriptenbuild
./build.sh Release
./build.sh Release-async
cd ..
set -e
npm run test
export VERSION=`npm view wasm-git dist-tags.latest`
export VERSION=`npm view wasm-git-browser dist-tags.latest`
export NEWVERSION=`node -p "require('./package.json').version"`
echo $VERSION $NEWVERSION
./preparepublishnpm.sh
Expand Down
59 changes: 3 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,5 @@
Wasm-git
========
(Wasm should be pronounced like `awesome` starting with a `W` ).

![](https://github.com/petersalomonsen/wasm-git/actions/workflows/main.yml/badge.svg)

GIT for nodejs and the browser using [libgit2](https://libgit2.org/) compiled to WebAssembly with [Emscripten](https://emscripten.org).

The main purpose of bringing git to the browser, is to enable storage of web application data locally in the users web browser, with the option to synchronize with a remote server.

# Demo in the browser

A simple demo in the browser can be found at:

https://wasm-git.petersalomonsen.com/

**Please do not abuse, this is open for you to test and see the proof of concept**

The sources for the demo can be found in the [githttpserver](https://github.com/petersalomonsen/githttpserver) project. It shows basic operations like cloning, edit files, add and commit, push and pull.

# Demo videos

Videos showing example applications using wasm-git can bee seen in [this playlist](https://www.youtube.com/watch?v=1Hqy7cVkygU&list=PLv5wm4YuO4Iyx00ifs6xUwIRSFnBI8GZh). Wasm-git is used for local and offline storage of web application data, and for syncing with a remote server.

# Examples

Wasm-git packages are built in two variants: Synchronuous and Asynchronuous. To run the sync version in the browser, a [webworker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers) is needed. This is because of the use of synchronous http requests and long running operations that would block if running on the main thread. The sync version has the smallest binary, but need extra client code to communicate with the web worker. When using the sync version in nodejs [worker_threads](https://nodejs.org/api/worker_threads.html) are used, with [Atomics](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics) to exchange data between threads.

The async version use [Emscripten Asyncify](https://emscripten.org/docs/porting/asyncify.html), which allows calling the Wasm-git functions with `async` / `await`. It can also run from the main thread in the browser. Asyncify increase the binary size because of instrumentation to unwind and rewind WebAssembly state, but makes it possible to have simple client code without exchanging data with worker threads like in the sync version.

Examples of using Wasm-git can be found in the tests:

- [test](./test/) for NodeJS
- [test-browser](./test-browser/) for the sync version in the browser with a web worker
- [test-browser-async](./test-browser-async/)] for the async version in the browser

The examples shows importing the `lg2.js` / `lg2-async.js` modules from the local build, but you may also access these from releases available at public CDNs.

# Building and developing

The [Github actions test pipeline](./.github/workflows/main.yml) shows all the commands needed to install dependencies, build the packages and run the tests.

Another option is loading the repository into a github codespace, where the configuration in [.devcontainer](./.devcontainer) folder will be used to install dependencies and set up a full development environment.

# Emscripten fixes that were needed for making Wasm-git work

As part of being able to compile libgit2 to WebAssembly and run it in a Javascript environment, some fixes to [Emscripten](https://emscripten.org/) were needed.

Here are the Pull Requests that resolved the issues identified when the first version was developed:

- https://github.com/emscripten-core/emscripten/pull/10095
- https://github.com/emscripten-core/emscripten/pull/10526
- https://github.com/emscripten-core/emscripten/pull/10782

for using with `NODEFS` you'll also need https://github.com/emscripten-core/emscripten/pull/10669

All of these pull requests are merged to emscripten master as of 2020-03-29.

built for the browser with [wasm-git](https://github.com/petersalomonsen/wasm-git)
<br/>
[issues](https://github.com/petersalomonsen/wasm-git/issues/16)
21 changes: 3 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "wasm-git",
"name": "wasm-git-browser",
"version": "0.0.13",
"main": "lg2_async.js",
"type": "module",
"author": {
"name": "Peter Salomonsen",
Expand All @@ -10,24 +11,8 @@
"url": "https://github.com/petersalomonsen/wasm-git"
},
"files": [
"lg2.js",
"lg2.wasm",
"lg2_async.js",
"lg2_async.wasm",
"README.md"
],
"scripts": {
"test": "mocha test/**/*.spec.js",
"test-browser": "wtr test-browser/**/*.spec.js",
"test-browser-watch": "wtr test-browser/**/*.spec.js --watch",
"test-browser-async": "wtr test-browser-async/**/*.spec.js",
"patch-version": "npm --no-git-tag-version version patch"
},
"devDependencies": {
"@web/test-runner": "^0.18.2",
"@web/test-runner-playwright": "^0.11.0",
"cgi": "^0.3.1",
"chai": "^4.3.7",
"mocha": "^10.2.0"
}
]
}
2 changes: 0 additions & 2 deletions preparepublishnpm.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/bin/bash
set -e
echo "copy lg2.wasm and lg2.js from build folder"
cp emscriptenbuild/libgit2/examples/lg2.wasm .
cp emscriptenbuild/libgit2/examples/lg2.js .
cp emscriptenbuild/libgit2/examples/lg2_async.wasm .
cp emscriptenbuild/libgit2/examples/lg2_async.js .
echo "publish --dry-run (run npm publish to finalize)"
Expand Down

0 comments on commit 175a5ca

Please sign in to comment.