scratch-vm/test/fixtures/dispatch-test-worker-shim.js

22 lines
688 B
JavaScript
Raw Normal View History

const Module = require('module');
const callsite = require('callsite');
const path = require('path');
const oldRequire = Module.prototype.require;
Module.prototype.require = function (target) {
if (target.indexOf('/') === -1) {
2023-12-15 20:40:25 -05:00
// we really do just want to forward the arguments here
// eslint-disable-next-line prefer-rest-params
return oldRequire.apply(this, arguments);
}
const stack = callsite();
const callerFile = stack[2].getFileName();
const callerDir = path.dirname(callerFile);
target = path.resolve(callerDir, target);
return oldRequire.call(this, target);
};
oldRequire(path.resolve(__dirname, 'dispatch-test-worker'));