Skip to content

Commit

Permalink
Merge pull request #81 from anyroadcom/hotfix/local-dep-lookup-bug
Browse files Browse the repository at this point in the history
Local dependencies in different paths with matching prefixes bug in new dependency lookup
  • Loading branch information
timaschew committed Sep 26, 2014
2 parents 28ad457 + 76ae462 commit a4c8a33
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/builders/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,10 @@ Scripts.prototype.lookupDependency = function (file, target) {
for (var i = 0; i < localDeps.length; i++) {
// Find a local dependency that matches as a prefix of the target
// or the whole target, and return the canonical path.
var re = new RegExp("^("+localDeps[i]+")(.*)$");
var re = new RegExp("^("+localDeps[i]+")(/.*)?$");
if (m = re.exec(target)) {
var dep = m[1];
var tail = m[2];
var tail = m[2] || '';
return branch.locals[dep].canonical + tail;
}
}
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/js-matching-prefixes/component.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"scripts": [ "index.js" ],
"paths": [
"lib1",
"lib2"
],
"locals": [
"test",
"test_again"
]
}
7 changes: 7 additions & 0 deletions test/fixtures/js-matching-prefixes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var test = require('test')
, test_again = require('test_again');

module.exports = {
test_name: test.name,
test_again_name: test_again.name
}
4 changes: 4 additions & 0 deletions test/fixtures/js-matching-prefixes/lib1/test/component.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "test",
"scripts": [ "index.js" ]
}
3 changes: 3 additions & 0 deletions test/fixtures/js-matching-prefixes/lib1/test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
name: 'test'
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "test_again",
"scripts": [ "index.js" ]
}
3 changes: 3 additions & 0 deletions test/fixtures/js-matching-prefixes/lib2/test_again/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
name: 'test_again'
};
34 changes: 32 additions & 2 deletions test/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,36 @@ describe('js-nested-locals', function() {
})
})

describe('js-matching-prefixes', function() {
var tree
var js = Builder.require

it('should install', co(function* () {
tree = yield* resolve(fixture('js-matching-prefixes'), options)
}))

it('should build', co(function* () {
js += yield build(tree).end();
}))


it('should rewrite the component require correctly', function() {
js.should.not.include("require('test')")
js.should.not.include("require('test_again')")

js.should.include("require('./lib1/test')")
js.should.include("require('./lib2/test_again')")
})

it('should execute', function () {
var ctx = vm.createContext()
vm.runInContext(js, ctx)
vm.runInContext('this.test = require("js-matching-prefixes")', ctx)
ctx.test.test_name.should.equal('test')
ctx.test.test_again_name.should.equal('test_again')
})
})

describe('js-scripts -dev', function () {
var tree
var js = Builder.require
Expand Down Expand Up @@ -495,7 +525,7 @@ describe('js-locals', function () {
js.should.not.include('require("subcomponent-1")');
js.should.not.include("require('subcomponent-1/hello')");
js.should.not.include('require("subcomponent-1/hello")');

js.should.include("require('./subcomponents/subcomponent-1')");
js.should.include("require('./subcomponents/subcomponent-1/hello')");
})
Expand Down Expand Up @@ -533,4 +563,4 @@ describe('js-asset-path', function () {
js.should.not.include('/* component:file */ "../assets/foo.txt"');
js.should.include('"js-asset-path/assets/foo.txt"');
});
})
})

0 comments on commit a4c8a33

Please sign in to comment.