Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

main-bower-files

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

main-bower-files - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

.jscsrc

2

index.js

@@ -1,1 +0,1 @@

module.exports = process.env.LIB_COV ? require('./lib-cov') : require('./lib')
module.exports = process.env.LIB_COV ? require('./lib-cov') : require('./lib');

@@ -1,25 +0,27 @@

var fs = require("fs");
var path = require("path");
var PackageCollection = require("./package_collection");
var logger = require("./logger");
var fs = require('fs'),
path = require('path'),
PackageCollection = require('./package_collection');
module.exports = function(opts){
var collection, files;
var defaults = {
paths: {
bowerJson : "./bower.json",
bowerrc : "./.bowerrc",
bowerDirectory: "./bower_components"
}
}
module.exports = function(opts) {
var collection,
files,
bowerrcJson,
defaults = {
paths: {
bowerJson: './bower.json',
bowerrc: './.bowerrc',
bowerDirectory: './bower_components'
}
};
opts = opts || {};
if(!opts.paths)
opts.paths = {}
if (!opts.paths) {
opts.paths = {};
}
if(typeof opts.paths === 'string'){
opts.paths.bowerJson = path.join(opts.paths, defaults.paths.bowerJson)
opts.paths.bowerrc = path.join(opts.paths, defaults.paths.bowerrc)
opts.paths.bowerDirectory = path.join(opts.paths, defaults.paths.bowerDirectory)
if (typeof opts.paths === 'string'){
opts.paths.bowerJson = path.join(opts.paths, defaults.paths.bowerJson);
opts.paths.bowerrc = path.join(opts.paths, defaults.paths.bowerrc);
opts.paths.bowerDirectory = path.join(opts.paths, defaults.paths.bowerDirectory);
}

@@ -31,24 +33,31 @@

if(fs.existsSync(opts.paths.bowerrc)){
var bowerrcJson = JSON.parse(fs.readFileSync(opts.paths.bowerrc));
if (fs.existsSync(opts.paths.bowerrc)){
bowerrcJson = JSON.parse(fs.readFileSync(opts.paths.bowerrc));
if (bowerrcJson && bowerrcJson.directory) {
opts.paths.bowerDirectory = path.dirname(opts.paths.bowerrc);
opts.paths.bowerDirectory = path.join(opts.paths.bowerDirectory, "/", bowerrcJson.directory);
opts.paths.bowerDirectory = path.join(
opts.paths.bowerDirectory,
'/',
bowerrcJson.directory
);
}
}
if(!opts.paths.bowerJson || !fs.existsSync(opts.paths.bowerJson)){
throw new Error("bower.json file does not exist at " + opts.paths.bowerJson);
if (!opts.paths.bowerJson || !fs.existsSync(opts.paths.bowerJson)){
throw new Error('bower.json file does not exist at ' + opts.paths.bowerJson);
}
if(!opts.paths.bowerDirectory || !fs.existsSync(opts.paths.bowerDirectory)){
throw new Error("Bower components directory does not exist at " + opts.paths.bowerDirectory);
if (!opts.paths.bowerDirectory || !fs.existsSync(opts.paths.bowerDirectory)){
throw new Error('Bower components directory does not exist at ' +
opts.paths.bowerDirectory);
}
if(!opts.base)
if (!opts.base) {
opts.base = opts.paths.bowerDirectory;
}
if(!opts.includeDev)
if (!opts.includeDev) {
opts.includeDev = false;
}

@@ -58,3 +67,11 @@ try {

files = collection.getFiles();
} catch(e) {
if (opts.filter instanceof RegExp) {
files = files.filter(function(file) {
return opts.filter.test(file);
});
} else if (typeof opts.filter === 'function') {
files = files.filter(opts.filter);
}
} catch (e) {
throw e;

@@ -64,2 +81,2 @@ }

return files || [];
}
};
require('colors');
var colors = ['red', 'blue', 'magenta', 'grey', 'yellow', 'green']
var colors = ['red', 'blue', 'magenta', 'grey', 'yellow', 'green'];
module.exports = logger = function() {
module.exports = function() {
var args = Array.prototype.slice.call(arguments);

@@ -13,2 +13,2 @@

console.log.apply(console.log, args);
}
};

@@ -1,5 +0,6 @@

var path = require("path");
var fs = require("fs");
var Package = require("./package");
var logger = require("./logger");
var path = require('path'),
fs = require('fs'),
Package = require('./package'),
logger = require('./logger'),
PackageCollection;

@@ -16,3 +17,3 @@ /**

*/
var PackageCollection = function(opts) {
PackageCollection = function(opts) {
this.opts = opts;

@@ -29,3 +30,3 @@ this.opts.main = opts.main || null;

this.collectPackages();
}
};

@@ -40,7 +41,8 @@ PackageCollection.prototype = {

add: function(name, path) {
if(typeof this._packages[name] !== "undefined")
if (typeof this._packages[name] !== 'undefined') {
return;
}
if(this.debugging) {
logger("PackageCollection", "add\t\t", name, path);
if (this.debugging) {
logger('PackageCollection', 'add\t\t', name, path);
}

@@ -50,3 +52,3 @@

var opts = this.overrides[name] || {}
var opts = this.overrides[name] || {};
opts.name = name;

@@ -62,12 +64,14 @@ opts.path = path;

collectPackages: function() {
if(!fs.existsSync(this.opts.paths.bowerJson))
throw new Error("bower.json does not exist at: " + this.opts.paths.bowerJson);
if (!fs.existsSync(this.opts.paths.bowerJson)) {
throw new Error('bower.json does not exist at: ' + this.opts.paths.bowerJson);
}
var bowerJson = JSON.parse(fs.readFileSync(this.opts.paths.bowerJson, "utf8"));
var dependencies = bowerJson.dependencies || {};
var name,
bowerJson = JSON.parse(fs.readFileSync(this.opts.paths.bowerJson, 'utf8')),
dependencies = bowerJson.dependencies || {};
this.overrides = bowerJson.overrides || {};
if(this.opts.includeDev === true && bowerJson.devDependencies) {
for(var name in bowerJson.devDependencies) {
if (this.opts.includeDev === true && bowerJson.devDependencies) {
for (name in bowerJson.devDependencies) {
dependencies[name] = bowerJson.devDependencies[name];

@@ -77,4 +81,4 @@ }

for(var name in dependencies) {
this.add(name, path.join(this.opts.paths.bowerDirectory, "/", name));
for (name in dependencies) {
this.add(name, path.join(this.opts.paths.bowerDirectory, '/', name));
}

@@ -89,3 +93,3 @@ },

getFiles: function() {
for(var name in this._packages) {
for (var name in this._packages) {
this._queue.push(this._packages[name]);

@@ -104,7 +108,7 @@ }

process: function() {
var queue = this._queue;
var srcs = [];
var force = false;
var queue = this._queue,
srcs = [],
force = false;
if(this._lastQueueLength === queue.length) {
if (this._lastQueueLength === queue.length) {
force = true;

@@ -120,3 +124,3 @@ }

if(packageSrcs === false) {
if (packageSrcs === false) {
return this._queue.push(package);

@@ -129,3 +133,3 @@ }

if(this._queue.length) {
if (this._queue.length) {
srcs.push.apply(srcs, this.process());

@@ -138,2 +142,2 @@ }

module.exports = PackageCollection;
module.exports = PackageCollection;

@@ -1,5 +0,6 @@

var path = require("path");
var fs = require("fs");
var glob = require("glob");
var logger = require("./logger");
var path = require('path'),
fs = require('fs'),
glob = require('glob'),
logger = require('./logger'),
Package;

@@ -17,4 +18,4 @@ /**

*/
var Package = function(opts, collection) {
this.collection = collection;
Package = function(opts, collection) {
this.collection = collection;
this.name = opts.name || null;

@@ -27,7 +28,9 @@ this.path = opts.path || null;

if(this.ignore) return;
if (this.ignore) {
return;
}
this.collectData();
this.addDependencies();
}
};

@@ -40,28 +43,50 @@ Package.prototype = {

var paths = [
path.join(this.path, ".bower.json"),
path.join(this.path, "bower.json"),
path.join(this.path, "package.json"),
path.join(this.path, "component.json")
];
path.join(this.path, '.bower.json'),
path.join(this.path, 'bower.json'),
path.join(this.path, 'package.json'),
path.join(this.path, 'component.json')
],
data = paths.reduce(function(prev, curr) {
if (prev !== null) {
return prev;
}
var data = paths.reduce(function(prev, curr) {
if(prev !== null) return prev;
if (!fs.existsSync(curr)) {
return prev;
}
if(!fs.existsSync(curr)) return prev;
try {
return JSON.parse(fs.readFileSync(curr, 'utf8'));
} catch (e) {
return null;
}
}, null);
try {
return JSON.parse(fs.readFileSync(curr, "utf8"));;
} catch(e) {
return null;
}
}, null);
if(data === null)
if (data === null) {
return;
}
if(!this.main && data.main)
if (!this.main && data.main) {
this.main = data.main;
if(this.dependencies === undefined && data.dependencies && data.dependencies)
if (this.debugging) {
logger('Package\t\t', 'overriding main\t', this.name, data.main);
}
}
if (!this.main && this.collection.opts.checkExistence === true) {
throw new Error('Main property of package "' + this.name + '" is missing.');
}
if (this.dependencies === undefined && data.dependencies && data.dependencies) {
this.dependencies = data.dependencies;
if (this.debugging) {
logger(
'Package\t\t',
'overriding depedependencies\t',
this.name,
data.dependencies);
}
}
},

@@ -73,4 +98,4 @@

addDependencies: function() {
for(var name in this.dependencies) {
this.collection.add(name, path.join(this.path, "..", name));
for (var name in this.dependencies) {
this.collection.add(name, path.join(this.path, '..', name));
}

@@ -82,14 +107,25 @@ },

*
* @param {Boolean} force If true it will not wait for the dependencies
* @return {Mixed} Returns false if the package has dependencies which were not processed yet otherwise an array of file paths
* @param {Boolean}
* force If true it will not wait for the dependencies
* @return {Mixed}
* Returns false if the package has dependencies which were not
* processed yet otherwise an array of file paths
*/
getFiles: function(force) {
if(this.ignore) return [];
if(this.main === null && (this.main = this.collection.opts.main) === null) return [];
if (this.ignore) {
return [];
}
var main = this.main;
var files = [];
if (this.main === null && (this.main = this.collection.opts.main) === null) {
return [];
}
if(typeof main === "object" && !Array.isArray(main)) {
if(!(main = main[this.collection.opts.env])) return [];
var main = this.main,
files = [],
name;
if (typeof main === 'object' &&
!Array.isArray(main) &&
!(main = main[this.collection.opts.env])) {
return [];
}

@@ -99,5 +135,5 @@

if(force !== true) {
for(var name in this.dependencies) {
if(this.collection._processed[name] !== true) {
if (force !== true) {
for (name in this.dependencies) {
if (this.collection._processed[name] !== true) {
return false;

@@ -113,4 +149,5 @@ }

if(!_files.length && this.collection.opts.checkExistence === true) {
throw new Error("File on path '" + path.join(this.path, pattern) + "' does not exist.");
if (!_files.length && this.collection.opts.checkExistence === true) {
throw new Error('File on path "' + path.join(this.path, pattern) +
'" does not exist.');
}

@@ -123,5 +160,5 @@

if(this.debugging) {
if (this.debugging) {
files.forEach(function(file) {
logger("Package\t\t", "select file\t", this.name, file);
logger('Package\t\t', 'select file\t', this.name, file);
}.bind(this));

@@ -134,2 +171,2 @@ }

module.exports = Package;
module.exports = Package;
{
"name": "main-bower-files",
"version": "1.0.1",
"version": "1.0.2",
"description": "Get main files from your installed bower packages.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1,1 +0,1 @@

// I do nothing
// I do nothing

@@ -1,1 +0,1 @@

// I do nothing
// I do nothing

@@ -1,1 +0,1 @@

// I do nothing
// I do nothing

@@ -1,1 +0,1 @@

// I do nothing and should not be listed.
// I do nothing and should not be listed.

@@ -1,1 +0,1 @@

// I do nothing and should not be on the list, because I was ignored by the bower.json
// I do nothing and should not be on the list, because I was ignored by the bower.json

@@ -1,1 +0,1 @@

// I do nothing
// I do nothing

@@ -1,1 +0,1 @@

// I do nothing
// I do nothing

@@ -1,1 +0,1 @@

// I do nothing, but I am on the list!
// I do nothing, but I am on the list!

@@ -1,1 +0,1 @@

// I do nothing and should not be on the list, because I was overwritten by the bower.json
// I do nothing and should not be on the list, because I was overwritten by the bower.json

@@ -1,1 +0,1 @@

// I do nothing
// I do nothing

@@ -1,1 +0,1 @@

// I do nothing
// I do nothing

@@ -1,6 +0,7 @@

var mainBowerFiles = require("../");
var path = require("path");
var should = require("should");
var mainBowerFiles = require('../'),
path = require('path');
describe('main-bower-files', function () {
require('should');
describe('main-bower-files', function() {
function expect(filenames) {

@@ -14,16 +15,19 @@ var expectedFiles = [].concat(filenames).map(function(filename) {

if(!options.paths)
if (!options.paths) {
options.paths = {};
}
if(!options.paths.bowerJson)
if (!options.paths.bowerJson) {
options.paths.bowerJson = __dirname + path;
}
if(!options.paths.bowerrc)
options.paths.bowerrc = __dirname + "/.bowerrc"
if (!options.paths.bowerrc) {
options.paths.bowerrc = __dirname + '/.bowerrc';
}
var srcFiles = mainBowerFiles(options)
var srcFiles = mainBowerFiles(options);
expectedFiles.should.be.eql(srcFiles);
if(done) {
if (done) {
done();

@@ -39,32 +43,53 @@ }

}
}
};
}
}
};
}
it('should select the expected files', function (done) {
it('should select the expected files', function(done) {
expect([
"/fixtures/simple/simple.js",
"/fixtures/overwritten/another.js",
"/fixtures/multi/multi.js",
"/fixtures/multi/multi.css",
"/fixtures/hasPackageNoBower/hasPackageNoBower.js",
"/fixtures/deepPaths/lib/deeppaths.js",
"/fixtures/decoy/decoy.js"
]).fromConfig("/_bower.json").when(done);
'/fixtures/simple/simple.js',
'/fixtures/overwritten/another.js',
'/fixtures/multi/multi.js',
'/fixtures/multi/multi.css',
'/fixtures/hasPackageNoBower/hasPackageNoBower.js',
'/fixtures/deepPaths/lib/deeppaths.js',
'/fixtures/decoy/decoy.js'
]).fromConfig('/_bower.json').when(done);
});
it('should select the expected files with relative path', function (done) {
it('should select only files that pass a given filter regular expression', function(done) {
expect([
"/fixtures/simple/simple.js",
"/fixtures/overwritten/another.js",
"/fixtures/multi/multi.js",
"/fixtures/multi/multi.css",
"/fixtures/hasPackageNoBower/hasPackageNoBower.js",
"/fixtures/deepPaths/lib/deeppaths.js",
"/fixtures/decoy/decoy.js"
]).fromConfig("/_bower.json", {
'/fixtures/simple/simple.js',
'/fixtures/overwritten/another.js',
'/fixtures/multi/multi.js',
'/fixtures/hasPackageNoBower/hasPackageNoBower.js',
'/fixtures/deepPaths/lib/deeppaths.js',
'/fixtures/decoy/decoy.js'
]).fromConfig('/_bower.json', { filter: /\.js$/i }).when(done);
});
it('should select only files that pass a given filter callback', function(done) {
expect([
'/fixtures/decoy/decoy.js'
]).fromConfig('/_bower.json', {
filter: function(file) {
return file.indexOf('decoy.js') > -1;
}
}).when(done);
});
it('should select the expected files with relative path', function(done) {
expect([
'/fixtures/simple/simple.js',
'/fixtures/overwritten/another.js',
'/fixtures/multi/multi.js',
'/fixtures/multi/multi.css',
'/fixtures/hasPackageNoBower/hasPackageNoBower.js',
'/fixtures/deepPaths/lib/deeppaths.js',
'/fixtures/decoy/decoy.js'
]).fromConfig('/_bower.json', {
paths: {
bowerJson: "./test/_bower.json",
bowerDirectory: "./test/fixtures",
bowerJson: './test/_bower.json',
bowerDirectory: './test/fixtures'
}

@@ -74,71 +99,71 @@ }).when(done);

it("should ignore packages without any json files", function(done) {
it('should ignore packages without any json files', function(done) {
expect([
"/fixtures/simple/simple.js"
]).fromConfig("/_nojson_bower.json").when(done);
'/fixtures/simple/simple.js'
]).fromConfig('/_nojson_bower.json').when(done);
});
it("should select files via default option", function(done) {
it('should select files via default option', function(done) {
expect([
"/fixtures/noconfig/noconfig.js",
"/fixtures/simple/simple.js"
]).fromConfig("/_nojson_bower.json", { main: "./**/*.js" }).when(done);
'/fixtures/noconfig/noconfig.js',
'/fixtures/simple/simple.js'
]).fromConfig('/_nojson_bower.json', { main: './**/*.js' }).when(done);
});
it("should recurse through dependencies pulling in their dependencies", function(done) {
it('should recurse through dependencies pulling in their dependencies', function(done) {
expect([
"/fixtures/simple/simple.js",
"/fixtures/recursive/recursive.js"
]).fromConfig("/_recursive_bower.json").when(done);
'/fixtures/simple/simple.js',
'/fixtures/recursive/recursive.js'
]).fromConfig('/_recursive_bower.json').when(done);
});
it("should not get hungup on cyclic dependencies", function(done) {
it('should not get hungup on cyclic dependencies', function(done) {
expect([
"/fixtures/cyclic-a/cyclic-a.js",
"/fixtures/cyclic-b/cyclic-b.js",
]).fromConfig("/_cyclic_bower.json").when(done);
'/fixtures/cyclic-a/cyclic-a.js',
'/fixtures/cyclic-b/cyclic-b.js'
]).fromConfig('/_cyclic_bower.json').when(done);
});
it("should get devDependencies", function(done) {
it('should get devDependencies', function(done) {
expect([
"/fixtures/simple/simple.js",
"/fixtures/includeDev/includeDev.js"
]).fromConfig("/_includedev_bower.json", { includeDev: true }).when(done);
'/fixtures/simple/simple.js',
'/fixtures/includeDev/includeDev.js'
]).fromConfig('/_includedev_bower.json', { includeDev: true }).when(done);
});
it("should get devDependencies from a bower.json with no 'dependencies' section", function(done) {
it('should get devDependencies and ignore missing dependencies', function(done) {
expect([
"/fixtures/includeDev/includeDev.js"
]).fromConfig("/_includedev_devdepsonly_bower.json", { includeDev: true }).when(done);
'/fixtures/includeDev/includeDev.js'
]).fromConfig('/_includedev_devdepsonly_bower.json', { includeDev: true }).when(done);
});
it("should not load any deeper dependencies", function(done) {
it('should not load any deeper dependencies', function(done) {
expect([
"/fixtures/recursive/recursive.js"
]).fromConfig("/_dependencies_bower.json").when(done);
'/fixtures/recursive/recursive.js'
]).fromConfig('/_dependencies_bower.json').when(done);
});
it("should load other dependencies than defined", function(done) {
it('should load other dependencies than defined', function(done) {
expect([
"/fixtures/decoy/decoy.js",
"/fixtures/recursive/recursive.js"
]).fromConfig("/_other_dependencies_bower.json").when(done);
'/fixtures/decoy/decoy.js',
'/fixtures/recursive/recursive.js'
]).fromConfig('/_other_dependencies_bower.json').when(done);
});
it("should select prod.js on prod environment", function(done) {
process.env.NODE_ENV = "prod";
it('should select prod.js on prod environment', function(done) {
process.env.NODE_ENV = 'prod';
expect([
"/fixtures/envBased/prod.js"
]).fromConfig("/_env_based_bower.json").when(done);
'/fixtures/envBased/prod.js'
]).fromConfig('/_env_based_bower.json').when(done);
});
it("should select dev.js on dev environment", function(done) {
process.env.NODE_ENV = "dev";
it('should select dev.js on dev environment', function(done) {
process.env.NODE_ENV = 'dev';
expect([
"/fixtures/envBased/dev.js"
]).fromConfig("/_env_based_bower.json").when(done);
'/fixtures/envBased/dev.js'
]).fromConfig('/_env_based_bower.json').when(done);
});
it("should not throw an exception if main file does not exists and checkExistence option is false", function() {
var when = expect([]).fromConfig("/_not_existing_file.json").when;
it('should ignore missing main file if checkExistence is false', function() {
var when = expect([]).fromConfig('/_not_existing_file.json').when;

@@ -148,4 +173,4 @@ when.should.not.throw();

it("should throw an exception if main file does not exists and checkExistence option is true", function() {
var when = expect([]).fromConfig("/_not_existing_file.json", { checkExistence: true }).when;
it('should not ignore missing main file if checkExistence is true', function() {
var when = expect([]).fromConfig('/_not_existing_file.json', { checkExistence: true }).when;

@@ -155,4 +180,4 @@ when.should.throw();

it("should not throw an exception if there are no packages", function() {
var when = expect([]).fromConfig("/_empty.json").when;
it('should ignore missing main property if checkExistence is false', function() {
var when = expect([]).fromConfig('/_not_existing_main.json').when;

@@ -162,4 +187,4 @@ when.should.not.throw();

it("should throw an exception if bower.json does not exists", function() {
var when = expect([]).fromConfig("/_unknown.json").when;
it('should not ignore missing main property if checkExistence is true', function() {
var when = expect([]).fromConfig('/_not_existing_main.json', { checkExistence: true }).when;

@@ -169,7 +194,19 @@ when.should.throw();

it("should not throw an exception if bowerrc has no directory property defined", function() {
var when = expect([]).fromConfig("/_empty.json", {
it('should not throw an exception if there are no packages', function() {
var when = expect([]).fromConfig('/_empty.json').when;
when.should.not.throw();
});
it('should throw an exception if bower.json does not exists', function() {
var when = expect([]).fromConfig('/_unknown.json').when;
when.should.throw();
});
it('should not throw an exception if bowerrc has no directory property defined', function() {
var when = expect([]).fromConfig('/_empty.json', {
paths: {
bowerDirectory: __dirname + "/fixtures",
bowerrc: __dirname + "/.bowerrc_without_directory"
bowerDirectory: __dirname + '/fixtures',
bowerrc: __dirname + '/.bowerrc_without_directory'
}

@@ -176,0 +213,0 @@ }).when;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc