Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --dev install option for devDependencies, cleaned up #251

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion README.md
Expand Up @@ -117,7 +117,7 @@ You can create a `component.json` file in your project's root, specifying all of

Put this under your project's root, listing all of your dependencies. When you run `bower install`, Bower will read this `component.json` file, resolve all the relevant dependencies and install them.

For now, `name`, `version`, `main`, `dependencies`, and `ignore` are the only properties that are used by Bower. If you have several files you're distributing as part of your package, pass an array to `main` like this:
For now, `name`, `version`, `main`, `dependencies`, `devDependencies`, and `ignore` are the only properties that are used by Bower. If you have several files you're distributing as part of your package, pass an array to `main` like this:

```json
{
Expand Down Expand Up @@ -157,6 +157,16 @@ Chances are you have a bunch of extra stuff in the repo that are not needed in p
}
```

You may add non-essential packages in `devDependencies`. This is useful for packages aren't required to support the package, but that are used in your project, i.e. to build documentation, run a demo, or run tests.

```json
{
"devDependencies": [
"qunit": "~1"
]
}
```

### Installing dependencies

Dependencies are installed locally via the `bower install` command. First they’re resolved to find conflicts. Then they’re downloaded and unpacked in a local subdirectory called `./components`, for example:
Expand Down
7 changes: 4 additions & 3 deletions lib/commands/install.js
Expand Up @@ -17,16 +17,17 @@ var source = require('../core/source');
var save = require('../util/save');
var help = require('./help');

var optionTypes = { help: Boolean, save: Boolean, force: Boolean, 'force-latest': Boolean };
var shorthand = { 'h': ['--help'], 'S': ['--save'], 'f': ['--force'], 'F': ['--force-latest'] };
var optionTypes = { help: Boolean, save: Boolean, force: Boolean, 'force-latest': Boolean, production: Boolean };
var shorthand = { 'h': ['--help'], 'S': ['--save'], 'f': ['--force'], 'F': ['--force-latest'], 'p': ['--production'] };

module.exports = function (paths, options) {
options = options || {};

var emitter = new Emitter;
var manager = new Manager(paths, {
force: options.force,
forceLatest: options['force-latest']
forceLatest: options['force-latest'],
production: options.production
});

if (options.save) save(manager);
Expand Down
11 changes: 8 additions & 3 deletions lib/core/manager.js
Expand Up @@ -141,10 +141,15 @@ Manager.prototype.resolveEndpoints = function () {

Manager.prototype.resolveFromJson = function () {
this.once('loadJSON', function () {
if (!this.json.dependencies) return this.emit('error', new Error('Could not find any dependencies'));
var dependencies = this.json.dependencies;
// add devDependencies
if (!this.opts.production && this.json.devDependencies) {
dependencies = _.extend({}, dependencies, this.json.devDependencies)
}
if (!dependencies) return this.emit('error', new Error('Could not find any dependencies'));

async.forEach(Object.keys(this.json.dependencies), function (name, next) {
var endpoint = this.json.dependencies[name];
async.forEach(Object.keys(dependencies), function (name, next) {
var endpoint = dependencies[name];
var pkg = new Package(name, endpoint, this);
pkg.root = true;
this.dependencies[name] = this.dependencies[name] || [];
Expand Down
1 change: 1 addition & 0 deletions templates/help-install.mustache
Expand Up @@ -11,6 +11,7 @@ Options:
{{#yellow}}--save{{/yellow}} - Updates dependencies entries in the project's {{{json}}}
{{#yellow}}--force{{/yellow}} - Force fetching remote resources even if a local copy exists on disk
{{#yellow}}--force-latest{{/yellow}} - Force latest version on conflict
{{#yellow}}--production{{/yellow}} - Do not install project devDependencies
{{#yellow}}--no-color{{/yellow}} - Do not print colors

Can specify one or more:
Expand Down
7 changes: 7 additions & 0 deletions test/assets/package-dev-dep/component.json
@@ -0,0 +1,7 @@
{
"name": "package-dev-dep",
"version": "1.0.0",
"devDependencies": {
"qunit": "latest"
}
}
12 changes: 12 additions & 0 deletions test/assets/project-dev-deps/component.json
@@ -0,0 +1,12 @@
{
"name": "myproject",
"version": "1.0.0",
"dependencies": {
"jquery": "test/assets/package-jquery",
"package-dev-dep": "test/assets/package-dev-dep"
},
"devDependencies": {
"bootstrap": "test/assets/package-bootstrap",
"turtles": "test/assets/package-ignorables"
}
}
39 changes: 39 additions & 0 deletions test/manager.js
Expand Up @@ -185,4 +185,43 @@ describe('manager', function () {
});
});

it('Should resolve devDependencies by default', function (next) {
var manager = new Manager([]);
manager.cwd = __dirname + '/assets/project-dev-deps';

manager.on('resolve', function () {
assert.ok(manager.dependencies.jquery);
assert.ok(manager.dependencies['package-dev-dep']);
assert.ok(manager.dependencies.bootstrap);
assert.ok(manager.dependencies.turtles);
// no devDependencies of dependencies
assert.ok(!manager.dependencies.qunit);
next();
});

manager.on('error', function (err) {
throw err;
});

manager.resolve();
});

it('Should not resolve devDependencies when specified', function (next) {
var manager = new Manager([], { production: true });
manager.cwd = __dirname + '/assets/project-dev-deps';

manager.on('resolve', function () {
assert.ok(manager.dependencies.jquery);
assert.ok(!manager.dependencies.bootstrap);
assert.ok(!manager.dependencies.turtles);
next();
});

manager.on('error', function (err) {
throw err;
});

manager.resolve();
});

});