Skip to content

Commit

Permalink
Merge branch 'Feature-2' of github.com:metcoder95/web-worker into met…
Browse files Browse the repository at this point in the history
…coder95-Feature-2
  • Loading branch information
developit committed Jan 31, 2025
2 parents 1fda46c + 4ce1305 commit 937775c
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* limitations under the License.
*/

import URL, { fileURLToPath } from 'node:url';
import URL, { fileURLToPath } from 'url';
import fs from 'fs';
import VM from 'vm';
import threads from 'worker_threads';

Expand Down Expand Up @@ -192,7 +193,7 @@ function workerThread() {
evaluateDataUrl(mod, name);
}
else {
require(mod);
importScripts(mod);
}
}
catch (err) {
Expand Down Expand Up @@ -221,3 +222,17 @@ function parseDataUrl(url) {
}
return { type, data };
}

function importScripts() {
for (let i = 0; i < arguments.length; i++) {
const url = arguments[i];
let code;
if (/^data:/.test(url)) {
code = parseDataUrl(url).data;
}
else {
code = fs.readFileSync(url, 'utf-8');
}
VM.runInThisContext(code, { filename: url });
}
}

0 comments on commit 937775c

Please sign in to comment.