Skip to content

Commit 648d007

Browse files
committed
Merge pull request #87 from tetsuo/feature-js-nonrelative-camelcase
Feature: camelCase
2 parents d4d81bb + a2bb22c commit 648d007

File tree

24 files changed

+189
-9
lines changed

24 files changed

+189
-9
lines changed

lib/builders/lookup.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ function Lookup (file, opts) {
3636
*/
3737
Lookup.prototype.exec = function* (target) {
3838
var ret;
39-
target = target.toLowerCase();
40-
4139
if (RELATIVE_PATH.exec(target)) {
4240
ret = this.relatives(target);
4341
if (ret != null) return ret
@@ -68,10 +66,10 @@ Lookup.prototype.relatives = function (target, file) {
6866

6967
for (var j = 0; j < EXTENSIONS.length; j++) {
7068
// check by adding extensions
71-
if (f.path.toLowerCase() === path_ + EXTENSIONS[j]) return name;
69+
if (f.path === path_ + EXTENSIONS[j]) return name;
7270
}
7371
// check by removing extensions
74-
if (f.path.replace(/\.\w+$/, '').toLowerCase() === path_) return name;
72+
if (f.path.replace(/\.\w+$/, '') === path_) return name;
7573
};
7674

7775
var message = 'ignore "' + target + '" , could not resolve from "' + file.branch.name + '"\'s file "' + file.path + '"';
@@ -263,7 +261,7 @@ Lookup.prototype.dependencies = function* (target) {
263261
*/
264262
function tofrags (target) {
265263
var frags = target.split('/');
266-
var head = frags[0];
264+
var head = frags[0].toLowerCase();
267265
var tail = frags.length > 1
268266
? frags.slice(1).join('/')
269267
: '';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "js-deps-camelcase",
3+
"scripts": [
4+
"index.js"
5+
],
6+
"dependencies": {
7+
"bar/baz": "*"
8+
}
9+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 'Qu';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "baz",
3+
"version": "1.2.3",
4+
"repository": "bar/baz",
5+
"scripts": ["index.js", "QuxQuux.js", "qux/*.js"],
6+
"main": "index.js"
7+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var qu = require('./QuxQuux');
2+
var fu = require('./qux/FooBar');
3+
module.exports = 'baz' + qu + fu;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 'Foo';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 'qux';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 'quux';
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
this.baz = require('baz');
2+
this.qux = require('baz/qux');
3+
this.quux = require('baz/qux/quux');
4+
this.Foo = require('baz/qux/FooBar');
5+
this.Qu = require('baz/QuxQuux');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 'WoRLd'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"scripts": ["index.js", "Hello.js"]
3+
}

test/fixtures/js-locals-camelcase/SubComponents/SubComponent-1/index.js

Whitespace-only changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "js-locals-camelcase",
3+
"dependencies": {
4+
},
5+
"scripts": [
6+
"index.js"
7+
],
8+
"locals": [
9+
"SubComponent-1"
10+
],
11+
"paths": [
12+
"SubComponents"
13+
]
14+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require('SubComponent-1');
2+
var hello = require('SubComponent-1/Hello');
3+
this.one = hello;

test/fixtures/js-locals/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
require('subcomponent-1');
2-
require('subcomponent-1/hello');
3-
this.one = true;
2+
var hello = require('subcomponent-1/hello');
3+
this.one = hello;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
this.hello = true;
1+
module.exports = 'world'
Lines 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+
}
Lines 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-uppercase/lib/index.js

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {inside: true};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"scripts": [ "index.js", "SMTH.js" ]
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {main: true};
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
var emitter = require("COMPONENT~EMITTER")
1+
var emitter = require("COMPONENT~EMITTER")
2+
var emitter_ = require("COMPONENT-EMITTER")

test/scripts.js

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ describe('js-require-uppercase', function () {
378378

379379
it('should have resolved the require()', function () {
380380
js.should.include('var emitter = require("[email protected]"')
381+
js.should.include('var emitter_ = require("[email protected]"')
381382
})
382383
})
383384

@@ -532,6 +533,8 @@ describe('js-locals', function () {
532533
it('should execute', function () {
533534
var ctx = vm.createContext();
534535
vm.runInContext(js, ctx);
536+
vm.runInContext('require("js-locals")', ctx)
537+
ctx.one.should.equal('world');
535538
})
536539
})
537540

@@ -665,3 +668,114 @@ describe('js-relative-extension-deps', function () {
665668
ctx.quux.should.equal('quux');
666669
})
667670
})
671+
672+
describe('js-locals-camelcase', function () {
673+
var tree;
674+
var js = Builder.require;
675+
676+
it('should install', co(function* () {
677+
tree = yield* resolve(fixture('js-locals-camelcase'), options);
678+
}))
679+
680+
it('should build', co(function* () {
681+
js += yield build(tree).end();
682+
}))
683+
684+
it('should rewrite requires for files inside locals', function () {
685+
js.should.not.include("require('subcomponent-1')");
686+
js.should.not.include('require("subcomponent-1")');
687+
js.should.not.include("require('subcomponent-1/hello')");
688+
js.should.not.include('require("subcomponent-1/hello")');
689+
js.should.not.include("require('./subcomponents/subcomponent-1')");
690+
js.should.not.include("require('./subcomponents/subcomponent-1/hello.js')");
691+
js.should.not.include("require('SubComponent-1')");
692+
js.should.not.include('require("SubComponent-1")');
693+
js.should.not.include("require('SubComponent-1/Hello')");
694+
js.should.not.include('require("SubComponent-1/Hello")');
695+
js.should.include("require('./SubComponents/SubComponent-1')");
696+
js.should.include("require('./SubComponents/SubComponent-1/Hello.js')");
697+
})
698+
699+
it('should execute', function () {
700+
var ctx = vm.createContext();
701+
vm.runInContext(js, ctx);
702+
vm.runInContext("require('js-locals-camelcase')", ctx);
703+
ctx.one.should.equal('WoRLd');
704+
})
705+
})
706+
707+
describe('js-nested-locals-uppercase', function() {
708+
var tree
709+
var js = Builder.require
710+
711+
it('should install', co(function* () {
712+
tree = yield* resolve(fixture('js-nested-locals-uppercase'), options)
713+
}))
714+
715+
it('should build', co(function* () {
716+
js += yield build(tree).end();
717+
}))
718+
719+
it('should rewrite the component require correctly', function() {
720+
js.should.not.include("require('nested/BOOT')")
721+
js.should.not.include("require('./lib/nested/BOOT/BOOT')")
722+
js.should.include("require('./lib/nested/BOOT')")
723+
})
724+
725+
it('should rewrite requires inside of components correctly', function () {
726+
js.should.not.include("require('nested/BOOT/SMTH.js')")
727+
js.should.include("require('./lib/nested/BOOT/SMTH.js')")
728+
})
729+
730+
it('should execute', function () {
731+
var ctx = vm.createContext()
732+
vm.runInContext(js, ctx)
733+
vm.runInContext('require("js-nested-locals-uppercase")', ctx)
734+
ctx.boot.main.should.be.ok
735+
ctx.insideBoot.inside.should.be.ok
736+
})
737+
})
738+
739+
describe('js-deps-camelcase', function () {
740+
var tree
741+
var js = Builder.require
742+
var dir = fixture('js-deps-camelcase');
743+
744+
it('should install', co(function* () {
745+
tree = yield* resolve(dir, { install: true, out: join(dir, 'foo') })
746+
}))
747+
748+
it('should build', co(function* () {
749+
js += yield build(tree).end();
750+
}))
751+
752+
it('should rewrite requires', function () {
753+
js.should.include('require.register("[email protected]"')
754+
js.should.include('require.register("[email protected]/qux/index.js"')
755+
js.should.not.include('require.register("[email protected]/qux"')
756+
js.should.include('require.register("[email protected]/qux/quux.js"')
757+
js.should.include('require.register("[email protected]/QuxQuux.js"')
758+
js.should.include('require.register("[email protected]/qux/FooBar.js"')
759+
js.should.not.include('require.register("[email protected]/qux/quux"')
760+
js.should.include("require('[email protected]')")
761+
js.should.include("require('[email protected]/qux/index.js')")
762+
js.should.include("require('[email protected]/qux/quux.js')")
763+
js.should.include("require('[email protected]/QuxQuux.js')")
764+
js.should.not.include("require('[email protected]/qux/quxquux')")
765+
js.should.not.include("require('[email protected]/qux/quxquux.js')")
766+
js.should.not.include("require('[email protected]/qux')")
767+
js.should.not.include("require('[email protected]/qux/quux')")
768+
js.should.not.include("require('[email protected]/qux/foobar')")
769+
})
770+
771+
it('should execute', function () {
772+
var ctx = vm.createContext()
773+
vm.runInContext(js, ctx)
774+
vm.runInContext('require("js-deps-camelcase")', ctx)
775+
ctx.baz.should.equal('bazQuFoo');
776+
ctx.qux.should.equal('qux');
777+
ctx.quux.should.equal('quux');
778+
ctx.Foo.should.equal('Foo');
779+
ctx.Qu.should.equal('Qu');
780+
})
781+
})

0 commit comments

Comments
 (0)