Socket
Socket
Sign inDemoInstall

bower

Package Overview
Dependencies
Maintainers
1
Versions
99
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bower - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

lib/util/file-exists.js

26

lib/commands/cache-clean.js

@@ -9,14 +9,14 @@ // ==========================================

var Emitter = require('events').EventEmitter;
var async = require('async');
var nopt = require('nopt');
var rimraf = require('rimraf');
var path = require('path');
var fs = require('fs');
var glob = require('glob');
var _ = require('lodash');
var Emitter = require('events').EventEmitter;
var async = require('async');
var nopt = require('nopt');
var rimraf = require('rimraf');
var path = require('path');
var glob = require('glob');
var _ = require('lodash');
var help = require('./help');
var config = require('../core/config');
var template = require('../util/template');
var help = require('./help');
var config = require('../core/config');
var template = require('../util/template');
var fileExists = require('../util/file-exists');

@@ -29,4 +29,4 @@ var optionTypes = { help: Boolean, force: Boolean };

fs.exists(folder, function (exists) {
if (!exists) return emitter.emit('error', new Error(pkg + ' is not cached'));
fileExists(folder, function (exists) {
if (!exists) return emitter.emit('error', new Error('Package ' + pkg + ' is not installed'));

@@ -33,0 +33,0 @@ rimraf(folder, function (err) {

@@ -28,3 +28,3 @@ // ==========================================

var emitter = new Emitter;
var manager = new Manager(paths, { force: options.force });
var manager = new Manager(paths, { force: options & options.force });

@@ -31,0 +31,0 @@ if (options && options.save) save(emitter, manager, paths);

@@ -112,3 +112,3 @@ // ==========================================

&& packages[key]
&& packages[key].version == "0.0.0" ?
&& packages[key].version == '0.0.0' ?
packages[key].json.repository.url : packages[key] && packages[key].version;

@@ -122,7 +122,7 @@

return {
label: template('tree-branch', { package: key, version: version, upgrade: upgrade }, true),
label: template('tree-branch', { 'package': key, version: version, upgrade: upgrade }, true),
nodes: getNodes(packages, tree[key])
};
} else {
return template('tree-branch', { package: key, version: version, upgrade: upgrade }, true);
return template('tree-branch', { 'package': key, version: version, upgrade: upgrade }, true);
}

@@ -129,0 +129,0 @@ });

@@ -18,7 +18,7 @@ // ==========================================

var shorthand = { 'h': ['--help'] };
var optionTypes = { help: Boolean };
var shorthand = { 'h': ['--help'], 'f': ['--force'] };
var optionTypes = { help: Boolean, force: Boolean };
module.exports = function (argv, options) {
var manager = new Manager;
module.exports = function (names, options) {
var manager = new Manager([], { force: options.force });
var emitter = new Emitter;

@@ -29,20 +29,33 @@

var installURLS = function (err, urls) {
var installEmitter = install(urls, options);
installEmitter.on('data', emitter.emit.bind(emitter, 'data'));
installEmitter.on('error', emitter.emit.bind(emitter, 'error'));
installEmitter.on('end', emitter.emit.bind(emitter, 'end'));
var installURLS = function (err, arr) {
var mappings = {},
urls = [];
_.each(arr, function (info) {
urls.push(info.url);
mappings[info.url] = info.name;
});
options.endpointNames = mappings;
// By default the manager will guess the name of the package from the url
// But this leads to problems when the package name does not match the one in the url
// So the manager now has an option (endpointNames) to deal with this
manager = new Manager(urls, options);
manager.on('data', emitter.emit.bind(emitter, 'data'));
manager.on('error', emitter.emit.bind(emitter, 'error'));
manager.on('install', emitter.emit.bind(emitter, 'end'));
manager.resolve();
};
manager.once('resolveLocal', function () {
var packages = {};
names = names.length ? _.uniq(names) : null;
_.each(manager.dependencies, function (value, name) {
packages[name] = value[0];
});
var urls = async.map(_.values(packages), function (pkg, next) {
async.map(_.values(manager.dependencies), function (pkgs, next) {
var pkg = pkgs[0];
pkg.once('loadJSON', function () {
pkg.once('fetchURL', function (url) {
next(null, url + (pkg.json.commit && pkg.json.version === '0.0.0' ? '' : '#~' + pkg.version));
if (pkg.json.commit && pkg.json.version === '0.0.0') url += '';
else url += '#' + ((!names || names.indexOf(pkg.name) > -1) ? '~' : '') + pkg.version;
next(null, { url: url, name: pkg.name });
}).fetchURL();

@@ -49,0 +62,0 @@ }).loadJSON();

@@ -1,4 +0,5 @@

var path = require('path');
var fs = require('fs');
var _ = require('lodash');
var path = require('path');
var fs = require('fs');
var _ = require('lodash');
var fileExists = require('../util/file-exists').sync;

@@ -28,3 +29,3 @@ var temp = process.env.TMPDIR

var localFile = path.join(this.cwd, '.bowerrc');
if (fs.existsSync(localFile)) {
if (fileExists(localFile)) {
_.extend(config, JSON.parse(fs.readFileSync(localFile)));

@@ -31,0 +32,0 @@ }

@@ -16,13 +16,15 @@ // ==========================================

var Package = require('./package');
var UnitWork = require('./unit_work');
var config = require('./config');
var prune = require('../util/prune');
var events = require('events');
var async = require('async');
var path = require('path');
var glob = require('glob');
var fs = require('fs');
var _ = require('lodash');
var Package = require('./package');
var UnitWork = require('./unit_work');
var config = require('./config');
var prune = require('../util/prune');
var events = require('events');
var async = require('async');
var path = require('path');
var glob = require('glob');
var fs = require('fs');
var _ = require('lodash');
var fileExists = require('../util/file-exists');
// read local dependencies (with versions)

@@ -80,4 +82,6 @@ // read json dependencies (resolving along the way into temp dir)

var endpointNames = this.opts.endpointNames || {};
async.forEach(this.endpoints, function (endpoint, next) {
var name = path.basename(endpoint).replace(/(\.git)?(#.*)?$/, '');
var name = endpointNames[endpoint] || path.basename(endpoint).replace(/(\.git)?(#.*)?$/, '');
var pkg = new Package(name, endpoint, this);

@@ -92,3 +96,3 @@ this.dependencies[name] = this.dependencies[name] || [];

var json = path.join(this.cwd, config.json);
fs.exists(json, function (exists) {
fileExists(json, function (exists) {
if (!exists) return this.emit('error', new Error('Could not find local ' + config.json));

@@ -95,0 +99,0 @@ fs.readFile(json, 'utf8', function (err, json) {

@@ -15,22 +15,24 @@ // ==========================================

var spawn = require('child_process').spawn;
var _ = require('lodash');
var fstream = require('fstream');
var mkdirp = require('mkdirp');
var events = require('events');
var rimraf = require('rimraf');
var semver = require('semver');
var async = require('async');
var https = require('https');
var http = require('http');
var path = require('path');
var url = require('url');
var tmp = require('tmp');
var fs = require('fs');
var spawn = require('child_process').spawn;
var _ = require('lodash');
var fstream = require('fstream');
var mkdirp = require('mkdirp');
var events = require('events');
var rimraf = require('rimraf');
var semver = require('semver');
var async = require('async');
var https = require('https');
var http = require('http');
var path = require('path');
var url = require('url');
var tmp = require('tmp');
var fs = require('fs');
var crypto = require('crypto');
var config = require('./config');
var source = require('./source');
var template = require('../util/template');
var readJSON = require('../util/read-json');
var UnitWork = require('./unit_work');
var config = require('./config');
var source = require('./source');
var template = require('../util/template');
var readJSON = require('../util/read-json');
var fileExists = require('../util/file-exists');
var UnitWork = require('./unit_work');

@@ -76,3 +78,3 @@ var Package = function (name, endpoint, manager) {

} else if (fs.existsSync(endpoint)) {
} else if (fileExists.sync(endpoint)) {
this.path = path.resolve(endpoint);

@@ -88,7 +90,7 @@ } else {

// Generate an id and a resourceId
// The id is an unique id that describes this package
// The resourceId is an unique id that describes the resource of this package
this.id = new Buffer(this.name + '%' + this.tag + '%' + this.gitUrl + '%' + this.path + '%' + this.assetUrl).toString('base64');
this.resourceId = new Buffer(this.gitUrl + '%' + this.path + '%' + this.assetUrl).toString('base64');
this.id = crypto.createHash('md5').update(this.name + '%' + this.tag + '%' + this.gitUrl + '%' + this.path + '%' + this.assetUrl).digest('hex');
// Generate a resource id
if (this.gitUrl) this.generateResourceId();
}

@@ -125,10 +127,2 @@

}
// Check if this exact package resource is the last resolved one
// This is to prevent it from being downloaded or copied over and over again in such case
if (data.resourceId === this.resourceId) {
this.path = data.path;
this.unitWork.lock(this.name, this);
this.once('loadJSON', this.saveUnit).checkout();
return this;
}
}

@@ -157,2 +151,3 @@

this.gitUrl = url;
this.generateResourceId();
this.emit('lookup');

@@ -207,3 +202,3 @@ }.bind(this));

fs.writeFile(path.join(this.localPath, config.json), jsonStr);
fs.writeFile(path.join(path.resolve(config.cache, this.name), config.json), jsonStr);
if (this.gitUrl) fs.writeFile(path.join(path.resolve(config.cache, this.name, this.resourceId), config.json), jsonStr);

@@ -242,3 +237,3 @@ rimraf(path.join(this.localPath, '.git'), this.emit.bind(this, 'install'));

if (!name) {
if (!this.assetType && fs.existsSync(jsonFile)) return this.emit('error', err);
if (!this.assetType && fileExists.sync(jsonFile)) return this.emit('error', err);
return this.loadJSON('package.json');

@@ -255,8 +250,13 @@ }

this.json = json;
this.version = this.commit || json.commit || json.version;
this.commit = this.commit || json.commit;
// Only overwrite the name if not already set
// This is because some packages have different names declared in the registry and the json
if (!this.name) this.name = json.name;
this.json = json;
this.version = this.commit || json.commit || json.version;
this.commit = this.commit || json.commit;
// Generate the resource id based on the gitUrl
if (!this.gitUrl && json.repository && json.repository.type === 'git') {
this.gitUrl = json.repository.url;
this.generateResourceId();
}

@@ -370,3 +370,3 @@ // TODO: bower could detect if the tag mismatches the json.version

Package.prototype.exists = function (callback) {
fs.exists(this.localPath, callback);
fileExists(this.localPath, callback);
};

@@ -376,3 +376,3 @@

template('action', { name: 'cloning', shizzle: this.gitUrl }).on('data', this.emit.bind(this, 'data'));
this.path = path.resolve(config.cache, this.name);
this.path = path.resolve(config.cache, this.name, this.resourceId);
this.once('cache', function () {

@@ -387,6 +387,6 @@ this.once('loadJSON', this.copy.bind(this)).checkout();

// To prevent that we check the unit of work storage
if (this.opts.force && !this.unitWork.retrieve('flushed#' + this.name)) {
if (this.opts.force && !this.unitWork.retrieve('flushed#' + this.name + '_' + this.resourceId)) {
rimraf(this.path, function (err) {
if (err) return this.emit('error', err);
this.unitWork.store('flushed#' + this.name, true);
this.unitWork.store('flushed#' + this.name + '_' + this.resourceId, true);
this.cache();

@@ -399,3 +399,3 @@ }.bind(this));

if (err) return this.emit('error', err);
fs.exists(this.path, function (exists) {
fileExists(this.path, function (exists) {
if (exists) {

@@ -410,7 +410,12 @@ template('action', { name: 'cached', shizzle: this.gitUrl }).on('data', this.emit.bind(this, 'data'));

}
var cp = spawn('git', ['clone', url, this.path]);
cp.on('close', function (code) {
if (code != 0) return this.emit('error', new Error('Git status: ' + code));
this.emit('cache');
mkdirp(this.path, function (err) {
if (err) return this.emit('error', ee);
var cp = spawn('git', ['clone', url, this.path]);
cp.on('close', function (code) {
if (code) return this.emit('error', new Error('Git status: ' + code));
this.emit('cache');
}.bind(this));
}.bind(this));

@@ -456,6 +461,6 @@ }.bind(this));

spawn('git', [ 'checkout', this.tag, '-f'], { cwd: this.path }).on('close', function (code) {
if (code != 0) return this.emit('error', new Error('Git status: ' + code));
if (code) return this.emit('error', new Error('Git status: ' + code));
// Ensure that checkout the tag as it is, removing all untracked files
spawn('git', ['clean', '-f', '-d'], { cwd: this.path }).on('close', function (code) {
if (code != 0) return this.emit('error', new Error('Git status: ' + code));
if (code) return this.emit('error', new Error('Git status: ' + code));
this.emit('checkout');

@@ -470,3 +475,3 @@ this.loadJSON();

Package.prototype.describeTag = function () {
var cp = spawn('git', ['describe', '--always', '--tag'], { cwd: path.resolve(config.cache, this.name) });
var cp = spawn('git', ['describe', '--always', '--tag'], { cwd: path.resolve(config.cache, this.name, this.resourceId) });

@@ -482,3 +487,3 @@ var tag = '';

if (code == 128) tag = 'unspecified'.grey; // not a git repo
else if (code != 0) return this.emit('error', new Error('Git status: ' + code));
else if (code) return this.emit('error', new Error('Git status: ' + code));
this.emit('describeTag', tag.replace(/\n$/, ''));

@@ -490,3 +495,3 @@ }.bind(this));

this.on('fetch', function () {
var cp = spawn('git', ['tag'], { cwd: path.resolve(config.cache, this.name) });
var cp = spawn('git', ['tag'], { cwd: path.resolve(config.cache, this.name, this.resourceId) });

@@ -514,3 +519,3 @@ var versions = '';

versions = '';
cp = spawn('git', ['log', '-n', 1, '--format=%H'], { cwd: path.resolve(config.cache, this.name) });
cp = spawn('git', ['log', '-n', 1, '--format=%H'], { cwd: path.resolve(config.cache, this.name, this.resourceId) });

@@ -530,8 +535,8 @@ cp.stdout.setEncoding('utf8');

Package.prototype.fetch = function () {
var cp = spawn('git', ['fetch'], { cwd: path.resolve(config.cache, this.name) });
var cp = spawn('git', ['fetch'], { cwd: path.resolve(config.cache, this.name, this.resourceId) });
cp.on('close', function (code) {
if (code != 0) return this.emit('error', new Error('Git status: ' + code));
cp = spawn('git', ['reset', '--hard', 'origin/HEAD'], { cwd: path.resolve(config.cache, this.name) });
if (code) return this.emit('error', new Error('Git status: ' + code));
cp = spawn('git', ['reset', '--hard', 'origin/HEAD'], { cwd: path.resolve(config.cache, this.name, this.resourceId) });
cp.on('close', function (code) {
if (code != 0) return this.emit('error', new Error('Git status: ' + code));
if (code) return this.emit('error', new Error('Git status: ' + code));
this.emit('fetch');

@@ -544,5 +549,7 @@ }.bind(this));

if (this.json.repository && this.json.repository.type == 'git') {
this.emit('fetchURL', this.json.repository.url);
this.gitUrl = this.json.repository.url;
this.generateResourceId();
this.emit('fetchURL', this.gitUrl);
} else {
this.emit('error', new Error('No git url found for ' + this.json.name));
this.emit('error', new Error('No git url found for ' + this.name));
}

@@ -583,2 +590,6 @@ };

Package.prototype.generateResourceId = function () {
this.resourceId = crypto.createHash('md5').update(this.name + '%' + this.gitUrl).digest('hex');
};
Package.prototype.__defineGetter__('localPath', function () {

@@ -585,0 +596,0 @@ return path.join(process.cwd(), config.directory, this.name);

{
"name": "bower",
"description": "The browser package manager.",
"version": "0.3.0",
"version": "0.3.1",
"author": "Twitter",

@@ -6,0 +6,0 @@ "licenses": [ { "type": "MIT", "url": "https://github.com/twitter/bower/blob/master/LICENSE" } ],

@@ -53,2 +53,10 @@ BOWER [![Build Status](https://secure.travis-ci.org/twitter/bower.png)](http://travis-ci.org/twitter/bower)

To clean the cache:
bower cache-clean [name]
Several packages can be cleaned at the same time.
To clean the entire cache, just call `bower cache-clean` without any names.
Also, both the install and update commands have a `--force` flag that tells bower to bypass the cache and always fetch remote sources.
You can disable colors by using the `--no-color` flag.

@@ -58,3 +66,3 @@

Bower can be configured by creating a ~/.bowerrc file with one or all of the following configuration parameters.
Bower can be configured by creating a .bowerrc file in your home folder (usually ~/bowerrc) with one or all of the following configuration parameters.

@@ -61,0 +69,0 @@ ```json

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