eugeneware / debowerify

A browserify transform to enable the easy use of bower components in browserify client javascript projects. This can be used in conjunction with deamdify to require AMD components from bower as well.
491 stars 51 forks source link

Fails to rewrite paths in nested dependencies #10

Closed triblondon closed 10 years ago

triblondon commented 11 years ago

debowerify fails to rewrite the require statements correctly where the component being required is not a direct dependency of the containing project. So if I have a project A which requires B and B requires C, the require in B referring to C will not be resolved by browserify because debowerify doesn't rewrite it.

I believe this to be because using the programmatic interface to bower in the way that debowerify does will only ever return data about A, even if the file passed to debowerify from browserify is a member of B.

I have fixed this by refactoring debowerify to remove the bower dependency and instead simply read the bower.json files using fs, but there may be a better method.

eugeneware commented 11 years ago

Hi @triblondon

Thanks so much for the PR. However, I think I may have found a few problems:

I've written some proper tests to verify correct operation of debowerify.

When I run this branch against the tests it's failing for the simple case and failing with the error:

Error: Cannot find module 'js-base64'

I've added in a simple bower component js-base64 for testing purposes.

Also, I'm not sure your code takes into account the presence of a .bowerrc which may override the bower_components directory location.

Eg.

{
  "directory": "my_components"
}

From the bower config file spec:

The Bower configuration alters the behaviour of Bower on the local system.

The config is obtained by merging multiple configurations by this order of importance:

Also, can you provide an example component that has these nested dependencies? I'll try to see if I can come up with a test that demonstrates the failing behaviour so we can fix it.

triblondon commented 11 years ago

I was pretty sure I was going to come unstuck somewhere, trying to ignore the bower API in favour of reading the config myself :-)

I set up some repos to test nested deps: https://github.com/triblondon/test-a https://github.com/triblondon/test-b https://github.com/triblondon/test-c

A and B both depend on C, and just for kicks, specify their dependence on C using semver patterns that cannot both be satisfied by the same version of C. In my local project, I set up bower.json to require only A and B:

{
  "name": "test-main",
  "version": "1.0.0",
  "dependencies": {
    "test-a": "git://github.com/triblondon/test-a.git",
    "test-b": "git://github.com/triblondon/test-b.git"
  }
}

This works fine. First bower installs A, B and C (and also D3.js, which is another dependency of both A and B), prompting the user to resolve the conflict. Then browserify bundles the JS, using my hacked debowerify to locate C. If I don't use my hacked version, browserify can't find C or D3.

eugeneware commented 10 years ago

This should be fixed with #20