From 4b33d8671b8a30a28bb991ca09cf97416343c341 Mon Sep 17 00:00:00 2001 From: Matt Radbourne <1254508+mradbourne@users.noreply.github.com> Date: Thu, 6 Jun 2024 17:17:10 +0100 Subject: [PATCH 1/2] Ensure bundle is an ArrayBuffer --- src/runtime.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/runtime.ts b/src/runtime.ts index c7c9b26..cae4478 100644 --- a/src/runtime.ts +++ b/src/runtime.ts @@ -8,6 +8,7 @@ import * as VM from 'node:vm'; import * as OS from 'node:os'; import * as FS from 'node:fs'; import { Module } from 'node:module'; +import assert from 'node:assert'; const VERSION = 1; const COMPRESSION = { @@ -25,7 +26,9 @@ const HASH = { const PROTO = 'sea:'; const resolutions: Record> = JSON.parse(SEA.getAsset('resolv', 'utf8')); -const blobs = extractBlobs(SEA.getRawAsset('bundle')); +const bundle = SEA.getRawAsset('bundle'); +assert(typeof bundle === 'object', 'bundle is not an ArrayBuffer'); +const blobs = extractBlobs(bundle); function extractBlobs(data: ArrayBuffer) { const index: Record> = {}; From 98b1080b2372bbf6e20bc7e86a7d6a155fdf5bc5 Mon Sep 17 00:00:00 2001 From: Matt Radbourne <1254508+mradbourne@users.noreply.github.com> Date: Thu, 6 Jun 2024 17:34:11 +0100 Subject: [PATCH 2/2] Handle .cjs modules in load function --- src/runtime.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/runtime.ts b/src/runtime.ts index cae4478..3053f6f 100644 --- a/src/runtime.ts +++ b/src/runtime.ts @@ -354,7 +354,8 @@ function load(parent?: string, specifier?: string) { switch (Path.extname(name).toLowerCase()) { case '.json': return (module.exports = JSON.parse(asset(id, 'utf-8'))); - case '.js': { + case '.js': + case '.cjs': { const dirname = new URL('./', url).toString(); const exec = new VM.Script(`(function module(module,exports,require,__dirname,__filename) {\n${asset(id, 'utf-8')}\n})`, { filename: id, lineOffset: -1 }).runInThisContext(); const main = modules[resolve().toString()];