developit / web-worker

Consistent Web Workers in browser and Node.
https://npm.im/web-worker
Apache License 2.0
1.06k stars 55 forks source link

Add support for importScripts() #2

Open developit opened 4 years ago

developit commented 4 years ago

The implementation could be relatively simple:

const vm = require('vm');
const fs = require('fs');
function importScripts() {
  for (var i=0; i<arguments.length; i++) {
    var url = arguments[i];
    vm.runInThisContext(fs.readFileSync(url,'utf-8')),{ filename: url });
  }
}
metcoder95 commented 4 years ago

Hi! I would like to help, but is that all the context or really is so easy as the example?

developit commented 4 years ago

@MetCoder95 it should really just be that easy! We will just want to make sure this is only enabled when the Worker is instantiated without {type:'module'}.

AmitMY commented 2 years ago

Hi @developit Any chance of having this merged/fixed?