@jupyterlite/terminal 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/shell.d.ts +16 -0
- package/lib/shell.js +23 -0
- package/lib/terminal.js +6 -6
- package/lib/worker.d.ts +1 -0
- package/lib/worker.js +35 -0
- package/package.json +8 -6
- package/src/shell.ts +25 -0
- package/src/terminal.ts +8 -7
- package/src/worker.ts +53 -0
package/lib/shell.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseShell, IShell } from '@jupyterlite/cockle';
|
|
2
|
+
/**
|
|
3
|
+
* Shell class that uses web worker that plugs into a DriveFS via the service worker.
|
|
4
|
+
*/
|
|
5
|
+
export declare class Shell extends BaseShell {
|
|
6
|
+
/**
|
|
7
|
+
* Instantiate a new Shell
|
|
8
|
+
*
|
|
9
|
+
* @param options The instantiation options for a new shell
|
|
10
|
+
*/
|
|
11
|
+
constructor(options: IShell.IOptions);
|
|
12
|
+
/**
|
|
13
|
+
* Load the web worker.
|
|
14
|
+
*/
|
|
15
|
+
protected initWorker(options: IShell.IOptions): Worker;
|
|
16
|
+
}
|
package/lib/shell.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BaseShell } from '@jupyterlite/cockle';
|
|
2
|
+
/**
|
|
3
|
+
* Shell class that uses web worker that plugs into a DriveFS via the service worker.
|
|
4
|
+
*/
|
|
5
|
+
export class Shell extends BaseShell {
|
|
6
|
+
/**
|
|
7
|
+
* Instantiate a new Shell
|
|
8
|
+
*
|
|
9
|
+
* @param options The instantiation options for a new shell
|
|
10
|
+
*/
|
|
11
|
+
constructor(options) {
|
|
12
|
+
super(options);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Load the web worker.
|
|
16
|
+
*/
|
|
17
|
+
initWorker(options) {
|
|
18
|
+
console.log('Terminal create webworker');
|
|
19
|
+
return new Worker(new URL('./worker.js', import.meta.url), {
|
|
20
|
+
type: 'module'
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
package/lib/terminal.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Copyright (c) Jupyter Development Team.
|
|
2
2
|
// Distributed under the terms of the Modified BSD License.
|
|
3
|
-
import { Shell } from '@jupyterlite/cockle';
|
|
4
3
|
import { Signal } from '@lumino/signaling';
|
|
5
4
|
import { Server as WebSocketServer } from 'mock-socket';
|
|
5
|
+
import { Shell } from './shell';
|
|
6
6
|
export class Terminal {
|
|
7
7
|
/**
|
|
8
8
|
* Construct a new Terminal.
|
|
@@ -58,10 +58,10 @@ export class Terminal {
|
|
|
58
58
|
return this.options.name;
|
|
59
59
|
}
|
|
60
60
|
async wsConnect(url) {
|
|
61
|
-
console.log('
|
|
61
|
+
console.log('Terminal wsConnect', url);
|
|
62
62
|
this._server = new WebSocketServer(url);
|
|
63
63
|
this._server.on('connection', async (socket) => {
|
|
64
|
-
console.log('
|
|
64
|
+
console.log('Terminal server connection');
|
|
65
65
|
if (this._socket !== undefined) {
|
|
66
66
|
this._socket.send(JSON.stringify(['disconnect']));
|
|
67
67
|
this._socket.close();
|
|
@@ -83,14 +83,14 @@ export class Terminal {
|
|
|
83
83
|
}
|
|
84
84
|
});
|
|
85
85
|
socket.on('close', () => {
|
|
86
|
-
console.log('
|
|
86
|
+
console.log('Terminal socket close');
|
|
87
87
|
});
|
|
88
88
|
socket.on('error', () => {
|
|
89
|
-
console.log('
|
|
89
|
+
console.log('Terminal socket error');
|
|
90
90
|
});
|
|
91
91
|
// Return handshake.
|
|
92
92
|
const res = JSON.stringify(['setup']);
|
|
93
|
-
console.log('
|
|
93
|
+
console.log('Terminal returning handshake via socket');
|
|
94
94
|
socket.send(res);
|
|
95
95
|
if (!this._running) {
|
|
96
96
|
this._running = true;
|
package/lib/worker.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/worker.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { expose } from 'comlink';
|
|
2
|
+
import { BaseShellWorker } from '@jupyterlite/cockle';
|
|
3
|
+
import { DriveFS, ServiceWorkerContentsAPI } from '@jupyterlite/contents';
|
|
4
|
+
/**
|
|
5
|
+
* Custom DriveFS implementation using the service worker.
|
|
6
|
+
*/
|
|
7
|
+
class MyDriveFS extends DriveFS {
|
|
8
|
+
createAPI(options) {
|
|
9
|
+
return new ServiceWorkerContentsAPI(options.baseUrl, options.driveName, options.mountpoint, options.FS, options.ERRNO_CODES);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Shell web worker that uses DriveFS via service worker.
|
|
14
|
+
* Note that this is not exported as it is accessed from Shell via the filename.
|
|
15
|
+
*/
|
|
16
|
+
class ShellWorker extends BaseShellWorker {
|
|
17
|
+
/**
|
|
18
|
+
* Initialize the DriveFS to mount an external file system.
|
|
19
|
+
*/
|
|
20
|
+
initDriveFS(driveFsBaseUrl, mountpoint, fileSystem) {
|
|
21
|
+
console.log('Terminal initDriveFS', driveFsBaseUrl, mountpoint);
|
|
22
|
+
const { FS, ERRNO_CODES, PATH } = fileSystem;
|
|
23
|
+
const driveFS = new MyDriveFS({
|
|
24
|
+
FS,
|
|
25
|
+
PATH,
|
|
26
|
+
ERRNO_CODES,
|
|
27
|
+
baseUrl: driveFsBaseUrl,
|
|
28
|
+
driveName: '',
|
|
29
|
+
mountpoint
|
|
30
|
+
});
|
|
31
|
+
FS.mount(driveFS, {}, mountpoint);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const worker = new ShellWorker();
|
|
35
|
+
expose(worker);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyterlite/terminal",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "A terminal for JupyterLite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jupyter",
|
|
@@ -30,12 +30,14 @@
|
|
|
30
30
|
"url": "https://github.com/jupyterlite/terminal.git"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
|
-
"build": "jlpm build:lib && jlpm build:labextension:dev",
|
|
34
|
-
"build:prod": "jlpm clean && jlpm build:lib:prod && jlpm build:labextension",
|
|
33
|
+
"build": "jlpm build:lib && jlpm build:labextension:dev && jlpm build:webworker",
|
|
34
|
+
"build:prod": "jlpm clean && jlpm build:lib:prod && jlpm build:labextension && jlpm build:webworker:prod",
|
|
35
35
|
"build:labextension": "jupyter labextension build .",
|
|
36
36
|
"build:labextension:dev": "jupyter labextension build --development True .",
|
|
37
37
|
"build:lib": "tsc --sourceMap",
|
|
38
38
|
"build:lib:prod": "tsc",
|
|
39
|
+
"build:webworker": "webpack -c webpack.worker.config.js --env=dev",
|
|
40
|
+
"build:webworker:prod": "webpack -c webpack.worker.config.js",
|
|
39
41
|
"clean": "jlpm clean:lib",
|
|
40
42
|
"clean:lib": "rimraf lib tsconfig.tsbuildinfo",
|
|
41
43
|
"clean:lintcache": "rimraf .eslintcache .stylelintcache",
|
|
@@ -61,7 +63,7 @@
|
|
|
61
63
|
"@jupyterlab/services": "^7.3.5",
|
|
62
64
|
"@jupyterlab/terminal": "^4.3.5",
|
|
63
65
|
"@jupyterlab/terminal-extension": "^4.3.5",
|
|
64
|
-
"@jupyterlite/cockle": "^0.0.
|
|
66
|
+
"@jupyterlite/cockle": "^0.0.16",
|
|
65
67
|
"@jupyterlite/contents": "^0.5.1",
|
|
66
68
|
"@jupyterlite/server": "^0.5.1",
|
|
67
69
|
"@lumino/coreutils": "^2.2.0",
|
|
@@ -91,6 +93,7 @@
|
|
|
91
93
|
"stylelint-config-standard": "^34.0.0",
|
|
92
94
|
"stylelint-csstree-validator": "^3.0.0",
|
|
93
95
|
"stylelint-prettier": "^4.0.0",
|
|
96
|
+
"ts-loader": "^9.5.2",
|
|
94
97
|
"typescript": "~5.0.2",
|
|
95
98
|
"webpack": "^5.87.0",
|
|
96
99
|
"webpack-cli": "^5.1.4",
|
|
@@ -106,8 +109,7 @@
|
|
|
106
109
|
},
|
|
107
110
|
"jupyterlab": {
|
|
108
111
|
"extension": true,
|
|
109
|
-
"outputDir": "jupyterlite_terminal/labextension"
|
|
110
|
-
"webpackConfig": "./webpack.extra.config.js"
|
|
112
|
+
"outputDir": "jupyterlite_terminal/labextension"
|
|
111
113
|
},
|
|
112
114
|
"jupyterlite": {
|
|
113
115
|
"liteExtension": true
|
package/src/shell.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BaseShell, IShell } from '@jupyterlite/cockle';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Shell class that uses web worker that plugs into a DriveFS via the service worker.
|
|
5
|
+
*/
|
|
6
|
+
export class Shell extends BaseShell {
|
|
7
|
+
/**
|
|
8
|
+
* Instantiate a new Shell
|
|
9
|
+
*
|
|
10
|
+
* @param options The instantiation options for a new shell
|
|
11
|
+
*/
|
|
12
|
+
constructor(options: IShell.IOptions) {
|
|
13
|
+
super(options);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Load the web worker.
|
|
18
|
+
*/
|
|
19
|
+
protected override initWorker(options: IShell.IOptions): Worker {
|
|
20
|
+
console.log('Terminal create webworker');
|
|
21
|
+
return new Worker(new URL('./worker.js', import.meta.url), {
|
|
22
|
+
type: 'module'
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
package/src/terminal.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Jupyter Development Team.
|
|
2
2
|
// Distributed under the terms of the Modified BSD License.
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { IShell } from '@jupyterlite/cockle';
|
|
5
5
|
import { JSONPrimitive } from '@lumino/coreutils';
|
|
6
6
|
import { ISignal, Signal } from '@lumino/signaling';
|
|
7
7
|
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
Client as WebSocketClient
|
|
11
11
|
} from 'mock-socket';
|
|
12
12
|
|
|
13
|
+
import { Shell } from './shell';
|
|
13
14
|
import { ITerminal } from './tokens';
|
|
14
15
|
|
|
15
16
|
export class Terminal implements ITerminal {
|
|
@@ -74,11 +75,11 @@ export class Terminal implements ITerminal {
|
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
async wsConnect(url: string) {
|
|
77
|
-
console.log('
|
|
78
|
+
console.log('Terminal wsConnect', url);
|
|
78
79
|
this._server = new WebSocketServer(url);
|
|
79
80
|
|
|
80
81
|
this._server.on('connection', async (socket: WebSocketClient) => {
|
|
81
|
-
console.log('
|
|
82
|
+
console.log('Terminal server connection');
|
|
82
83
|
if (this._socket !== undefined) {
|
|
83
84
|
this._socket.send(JSON.stringify(['disconnect']));
|
|
84
85
|
this._socket.close();
|
|
@@ -102,16 +103,16 @@ export class Terminal implements ITerminal {
|
|
|
102
103
|
});
|
|
103
104
|
|
|
104
105
|
socket.on('close', () => {
|
|
105
|
-
console.log('
|
|
106
|
+
console.log('Terminal socket close');
|
|
106
107
|
});
|
|
107
108
|
|
|
108
109
|
socket.on('error', () => {
|
|
109
|
-
console.log('
|
|
110
|
+
console.log('Terminal socket error');
|
|
110
111
|
});
|
|
111
112
|
|
|
112
113
|
// Return handshake.
|
|
113
114
|
const res = JSON.stringify(['setup']);
|
|
114
|
-
console.log('
|
|
115
|
+
console.log('Terminal returning handshake via socket');
|
|
115
116
|
socket.send(res);
|
|
116
117
|
|
|
117
118
|
if (!this._running) {
|
|
@@ -125,6 +126,6 @@ export class Terminal implements ITerminal {
|
|
|
125
126
|
private _isDisposed = false;
|
|
126
127
|
private _server?: WebSocketServer;
|
|
127
128
|
private _socket?: WebSocketClient;
|
|
128
|
-
private _shell:
|
|
129
|
+
private _shell: IShell;
|
|
129
130
|
private _running = false;
|
|
130
131
|
}
|
package/src/worker.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { expose } from 'comlink';
|
|
2
|
+
|
|
3
|
+
import { BaseShellWorker, IFileSystem } from '@jupyterlite/cockle';
|
|
4
|
+
import {
|
|
5
|
+
ContentsAPI,
|
|
6
|
+
DriveFS,
|
|
7
|
+
ServiceWorkerContentsAPI
|
|
8
|
+
} from '@jupyterlite/contents';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Custom DriveFS implementation using the service worker.
|
|
12
|
+
*/
|
|
13
|
+
class MyDriveFS extends DriveFS {
|
|
14
|
+
createAPI(options: DriveFS.IOptions): ContentsAPI {
|
|
15
|
+
return new ServiceWorkerContentsAPI(
|
|
16
|
+
options.baseUrl,
|
|
17
|
+
options.driveName,
|
|
18
|
+
options.mountpoint,
|
|
19
|
+
options.FS,
|
|
20
|
+
options.ERRNO_CODES
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Shell web worker that uses DriveFS via service worker.
|
|
27
|
+
* Note that this is not exported as it is accessed from Shell via the filename.
|
|
28
|
+
*/
|
|
29
|
+
class ShellWorker extends BaseShellWorker {
|
|
30
|
+
/**
|
|
31
|
+
* Initialize the DriveFS to mount an external file system.
|
|
32
|
+
*/
|
|
33
|
+
protected override initDriveFS(
|
|
34
|
+
driveFsBaseUrl: string,
|
|
35
|
+
mountpoint: string,
|
|
36
|
+
fileSystem: IFileSystem
|
|
37
|
+
): void {
|
|
38
|
+
console.log('Terminal initDriveFS', driveFsBaseUrl, mountpoint);
|
|
39
|
+
const { FS, ERRNO_CODES, PATH } = fileSystem;
|
|
40
|
+
const driveFS = new MyDriveFS({
|
|
41
|
+
FS,
|
|
42
|
+
PATH,
|
|
43
|
+
ERRNO_CODES,
|
|
44
|
+
baseUrl: driveFsBaseUrl,
|
|
45
|
+
driveName: '',
|
|
46
|
+
mountpoint
|
|
47
|
+
});
|
|
48
|
+
FS.mount(driveFS, {}, mountpoint);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const worker = new ShellWorker();
|
|
53
|
+
expose(worker);
|