예제 #1
0
        private RequireShim GetShim(JObject document)
        {
            var shim = new RequireShim();

            shim.ShimEntries = new List <ShimEntry>();
            if (document != null && document["shim"] != null)
            {
                shim.ShimEntries = document["shim"].Select(
                    r =>
                {
                    var result          = new ShimEntry();
                    var prop            = (JProperty)r;
                    result.For          = prop.Name;
                    var shimObj         = (JObject)prop.Value;
                    result.Exports      = shimObj["exports"] != null ? shimObj["exports"].ToString() : null;
                    var depArr          = (JArray)shimObj["deps"];
                    result.Dependencies = new List <RequireDependency>();
                    if (depArr != null)
                    {
                        result.Dependencies = depArr.Select(dep => new RequireDependency
                        {
                            Dependency = dep.ToString()
                        })
                                              .ToList();
                    }

                    return(result);
                })
                                   .ToList();
            }

            return(shim);
        }
        public void MergeShimsWithSameKey()
        {
            var jqueryShim = new ShimEntry
            {
                For          = "jquery",
                Dependencies = new List <RequireDependency>
                {
                    new RequireDependency {
                        Dependency = "depA"
                    },
                    new RequireDependency {
                        Dependency = "depB"
                    }
                }
            };

            var altJqueryShim = new ShimEntry
            {
                For          = "jquery",
                Dependencies = new List <RequireDependency>
                {
                    new RequireDependency {
                        Dependency = "depB"
                    },
                    new RequireDependency {
                        Dependency = "depD"
                    }
                }
            };

            var firstCollection  = ConfigurationCreators.CreateCollectionWithShims(jqueryShim);
            var secondCollection = ConfigurationCreators.CreateCollectionWithShims(altJqueryShim);

            var merger = ConfigurationCreators.CreateDefaultConfigMerger(firstCollection, secondCollection);
            var merged = merger.GetMerged();

            var expectedShim = new ShimEntry
            {
                For          = "jquery",
                Dependencies = new List <RequireDependency>
                {
                    new RequireDependency {
                        Dependency = "depA"
                    },
                    new RequireDependency {
                        Dependency = "depB"
                    },
                    new RequireDependency {
                        Dependency = "depD"
                    }
                }
            };

            var expected = ConfigurationCreators.CreateCollectionWithShims(expectedShim);

            CustomAssert.JsonEquals(expected, merged);
        }
예제 #3
0
        public void ReadShimWithExports()
        {
            var config = ReadJson(new TestFileReader());
            var shim   = new ShimEntry
            {
                For          = "jquery-validate",
                Dependencies =
                    new List <RequireDependency>
                {
                    new RequireDependency {
                        Dependency = "jquery"
                    }
                },
                Exports = "jqVal"
            };
            var expected = ConfigurationCreators.CreateCollectionWithShims(shim);

            CustomAssert.JsonEquals(expected, config);
        }
예제 #4
0
        private RequireShim GetShim(JObject document)
        {
            var shim = new RequireShim();

            shim.ShimEntries = new List <ShimEntry>();
            string parseSection = "shim";

            if (document != null && document[parseSection] != null)
            {
                JToken shimParent = JsonParseOrThrow <JObject>(document[parseSection], parseSection, Path, null);
                shim.ShimEntries = shimParent.Select(
                    r =>
                {
                    var result = new ShimEntry();
                    var prop   = (JProperty)r;
                    result.For = prop.Name;
                    string parseSectionHint = parseSection + "." + prop.Name;
                    JObject shimObj         = JsonParseOrThrow <JObject>(prop.Value, parseSectionHint, Path, r);
                    result.Exports          = JsonParseStringOrThrow(shimObj, "exports", parseSectionHint, Path);
                    JArray depArr           = JsonParseArrayOrThrow(shimObj, "deps", parseSectionHint, Path);
                    result.Dependencies     = new List <RequireDependency>();
                    if (depArr != null)
                    {
                        result.Dependencies = depArr.Select(dep => new RequireDependency
                        {
                            Dependency = dep.ToString()
                        })
                                              .ToList();
                    }

                    return(result);
                })
                                   .ToList();
            }

            return(shim);
        }
        public void OverrideExportsValueForShimsWithSameKey()
        {
            var jqueryShim = new ShimEntry
            {
                For          = "jquery",
                Dependencies = new List <RequireDependency>(),
                Exports      = "jqu"
            };

            var altJqueryShim = new ShimEntry
            {
                For          = "jquery",
                Dependencies = new List <RequireDependency>(),
                Exports      = "jlo"
            };

            var firstCollection  = ConfigurationCreators.CreateCollectionWithShims(jqueryShim);
            var secondCollection = ConfigurationCreators.CreateCollectionWithShims(altJqueryShim);

            var merger = ConfigurationCreators.CreateDefaultConfigMerger(firstCollection, secondCollection);
            var merged = merger.GetMerged();

            Assert.Equal("jlo", merged.Shim.ShimEntries.FirstOrDefault().Exports);
        }