Пример #1
0
        public void Returns_resolved_modules()
        {
            var moduleA = new UnresolvedModule("module-a", new[] { CreateScript("module-a", "foo") }, null, false);
            var moduleB = new UnresolvedModule("module-b", new[] { CreateScript("module-b", "bar", "../module-a/foo") }, null, false);

            var modules = UnresolvedModule.ResolveAll(new[] { moduleA, moduleB }).ToArray();

            modules[0].Path.ShouldEqual("module-a");
            modules[1].Path.ShouldEqual("module-b");
            modules[1].References[0].ShouldEqual("module-a");
        }
        public override ModuleContainer Build()
        {
            var moduleBuilder     = new UnresolvedScriptModuleBuilder(rootDirectory);
            var unresolvedModules = relativeModuleDirectories.Select(x => moduleBuilder.Build(x.Item1, x.Item2));
            var modules           = UnresolvedModule.ResolveAll(unresolvedModules);

            return(new ModuleContainer(
                       modules,
                       storage,
                       textWriter => new ScriptModuleWriter(textWriter, rootDirectory, LoadFile, coffeeScriptCompiler)
                       ));
        }
        public override ModuleContainer Build()
        {
            var moduleBuilder     = new UnresolvedStylesheetModuleBuilder(rootDirectory, applicationRoot);
            var unresolvedModules = relativeModuleDirectories.Select(x => moduleBuilder.Build(x.Item1, x.Item2));
            var modules           = UnresolvedModule.ResolveAll(unresolvedModules);

            return(new ModuleContainer(
                       modules,
                       storage,
                       textWriter => new StylesheetModuleWriter(textWriter, rootDirectory, applicationRoot, LoadFile)
                       ));
        }
Пример #4
0
        public void Throws_useful_exception_when_resource_not_found()
        {
            var moduleA = new UnresolvedModule("module-a", new[] { CreateScript("module-a", "foo") }, null, false);
            var moduleB = new UnresolvedModule("module-b", new[] { CreateScript("module-b", "bar", "../module-a/missing") }, null, false);

            var exception = Assert.Throws <FileNotFoundException>(delegate
            {
                UnresolvedModule.ResolveAll(new[] { moduleA, moduleB }).ToArray();
            });

            exception.FileName.ShouldEqual("module-a/missing.js");
            exception.Message.ShouldEqual(
                "The file \"module-a/missing.js\" is referenced by \"module-b/bar.js\", but cannot be found. " +
                "Either add \"module-a/missing.js\" or change the reference(s) to a file that exists.");
        }
Пример #5
0
        public UnresolvedModule_with_scripts_having_only_internal_references()
        {
            var scriptA = CreateScript("a", "c");
            var scriptB = CreateScript("b");
            var scriptC = CreateScript("c", "b");

            // Dependency chain: b <- c <- a

            unresolvedModule = new UnresolvedModule(
                @"scripts/module-a",
                new[] { scriptA, scriptB, scriptC },
                null,
                false
                );

            module = unresolvedModule.Resolve(s => null);
        }
Пример #6
0
        public Resolve_a_UnresolvedModule_with_script_having_an_external_reference()
        {
            var script = new UnresolvedResource(
                @"scripts/module-a/test.js",
                new byte[0],
                new[] { @"scripts/module-b/lib.js" }
                );

            unresolvedModule = new UnresolvedModule(
                @"scripts/module-a",
                new[] { script },
                null,
                false
                );

            module = unresolvedModule.Resolve(s => @"scripts/module-b");
        }
Пример #7
0
        public UnresolvedModule_with_fixed_resource_order()
        {
            // Create scripts with some dependencies declared.
            var scriptA = CreateScript("a", "c");
            var scriptB = CreateScript("b");
            var scriptC = CreateScript("c", "b");

            // Declared dependency chain: b <- c <- a

            unresolvedModule = new UnresolvedModule(
                @"scripts/module-a",
                new[] { scriptA, scriptB, scriptC },
                null,
                isResourceOrderFixed: true
                );

            module = unresolvedModule.Resolve(s => null);
        }
Пример #8
0
        public Resolve_an_UnresolvedModule_with_scripts_in_subdirectory()
        {
            var script1 = new UnresolvedResource(
                @"scripts/module-a/sub/test-1.js",
                new byte[0],
                new[] { @"test-2.js" }
            );
            var script2 = new UnresolvedResource(
                @"scripts/module-a/sub/test-2.js",
                new byte[0],
                new string[] { }
            );
            unresolvedModule = new UnresolvedModule(
                @"scripts/module-a",
                new[] { script1, script2 },
                null,
                false
            );

            module = unresolvedModule.Resolve(s => @"scripts/module-a");
        }
Пример #9
0
        public Resolve_an_UnresolvedModule_with_scripts_in_subdirectory()
        {
            var script1 = new UnresolvedResource(
                @"scripts/module-a/sub/test-1.js",
                new byte[0],
                new[] { @"test-2.js" }
                );
            var script2 = new UnresolvedResource(
                @"scripts/module-a/sub/test-2.js",
                new byte[0],
                new string[] { }
                );

            unresolvedModule = new UnresolvedModule(
                @"scripts/module-a",
                new[] { script1, script2 },
                null,
                false
                );

            module = unresolvedModule.Resolve(s => @"scripts/module-a");
        }
Пример #10
0
 static string FindModulePathOrThrow(Dictionary<string, string> modulesByResourcePath, UnresolvedModule m, string resourcePath)
 {
     string module;
     if (modulesByResourcePath.TryGetValue(resourcePath, out module))
     {
         return module;
     }
     else
     {
         var referencers = string.Join(
             "\", \"",
             m.GetResourcePathsThatReferencePath(resourcePath)
         );
         throw new FileNotFoundException(
             string.Format(
                 "The file \"{0}\" is referenced by \"{1}\", but cannot be found. " +
                 "Either add \"{0}\" or change the reference(s) to a file that exists.",
                 resourcePath,
                 referencers
             ),
             resourcePath
         );
     }
 }
Пример #11
0
        public Resolve_a_UnresolvedModule_with_script_having_an_external_reference()
        {
            var script = new UnresolvedResource(
                @"scripts/module-a/test.js",
                new byte[0],
                new[] { @"scripts/module-b/lib.js" }
            );

            unresolvedModule = new UnresolvedModule(
                @"scripts/module-a",
                new[] { script },
                null,
                false
            );

            module = unresolvedModule.Resolve(s => @"scripts/module-b");
        }
Пример #12
0
        public UnresolvedModule_with_scripts_having_only_internal_references()
        {
            var scriptA = CreateScript("a", "c");
            var scriptB = CreateScript("b");
            var scriptC = CreateScript("c", "b");
            // Dependency chain: b <- c <- a

            unresolvedModule = new UnresolvedModule(
                @"scripts/module-a",
                new[] { scriptA, scriptB, scriptC },
                null,
                false
            );

            module = unresolvedModule.Resolve(s => null);
        }
Пример #13
0
        public UnresolvedModule_with_fixed_resource_order()
        {
            // Create scripts with some dependencies declared.
            var scriptA = CreateScript("a", "c");
            var scriptB = CreateScript("b");
            var scriptC = CreateScript("c", "b");
            // Declared dependency chain: b <- c <- a

            unresolvedModule = new UnresolvedModule(
                @"scripts/module-a",
                new[] { scriptA, scriptB, scriptC },
                null,
                isResourceOrderFixed: true
            );

            module = unresolvedModule.Resolve(s => null);
        }
Пример #14
0
        public void Throws_useful_exception_when_resource_not_found()
        {
            var moduleA = new UnresolvedModule("module-a", new[] { CreateScript("module-a", "foo") }, null, false);
            var moduleB = new UnresolvedModule("module-b", new[] { CreateScript("module-b", "bar", "../module-a/missing") }, null, false);

            var exception = Assert.Throws<FileNotFoundException>(delegate
            {
                UnresolvedModule.ResolveAll(new[] { moduleA, moduleB }).ToArray();
            });
            exception.FileName.ShouldEqual("module-a/missing.js");
            exception.Message.ShouldEqual(
                "The file \"module-a/missing.js\" is referenced by \"module-b/bar.js\", but cannot be found. " +
                "Either add \"module-a/missing.js\" or change the reference(s) to a file that exists.");
        }
Пример #15
0
        public void Returns_resolved_modules()
        {
            var moduleA = new UnresolvedModule("module-a", new[] { CreateScript("module-a", "foo") }, null, false);
            var moduleB = new UnresolvedModule("module-b", new[] { CreateScript("module-b", "bar", "../module-a/foo") }, null, false);

            var modules = UnresolvedModule.ResolveAll(new[] { moduleA, moduleB }).ToArray();

            modules[0].Path.ShouldEqual("module-a");
            modules[1].Path.ShouldEqual("module-b");
            modules[1].References[0].ShouldEqual("module-a");
        }
Пример #16
0
        static string FindModulePathOrThrow(Dictionary <string, string> modulesByResourcePath, UnresolvedModule m, string resourcePath)
        {
            string module;

            if (modulesByResourcePath.TryGetValue(resourcePath, out module))
            {
                return(module);
            }
            else
            {
                var referencers = string.Join(
                    "\", \"",
                    m.GetResourcePathsThatReferencePath(resourcePath)
                    );
                throw new FileNotFoundException(
                          string.Format(
                              "The file \"{0}\" is referenced by \"{1}\", but cannot be found. " +
                              "Either add \"{0}\" or change the reference(s) to a file that exists.",
                              resourcePath,
                              referencers
                              ),
                          resourcePath
                          );
            }
        }