Skip to content

Commit

Permalink
Handle .cjs modules in load function
Browse files Browse the repository at this point in the history
  • Loading branch information
mradbourne committed Jun 6, 2024
1 parent 4b33d86 commit 98b1080
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()];
Expand Down

0 comments on commit 98b1080

Please sign in to comment.