Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ef61734

Browse filesBrowse files
committed
Merge branch 'feature/lookup-components-in-dirs' of https://github.com/anyroadcom/builder2.js into anyroadcom-feature/lookup-components-in-dirs
2 parents 0e7538c + 6b27e01 commit ef61734
Copy full SHA for ef61734

File tree

Expand file treeCollapse file tree

8 files changed

+65
-2
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+65
-2
lines changed

‎lib/builders/scripts.js

Copy file name to clipboardExpand all lines: lib/builders/scripts.js
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,17 @@ Scripts.prototype.lookupDependency = function (file, target) {
395395
}
396396

397397
// local
398-
if (branch.locals[target]) return branch.locals[target].canonical + tail;
398+
var localDeps = Object.keys(branch.locals);
399+
for (var i = 0; i < localDeps.length; i++) {
400+
// Find a local dependency that matches as a prefix of the target
401+
// or the whole target, and return the canonical path.
402+
var re = new RegExp("^("+localDeps[i]+")(.*)$");
403+
if (m = re.exec(target)) {
404+
var dep = m[1];
405+
var tail = m[2];
406+
return branch.locals[dep].canonical + tail;
407+
}
408+
}
399409

400410
// <repo>
401411
for (var i = 0; i < names.length; i++) {
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"scripts": [ "index.js" ],
3+
"paths": [
4+
"lib"
5+
],
6+
"locals": [
7+
"nested/boot"
8+
]
9+
}
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
this.boot = require('nested/boot')
2+
this.insideBoot = require('nested/boot/smth.js')
3+
4+
module.exports = {}

‎test/fixtures/js-nested-locals/lib/index.js

Copy file name to clipboardExpand all lines: test/fixtures/js-nested-locals/lib/index.js
Whitespace-only changes.
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "nested/boot",
3+
"scripts": [ "index.js", "smth.js" ]
4+
}
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {main: true};
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {inside: true};

‎test/scripts.js

Copy file name to clipboardExpand all lines: test/scripts.js
+35-1Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,40 @@ describe('js-scripts', function () {
5656
})
5757
})
5858

59+
describe('js-nested-locals', function() {
60+
var tree
61+
var js = Builder.require
62+
63+
it('should install', co(function* () {
64+
tree = yield* resolve(fixture('js-nested-locals'), options)
65+
}))
66+
67+
it('should build', co(function* () {
68+
js += yield build(tree).end();
69+
}))
70+
71+
it('should rewrite the component require correctly', function() {
72+
js.should.not.include("require('nested/boot')")
73+
js.should.not.include("require('./lib/nested/boot/boot')")
74+
75+
js.should.include("require('./lib/nested/boot')")
76+
})
77+
78+
it('should rewrite requires inside of components correctly', function () {
79+
js.should.not.include("require('nested/boot/smth.js')")
80+
81+
js.should.include("require('./lib/nested/boot/smth.js')")
82+
})
83+
84+
it('should execute', function () {
85+
var ctx = vm.createContext()
86+
vm.runInContext(js, ctx)
87+
vm.runInContext('require("js-nested-locals")', ctx)
88+
ctx.boot.main.should.be.ok
89+
ctx.insideBoot.inside.should.be.ok
90+
})
91+
})
92+
5993
describe('js-scripts -dev', function () {
6094
var tree
6195
var js = Builder.require
@@ -441,4 +475,4 @@ describe('js-require-single-quotes', function () {
441475
js.should.include("require(\'js-require-single-quotes/something.js\')")
442476
js.should.not.include('require("js-require-single-quotes/something.js")')
443477
})
444-
})
478+
})

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.