fix(npm/js-api): Lazy load backend implementations
MODIFY
npm/js-api/package.json
npm/js-api/package.json
{
"name": "@rometools/js-api",
- "version": "0.1.2",
+ "version": "0.1.3",
"description": "JavaScript APIs for the Rome package",
"scripts": {
"tsc": "tsc --noEmit",

MODIFY
npm/js-api/src/daemon.ts
npm/js-api/src/daemon.ts
-import {
- createWorkspace,
- createWorkspaceWithBinary,
- Workspace,
-} from "@rometools/backend-jsonrpc";
+import type { Workspace } from "@rometools/backend-jsonrpc";
/**
* Class responsible to communicate with the Rome daemon.
@@ -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) {

MODIFY
npm/js-api/src/nodeWasm.ts
npm/js-api/src/nodeWasm.ts
-import { main, Workspace } from "@rometools/wasm-nodejs";
+import type { Workspace } from "@rometools/wasm-nodejs";
/**
* Class responsible to connect with the WebAssembly backend of Rome.
@@ -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());
}
}

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