diff --git a/packages/pyodide-kernel/package.json b/packages/pyodide-kernel/package.json index 91b72b79..13d99a82 100644 --- a/packages/pyodide-kernel/package.json +++ b/packages/pyodide-kernel/package.json @@ -55,7 +55,7 @@ "@jupyterlab/coreutils": "^6.1.1", "@jupyterlite/contents": "^0.4.0-alpha.3", "@jupyterlite/kernel": "^0.4.0-alpha.3", - "comlink": "^4.4.1" + "coincident": "^1.2.3" }, "devDependencies": { "@babel/core": "^7.22.17", diff --git a/packages/pyodide-kernel/src/coincident.worker.ts b/packages/pyodide-kernel/src/coincident.worker.ts new file mode 100644 index 00000000..35d3321a --- /dev/null +++ b/packages/pyodide-kernel/src/coincident.worker.ts @@ -0,0 +1,25 @@ +// Copyright (c) Jupyter Development Team. +// Distributed under the terms of the Modified BSD License. + +/** + * A WebWorker entrypoint that uses coincident to handle postMessage details + */ +import coincident from 'coincident'; + +import { PyodideRemoteKernel } from './worker'; +import { IPyodideWorkerKernel } from './tokens'; + +const worker = new PyodideRemoteKernel(); + +const workerAPI: IPyodideWorkerKernel = coincident(self) as IPyodideWorkerKernel; + +workerAPI.initialize = worker.initialize.bind(worker); +workerAPI.execute = worker.execute.bind(worker); +workerAPI.complete = worker.complete.bind(worker); +workerAPI.inspect = worker.inspect.bind(worker); +workerAPI.isComplete = worker.isComplete.bind(worker); +workerAPI.commInfo = worker.commInfo.bind(worker); +workerAPI.commOpen = worker.commOpen.bind(worker); +workerAPI.commMsg = worker.commMsg.bind(worker); +workerAPI.commClose = worker.commClose.bind(worker); +workerAPI.inputReply = worker.inputReply.bind(worker); diff --git a/packages/pyodide-kernel/src/comlink.worker.ts b/packages/pyodide-kernel/src/comlink.worker.ts index 736a0734..7c1aa92e 100644 --- a/packages/pyodide-kernel/src/comlink.worker.ts +++ b/packages/pyodide-kernel/src/comlink.worker.ts @@ -2,12 +2,8 @@ // Distributed under the terms of the Modified BSD License. /** - * A WebWorker entrypoint that uses comlink to handle postMessage details + * A WebWorker entrypoint that uses coincident to handle postMessage details */ -import { expose } from 'comlink'; -import { PyodideRemoteKernel } from './worker'; - -const worker = new PyodideRemoteKernel(); - -expose(worker); +// This file is only here for backward compat +export * from './coincident.worker'; diff --git a/packages/pyodide-kernel/src/kernel.ts b/packages/pyodide-kernel/src/kernel.ts index 66597bd2..184e6207 100644 --- a/packages/pyodide-kernel/src/kernel.ts +++ b/packages/pyodide-kernel/src/kernel.ts @@ -1,3 +1,5 @@ +import coincident from 'coincident'; + import { PromiseDelegate } from '@lumino/coreutils'; import { PageConfig } from '@jupyterlab/coreutils'; @@ -5,8 +7,6 @@ import { KernelMessage } from '@jupyterlab/services'; import { BaseKernel, IKernel } from '@jupyterlite/kernel'; -import { wrap } from 'comlink'; - import { IPyodideWorkerKernel, IRemotePyodideWorkerKernel } from './tokens'; import { allJSONUrl, pipliteWheelUrl } from './_pypi'; @@ -24,7 +24,7 @@ export class PyodideKernel extends BaseKernel implements IKernel { super(options); this._worker = this.initWorker(options); this._worker.onmessage = (e) => this._processWorkerMessage(e.data); - this._remoteKernel = wrap(this._worker); + this._remoteKernel = coincident(this._worker) as IPyodideWorkerKernel; this.initRemote(options); } diff --git a/packages/pyodide-kernel/src/tokens.ts b/packages/pyodide-kernel/src/tokens.ts index 3460cb99..90ae6bdf 100644 --- a/packages/pyodide-kernel/src/tokens.ts +++ b/packages/pyodide-kernel/src/tokens.ts @@ -5,8 +5,6 @@ * Definitions for the Pyodide kernel. */ -import type { Remote } from 'comlink'; - import { IWorkerKernel } from '@jupyterlite/kernel'; /** @@ -25,9 +23,9 @@ export interface IPyodideWorkerKernel extends IWorkerKernel { } /** - * An convenience interface for Pyodide workers wrapped by a comlink Remote. + * Deprecated. */ -export type IRemotePyodideWorkerKernel = Remote; +export type IRemotePyodideWorkerKernel = IPyodideWorkerKernel; /** * An namespace for Pyodide workers. diff --git a/packages/pyodide-kernel/src/worker.ts b/packages/pyodide-kernel/src/worker.ts index 05f8d744..e17ba0cf 100644 --- a/packages/pyodide-kernel/src/worker.ts +++ b/packages/pyodide-kernel/src/worker.ts @@ -349,7 +349,7 @@ export class PyodideRemoteKernel { * * @param content The incoming message with the comm target name. */ - async commInfo(content: any, parent: any) { + async commInfo(content: any, parent: any): Promise<{ comms: any; status: 'ok' }> { await this.setup(parent); const res = this._kernel.comm_info(content.target_name); diff --git a/yarn.lock b/yarn.lock index 6c6cfa5d..955f74f3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2983,7 +2983,7 @@ __metadata: "@jupyterlite/contents": ^0.4.0-alpha.3 "@jupyterlite/kernel": ^0.4.0-alpha.3 "@types/jest": ^29.5.4 - comlink: ^4.4.1 + coincident: ^1.2.3 esbuild: ^0.19.2 jest: ^29.7.0 pyodide: 0.26.0 @@ -4463,6 +4463,13 @@ __metadata: languageName: node linkType: hard +"@ungap/with-resolvers@npm:^0.1.0": + version: 0.1.0 + resolution: "@ungap/with-resolvers@npm:0.1.0" + checksum: ac0c6234414b87ec26e9603c5e57f6ae48477ccc901841e725e820bc026367987cc82dbdb8c702e058179dadbd16578c0fcc607d2122e72d9fe91373bade126c + languageName: node + linkType: hard + "@webassemblyjs/ast@npm:1.11.6, @webassemblyjs/ast@npm:^1.11.5": version: 1.11.6 resolution: "@webassemblyjs/ast@npm:1.11.6" @@ -5705,6 +5712,22 @@ __metadata: languageName: node linkType: hard +"coincident@npm:^1.2.3": + version: 1.2.3 + resolution: "coincident@npm:1.2.3" + dependencies: + "@ungap/structured-clone": ^1.2.0 + "@ungap/with-resolvers": ^0.1.0 + gc-hook: ^0.3.1 + proxy-target: ^3.0.2 + ws: ^8.16.0 + dependenciesMeta: + ws: + optional: true + checksum: 21c44d9d74be393b12d6f91c885c8b6c640dce570b01b5d5156327488390c858de8e40c0af08763e3cd7041bcf32bee70c058a1b24aa25b145376a92b1c520a3 + languageName: node + linkType: hard + "collect-v8-coverage@npm:^1.0.0": version: 1.0.2 resolution: "collect-v8-coverage@npm:1.0.2" @@ -5779,7 +5802,7 @@ __metadata: languageName: node linkType: hard -"comlink@npm:^4.3.1, comlink@npm:^4.4.1": +"comlink@npm:^4.3.1": version: 4.4.1 resolution: "comlink@npm:4.4.1" checksum: 16d58a8f590087fc45432e31d6c138308dfd4b75b89aec0b7f7bb97ad33d810381bd2b1e608a1fb2cf05979af9cbfcdcaf1715996d5fcf77aeb013b6da3260af @@ -7200,6 +7223,13 @@ __metadata: languageName: node linkType: hard +"gc-hook@npm:^0.3.1": + version: 0.3.1 + resolution: "gc-hook@npm:0.3.1" + checksum: bda26ab6493faf8593eb8e1ff636c91ba4b38f3d87867ede757b24c4677e4f55ec696977a2b884503e3e56243d5e38abf8cec52257b1fd0685622ec5a3d9c84b + languageName: node + linkType: hard + "gensync@npm:^1.0.0-beta.2": version: 1.0.0-beta.2 resolution: "gensync@npm:1.0.0-beta.2" @@ -10826,6 +10856,13 @@ __metadata: languageName: node linkType: hard +"proxy-target@npm:^3.0.2": + version: 3.0.2 + resolution: "proxy-target@npm:3.0.2" + checksum: 9d8aa207ce8d3d50273e6926a61bb0205848f2a9de7b6781feeb115072242d9803255351d4da2f2980c573fd2164609257d8c8feaa39b80147867805f2c5d101 + languageName: node + linkType: hard + "psl@npm:^1.1.33": version: 1.9.0 resolution: "psl@npm:1.9.0" @@ -13001,6 +13038,21 @@ __metadata: languageName: node linkType: hard +"ws@npm:^8.16.0": + version: 8.17.0 + resolution: "ws@npm:8.17.0" + peerDependencies: + bufferutil: ^4.0.1 + utf-8-validate: ">=5.0.2" + peerDependenciesMeta: + bufferutil: + optional: true + utf-8-validate: + optional: true + checksum: 147ef9eab0251364e1d2c55338ad0efb15e6913923ccbfdf20f7a8a6cb8f88432bcd7f4d8f66977135bfad35575644f9983201c1a361019594a4e53977bf6d4e + languageName: node + linkType: hard + "xml-name-validator@npm:^4.0.0": version: 4.0.0 resolution: "xml-name-validator@npm:4.0.0"