resolvewithplus
Advanced tools
Comparing version 0.0.3 to 0.0.5
{ | ||
"name": "resolvewithplus", | ||
"version": "0.0.3", | ||
"version": "0.0.5", | ||
"license" : "MIT", | ||
@@ -20,4 +20,2 @@ "main": "src/resolvewithplus.js", | ||
], | ||
"dependencies" : { | ||
}, | ||
"devDependencies" : { | ||
@@ -24,0 +22,0 @@ "jasmine-node" : "~1.14.x", |
@@ -1,3 +0,3 @@ | ||
// Filename: resolvewith.js | ||
// Timestamp: 2015.12.15-07:20:04 (last modified) | ||
// Filename: resolvewithplus.js | ||
// Timestamp: 2016.02.12-16:47:59 (last modified) | ||
// Author(s): bumblehead <chris@bumblehead.com> | ||
@@ -8,3 +8,3 @@ | ||
var resolvewith = module.exports = (function (o) { | ||
var resolvewithplus = module.exports = (function (o) { | ||
@@ -27,6 +27,13 @@ o = function (requirepath, withpath, opts) { | ||
o.begin = function (requirepath, withpath, opts) { | ||
var fullpath = null; | ||
var fullpath = null, | ||
altrequirepath = null; | ||
if (typeof withpath === 'string') { | ||
withpath = o.getasdirname(withpath); | ||
// bower, tragically, allows parent package.json files to define alternative | ||
// paths to required files. More tragically, some pacakges use this behaviour | ||
if (opts.browser) { | ||
requirepath = o.getbower_alternate_requirepath(withpath, requirepath, opts) | ||
|| requirepath; | ||
} | ||
} else { | ||
@@ -75,5 +82,21 @@ withpath = process.cwd(); | ||
o.getbrowserindex = function (packagejson, opts) { | ||
var browserobj = opts && opts.browser && packagejson.browser, | ||
indexprop, | ||
indexval; | ||
if (browserobj) { | ||
indexprop = Object.keys(browserobj).filter(function (prop) { | ||
return /index.js$/.test(prop); | ||
})[0]; | ||
indexval = indexprop in browserobj && browserobj[indexprop]; | ||
} | ||
return indexval; | ||
}; | ||
o.getpackagepath = function (jsonfile, opts) { | ||
return o.isfilesync(jsonfile) && (jsonfile = require(jsonfile)) && | ||
((opts && opts.browser && jsonfile.browser && jsonfile.browser['index.js']) || jsonfile.main); | ||
(o.getbrowserindex(jsonfile, opts) || jsonfile.main); | ||
}; | ||
@@ -119,3 +142,3 @@ | ||
json_bower = path.join(d, 'bower.json'); | ||
if ((relpath = | ||
@@ -129,4 +152,4 @@ o.getpackagepath(json, opts) || | ||
'index.node'].some(function (f) { | ||
return o.isfilesync(path.join(d, f)) && (filepath = path.join(d, f)); | ||
}); | ||
return o.isfilesync(path.join(d, f)) && (filepath = path.join(d, f)); | ||
}); | ||
} | ||
@@ -168,2 +191,34 @@ | ||
o.getfirstparent_packagejson = function (start) { | ||
var join = path.join, | ||
parts = start.split(path.sep), x, | ||
packagejson, | ||
packagejsonpath; | ||
for (x = parts.length; x--;) { | ||
if (parts[x]) { | ||
packagejsonpath = join('/', join.apply(x, parts.slice(0, x + 1)), 'package.json'); | ||
if (o.isfilesync(packagejsonpath)) { | ||
packagejson = require(packagejsonpath); | ||
break; | ||
} | ||
} | ||
} | ||
return packagejson; | ||
}; | ||
o.getbower_alternate_requirepath = function (start, requirepath, opts) { | ||
var parent_packagejson = o.getfirstparent_packagejson(start), | ||
alternate_requirepath; | ||
if (parent_packagejson) { | ||
if (parent_packagejson.browser) { | ||
alternate_requirepath = parent_packagejson.browser[requirepath]; | ||
} | ||
} | ||
return alternate_requirepath; | ||
}; | ||
// https://nodejs.org/api/modules.html#modules_module_require_id | ||
@@ -196,3 +251,3 @@ // | ||
} | ||
return dirarr; | ||
@@ -199,0 +254,0 @@ }; |
// Filename: resolvewithplus.spec.js | ||
// Timestamp: 2015.12.15-07:19:46 (last modified) | ||
// Timestamp: 2016.02.12-17:06:52 (last modified) | ||
// Author(s): bumblehead <chris@bumblehead.com> | ||
@@ -9,6 +9,6 @@ | ||
describe("resolvewithplus", function () { | ||
/* | ||
it("should return the path to a bower module file", function () { | ||
expect( | ||
resolvewithplus('bowercomponent', './test/resolvewithplus.spec.js') | ||
resolvewithplus('bowercomponent', './test/resolvewithplus.spec.js', { browser : true }) | ||
).toBe( | ||
@@ -34,2 +34,3 @@ path.resolve('./test/bower_components/bowercomponent/src/bower-component.js') | ||
}); | ||
*/ | ||
}); | ||
@@ -150,3 +151,1 @@ | ||
}); | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14847
341
4