Comparing version 0.4.1 to 0.4.2
@@ -210,3 +210,3 @@ makeInstaller = function (options) { | ||
function fileIsDirectory(file) { | ||
return isObject(file.c); | ||
return file && isObject(file.c); | ||
} | ||
@@ -305,3 +305,3 @@ | ||
function fileResolve(file, id) { | ||
function fileResolve(file, id, seenDirFiles) { | ||
file = | ||
@@ -322,13 +322,48 @@ // Absolute module identifiers (i.e. those that begin with a `/` | ||
// Node to find an `index.js` or `package.json` file to evaluate. | ||
while (file && fileIsDirectory(file)) { | ||
// If `package.json` does not exist, `fileEvaluate` will return the | ||
// `MISSING` object, which has no `.main` property. | ||
var pkg = fileEvaluate(fileAppendIdPart(file, "package.json")); | ||
file = pkg && isString(pkg.main) && | ||
fileAppendId(file, pkg.main) || // Might resolve to another directory! | ||
fileAppendIdPart(file, "index.js"); | ||
while (fileIsDirectory(file)) { | ||
seenDirFiles = seenDirFiles || []; | ||
// If the "main" field of a `package.json` file resolves to a | ||
// directory we've already considered, then we should not attempt to | ||
// read the same `package.json` file again. Using an array as a set | ||
// is acceptable here because the number of directories to consider | ||
// is rarely greater than 1 or 2. Also, using indexOf allows us to | ||
// store File objects instead of strings. | ||
if (seenDirFiles.indexOf(file) < 0) { | ||
seenDirFiles.push(file); | ||
// If `package.json` does not exist, `fileEvaluate` will return | ||
// the `MISSING` object, which has no `.main` property. | ||
var pkg = fileEvaluate(fileAppendIdPart(file, "package.json")); | ||
if (pkg && isString(pkg.main)) { | ||
// The "main" field of package.json does not have to begin with | ||
// ./ to be considered relative, so first we try simply | ||
// appending it to the directory path before falling back to a | ||
// full fileResolve, which might return a package from a | ||
// node_modules directory. | ||
file = fileAppendId(file, pkg.main) || | ||
fileResolve(file, pkg.main, seenDirFiles); | ||
if (file) { | ||
// The fileAppendId call above may have returned a directory, | ||
// so continue the loop to make sure we resolve it to a | ||
// non-directory file. | ||
continue; | ||
} | ||
} | ||
} | ||
// If we didn't find a `package.json` file, or it didn't have a | ||
// resolvable `.main` property, the only possibility left to | ||
// consider is that this directory contains an `index.js` module. | ||
// This assignment almost always terminates the while loop, because | ||
// there's very little chance `fileIsDirectory(file)` will be true | ||
// for the result of `fileAppendIdPart(file, "index.js")`. However, | ||
// in principle it is remotely possible that a file called | ||
// `index.js` could be a directory instead of a file. | ||
file = fileAppendIdPart(file, "index.js"); | ||
} | ||
if (file && isString(file.c)) { | ||
file = fileResolve(file, file.c); | ||
file = fileResolve(file, file.c, seenDirFiles); | ||
} | ||
@@ -335,0 +370,0 @@ |
@@ -1,1 +0,1 @@ | ||
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); | ||
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(x))throw e;t=x(r,n.m.id,e)}return t}return r.ready=function(r){return c(v(n,r))},k&&Object.keys(k).forEach(function(n){i(k[n])&&(r[n]=k[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 n&&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<y.length;++u){var o=t(n.c,r+y[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,t){for(n="/"===r.charAt(0)?d(g,r):"."===r.charAt(0)?d(n,r):h(n,r);l(n);){if(t=t||[],t.indexOf(n)<0){t.push(n);var e=a(p(n,"package.json"));if(e&&u(e.main)&&(n=d(n,e.main)||v(n,e.main,t)))continue}n=p(n,"index.js")}return n&&u(n.c)&&(n=v(n,n.c,t)),n}function h(n,r){return l(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,x=n.fallback,k=n.requireMethods,b={},w=b.hasOwnProperty,g=new f({});return r},"object"==typeof exports&&(exports.makeInstaller=makeInstaller); |
@@ -18,3 +18,3 @@ { | ||
], | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"license": "MIT", | ||
@@ -21,0 +21,0 @@ "homepage": "http://github.com/benjamn/install", |
424599
1152