Comparing version 1.0.1 to 1.0.2
@@ -6,4 +6,3 @@ 'use strict'; | ||
path = require('path'); | ||
var getComponentName = require('../getComponentName'), | ||
pkg = require(path.resolve(process.cwd(), 'package.json')); | ||
var getComponentName = require('../getComponentName'); | ||
@@ -15,5 +14,6 @@ | ||
* @param {string} name, e.g. 'clay-header' | ||
* @param {object} pkg for testing | ||
* @returns {string|undefined} e.g. '@nymdev/clay-header' | ||
*/ | ||
function getScopedModuleName(name) { | ||
function getScopedModuleName(name, pkg) { | ||
return _.findKey(pkg.dependencies, function (version, dep) { | ||
@@ -28,5 +28,6 @@ return _.includes(dep, name); | ||
* @param {string} name | ||
* @param {object} pkg for testing | ||
* @return {string} | ||
*/ | ||
function getComponentPath(name) { | ||
function getComponentPath(name, pkg = require(path.resolve(process.cwd(), 'package.json'))) { | ||
let result = null, | ||
@@ -42,3 +43,3 @@ modulePath, npmName; | ||
} else { | ||
npmName = getScopedModuleName(name); | ||
npmName = getScopedModuleName(name, pkg); | ||
modulePath = npmName && path.resolve(process.cwd(), 'node_modules', npmName); | ||
@@ -56,2 +57,1 @@ result = modulePath; | ||
module.exports.setGetComponentName = (mod) => { getComponentName = mod; }; | ||
module.exports.setPackageConfiguration = (val) => { pkg = val; }; |
@@ -22,4 +22,2 @@ 'use strict'; | ||
// package file can never be real | ||
lib.setPackageConfiguration(pkg); | ||
lib.setGetComponentName(getComponentName); | ||
@@ -50,17 +48,17 @@ lib.cache = new _.memoize.Cache(); | ||
it('returns null if name isn\'t a component', function () { | ||
expect(lib('c0')).to.equal(null); | ||
expect(lib('c0', pkg)).to.equal(null); | ||
}); | ||
it('gets an internal path', function () { | ||
expect(lib('c1')).to.equal('components/c1'); | ||
expect(lib('c1', pkg)).to.equal('components/c1'); | ||
}); | ||
it('gets an npm path', function () { | ||
expect(lib('clay-c3')).to.equal('node_modules/clay-c3'); | ||
expect(lib('clay-c3', pkg)).to.equal('node_modules/clay-c3'); | ||
}); | ||
it('gets a scoped npm path', function () { | ||
expect(lib('clay-c5')).to.equal('node_modules/@a/clay-c5'); | ||
expect(lib('clay-c5', pkg)).to.equal('node_modules/@a/clay-c5'); | ||
}); | ||
}); | ||
}); |
@@ -10,4 +10,3 @@ 'use strict'; | ||
var getFolders = require('../getFolders'), | ||
pkg = require(path.resolve(process.cwd(), 'package.json')); | ||
var getFolders = require('../getFolders'); | ||
@@ -18,5 +17,6 @@ /** | ||
* Should only occur once! | ||
* @param {object} pkg injected for testing | ||
* @return {[]} | ||
*/ | ||
function getComponents() { | ||
function getComponents(pkg = require(path.resolve(process.cwd(), 'package.json'))) { | ||
const npmComponents = _(pkg.dependencies).map(function (version, name) { | ||
@@ -41,5 +41,4 @@ if (_.includes(name, 'clay-') && !_.includes(IGNORED_CLAY_MODULES, name) ) { | ||
// For testing | ||
module.exports.setPackageConfiguration = (val) => { pkg = val; }; | ||
module.exports.setDeps = (gF) => { | ||
getFolders = gF; | ||
}; |
@@ -19,5 +19,2 @@ 'use strict'; | ||
lib.cache = new _.memoize.Cache(); | ||
// package file can never be real | ||
lib.setPackageConfiguration(pkg); | ||
}); | ||
@@ -32,4 +29,3 @@ | ||
getFolders.returns([]); | ||
lib.setPackageConfiguration({ dependencies: [] }); | ||
expect(lib()).to.eql([]); | ||
expect(lib({ dependencies: [] })).to.eql([]); | ||
}); | ||
@@ -40,3 +36,3 @@ | ||
expect(lib()).to.contain('c1', 'c2'); | ||
expect(lib(pkg)).to.contain('c1', 'c2'); | ||
}); | ||
@@ -47,5 +43,5 @@ | ||
expect(lib()).to.contain('clay-c3', 'clay-c4'); | ||
expect(lib(pkg)).to.contain('clay-c3', 'clay-c4'); | ||
}); | ||
}); | ||
}); |
{ | ||
"name": "amphora-fs", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "File system utils for Amphora and the Clay ecosystem", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
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
46097
1246