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

bower

Package Overview
Dependencies
Maintainers
2
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.2 to 0.4.0

2

lib/commands/list.js

@@ -52,3 +52,3 @@ // ==========================================

return path.join(config.directory, name, main);
} else {
} else if (_.isArray(main)) {
main = main.map(function (main) { return generatePath(name, main); });

@@ -55,0 +55,0 @@ return main.length == 1 ? main[0] : main;

@@ -55,5 +55,10 @@ // ==========================================

pkg.once('loadJSON', function () {
pkg.once('fetchURL', function (url) {
if (pkg.json.commit && pkg.json.version === '0.0.0') url += '';
else url += '#' + ((!names || names.indexOf(pkg.name) > -1) ? '~' : '') + pkg.version;
pkg.once('fetchURL', function (url, type) {
if (!url) return emitter.emit('error', new Error('No url found for ' + pkg.name));
if (type == 'git') {
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 });

@@ -60,0 +65,0 @@ }).fetchURL();

@@ -30,2 +30,4 @@ // ==========================================

var crypto = require('crypto');
var unzip = require('unzip');
var tar = require('tar');

@@ -65,3 +67,2 @@ var config = require('./config');

} else if (/^[\.\/~]\.?[^.]*\.(js|css)/.test(endpoint) && fs.statSync(endpoint).isFile()) {
this.path = path.resolve(endpoint);

@@ -81,2 +82,7 @@ this.assetType = path.extname(endpoint);

this.path = path.resolve(endpoint);
} else if (endpoint.split('/').length === 2) {
var split = endpoint.split('#', 2);
this.gitUrl = 'git://github.com/' + split[0] + '.git';
this.tag = split[1];
} else {

@@ -157,4 +163,6 @@ this.tag = endpoint.split('#', 2)[1];

// Only print the installing action if this package has been resolved
if (this.version) template('action', { name: 'installing', shizzle: this.name + (this.version ? '#' + this.version : '') })
.on('data', this.emit.bind(this, 'data'));
if (this.unitWork.retrieve(this.name)) {
template('action', { name: 'installing', shizzle: this.name + (this.version ? '#' + this.version : '') })
.on('data', this.emit.bind(this, 'data'));
}

@@ -197,3 +205,3 @@ if (path.resolve(this.path) == this.localPath) {

if (this.gitUrl) this.json.repository = { type: "git", url: this.gitUrl };
if (this.assetUrl) this.json = this.generateAssetJSON();
else if (this.assetUrl) this.json = this.generateAssetJSON();

@@ -211,3 +219,3 @@ var jsonStr = JSON.stringify(this.json, null, 2);

name: this.name,
main: 'index' + this.assetType,
main: this.assetType != '.zip' && this.assetType != '.tar' ? 'index' + this.assetType : '',
version: semverParser.exec(this.assetUrl) ? RegExp.$1 : "0.0.0",

@@ -300,3 +308,9 @@ repository: { type: "asset", url: this.assetUrl }

file.end();
this.once('loadJSON', this.saveUnit).loadJSON();
var next = function () {
this.once('loadJSON', this.saveUnit).loadJSON();
}.bind(this);
if (this.assetType === '.zip' || this.assetType == '.tar') this.once('extract', next).extract();
else next();
}.bind(this));

@@ -309,2 +323,45 @@

Package.prototype.extract = function () {
var file = path.join(this.path, 'index' + this.assetType);
template('action', { name: 'extracting', shizzle: file }).on('data', this.emit.bind(this, 'data'));
fs.createReadStream(file).pipe(this.assetType === '.zip' ? unzip.Extract({ path: this.path }) : tar.Extract({ path: this.path }))
.on('error', this.emit.bind(this, 'error'))
.on('end', function () {
// Delete zip
fs.unlink(file, function (err) {
if (err) return this.emit('error', err);
// If we extracted only a folder, move all the files within it to the original path
fs.readdir(this.path, function (err, files) {
if (err) return this.emit('error', err);
if (files.length != 1) return this.emit('extract');
var dir = path.join(this.path, files[0]);
fs.stat(dir, function (err, stat) {
if (err) return this.emit('error', err);
if (!stat.isDirectory()) return this.emit('extract');
fs.readdir(dir, function (err, files) {
if (err) return this.emit('error', err);
async.forEachSeries(files, function (file, next) {
fs.rename(path.join(dir, file), path.join(this.path, file), next);
}.bind(this), function (err) {
if (err) return this.emit('error');
fs.rmdir(dir, function (err) {
if (err) return this.emit('error');
this.emit('extract');
}.bind(this));
}.bind(this));
}.bind(this));
}.bind(this));
}.bind(this));
}.bind(this));
}.bind(this));
};
Package.prototype.copy = function () {

@@ -537,8 +594,11 @@ template('action', { name: 'copying', shizzle: this.path }).on('data', this.emit.bind(this, 'data'));

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

@@ -545,0 +605,0 @@ };

@@ -10,3 +10,4 @@ // ==========================================

module.exports = {
commands: require('./commands')
commands: require('./commands'),
config: require('./core/config')
};
{
"name": "bower",
"description": "The browser package manager.",
"version": "0.3.2",
"version": "0.4.0",
"author": "Twitter",

@@ -34,3 +34,5 @@ "licenses": [

"stable": "~0.1.2",
"rc": "~0.0.6"
"rc": "~0.0.6",
"unzip": "0.0.4",
"tar": "~0.1.13"
},

@@ -37,0 +39,0 @@ "scripts": {

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

bower install git://github.com/maccman/package-jquery.git
bower install maccman/package-jquery (same as above)
bower install http://code.jquery.com/jquery-1.7.2.js
bower install ./repos/jquery
As you can see, packages can be installed by name, Git endpoint, URL or local path.
As you can see, packages can be installed by name, Git endpoint, Github shorthand, URL or local path.
If you install and URL that is a zip or tar file, bower will automatically extract the contents of it.

@@ -34,0 +36,0 @@ [View all packages available through Bower's registry](http://sindresorhus.com/bower-components/).

@@ -35,2 +35,13 @@ var assert = require('assert');

it('Should resolve git shorthands (username/project)', function () {
var pkg = new Package('jquery', 'jquery/jquery');
assert.equal(pkg.gitUrl, 'git://github.com/jquery/jquery.git');
});
it('Should resolve git shorthands (username/project) with specific tag', function () {
var pkg = new Package('jquery', 'jquery/jquery#1.0.0');
assert.equal(pkg.gitUrl, 'git://github.com/jquery/jquery.git');
assert.equal(pkg.tag, '1.0.0');
});
it('Should resolve git HTTP URLs properly', function () {

@@ -57,3 +68,24 @@ var pkg = new Package('jquery', 'git+http://example.com/project.git');

it('Should resolve normal HTTP URLs', function (next) {
var pkg = new Package('bootstrap', 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js');
pkg.on('resolve', function () {
assert(pkg.assetUrl);
assert.equal(pkg.assetUrl, 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js');
next();
});
pkg.on('error', function (err) {
throw new Error(err);
});
pkg.resolve();
});
it('Should resolve url when we got redirected', function (next) {
after(function () {
nock.cleanAll();
});
var redirecting_url = 'http://redirecting-url.com';

@@ -63,16 +95,15 @@ var redirecting_to_url = 'http://redirected-to-url.com';

var redirect_scope = nock(redirecting_url)
.defaultReplyHeaders({'location': redirecting_to_url + '/jquery.zip'})
.get('/jquery.zip')
.defaultReplyHeaders({'location': redirecting_to_url + '/jquery.js'})
.get('/jquery.js')
.reply(302);
var redirect_to_scope = nock(redirecting_to_url)
.get('/jquery.zip')
.get('/jquery.js')
.reply(200, 'jquery content');
var pkg = new Package('jquery', redirecting_url + '/jquery.zip');
var pkg = new Package('jquery', redirecting_url + '/jquery.js');
pkg.on('resolve', function () {
assert(pkg.assetUrl);
assert.equal(pkg.assetUrl, redirecting_to_url + '/jquery.zip');
nock.restore();
assert.equal(pkg.assetUrl, redirecting_to_url + '/jquery.js');
next();

@@ -85,3 +116,3 @@ });

pkg.download();
pkg.resolve();
});

@@ -102,5 +133,17 @@

pkg.clone();
pkg.resolve();
});
it('Should error on clone fail', function (next) {
var pkg = new Package('random', 'git://example.com');
pkg.on('error', function (err) {
assert(err);
next();
});
pkg.resolve();
});
it('Should copy path packages', function (next) {

@@ -119,16 +162,5 @@ var pkg = new Package('jquery', __dirname + '/assets/package-jquery');

pkg.copy();
pkg.resolve();
});
it('Should error on clone fail', function (next) {
var pkg = new Package('random', 'git://example.com');
pkg.on('error', function (err) {
assert(err);
next();
});
pkg.clone();
});
it('Should load correct json', function (next) {

@@ -209,3 +241,3 @@ var pkg = new Package('jquery', __dirname + '/assets/package-jquery');

pkg.clone();
pkg.resolve();
});

@@ -241,5 +273,80 @@

pkg.clone();
pkg.resolve();
});
it('Should download normal URL packages', function (next) {
var pkg = new Package('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js');
pkg.on('resolve', function () {
pkg.install();
});
pkg.on('error', function (err) {
throw new Error(err);
});
pkg.on('install',function () {
fs.readdir(pkg.localPath, function (err, files) {
if (err) throw new Error(err);
assert(files.indexOf('index.js') !== -1);
next();
});
});
pkg.resolve();
});
it('Should extract tar and zip files from normal URL packages', function (next) {
var pkg = new Package('jquery', 'http://github.com/satazor/SparkMD5/archive/master.zip');
pkg.on('resolve', function () {
pkg.install();
});
pkg.on('error', function (err) {
throw new Error(err);
});
pkg.on('install',function () {
fs.readdir(pkg.localPath, function (err, files) {
if (err) throw new Error(err);
assert(files.indexOf('index.js') === -1);
assert(files.indexOf('master.zip') === -1);
assert(files.indexOf('spark-md5.js') !== -1);
assert(files.indexOf('spark-md5.min.js') !== -1);
next();
});
});
pkg.resolve();
});
it('Should extract tar and zip files from normal URL packages and move them if the archive only contains a folder', function (next) {
var pkg = new Package('jquery', 'http://twitter.github.com/bootstrap/assets/bootstrap.zip');
pkg.on('resolve', function () {
pkg.install();
});
pkg.on('error', function (err) {
throw new Error(err);
});
pkg.on('install',function () {
fs.readdir(pkg.localPath, function (err, files) {
if (err) throw new Error(err);
assert(files.indexOf('index.js') === -1);
assert(files.indexOf('bootstrap.zip') === -1);
assert(files.indexOf('js') !== -1);
assert(files.indexOf('css') !== -1);
assert(files.indexOf('img') !== -1);
next();
});
});
pkg.resolve();
});
});
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