Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

fix(npm/js-api): Lazy load backend implementations #3652

Merged
merged 2 commits into from
Nov 10, 2022
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 npm/js-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rometools/js-api",
"version": "0.1.2",
"version": "0.1.3",
"description": "JavaScript APIs for the Rome package",
"scripts": {
"tsc": "tsc --noEmit",
Expand Down
10 changes: 5 additions & 5 deletions npm/js-api/src/daemon.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
createWorkspace,
createWorkspaceWithBinary,
Workspace,
} from "@rometools/backend-jsonrpc";
import type { Workspace } from "@rometools/backend-jsonrpc";

/**
* Class responsible to communicate with the Rome daemon.
Expand All @@ -20,6 +16,10 @@ export class Deamon {
* It creates a new instance of a workspace connected to the Daemon
*/
public static async connectToDaemon(pathToBinary?: string): Promise<Deamon> {
const { createWorkspace, createWorkspaceWithBinary } = await import(
"@rometools/backend-jsonrpc"
);

if (pathToBinary) {
let workspace = await createWorkspaceWithBinary(pathToBinary);
if (workspace) {
Expand Down
9 changes: 4 additions & 5 deletions npm/js-api/src/nodeWasm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { main, Workspace } from "@rometools/wasm-nodejs";
import type { Workspace } from "@rometools/wasm-nodejs";

/**
* Class responsible to connect with the WebAssembly backend of Rome.
Expand All @@ -13,13 +13,12 @@ export class NodeWasm {
* It creates a new instance of a workspace connected to the WebAssembly backend
*/
public static async loadWebAssembly(): Promise<NodeWasm> {
return new NodeWasm(await NodeWasm.loadWorkspace());
}
const { main, Workspace } = await import("@rometools/wasm-nodejs");

private static async loadWorkspace(): Promise<Workspace> {
// load the web assembly module
main();
return Promise.resolve(new Workspace());

return new NodeWasm(new Workspace());
}
}

Expand Down