Skip to content
Merged
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
2 changes: 1 addition & 1 deletion wasm/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ package-lock.json
cockle/
lite-deploy/package.json
recipe/em-forge-recipes/
serve/*/
serve/dist/*/
test/assets/*/
test/lib/
6 changes: 2 additions & 4 deletions wasm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@ option(USE_COCKLE_RELEASE "Use latest cockle release rather than repo main branc
add_subdirectory(recipe)
add_subdirectory(cockle-deploy)
add_subdirectory(lite-deploy)
add_subdirectory(serve)
add_subdirectory(test)

# Build everything (package, cockle and lite deployments, tests).
add_custom_target(build ALL DEPENDS build-recipe build-cockle build-lite build-test)
add_custom_target(build ALL DEPENDS build-recipe build-cockle build-lite build-serve build-test)

# Rebuild after change in C++ code.
add_custom_target(rebuild DEPENDS rebuild-recipe rebuild-cockle rebuild-lite rebuild-test)

# Serve both cockle and JupyterLite deployments.
add_custom_target(serve COMMAND npx static-handler --cors --coop --coep --corp serve)

if (USE_COCKLE_RELEASE)
execute_process(COMMAND npm view @jupyterlite/cockle version OUTPUT_VARIABLE COCKLE_BRANCH)
set(COCKLE_BRANCH "v${COCKLE_BRANCH}")
Expand Down
9 changes: 9 additions & 0 deletions wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ Note that the `source` for the `git2cpp` package is the local filesystem rather
version number of the current Emscripten-forge recipe rather than the version of the local `git2cpp`
source code which can be checked using `git2cpp -v` at the `cockle`/`terminal` command line.

If you want to remotely access git servers using `git2cpp` subcommands such as `clone`, `fetch`
and `push`, then serve with a local CORS proxy using:

```bash
make serve-with-cors
```

which will use the CORS proxy on `http://localhost:8881/`.

## Rebuild

After making changes to the local `git2cpp` source code you can rebuild the WebAssembly package,
Expand Down
2 changes: 1 addition & 1 deletion wasm/cockle-deploy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project(git2cpp-wasm-cockle-deploy)

include("../common.cmake")

set(SERVE_DIR "../serve/cockle")
set(SERVE_DIR "../serve/dist/cockle")

add_custom_target(build-cockle
DEPENDS build-recipe cockle
Expand Down
8 changes: 4 additions & 4 deletions wasm/cockle-deploy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"scripts": {
"build": "rspack build",
"postbuild": "npm run postbuild:wasm && npm run postbuild:index",
"postbuild:wasm": "node node_modules/@jupyterlite/cockle/lib/tools/prepare_wasm.js --copy ../serve/cockle/",
"postbuild:index": "cp assets/index.html ../serve/cockle/"
"postbuild:wasm": "node node_modules/@jupyterlite/cockle/lib/tools/prepare_wasm.js --copy ../serve/dist/cockle/",
"postbuild:index": "cp assets/index.html ../serve/dist/cockle/"
},
"main": "../serve/cockle/index.js",
"types": "../serve/cockle/index.d.ts",
"main": "../serve/dist/cockle/index.js",
"types": "../serve/dist/cockle/index.d.ts",
"keywords": [],
"author": "",
"license": "ISC",
Expand Down
2 changes: 1 addition & 1 deletion wasm/cockle-deploy/rspack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ module.exports = {
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, '../serve/cockle'),
path: path.resolve(__dirname, '../serve/dist/cockle'),
}
};
1 change: 1 addition & 0 deletions wasm/cockle-deploy/src/defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export namespace IDeployment {
browsingContextId: string;
shellManager: IShellManager;
targetDiv: HTMLElement;
useLocalCors?: string;
}
}
11 changes: 8 additions & 3 deletions wasm/cockle-deploy/src/deployment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Shell } from '@jupyterlite/cockle'
import { IShell, Shell } from '@jupyterlite/cockle'
import { FitAddon } from '@xterm/addon-fit'
import { Terminal } from '@xterm/xterm'
import { IDeployment } from './defs'
Expand All @@ -22,13 +22,18 @@ export class Deployment {

const { baseUrl, browsingContextId, shellManager } = options;

this._shell = new Shell({
const shellOptions: IShell.IOptions = {
browsingContextId,
baseUrl,
wasmBaseUrl: baseUrl,
shellManager,
outputCallback: this.outputCallback.bind(this),
})
};
if (options.useLocalCors) {
shellOptions.environment = { GIT_CORS_PROXY: options.useLocalCors };
}

this._shell = new Shell(shellOptions);
}

async start(): Promise<void> {
Expand Down
19 changes: 17 additions & 2 deletions wasm/cockle-deploy/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
import { ShellManager } from '@jupyterlite/cockle';
import "./style/deployment.css"
import { IDeployment } from './defs';
import { Deployment } from "./deployment";

document.addEventListener("DOMContentLoaded", async () => {
const baseUrl = window.location.href;
const shellManager = new ShellManager();
const browsingContextId = await shellManager.installServiceWorker(baseUrl);

const targetDiv: HTMLElement = document.getElementById('targetdiv')!;
const playground = new Deployment({ baseUrl, browsingContextId, shellManager, targetDiv });

const options: IDeployment.IOptions = {
baseUrl, browsingContextId, shellManager, targetDiv
}

// See if a local CORS proxy is available where we are expecting it by checking if it is there.
// This isn't good practice but is OK for local manual testing.
try {
const corsProxy = "http://localhost:8881/"
const response = await fetch(corsProxy);
if (response.ok && response.type == "cors") {
options.useLocalCors = corsProxy;
}
} catch (error) {}

const playground = new Deployment(options);
await playground.start();
})
2 changes: 1 addition & 1 deletion wasm/cockle-deploy/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"noUnusedLocals": true,
"preserveWatchOutput": true,
"resolveJsonModule": true,
"outDir": "../serve/cockle",
"outDir": "../serve/dist/cockle",
"rootDir": "src",
"strict": true,
"strictNullChecks": true,
Expand Down
2 changes: 1 addition & 1 deletion wasm/lite-deploy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project(git2cpp-wasm-lite-deploy)

include("../common.cmake")

set(SERVE_DIR "../serve/lite")
set(SERVE_DIR "../serve/dist/lite")

add_custom_target(build-lite
DEPENDS build-recipe cockle
Expand Down
8 changes: 8 additions & 0 deletions wasm/serve/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.28)
project(git2cpp-wasm)

add_custom_target(build-serve COMMAND npm install)

# Serve both cockle and JupyterLite deployments.
add_custom_target(serve COMMAND npm run serve)
add_custom_target(serve-with-cors COMMAND npm run serve-with-cors)
File renamed without changes.
17 changes: 17 additions & 0 deletions wasm/serve/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "serve",
"version": "1.0.0",
"license": "BSD-3-Clause",
"private": true,
"scripts": {
"serve": "npm run serve:basic",
"serve-with-cors": "COCKLE_LOCAL_CORS=1 concurrently 'npm run serve:basic' 'npm run serve:cors'",
"serve:basic": "npx static-handler --cors --coop --coep --corp dist",
"serve:cors": "HOST=localhost PORT=8881 node node_modules/cors-anywhere/server.js "
},
"devDependencies": {
"concurrently": "^9.2.1",
"cors-anywhere": "^0.4.4",
"static-handler": "^0.5.3"
}
}