Skip to content

Commit

Permalink
If cwd provided explicitly, force using it, fixes #1866
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerun committed Aug 23, 2015
1 parent 8531534 commit dd67cc7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
6 changes: 6 additions & 0 deletions lib/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ var createError = require('../util/createError');
function init(logger, config) {
var project;

config = config || {};

if (!config.cwd) {
config.cwd = process.cwd();
}

config = defaultConfig(config);

// This command requires interactive to be enabled
Expand Down
6 changes: 3 additions & 3 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ var cachedConfigs = {};
function defaultConfig(config) {
config = config || {};

var cwd = path.dirname(findup('bower.json', {
cwd: config.cwd || process.cwd()
})) || config.cwd || process.cwd();
var cwd = config.cwd || path.dirname(findup('bower.json', {
cwd: process.cwd()
})) || process.cwd();

config.cwd = cwd;

Expand Down
2 changes: 1 addition & 1 deletion lib/core/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ module.exports = {
postinstall: mout.function.partial(hook, 'postinstall', true),
//only exposed for test
_orderByDependencies: orderByDependencies
};
};
5 changes: 4 additions & 1 deletion test/commands/install.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var path = require('path');
var expect = require('expect.js');
var helpers = require('../helpers');

Expand Down Expand Up @@ -147,7 +148,9 @@ describe('bower install', function () {
}
});

return helpers.run(install, [undefined, undefined, { cwd: tempDir.path + '/foo/bar' }]).then(function() {
process.chdir(path.join(tempDir.path, '/foo/bar'));

return helpers.run(install).then(function() {
expect(tempDir.read('assets/package/foo')).to.be('bar');
});
});
Expand Down

0 comments on commit dd67cc7

Please sign in to comment.