UNPKG

systemjs-cjs-extra

Version:

An extra for SystemJS 6 to load CommonJS modules in the browser

8 lines (7 loc) 3.09 kB
(function(c){"use strict";const u=/(?:^\uFEFF?|[^$_a-zA-Z\xA0-\uFFFF."'])require\s*\(\s*("[^"\\]*(?:\\.[^"\\]*)*"|'[^'\\]*(?:\\.[^'\\]*)*'|`[^`\\]*(?:\\.[^`\\]*)*`)\s*\)/g,R=/(?:^\uFEFF?|[^$_a-zA-Z\xA0-\uFFFF.])define\s*\(\s*("[^"]+"\s*,\s*|'[^']+'\s*,\s*)?\s*(\[(\s*(("[^"]+"|'[^']+')\s*,|\/\/.*\r?\n|\/\*(.|\s)*?\*\/))*(\s*("[^"]+"|'[^']+')\s*,?)?(\s*(\/\/.*\r?\n|\/\*(.|\s)*?\*\/))*\s*\]|function\s*|{|[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*\))/,S=/(?:^\uFEFF?|[^$_a-zA-Z\xA0-\uFFFF.])(exports\s*(\[['"]|\.)|module(\.exports|\['exports'\]|\["exports"\])\s*(\[['"]|[=,\.]))/,y=/__filename|__dirname]/,_=/(^|[^\\])(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,m=/("[^"\\\n\r]*(\\.[^"\\\n\r]*)*"|'[^'\\\n\r]*(\\.[^'\\\n\r]*)*')/g,p=/^[^#?]+\.js([?#].*)?$/,A=/^(text|application)\/(x-)?javascript(;|$)/;function I(t){return!R.test(t)&&(u.test(t)||S.test(t)||y.test(t))}function x(t,n){return(n||"")+" (SystemJS Error#"+t+" https://github.com/systemjs/systemjs/blob/main/docs/errors.md#"+t+")"}function L(t){const n=t.substring(t.lastIndexOf("/")+1);let s=t.split("/");return s.pop(),s=s.join("/"),{filename:n,dirname:s}}function G(t){u.lastIndex=_.lastIndex=m.lastIndex=0;let n=[],s=[],r=[],e;if(t.length/t.split(` `).length<200){for(;e=m.exec(t);)s.push([e.index,e.index+e[0].length]);for(;e=_.exec(t);)d(s,e)||r.push([e.index+e[1].length,e.index+e[0].length-1])}for(;e=u.exec(t);)if(!d(s,e)&&!d(r,e)){var i=e[1].substring(1,e[1].length-1);if(i.match(/"|'/))continue;n.push(i)}return n}function d(t,n){for(var s=0;s<t.length;s++)if(t[s][0]<n.index&&t[s][1]>n.index)return!0;return!1}function T(t){return`(function (module,exports,require,__filename,__dirname, global, GLOBAL) { ${t} }).apply(__cjsWrapper.exports, __cjsWrapper.args)`}function j(t,n){return function(r){const e=t.resolve(r,n),i=t.get(e);if(!i)throw new Error('Module not already loaded loading "'+r+'" as '+e+(n?' from "'+n+'".':"."));return"__useDefault"in i?i.default:i}}const o=c.System.constructor.prototype,l=o.instantiate,J=o.shouldFetch.bind(o);o.shouldFetch=function(t){return J(t)||p.test(t)},o.instantiate=function(t,n,s){const r=p.test(t);return this.shouldFetch(t)?r?o.fetch(t,{credentials:"same-origin",meta:s}).then(e=>{if(!e.ok)throw Error(x(7,e.status+" "+e.statusText+", loading "+t+(n?" from "+n:"")));const i=e.headers.get("content-type");if(!i||!A.test(i))throw Error(x(4,'Unknown Content-Type "'+i+'", loading '+t+(n?" from "+n:"")));return e.text().then(a=>{if(I(a)){const h={},F={exports:h},X=j(this,n??t),E=G(a),$=E.map(f=>c.System.import(f,n??t));return Promise.all($).then(()=>{let f=T(a);f.indexOf("//# sourceURL=")<0&&(f+=` //# sourceURL=`+t);const{filename:v,dirname:w}=L(t);return c.__cjsWrapper={exports:h,args:[F,h,X,v,w,c,c]},(0,eval)(f),c.__cjsWrapper=void 0,o.register(E,function(g){return{setters:[],execute:function(){g(F.exports),g("default",F.exports)}}}),o.getRegister(t)})}else return a.indexOf("//# sourceURL=")<0&&(a+=` //# sourceURL=`+t),(0,eval)(a),o.getRegister(t)})}):l.call(this,t,n,s):l.call(this,t,n,s)}})(typeof self<"u"?self:global); //# sourceMappingURL=index.min.js.map