Skip to content

Commit

Permalink
Merge pull request #1866 from bower/feature/cwd
Browse files Browse the repository at this point in the history
Make bower commands work from subdirectories
  • Loading branch information
sheerun committed Aug 23, 2015
2 parents 793268e + 7acafc2 commit 63b4d37
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ var tty = require('tty');
var object = require('mout').object;
var bowerConfig = require('bower-config');
var Configstore = require('configstore');
var findup = require('findup-sync');
var path = require('path');

var cachedConfigs = {};

function defaultConfig(config) {
config = config || {};

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

config.cwd = cwd;

var cachedConfig = readCachedConfig(cwd);

return object.merge(cachedConfig, config);
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"configstore": "^0.3.2",
"decompress-zip": "^0.1.0",
"deep-sort-object": "~0.1.1",
"findup-sync": "^0.2.1",
"fstream": "^1.0.3",
"fstream-ignore": "^1.0.2",
"github": "^0.2.3",
Expand Down
19 changes: 19 additions & 0 deletions test/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,25 @@ describe('bower install', function () {
});
});

it.only('works if bower is run in child directory', function () {
package.prepare({ foo: 'bar' });

tempDir.prepare({
'.bowerrc': { directory: 'assets' },
'foo/bar/baz.txt': 'Hello world',
'bower.json': {
name: 'test',
dependencies: {
package: package.path
}
}
});

return helpers.run(install, [undefined, undefined, { cwd: tempDir.path + '/foo/bar' }]).then(function() {
expect(tempDir.read('assets/package/foo')).to.be('bar');
});
});

it('runs preinstall hook', function () {
package.prepare();

Expand Down

0 comments on commit 63b4d37

Please sign in to comment.