UNPKG

gulp-pathway

Version:

Gulp plugin to compile javascript source directories into Pathway modules

1 lines 1.48 kB
function makePathway(r,t){"use strict";function e(r,t){var e,a,f,s,u,c,w=i.get(r);if(void 0===w)throw new Error("Pathway: Failed to import package: '"+o(r)+"'"+(t?" from: "+t:""));if(w instanceof Array){e=w,w={},i.set(r,"In Progress!");var h=function(){};for(h.prototype=w,a=new h,c=e.length,u=0;c>u;u++)if(f=e[u](n(a,r),a),f&&"object"==typeof f)for(s in f){if(w.hasOwnProperty(s))throw new Error("Pathway: Key conflict: '"+s+"'"+(r?" at "+o(r):""));w[s]=f[s]}else if(void 0!==f)throw new Error("Pathway: Invalid export: '"+f+"' from "+o(r));i.set(r,w)}return w}function n(r,e){var n=o(e);return function(e){if("."===e)return r;var o,i=e.match(/^((@[^\/]*)?\/?)(.*)$/)||[],f=i[2],s=i[3];if(f){if("function"!=typeof t[f]){if(f.substr(1)in t)return t[f.substr(1)];throw new Error("Pathway: Failed to import library: "+e+" from "+n)}o=t[f](s,n)}else o=a(s,n);if("In Progress!"===o)throw new Error("Pathway: Circular import between: "+n+" and "+(e||"/"));return o}}function o(t){return"@"+r+"/"+t.replace(/^\//,"")}var i={set:function(r,t){return this["~"+(r||"/")]=t},get:function(r){return this["~"+(r||"/")]}},a=t["@"+r]=function(r,t,n){var a,f,s="/";switch(typeof r){case"string":s=r,a=t,f=n;break;case"function":a=r,f=t}var u=i.get(s);if("function"==typeof a){if(void 0===u&&(u=i.set(s,[])),!(u instanceof Array))throw new Error("Pathway: Package "+o(s)+" has already been initialized."+(f?" (from "+f+")":""));u.push(a)}else f=t,e(s,f);return i.get(s)};return a["import"]=a,a}