this repo has no description
at develop 1.8 kB view raw
1 2function filePackagerPatch_getPreloadedPackageNode(filename) { 3 var fs = require('fs'); 4 var path = require('path'); 5 filename = path.normalize(path.resolve(__dirname, filename)); 6 const buf = fs.readFileSync(filename); 7 // convert to ArrayBuffer 8 return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength); 9} 10 11function filePackagerPatch_isNodeOrShell() { 12 var ENVIRONMENT_IS_WEB = typeof window === 'object'; 13 var ENVIRONMENT_IS_WORKER = typeof importScripts === 'function'; 14 var ENVIRONMENT_IS_NODE = typeof process === 'object' && typeof require === 'function' && !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_WORKER; 15 var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER; 16 return ENVIRONMENT_IS_NODE || ENVIRONMENT_IS_SHELL; 17} 18 19if (typeof location === 'undefined') { 20 // create a fake location to overrule the file_packager 21 var location = { 22 pathname: '/' 23 }; 24} 25 26if (filePackagerPatch_isNodeOrShell()) { 27 Module.getPreloadedPackage = Module.getPreloadedPackage || filePackagerPatch_getPreloadedPackageNode; 28} else { 29 // need a hack to locate relative file in browser settings for the file packager 30 var wrappee = Module.locateFile || function (path, prefix) {return prefix + path}; 31 Module.locateFile = function (path, prefix) { 32 if (prefix || !path.endsWith('.data')) { 33 return wrappee(path, prefix); 34 } 35 // file packager is called before a proper script location decection 36 var base = _scriptDir ? _scriptDir : (typeof importScripts === 'function' ? self.location.href : (typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : '')); 37 if (base.indexOf('blob:') !== 0) { 38 base = base.substr(0, base.lastIndexOf('/') + 1); 39 } else { 40 base = ''; 41 } 42 return wrappee(path, base); 43 }; 44}