Skip to content

Commit 4ce1305

Browse files
committed
Feature: Add support for importScripts
1 parent 4a46d3a commit 4ce1305

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

node.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import URL from 'url';
18+
import fs from 'fs';
1819
import VM from 'vm';
1920
import threads from 'worker_threads';
2021

@@ -187,7 +188,7 @@ function workerThread() {
187188
evaluateDataUrl(mod, name);
188189
}
189190
else {
190-
require(mod);
191+
importScripts(mod);
191192
}
192193
}
193194
catch (err) {
@@ -216,3 +217,10 @@ function parseDataUrl(url) {
216217
}
217218
return { type, data };
218219
}
220+
221+
function importScripts(...fileNames) {
222+
for (let i=0; i < fileNames.length; i++) {
223+
const url = fileNames[i];
224+
VM.runInThisContext(fs.readFileSync(url,'utf-8'),{ filename: url });
225+
}
226+
}

0 commit comments

Comments
 (0)