-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from jupyterlite/wasm-with-webworker
Use WASM commands running in webworker
- Loading branch information
Showing
9 changed files
with
1,504 additions
and
1,402 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Shell } from '@jupyterlite/cockle'; | ||
import { DriveFS } from '@jupyterlite/contents'; | ||
|
||
import { expose } from 'comlink'; | ||
|
||
import { IWorkerTerminal } from './tokens'; | ||
|
||
class WorkerTerminal implements IWorkerTerminal { | ||
async initialize(options: IWorkerTerminal.IOptions): Promise<void> { | ||
this._options = options; | ||
console.log('WorkerTerminal.initialize', this._options, this._wantDriveFS); | ||
} | ||
|
||
async input(text: string): Promise<void> { | ||
await this._shell!.input(text); | ||
} | ||
|
||
async setSize(rows: number, columns: number): Promise<void> { | ||
await this._shell!.setSize(rows, columns); | ||
} | ||
|
||
async start(): Promise<void> { | ||
this._shell = new Shell(this.output, this._mountpoint); | ||
const { FS, PATH, ERRNO_CODES } = await this._shell.initFilesystem(); | ||
|
||
if (this._wantDriveFS) { | ||
this._driveFS = new DriveFS({ | ||
FS, | ||
PATH, | ||
ERRNO_CODES, | ||
baseUrl: this._options!.baseUrl, | ||
driveName: '', | ||
mountpoint: this._mountpoint | ||
}); | ||
FS.mount(this._driveFS, {}, this._mountpoint); | ||
FS.chdir(this._mountpoint); | ||
} else { | ||
// Add some dummy files if not using DriveFS. | ||
FS.writeFile('file.txt', 'This is the contents of the file'); | ||
FS.writeFile('other.txt', 'Some other file'); | ||
FS.mkdir('dir'); | ||
} | ||
|
||
await this._shell.start(); | ||
} | ||
|
||
private async output(text: string): Promise<void> { | ||
postMessage({ | ||
type: 'output', | ||
text: text | ||
}); | ||
} | ||
|
||
private _options: IWorkerTerminal.IOptions | null = null; | ||
private _shell?: Shell; | ||
private _mountpoint: string = '/drive'; | ||
private _wantDriveFS: boolean = true; | ||
private _driveFS?: DriveFS; | ||
} | ||
|
||
const obj = new WorkerTerminal(); | ||
|
||
expose(obj); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const path = require('path'); | ||
const rules = [ | ||
{ | ||
test: /\.js$/, | ||
exclude: /node_modules/, | ||
loader: 'source-map-loader' | ||
} | ||
]; | ||
|
||
const resolve = { | ||
fallback: { | ||
fs: false, | ||
child_process: false, | ||
crypto: false | ||
}, | ||
extensions: ['.js'] | ||
}; | ||
|
||
module.exports = [ | ||
{ | ||
entry: './lib/worker.js', | ||
output: { | ||
filename: 'worker.js', | ||
path: path.resolve(__dirname, 'lib'), | ||
libraryTarget: 'amd' | ||
}, | ||
module: { | ||
rules | ||
}, | ||
devtool: 'source-map', | ||
resolve | ||
} | ||
]; |
Oops, something went wrong.