Browse Source

local settings prevail

Herbert Vojčík 9 years ago
parent
commit
0d4308f1ca

+ 2 - 2
lib/config-builder.js

@@ -90,7 +90,7 @@ function queoeOfFilesToProcess(files, dirMap) {
             throw new Error("No location for " + file);
         }
     }
-    return  firstPass.reverse().concat(secondPass.reverse());
+    return  firstPass.concat(secondPass).reverse();
 }
 
 exports.produceConfigObject = function (root, callback) {
@@ -120,7 +120,7 @@ exports.produceConfigObject = function (root, callback) {
             transformShimDeps(json);
             transformPaths(json, root, file, dirMap);
             _.merge(result, json, function (a, b) {
-                return _.isArray(a) ? a.concat(b) : undefined;
+                return _.isArray(a) ? b.concat(a) : undefined;
             });
         }
         callback(null, result);

+ 19 - 9
test/produce.js

@@ -66,7 +66,7 @@ describe('#produceConfigObject merging', function () {
         });
     });
 
-    it('should include both local.amd.json if root and deep are present, deep first', function (done) {
+    it('should include both local.amd.json if root and deep are present, parent should win', function (done) {
         builder.produceConfigObject(fixture('two-locals-with-shared'), function (err, result) {
             assert.ifError(err);
             assert.deepEqual(result, {
@@ -76,21 +76,31 @@ describe('#produceConfigObject merging', function () {
         });
     });
 
-    it('should include {root,deep}/local.amd.json first and {foo,bar}.amd.json afterwards given {foo,bar} dir is present', function (done) {
+    it('should include both local.amd.json if root and deep are present, parent should be first in arrays', function (done) {
+        builder.produceConfigObject(fixture('two-locals-with-shared-array'), function (err, result) {
+            assert.ifError(err);
+            assert.deepEqual(result, {
+                config: {foo: {foo: "bar"}, fooDeep: {foo: "bar"}, shared: ["root", 0, "deep", 0]}
+            });
+            done();
+        });
+    });
+
+    it('should include {root,deep}/local.amd.json and {foo,bar}.amd.json given {foo,bar} dir is present, locals should win', function (done) {
         builder.produceConfigObject(fixture('two-locals-two-others'), function (err, result) {
             assert.ifError(err);
             assert.deepEqual(result, {
-                config: {a: 2, b: 2, c: 2, d: 2, e: 1, f: 1}
+                config: {a: 1, b: 1, c: 1, d: 1, e: 1, f: 1}
             });
             done();
         });
     });
 
-    it('should include {root,deep}/local.amd.json first and {foo,bar}.amd.json afterwards given {foo,bar} dir is present, deeps first', function (done) {
+    it('should include {root,deep}/local.amd.json and {foo,bar}.amd.json given {foo,bar} dir is present, locals and parents should win', function (done) {
         builder.produceConfigObject(fixture('two-locals-two-others-with-shared'), function (err, result) {
             assert.ifError(err);
             assert.deepEqual(result, {
-                config: {a: 2, b: 2, c: 2, d: 2, e: 1, f: 1, g: 2, h: 1}
+                config: {a: 1, b: 1, c: 1, d: 1, e: 1, f: 1, g: 2, h: 1}
             });
             done();
         });
@@ -108,14 +118,14 @@ describe('#produceConfigObject knows to deal with shims', function () {
         });
     });
 
-    it('should merge shims from {root,deep}/local.amd.json then from {foo,bar}.amd.json given {foo,bar} dir is present', function (done) {
+    it('should merge shims from {root,deep}/local.amd.json and from {foo,bar}.amd.json given {foo,bar} dir is present, locals and parent should win or be first', function (done) {
         builder.produceConfigObject(fixture('two-locals-two-others-shim'), function (err, result) {
             assert.ifError(err);
             assert.deepEqual(result, {
-                config: {a: 2, b: 2, c: 2, d: 2, e: 1, f: 1},
+                config: {a: 1, b: 1, c: 1, d: 1, e: 1, f: 1},
                 shim: {
-                    a: {deps: ["deeplocal", "other"], exports: "deep"},
-                    b: {deps: ["rootlocal", "deep"], exports: "other"}
+                    a: {deps: ["deeplocal", "other"], exports: "other"},
+                    b: {deps: ["rootlocal", "deep"], exports: "rootlocal"}
                 }
             });
             done();

+ 1 - 1
test/two-locals-two-others-shim/local.amd.json

@@ -3,7 +3,7 @@
         "c": 1, "d": 1, "f": 1
     },
     "shim": {
-        "a": {"exports": "rootlocal"},
+        "a": {},
         "b": {"deps": ["rootlocal"], "exports": "rootlocal"}
     }
 }

+ 1 - 1
test/two-locals-two-others-shim/other.amd.json

@@ -3,7 +3,7 @@
         "b": 2, "c": 2
     },
     "shim": {
-        "a": {"deps": ["other"]},
+        "a": {"deps": ["other"], "exports": "other"},
         "b": {"exports": "other"}
     }
 }

+ 6 - 0
test/two-locals-with-shared-array/deep/local.amd.json

@@ -0,0 +1,6 @@
+{
+    "config": {
+        "fooDeep": {"foo": "bar"},
+        "shared": ["deep", 0]
+    }
+}

+ 6 - 0
test/two-locals-with-shared-array/local.amd.json

@@ -0,0 +1,6 @@
+{
+    "config": {
+        "foo": {"foo": "bar"},
+        "shared": ["root", 0]
+    }
+}