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] 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()];