From b75e10fef608a87c886baa37c67786d48a7a9b77 Mon Sep 17 00:00:00 2001 From: Nathan Flurry Date: Wed, 12 Nov 2025 19:13:26 -0800 Subject: [PATCH] chore(rivetkit): switch dynamic node imports to use require --- rivetkit-asyncapi/asyncapi.json | 923 +++++++++--------- .../packages/rivetkit/scripts/dump-openapi.ts | 3 +- .../packages/rivetkit/src/drivers/default.ts | 6 +- .../rivetkit/src/drivers/file-system/mod.ts | 13 +- .../rivetkit/src/engine-process/mod.ts | 3 +- .../packages/rivetkit/src/registry/mod.ts | 6 +- .../packages/rivetkit/src/utils/node.ts | 122 +-- 7 files changed, 561 insertions(+), 515 deletions(-) diff --git a/rivetkit-asyncapi/asyncapi.json b/rivetkit-asyncapi/asyncapi.json index 0d9c7c7f98..e6074c7754 100644 --- a/rivetkit-asyncapi/asyncapi.json +++ b/rivetkit-asyncapi/asyncapi.json @@ -1,436 +1,489 @@ { - "asyncapi": "3.0.0", - "info": { - "title": "RivetKit WebSocket Protocol", - "version": "2.0.24-rc.1", - "description": "WebSocket protocol for bidirectional communication between RivetKit clients and actors" - }, - "channels": { - "/gateway/{actorId}/connect": { - "address": "/gateway/{actorId}/connect", - "parameters": { - "actorId": { - "description": "The unique identifier for the actor instance" - } - }, - "messages": { - "toClient": { - "$ref": "#/components/messages/ToClient" - }, - "toServer": { - "$ref": "#/components/messages/ToServer" - } - } - } - }, - "operations": { - "sendToClient": { - "action": "send", - "channel": { - "$ref": "#/channels/~1gateway~1{actorId}~1connect" - }, - "messages": [ - { - "$ref": "#/channels/~1gateway~1{actorId}~1connect/messages/toClient" - } - ], - "summary": "Send messages from server to client", - "description": "Messages sent from the RivetKit actor to connected clients" - }, - "receiveFromClient": { - "action": "receive", - "channel": { - "$ref": "#/channels/~1gateway~1{actorId}~1connect" - }, - "messages": [ - { - "$ref": "#/channels/~1gateway~1{actorId}~1connect/messages/toServer" - } - ], - "summary": "Receive messages from client", - "description": "Messages received by the RivetKit actor from connected clients" - } - }, - "components": { - "messages": { - "ToClient": { - "name": "ToClient", - "title": "Message To Client", - "summary": "A message sent from the server to the client", - "contentType": "application/json", - "payload": { - "type": "object", - "properties": { - "body": { - "anyOf": [ - { - "type": "object", - "properties": { - "tag": { - "type": "string", - "const": "Init" - }, - "val": { - "type": "object", - "properties": { - "actorId": { - "type": "string" - }, - "connectionId": { - "type": "string" - } - }, - "required": [ - "actorId", - "connectionId" - ], - "additionalProperties": false - } - }, - "required": ["tag", "val"], - "additionalProperties": false - }, - { - "type": "object", - "properties": { - "tag": { - "type": "string", - "const": "Error" - }, - "val": { - "type": "object", - "properties": { - "group": { - "type": "string" - }, - "code": { - "type": "string" - }, - "message": { - "type": "string" - }, - "metadata": {}, - "actionId": { - "type": ["integer", "null"] - } - }, - "required": [ - "group", - "code", - "message", - "actionId" - ], - "additionalProperties": false - } - }, - "required": ["tag", "val"], - "additionalProperties": false - }, - { - "type": "object", - "properties": { - "tag": { - "type": "string", - "const": "ActionResponse" - }, - "val": { - "type": "object", - "properties": { - "id": { - "type": "integer", - "format": "int64" - }, - "output": {} - }, - "required": ["id"], - "additionalProperties": false - } - }, - "required": ["tag", "val"], - "additionalProperties": false - }, - { - "type": "object", - "properties": { - "tag": { - "type": "string", - "const": "Event" - }, - "val": { - "type": "object", - "properties": { - "name": { - "type": "string" - }, - "args": {} - }, - "required": ["name"], - "additionalProperties": false - } - }, - "required": ["tag", "val"], - "additionalProperties": false - } - ] - } - }, - "required": ["body"], - "additionalProperties": false - }, - "examples": [ - { - "name": "Init message", - "summary": "Initial connection message", - "payload": { - "body": { - "tag": "Init", - "val": { - "actorId": "actor_123", - "connectionId": "conn_456" - } - } - } - }, - { - "name": "Error message", - "summary": "Error response", - "payload": { - "body": { - "tag": "Error", - "val": { - "group": "auth", - "code": "unauthorized", - "message": "Authentication failed", - "actionId": null - } - } - } - }, - { - "name": "Action response", - "summary": "Response to an action request", - "payload": { - "body": { - "tag": "ActionResponse", - "val": { - "id": "123", - "output": { - "result": "success" - } - } - } - } - }, - { - "name": "Event", - "summary": "Event broadcast to subscribed clients", - "payload": { - "body": { - "tag": "Event", - "val": { - "name": "stateChanged", - "args": { - "newState": "active" - } - } - } - } - } - ] - }, - "ToServer": { - "name": "ToServer", - "title": "Message To Server", - "summary": "A message sent from the client to the server", - "contentType": "application/json", - "payload": { - "type": "object", - "properties": { - "body": { - "anyOf": [ - { - "type": "object", - "properties": { - "tag": { - "type": "string", - "const": "ActionRequest" - }, - "val": { - "type": "object", - "properties": { - "id": { - "type": "integer", - "format": "int64" - }, - "name": { - "type": "string" - }, - "args": {} - }, - "required": ["id", "name"], - "additionalProperties": false - } - }, - "required": ["tag", "val"], - "additionalProperties": false - }, - { - "type": "object", - "properties": { - "tag": { - "type": "string", - "const": "SubscriptionRequest" - }, - "val": { - "type": "object", - "properties": { - "eventName": { - "type": "string" - }, - "subscribe": { - "type": "boolean" - } - }, - "required": [ - "eventName", - "subscribe" - ], - "additionalProperties": false - } - }, - "required": ["tag", "val"], - "additionalProperties": false - } - ] - } - }, - "required": ["body"], - "additionalProperties": false - }, - "examples": [ - { - "name": "Action request", - "summary": "Request to execute an action", - "payload": { - "body": { - "tag": "ActionRequest", - "val": { - "id": "123", - "name": "updateState", - "args": { - "key": "value" - } - } - } - } - }, - { - "name": "Subscription request", - "summary": "Request to subscribe/unsubscribe from an event", - "payload": { - "body": { - "tag": "SubscriptionRequest", - "val": { - "eventName": "stateChanged", - "subscribe": true - } - } - } - } - ] - } - }, - "schemas": { - "Init": { - "type": "object", - "properties": { - "actorId": { - "type": "string" - }, - "connectionId": { - "type": "string" - } - }, - "required": ["actorId", "connectionId"], - "additionalProperties": false, - "description": "Initial connection message sent from server to client" - }, - "Error": { - "type": "object", - "properties": { - "group": { - "type": "string" - }, - "code": { - "type": "string" - }, - "message": { - "type": "string" - }, - "metadata": {}, - "actionId": { - "type": ["integer", "null"] - } - }, - "required": ["group", "code", "message", "actionId"], - "additionalProperties": false, - "description": "Error message sent from server to client" - }, - "ActionResponse": { - "type": "object", - "properties": { - "id": { - "type": "integer", - "format": "int64" - }, - "output": {} - }, - "required": ["id"], - "additionalProperties": false, - "description": "Response to an action request" - }, - "Event": { - "type": "object", - "properties": { - "name": { - "type": "string" - }, - "args": {} - }, - "required": ["name"], - "additionalProperties": false, - "description": "Event broadcast to subscribed clients" - }, - "ActionRequest": { - "type": "object", - "properties": { - "id": { - "type": "integer", - "format": "int64" - }, - "name": { - "type": "string" - }, - "args": {} - }, - "required": ["id", "name"], - "additionalProperties": false, - "description": "Request to execute an action on the actor" - }, - "SubscriptionRequest": { - "type": "object", - "properties": { - "eventName": { - "type": "string" - }, - "subscribe": { - "type": "boolean" - } - }, - "required": ["eventName", "subscribe"], - "additionalProperties": false, - "description": "Request to subscribe or unsubscribe from an event" - } - } - } -} + "asyncapi": "3.0.0", + "info": { + "title": "RivetKit WebSocket Protocol", + "version": "2.0.24-rc.1", + "description": "WebSocket protocol for bidirectional communication between RivetKit clients and actors" + }, + "channels": { + "/gateway/{actorId}/connect": { + "address": "/gateway/{actorId}/connect", + "parameters": { + "actorId": { + "description": "The unique identifier for the actor instance" + } + }, + "messages": { + "toClient": { + "$ref": "#/components/messages/ToClient" + }, + "toServer": { + "$ref": "#/components/messages/ToServer" + } + } + } + }, + "operations": { + "sendToClient": { + "action": "send", + "channel": { + "$ref": "#/channels/~1gateway~1{actorId}~1connect" + }, + "messages": [ + { + "$ref": "#/channels/~1gateway~1{actorId}~1connect/messages/toClient" + } + ], + "summary": "Send messages from server to client", + "description": "Messages sent from the RivetKit actor to connected clients" + }, + "receiveFromClient": { + "action": "receive", + "channel": { + "$ref": "#/channels/~1gateway~1{actorId}~1connect" + }, + "messages": [ + { + "$ref": "#/channels/~1gateway~1{actorId}~1connect/messages/toServer" + } + ], + "summary": "Receive messages from client", + "description": "Messages received by the RivetKit actor from connected clients" + } + }, + "components": { + "messages": { + "ToClient": { + "name": "ToClient", + "title": "Message To Client", + "summary": "A message sent from the server to the client", + "contentType": "application/json", + "payload": { + "type": "object", + "properties": { + "body": { + "anyOf": [ + { + "type": "object", + "properties": { + "tag": { + "type": "string", + "const": "Init" + }, + "val": { + "type": "object", + "properties": { + "actorId": { + "type": "string" + }, + "connectionId": { + "type": "string" + } + }, + "required": [ + "actorId", + "connectionId" + ], + "additionalProperties": false + } + }, + "required": [ + "tag", + "val" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "tag": { + "type": "string", + "const": "Error" + }, + "val": { + "type": "object", + "properties": { + "group": { + "type": "string" + }, + "code": { + "type": "string" + }, + "message": { + "type": "string" + }, + "metadata": {}, + "actionId": { + "type": [ + "integer", + "null" + ] + } + }, + "required": [ + "group", + "code", + "message", + "actionId" + ], + "additionalProperties": false + } + }, + "required": [ + "tag", + "val" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "tag": { + "type": "string", + "const": "ActionResponse" + }, + "val": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "output": {} + }, + "required": [ + "id" + ], + "additionalProperties": false + } + }, + "required": [ + "tag", + "val" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "tag": { + "type": "string", + "const": "Event" + }, + "val": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "args": {} + }, + "required": [ + "name" + ], + "additionalProperties": false + } + }, + "required": [ + "tag", + "val" + ], + "additionalProperties": false + } + ] + } + }, + "required": [ + "body" + ], + "additionalProperties": false + }, + "examples": [ + { + "name": "Init message", + "summary": "Initial connection message", + "payload": { + "body": { + "tag": "Init", + "val": { + "actorId": "actor_123", + "connectionId": "conn_456" + } + } + } + }, + { + "name": "Error message", + "summary": "Error response", + "payload": { + "body": { + "tag": "Error", + "val": { + "group": "auth", + "code": "unauthorized", + "message": "Authentication failed", + "actionId": null + } + } + } + }, + { + "name": "Action response", + "summary": "Response to an action request", + "payload": { + "body": { + "tag": "ActionResponse", + "val": { + "id": "123", + "output": { + "result": "success" + } + } + } + } + }, + { + "name": "Event", + "summary": "Event broadcast to subscribed clients", + "payload": { + "body": { + "tag": "Event", + "val": { + "name": "stateChanged", + "args": { + "newState": "active" + } + } + } + } + } + ] + }, + "ToServer": { + "name": "ToServer", + "title": "Message To Server", + "summary": "A message sent from the client to the server", + "contentType": "application/json", + "payload": { + "type": "object", + "properties": { + "body": { + "anyOf": [ + { + "type": "object", + "properties": { + "tag": { + "type": "string", + "const": "ActionRequest" + }, + "val": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "args": {} + }, + "required": [ + "id", + "name" + ], + "additionalProperties": false + } + }, + "required": [ + "tag", + "val" + ], + "additionalProperties": false + }, + { + "type": "object", + "properties": { + "tag": { + "type": "string", + "const": "SubscriptionRequest" + }, + "val": { + "type": "object", + "properties": { + "eventName": { + "type": "string" + }, + "subscribe": { + "type": "boolean" + } + }, + "required": [ + "eventName", + "subscribe" + ], + "additionalProperties": false + } + }, + "required": [ + "tag", + "val" + ], + "additionalProperties": false + } + ] + } + }, + "required": [ + "body" + ], + "additionalProperties": false + }, + "examples": [ + { + "name": "Action request", + "summary": "Request to execute an action", + "payload": { + "body": { + "tag": "ActionRequest", + "val": { + "id": "123", + "name": "updateState", + "args": { + "key": "value" + } + } + } + } + }, + { + "name": "Subscription request", + "summary": "Request to subscribe/unsubscribe from an event", + "payload": { + "body": { + "tag": "SubscriptionRequest", + "val": { + "eventName": "stateChanged", + "subscribe": true + } + } + } + } + ] + } + }, + "schemas": { + "Init": { + "type": "object", + "properties": { + "actorId": { + "type": "string" + }, + "connectionId": { + "type": "string" + } + }, + "required": [ + "actorId", + "connectionId" + ], + "additionalProperties": false, + "description": "Initial connection message sent from server to client" + }, + "Error": { + "type": "object", + "properties": { + "group": { + "type": "string" + }, + "code": { + "type": "string" + }, + "message": { + "type": "string" + }, + "metadata": {}, + "actionId": { + "type": [ + "integer", + "null" + ] + } + }, + "required": [ + "group", + "code", + "message", + "actionId" + ], + "additionalProperties": false, + "description": "Error message sent from server to client" + }, + "ActionResponse": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "output": {} + }, + "required": [ + "id" + ], + "additionalProperties": false, + "description": "Response to an action request" + }, + "Event": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "args": {} + }, + "required": [ + "name" + ], + "additionalProperties": false, + "description": "Event broadcast to subscribed clients" + }, + "ActionRequest": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "args": {} + }, + "required": [ + "id", + "name" + ], + "additionalProperties": false, + "description": "Request to execute an action on the actor" + }, + "SubscriptionRequest": { + "type": "object", + "properties": { + "eventName": { + "type": "string" + }, + "subscribe": { + "type": "boolean" + } + }, + "required": [ + "eventName", + "subscribe" + ], + "additionalProperties": false, + "description": "Request to subscribe or unsubscribe from an event" + } + } + } +} \ No newline at end of file diff --git a/rivetkit-typescript/packages/rivetkit/scripts/dump-openapi.ts b/rivetkit-typescript/packages/rivetkit/scripts/dump-openapi.ts index 3bf19bd4aa..005fc4e210 100644 --- a/rivetkit-typescript/packages/rivetkit/scripts/dump-openapi.ts +++ b/rivetkit-typescript/packages/rivetkit/scripts/dump-openapi.ts @@ -20,7 +20,7 @@ async function main() { const registry = setup(registryConfig); const driverConfig: RunnerConfig = RunnerConfigSchema.parse({ - driver: await createFileSystemOrMemoryDriver(false), + driver: createFileSystemOrMemoryDriver(false), getUpgradeWebSocket: () => () => unimplemented(), inspector: { enabled: false, @@ -38,6 +38,7 @@ async function main() { proxyWebSocket: unimplemented, displayInformation: unimplemented, getOrCreateInspectorAccessToken: unimplemented, + listActors: unimplemented, }; const client = createClientWithDriver( diff --git a/rivetkit-typescript/packages/rivetkit/src/drivers/default.ts b/rivetkit-typescript/packages/rivetkit/src/drivers/default.ts index d55c407d8f..8fab1b3d65 100644 --- a/rivetkit-typescript/packages/rivetkit/src/drivers/default.ts +++ b/rivetkit-typescript/packages/rivetkit/src/drivers/default.ts @@ -7,9 +7,7 @@ import type { DriverConfig, RunnerConfig } from "@/registry/run-config"; /** * Chooses the appropriate driver based on the run configuration. */ -export async function chooseDefaultDriver( - runConfig: RunnerConfig, -): Promise { +export function chooseDefaultDriver(runConfig: RunnerConfig): DriverConfig { if (runConfig.endpoint && runConfig.driver) { throw new UserError( "Cannot specify both 'endpoint' and 'driver' in configuration", @@ -33,5 +31,5 @@ export async function chooseDefaultDriver( } loggerWithoutContext().debug({ msg: "using default file system driver" }); - return await createFileSystemOrMemoryDriver(true); + return createFileSystemOrMemoryDriver(true); } diff --git a/rivetkit-typescript/packages/rivetkit/src/drivers/file-system/mod.ts b/rivetkit-typescript/packages/rivetkit/src/drivers/file-system/mod.ts index e5fe8cf7c1..707399991d 100644 --- a/rivetkit-typescript/packages/rivetkit/src/drivers/file-system/mod.ts +++ b/rivetkit-typescript/packages/rivetkit/src/drivers/file-system/mod.ts @@ -9,12 +9,11 @@ export { FileSystemGlobalState } from "./global-state"; export { FileSystemManagerDriver } from "./manager"; export { getStoragePath } from "./utils"; -export async function createFileSystemOrMemoryDriver( +export function createFileSystemOrMemoryDriver( persist: boolean = true, customPath?: string, -): Promise { - // Import Node.js dependencies before creating the state - await importNodeDependencies(); +): DriverConfig { + importNodeDependencies(); const state = new FileSystemGlobalState(persist, customPath); const driverConfig: DriverConfig = { @@ -48,12 +47,10 @@ export async function createFileSystemOrMemoryDriver( return driverConfig; } -export async function createFileSystemDriver(opts?: { - path?: string; -}): Promise { +export function createFileSystemDriver(opts?: { path?: string }): DriverConfig { return createFileSystemOrMemoryDriver(true, opts?.path); } -export async function createMemoryDriver(): Promise { +export function createMemoryDriver(): DriverConfig { return createFileSystemOrMemoryDriver(false); } diff --git a/rivetkit-typescript/packages/rivetkit/src/engine-process/mod.ts b/rivetkit-typescript/packages/rivetkit/src/engine-process/mod.ts index a2d5da5003..b732ae9265 100644 --- a/rivetkit-typescript/packages/rivetkit/src/engine-process/mod.ts +++ b/rivetkit-typescript/packages/rivetkit/src/engine-process/mod.ts @@ -26,8 +26,7 @@ interface EnsureEngineProcessOptions { export async function ensureEngineProcess( options: EnsureEngineProcessOptions, ): Promise { - // Import Node.js dependencies first - await importNodeDependencies(); + importNodeDependencies(); logger().debug({ msg: "ensuring engine process", diff --git a/rivetkit-typescript/packages/rivetkit/src/registry/mod.ts b/rivetkit-typescript/packages/rivetkit/src/registry/mod.ts index 95be3bfa4a..f9f18d8900 100644 --- a/rivetkit-typescript/packages/rivetkit/src/registry/mod.ts +++ b/rivetkit-typescript/packages/rivetkit/src/registry/mod.ts @@ -58,9 +58,7 @@ export class Registry { /** * Runs the registry for a server. */ - public async start( - inputConfig?: RunnerConfigInput, - ): Promise> { + public start(inputConfig?: RunnerConfigInput): ServerOutput { const config = RunnerConfigSchema.parse(inputConfig); // Validate autoConfigureServerless is only used with serverless runner @@ -137,7 +135,7 @@ export class Registry { } // Choose the driver based on configuration - const driver = await chooseDefaultDriver(config); + const driver = chooseDefaultDriver(config); // Set defaults based on the driver if (driver.name === "engine") { diff --git a/rivetkit-typescript/packages/rivetkit/src/utils/node.ts b/rivetkit-typescript/packages/rivetkit/src/utils/node.ts index 746df0ba65..371443c5e3 100644 --- a/rivetkit-typescript/packages/rivetkit/src/utils/node.ts +++ b/rivetkit-typescript/packages/rivetkit/src/utils/node.ts @@ -1,4 +1,14 @@ -// Global variables for Node.js modules +import { createRequire } from "node:module"; + +// Global variables for Node.js modules. +// +// We use synchronous require() instead of async import() for Node.js module loading because: +// 1. These modules are only needed in Node.js environments (not browser/edge) +// 2. registry.start() cannot be async and needs immediate access to Node modules +// 3. The setup process must be synchronous to avoid breaking the API +// +// Biome only allows imports of node modules in this file in order to ensure +// we're forcing the use of dynamic imports. let nodeCrypto: typeof import("node:crypto") | undefined; let nodeFsSync: typeof import("node:fs") | undefined; let nodeFs: typeof import("node:fs/promises") | undefined; @@ -7,58 +17,64 @@ let nodeOs: typeof import("node:os") | undefined; let nodeChildProcess: typeof import("node:child_process") | undefined; let nodeStream: typeof import("node:stream/promises") | undefined; -// Singleton promise to ensure imports happen only once -let importPromise: Promise | undefined; +let hasImportedDependencies = false; + +// Helper to get a require function that works in both CommonJS and ESM. +// We use require() instead of await import() because registry.start() cannot +// be async and needs immediate access to Node.js modules during setup. +function getRequireFn() { + // CommonJS context - use global require + if (typeof require !== "undefined") { + return require; + } + + // ESM context - use createRequire with import.meta.url + // @ts-ignore - import.meta.url is available in ESM + return createRequire(import.meta.url); +} /** - * Dynamically imports all required Node.js dependencies. + * Dynamically imports all required Node.js dependencies. We do this early in a + * single function call in order to surface errors early. + * * This function is idempotent and will only import once. + * * @throws Error if Node.js modules are not available (e.g., in browser/edge environments) */ -export async function importNodeDependencies(): Promise { - if (importPromise) return importPromise; - - importPromise = (async () => { - try { - // Dynamic imports with webpack ignore comment to prevent bundling - const cryptoModule = "node:crypto"; - const fsModule = "node:fs"; - const fsPromisesModule = "node:fs/promises"; - const pathModule = "node:path"; - const osModule = "node:os"; - const childProcessModule = "node:child_process"; - const streamModule = "node:stream/promises"; +export function importNodeDependencies(): void { + // Check if already loaded + if (hasImportedDependencies) return; - const modules = await Promise.all([ - import(/* webpackIgnore: true */ cryptoModule), - import(/* webpackIgnore: true */ fsModule), - import(/* webpackIgnore: true */ fsPromisesModule), - import(/* webpackIgnore: true */ pathModule), - import(/* webpackIgnore: true */ osModule), - import(/* webpackIgnore: true */ childProcessModule), - import(/* webpackIgnore: true */ streamModule), - ]); + try { + // Get a require function that works in both CommonJS and ESM + const requireFn = getRequireFn(); - [ - nodeCrypto, - nodeFsSync, - nodeFs, - nodePath, - nodeOs, - nodeChildProcess, - nodeStream, - ] = modules; - } catch (err) { - // Node.js not available - will use memory driver fallback - console.warn( - "Node.js modules not available, file system driver will not work", - err, - ); - throw err; - } - })(); + // Use requireFn with webpack ignore comment to prevent bundling + // @ts-ignore - dynamic require usage + nodeCrypto = requireFn(/* webpackIgnore: true */ "node:crypto"); + // @ts-ignore + nodeFsSync = requireFn(/* webpackIgnore: true */ "node:fs"); + // @ts-ignore + nodeFs = requireFn(/* webpackIgnore: true */ "node:fs/promises"); + // @ts-ignore + nodePath = requireFn(/* webpackIgnore: true */ "node:path"); + // @ts-ignore + nodeOs = requireFn(/* webpackIgnore: true */ "node:os"); + // @ts-ignore + nodeChildProcess = requireFn( + /* webpackIgnore: true */ "node:child_process", + ); + // @ts-ignore + nodeStream = requireFn(/* webpackIgnore: true */ "node:stream/promises"); - return importPromise; + hasImportedDependencies = true; + } catch (err) { + console.warn( + "Node.js modules not available, file system driver will not work", + err, + ); + throw err; + } } /** @@ -151,19 +167,3 @@ export function getNodeStream(): typeof import("node:stream/promises") { } return nodeStream; } - -/** - * Checks if Node.js dependencies are available. - * @returns true if all Node.js modules are loaded - */ -export function areNodeDependenciesAvailable(): boolean { - return !!( - nodeCrypto && - nodeFsSync && - nodeFs && - nodePath && - nodeOs && - nodeChildProcess && - nodeStream - ); -}