require-from-url
Advanced tools
Comparing version 3.1.0 to 3.1.1
@@ -0,6 +1,8 @@ | ||
var parse = require("url").parse; | ||
var loader = require("./requireFromUrl.js"); | ||
var resolves = {}, listeners = {}; | ||
function addLoadListener(url, listener) { | ||
var href = url.href; | ||
function addLoadListener(urlString, listener) { | ||
var url = parse(urlString), | ||
href = url.href; | ||
if(href in resolves) listener(resolves[href]); | ||
@@ -7,0 +9,0 @@ else if(listeners[href]) listeners[href].push(listener); |
13
index.js
@@ -1,11 +0,10 @@ | ||
var parse = require("url").parse; | ||
var listen = require("./addLoadListener.js"); | ||
module.exports = function(_url, cb) { | ||
var _len = _url.length, | ||
values = Array(_len); | ||
_url.forEach(function(url, index) { | ||
listen(parse(url), function(value) { | ||
module.exports = function(urls, cb) { | ||
var len = urls.length, | ||
values = Array(len); | ||
urls.forEach(function(url, index) { | ||
listen(url, function(value) { | ||
values[index] = value; | ||
if(!--_len) { | ||
if(!--len) { | ||
for(var i=0; i<values.length; i++) | ||
@@ -12,0 +11,0 @@ if(values[i] instanceof Error) { |
{ | ||
"name": "require-from-url", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"description": "Require module from URL", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
17
sync.js
'use strict'; | ||
var parse = require("url").parse; | ||
var resolves = {}; | ||
var spawnSync = require('child_process').spawnSync; | ||
@@ -10,9 +12,14 @@ var options = { | ||
function sync(url) { | ||
var returns = spawnSync('node', ['fetch.js', url], options); | ||
var [err, str, filename] = JSON.parse(returns.stdout.toString()); | ||
if(err) throw new Error(err); | ||
return requireFromString(str, filename); | ||
function sync(urlString) { | ||
var url = parse(urlString), | ||
href = url.href; | ||
if(!resolves[href]) { | ||
var returns = spawnSync('node', ['fetch.js', href], options); | ||
var [err, str, filename] = JSON.parse(returns.stdout.toString()); | ||
if(err) throw new Error(err); | ||
resolves[href] = requireFromString(str, filename); | ||
} | ||
return resolves[href]; | ||
} | ||
module.exports = sync; |
4410
110