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

Remove WebWorker code that is now in cockle #21

Merged
merged 8 commits into from
Sep 12, 2024
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
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
"url": "https://github.com/jupyterlite/terminal.git"
},
"scripts": {
"build": "jlpm build:lib && jlpm build:worker && jlpm build:labextension:dev",
"build:prod": "jlpm clean && jlpm build:lib:prod && jlpm build:worker && jlpm build:labextension",
"build": "jlpm build:lib && jlpm build:labextension:dev && jlpm build:copywasm",
"build:prod": "jlpm clean && jlpm build:lib:prod && jlpm build:labextension && jlpm build:copywasm",
"build:labextension": "jupyter labextension build .",
"build:labextension:dev": "jupyter labextension build --development True .",
"build:lib": "tsc --sourceMap",
"build:lib:prod": "tsc",
"build:worker": "webpack --config worker.webpack.config.js --mode=development",
"build:copywasm": "cp -r node_modules/@jupyterlite/cockle/lib/wasm jupyterlite_terminal/labextension/static/",
"clean": "jlpm clean:lib",
"clean:lib": "rimraf lib tsconfig.tsbuildinfo",
"clean:lintcache": "rimraf .eslintcache .stylelintcache",
Expand All @@ -58,20 +58,19 @@
"watch:labextension": "jupyter labextension watch ."
},
"dependencies": {
"@jupyterlab/coreutils": "^6.2.2",
"@jupyterlab/services": "^7.2.0",
"@jupyterlab/terminal": "^4.2.0",
"@jupyterlab/terminal-extension": "^4.2.0",
"@jupyterlite/cockle": "^0.0.5",
"@jupyterlab/coreutils": "^6.2.4",
"@jupyterlab/services": "^7.2.4",
"@jupyterlab/terminal": "^4.2.4",
"@jupyterlab/terminal-extension": "^4.2.4",
"@jupyterlite/cockle": "^0.0.8",
"@jupyterlite/contents": "^0.4.0",
"@jupyterlite/server": "^0.4.0",
"@lumino/coreutils": "^2.1.2",
"comlink": "^4.4.1",
"@lumino/coreutils": "^2.2.0",
"mock-socket": "^9.3.1"
},
"devDependencies": {
"@jupyterlab/builder": "^4.0.0",
"@jupyterlab/testutils": "^4.0.0",
"@jupyterlab/builder": "^4.2.4",
"@jupyterlab/testutils": "^4.2.4",
"@types/jest": "^29.2.0",
"@types/json-schema": "^7.0.11",
"@types/react": "^18.0.26",
Expand Down Expand Up @@ -108,7 +107,8 @@
},
"jupyterlab": {
"extension": true,
"outputDir": "jupyterlite_terminal/labextension"
"outputDir": "jupyterlite_terminal/labextension",
"webpackConfig": "./webpack.extra.config.js"
},
"jupyterlite": {
"liteExtension": true
Expand Down
31 changes: 12 additions & 19 deletions src/terminal.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import { Shell } from '@jupyterlite/cockle';
import { JSONPrimitive } from '@lumino/coreutils';

import { proxy, wrap } from 'comlink';

import {
Server as WebSocketServer,
Client as WebSocketClient
} from 'mock-socket';

import { ITerminal, IRemoteWorkerTerminal } from './tokens';
import { ITerminal } from './tokens';

export class Terminal implements ITerminal {
/**
* Construct a new Terminal.
*/
constructor(readonly options: ITerminal.IOptions) {
this._initWorker();
}

private async _initWorker(): Promise<void> {
this._worker = new Worker(new URL('./worker.js', import.meta.url), {
type: 'module'
this._shell = new Shell({
mountpoint: '/drive',
driveFsBaseUrl: options.baseUrl,
wasmBaseUrl:
options.baseUrl + 'extensions/@jupyterlite/terminal/static/wasm/',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This path is currently hardcoded and works OK for default installations. I am not sure if the extension path is configurable and if so, we'll need to obtain this dynamically at runtime.

outputCallback: this._outputCallback.bind(this)
});

this._remote = wrap(this._worker);
const { baseUrl } = this.options;
await this._remote.initialize({ baseUrl });
this._remote.registerCallbacks(proxy(this._outputCallback.bind(this)));
}

private async _outputCallback(text: string): Promise<void> {
Expand Down Expand Up @@ -61,11 +55,11 @@ export class Terminal implements ITerminal {
const content = data.slice(1);

if (message_type === 'stdin') {
await this._remote!.input(content[0] as string);
await this._shell.input(content[0] as string);
} else if (message_type === 'set_size') {
const rows = content[0] as number;
const columns = content[1] as number;
await this._remote!.setSize(rows, columns);
await this._shell.setSize(rows, columns);
}
});

Expand All @@ -82,11 +76,10 @@ export class Terminal implements ITerminal {
console.log('==> Returning handshake via socket', res);
socket.send(res);

await this._remote!.start();
await this._shell.start();
});
}

private _worker?: Worker;
private _remote?: IRemoteWorkerTerminal;
private _socket?: WebSocketClient;
private _shell: Shell;
}
37 changes: 0 additions & 37 deletions src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@

import { TerminalAPI } from '@jupyterlab/services';

import { IOutputCallback } from '@jupyterlite/cockle';

import { Token } from '@lumino/coreutils';

import { ProxyMarked, Remote } from 'comlink';

/**
* The token for the Terminals service.
*/
Expand Down Expand Up @@ -57,36 +53,3 @@ export namespace ITerminal {
baseUrl: string;
}
}

export interface IWorkerTerminal {
input(text: string): Promise<void>;
setSize(rows: number, columns: number): Promise<void>;
start(): Promise<void>;
}

export namespace IWorkerTerminal {
/**
* Initialization options for a worker.
*/
export interface IOptions {
baseUrl: string;
}
}

export namespace IRemote {
export type OutputCallback = IOutputCallback & ProxyMarked;
}

export interface IRemote extends IWorkerTerminal {
/**
* Handle any lazy initialization activities.
*/
initialize(options: IWorkerTerminal.IOptions): Promise<void>;

registerCallbacks(outputCallback: IRemote.OutputCallback): void;
}

/**
* An convenience interface for Pyodide workers wrapped by a comlink Remote.
*/
export type IRemoteWorkerTerminal = Remote<IRemote>;
71 changes: 0 additions & 71 deletions src/worker.ts

This file was deleted.

15 changes: 15 additions & 0 deletions webpack.extra.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const path = require('path');
const webpack = require('webpack');

module.exports = {
plugins: [
new webpack.NormalModuleReplacementPlugin(
// Use pre-bundled shell_worker.
/\/cockle\/lib\/shell_worker.js$/,
path.resolve(
__dirname,
'node_modules/@jupyterlite/cockle/lib/worker_bundle/shell_worker.js'
)
)
]
};
33 changes: 0 additions & 33 deletions worker.webpack.config.js

This file was deleted.

Loading
Loading