Comparing version 0.4.0 to 0.4.1
@@ -113,9 +113,11 @@ makeInstaller = function (options) { | ||
// `.c` property is a function that can be invoked with the appropriate | ||
// `(require, exports, module)` arguments to evaluate the module. The | ||
// `.p` (parent) property of a File is either a directory `File` or | ||
// `null`. Note that a child may claim another `File` as its parent even | ||
// if the parent does not have an entry for that child in its `.c` | ||
// object. This is important for implementing anonymous files, and | ||
// preventing child modules from using `../relative/identifier` syntax | ||
// to examine unrelated modules. | ||
// `(require, exports, module)` arguments to evaluate the module. If the | ||
// `.c` property is a string, that string will be resolved as a module | ||
// identifier, and the exports of the resulting module will provide the | ||
// exports of the original file. The `.p` (parent) property of a File is | ||
// either a directory `File` or `null`. Note that a child may claim | ||
// another `File` as its parent even if the parent does not have an | ||
// entry for that child in its `.c` object. This is important for | ||
// implementing anonymous files, and preventing child modules from using | ||
// `../relative/identifier` syntax to examine unrelated modules. | ||
function File(contents, /*optional:*/ parent, name) { | ||
@@ -151,7 +153,8 @@ var file = this; | ||
// When the file is a directory, `file.ready` is an object mapping | ||
// module identifiers to boolean ready statuses. This information can | ||
// be shared by all files in the directory, because module resolution | ||
// always has the same results for all files in a given directory. | ||
file.ready = fileIsDirectory(file) && {}; | ||
// When the file is a directory, `file.rc` is an object mapping module | ||
// identifiers to boolean ready statuses ("rc" is short for "ready | ||
// cache"). This information can be shared by all files in the | ||
// directory, because module resolution always has the same results | ||
// for all files in a given directory. | ||
file.rc = fileIsDirectory(file) && {}; | ||
} | ||
@@ -162,17 +165,33 @@ | ||
var result = !! file; | ||
var factory = file && file.c; | ||
var deps = isFunction(factory) && factory.d; | ||
if (deps && ! getOwn(factory, "seen")) { | ||
factory.seen = true; | ||
var parentReadyCache = file.p.ready; | ||
result = deps.every(function (dep) { | ||
// By storing the results of these lookups in `parentReadyCache`, | ||
// we benefit when any other file in the same directory resolves | ||
// the same identifier. | ||
return parentReadyCache[dep] = | ||
parentReadyCache[dep] || | ||
fileReady(fileResolve(file.p, dep)); | ||
}); | ||
factory.seen = false; | ||
var contents = file && file.c; | ||
if (contents && ! file.inReady) { | ||
file.inReady = true; | ||
if (isString(contents)) { | ||
// This file is aliased (or symbolically linked) to the file | ||
// obtained by resolving the contents string as a module | ||
// identifier, so regard it as ready iff the resolved file exists | ||
// and is ready. | ||
result = fileReady(fileResolve(file, contents)); | ||
} else if (isFunction(contents)) { | ||
var deps = contents.d; | ||
if (deps) { | ||
var parentReadyCache = file.p.rc; | ||
result = deps.every(function (dep) { | ||
// By storing the results of these lookups in `parentReadyCache`, | ||
// we benefit when any other file in the same directory resolves | ||
// the same identifier. | ||
return parentReadyCache[dep] = | ||
parentReadyCache[dep] || | ||
fileReady(fileResolve(file.p, dep)); | ||
}); | ||
} | ||
} | ||
file.inReady = false; | ||
} | ||
return result; | ||
@@ -182,7 +201,7 @@ } | ||
function fileEvaluate(file) { | ||
var factory = file && file.c; | ||
if (isFunction(factory)) { | ||
var contents = file && file.c; | ||
if (isFunction(contents)) { | ||
var module = file.m; | ||
if (! hasOwn.call(module, "exports")) { | ||
factory(file.r, module.exports = {}, module); | ||
contents(file.r, module.exports = {}, module); | ||
} | ||
@@ -223,5 +242,6 @@ return module.exports; | ||
} else if (! isObject(contents)) { | ||
// If contents is neither an array nor a function nor an object, | ||
// just give up and merge nothing. | ||
} else if (! isString(contents) && | ||
! isObject(contents)) { | ||
// If contents is neither an array nor a function nor a string nor | ||
// an object, just give up and merge nothing. | ||
contents = null; | ||
@@ -232,3 +252,3 @@ } | ||
var fileContents = file.c = file.c || ( | ||
isFunction(contents) ? contents : {} | ||
isObject(contents) ? {} : contents | ||
); | ||
@@ -315,2 +335,6 @@ | ||
if (file && isString(file.c)) { | ||
file = fileResolve(file, file.c); | ||
} | ||
return file; | ||
@@ -317,0 +341,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
makeInstaller=function(n){function r(n){return e(n)&&(l(g,n),u(j)&&j(g.r)),g.r}function t(n,r){return w.call(n,r)&&n[r]}function e(n){return n&&"object"==typeof n}function u(n){return"function"==typeof n}function o(n){return"string"==typeof n}function i(n){function r(r){var t=a(v(n,r));if(t===b){var e=new Error("Cannot find module '"+r+"'");if(!u(k))throw e;t=k(r,n.m.id,e)}return t}return r.ready=function(r){return c(v(n,r))},x&&Object.keys(x).forEach(function(n){u(x[n])&&(r[n]=x[n].bind(r))}),r}function f(n,r,t){var u=this;u.p=r=r||null,u.m=new m(t?(r&&r.m.id||"")+"/"+t:null,r&&r.m),u.q=r&&r.q,u.r=e(n)?i(u):r&&r.r,l(u,n),u.ready=s(u)&&{}}function c(n){var r=!!n,e=n&&n.c,o=u(e)&&e.d;if(o&&!t(e,"seen")){e.seen=!0;var i=n.p.ready;r=o.every(function(r){return i[r]=i[r]||c(v(n.p,r))}),e.seen=!1}return r}function a(n){var r=n&&n.c;if(u(r)){var t=n.m;return w.call(t,"exports")||r(n.r,t.exports={},t),t.exports}return b}function s(n){return e(n.c)}function l(n,r){if(Array.isArray(r)){var i=[];r.forEach(function(n){o(n)?i.push(n):u(n)&&(r=n)}),u(r)?r.d=i:r=null}else u(r)?r.d=r.d||[]:e(r)||(r=null);if(r){var c=n.c=n.c||(u(r)?r:{});e(r)&&s(n)&&Object.keys(r).forEach(function(e){var u=t(c,e);u?l(u,r[e]):c[e]=new f(r[e],n,e)})}}function p(n,r,e){for(;n&&!s(n);)n=n.p;if(!n||!r||"."===r)return n;if(".."===r)return n.p;var u=t(n.c,r);if(e&&(!u||s(u)))for(var o=0;o<y.length;++o){var i=t(n.c,r+y[o]);if(i)return i}return u}function d(n,r){var t=r.split("/");return t.every(function(r,e){return n=p(n,r,e===t.length-1)}),n}function v(n,r){for(n="/"===r.charAt(0)?d(g,r):"."===r.charAt(0)?d(n,r):h(n,r);n&&s(n);){var t=a(p(n,"package.json"));n=t&&o(t.main)&&d(n,t.main)||p(n,"index.js")}return n}function h(n,r){return s(n)&&d(n,"node_modules/"+r)||n.p&&h(n.p,r)}n=n||{};var y=n.extensions||[".js",".json"],m=n.Module||function(n,r){this.id=n,this.parent=r},j=n.onInstall,k=n.fallback,x=n.requireMethods,b={},w=b.hasOwnProperty,g=new f({});return r},"object"==typeof exports&&(exports.makeInstaller=makeInstaller); | ||
makeInstaller=function(n){function r(n){return e(n)&&(s(g,n),i(j)&&j(g.r)),g.r}function t(n,r){return w.call(n,r)&&n[r]}function e(n){return n&&"object"==typeof n}function i(n){return"function"==typeof n}function u(n){return"string"==typeof n}function o(n){function r(r){var t=a(v(n,r));if(t===b){var e=new Error("Cannot find module '"+r+"'");if(!i(k))throw e;t=k(r,n.m.id,e)}return t}return r.ready=function(r){return c(v(n,r))},x&&Object.keys(x).forEach(function(n){i(x[n])&&(r[n]=x[n].bind(r))}),r}function f(n,r,t){var i=this;i.p=r=r||null,i.m=new m(t?(r&&r.m.id||"")+"/"+t:null,r&&r.m),i.q=r&&r.q,i.r=e(n)?o(i):r&&r.r,s(i,n),i.rc=l(i)&&{}}function c(n){var r=!!n,t=n&&n.c;if(t&&!n.inReady){if(n.inReady=!0,u(t))r=c(v(n,t));else if(i(t)){var e=t.d;if(e){var o=n.p.rc;r=e.every(function(r){return o[r]=o[r]||c(v(n.p,r))})}}n.inReady=!1}return r}function a(n){var r=n&&n.c;if(i(r)){var t=n.m;return w.call(t,"exports")||r(n.r,t.exports={},t),t.exports}return b}function l(n){return e(n.c)}function s(n,r){if(Array.isArray(r)){var o=[];r.forEach(function(n){u(n)?o.push(n):i(n)&&(r=n)}),i(r)?r.d=o:r=null}else i(r)?r.d=r.d||[]:u(r)||e(r)||(r=null);if(r){var c=n.c=n.c||(e(r)?{}:r);e(r)&&l(n)&&Object.keys(r).forEach(function(e){var i=t(c,e);i?s(i,r[e]):c[e]=new f(r[e],n,e)})}}function p(n,r,e){for(;n&&!l(n);)n=n.p;if(!n||!r||"."===r)return n;if(".."===r)return n.p;var i=t(n.c,r);if(e&&(!i||l(i)))for(var u=0;u<h.length;++u){var o=t(n.c,r+h[u]);if(o)return o}return i}function d(n,r){var t=r.split("/");return t.every(function(r,e){return n=p(n,r,e===t.length-1)}),n}function v(n,r){for(n="/"===r.charAt(0)?d(g,r):"."===r.charAt(0)?d(n,r):y(n,r);n&&l(n);){var t=a(p(n,"package.json"));n=t&&u(t.main)&&d(n,t.main)||p(n,"index.js")}return n&&u(n.c)&&(n=v(n,n.c)),n}function y(n,r){return l(n)&&d(n,"node_modules/"+r)||n.p&&y(n.p,r)}n=n||{};var h=n.extensions||[".js",".json"],m=n.Module||function(n,r){this.id=n,this.parent=r},j=n.onInstall,k=n.fallback,x=n.requireMethods,b={},w=b.hasOwnProperty,g=new f({});return r},"object"==typeof exports&&(exports.makeInstaller=makeInstaller); |
@@ -18,3 +18,3 @@ { | ||
], | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"license": "MIT", | ||
@@ -21,0 +21,0 @@ "homepage": "http://github.com/benjamn/install", |
422808
1121