From 89286cbe5babcbdeb59853a5c04c4dea3d1e280c Mon Sep 17 00:00:00 2001 From: Simon Davies Date: Thu, 9 Apr 2026 15:56:53 +0100 Subject: [PATCH] Add ESM support and re-export CJS entry point in js-host-api Signed-off-by: Simon Davies --- src/js-host-api/lib.mjs | 40 ++++++++++++++++++++++++++++++++++++ src/js-host-api/package.json | 13 ++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 src/js-host-api/lib.mjs diff --git a/src/js-host-api/lib.mjs b/src/js-host-api/lib.mjs new file mode 100644 index 0000000..da04dc1 --- /dev/null +++ b/src/js-host-api/lib.mjs @@ -0,0 +1,40 @@ +/* +Copyright 2026 The Hyperlight Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// ESM re-export of the CJS entry point (lib.js). +// This enables `import { SandboxBuilder } from '@hyperlight-dev/js-host-api'` +// while preserving the error-enrichment wrapper from lib.js. + +import native from './lib.js'; + +export const { + HostModule, + HostModuleWrapper, + InterruptHandle, + InterruptHandleWrapper, + JSSandbox, + JSSandboxWrapper, + LoadedJSSandbox, + LoadedJSSandboxWrapper, + ProtoJSSandbox, + ProtoJSSandboxWrapper, + SandboxBuilder, + SandboxBuilderWrapper, + Snapshot, + SnapshotWrapper, +} = native; + +export default native; diff --git a/src/js-host-api/package.json b/src/js-host-api/package.json index 4045332..1591889 100644 --- a/src/js-host-api/package.json +++ b/src/js-host-api/package.json @@ -3,7 +3,20 @@ "version": "0.2.0", "description": "Node.js API bindings for Hyperlight JS", "main": "lib.js", + "module": "lib.mjs", "types": "index.d.ts", + "exports": { + ".": { + "import": { + "types": "./index.d.ts", + "default": "./lib.mjs" + }, + "require": { + "types": "./index.d.ts", + "default": "./lib.js" + } + } + }, "repository": { "type": "git", "url": "git+https://github.com/hyperlight-dev/hyperlight-js.git"