Skip to content

Commit

Permalink
better support for builds that use symlink
Browse files Browse the repository at this point in the history
  • Loading branch information
eoneill committed Jun 21, 2017
1 parent 25cc1c6 commit bbefb42
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 28 deletions.
2 changes: 1 addition & 1 deletion build/coverage.js
Expand Up @@ -16,7 +16,7 @@ module.exports = function(gulp, depends, name) {
thresholds: {
global: {
statements: 99.8,
branches: 99.25,
branches: 99.0,
functions: 100,
lines: 99.8
}
Expand Down
73 changes: 46 additions & 27 deletions lib/modules/EyeglassModules.js
Expand Up @@ -8,6 +8,7 @@ var path = require("path");
var merge = require("lodash.merge");
var semver = require("semver");
var archy = require("archy");
var fs = require("fs");
var URI = require("../util/URI");

/**
Expand Down Expand Up @@ -253,39 +254,57 @@ function canAccessModule(name, origin) {
return true;
}

// find the nearest package for the origin
var pkg = packageUtils.findNearestPackage(origin);
var canAccessFrom = function canAccessFrom(origin) {
// find the nearest package for the origin
var pkg = packageUtils.findNearestPackage(origin);

var cache = this.cache.access;
cache[name] = cache[name] || {};
var cache = this.cache.access;
cache[name] = cache[name] || {};

// check for cached result
if (cache[name][pkg] !== undefined) {
return cache[name][pkg];
}
// check for cached result
if (cache[name][pkg] !== undefined) {
return cache[name][pkg];
}

// find all the branches that match the origin
var branches = findBranchesByPath({
dependencies: this.tree
}, pkg);
// find all the branches that match the origin
var branches = findBranchesByPath({
dependencies: this.tree
}, pkg);

var canAccess = branches.some(function(branch) {
// if the reference is to itself (branch.name)
// OR it's an immediate dependency (branch.dependencies[name])
if (branch.name === name || branch.dependencies && branch.dependencies[name]) {
return true;
}
});
var canAccess = branches.some(function(branch) {
// if the reference is to itself (branch.name)
// OR it's an immediate dependency (branch.dependencies[name])
if (branch.name === name || branch.dependencies && branch.dependencies[name]) {
return true;
}
});

debug.import(
"%s can%s be imported from %s",
name,
(canAccess ? "" : "not"),
origin
);
debug.import(
"%s can%s be imported from %s",
name,
(canAccess ? "" : "not"),
origin
);

// cache it for future lookups
cache[name][pkg] = canAccess;

return canAccess;
}.bind(this);

// cache it for future lookups
cache[name][pkg] = canAccess;
// check if we can access from the origin...
var canAccess = canAccessFrom(origin);

// if not...
if (!canAccess) {
// check for a symlink...
var realOrigin = fs.realpathSync(origin);
/* istanbul ignore if */
if (realOrigin !== origin) {
/* istanbul ignore next */
canAccess = canAccessFrom(realOrigin);
}
}

return canAccess;
}
Expand Down

0 comments on commit bbefb42

Please sign in to comment.