diff --git a/FSharpPacker.FSharp/Packer.fs b/FSharpPacker.FSharp/Packer.fs index 7544cd7..410aedf 100644 --- a/FSharpPacker.FSharp/Packer.fs +++ b/FSharpPacker.FSharp/Packer.fs @@ -93,6 +93,7 @@ let ParsePaths paths = type FsxLine = | SourceCode of string | Unsupported + | Skipped | IncludePath of seq | IncludeFiles of seq | IncludeReference of references: seq * packages: seq * projectReferences: seq @@ -151,6 +152,8 @@ let classifyLine (sourceFile: SourceFile) (normalizedLine: string) = let pathStrings = normalizedLine.Replace("#load ", ""); let files = ParsePaths(pathStrings) |> Seq.map sourceFile.ResolveRelativePath IncludeFiles(files) + elif normalizedLine.StartsWith("#!") then + Skipped else SourceCode(normalizedLine) else SourceCode(normalizedLine) @@ -161,6 +164,7 @@ let rec public ProcessLine verbose state sourceFile line = match lineResult with | SourceCode(code) -> sourceFile.WriteLine(code) | Unsupported -> () + | Skipped -> () | AddNugetFeed(code) -> state.nugetSources <- Seq.append state.nugetSources [code] | IncludePath(files) -> sourceFile.AddIncludePaths(files) | IncludeFiles(files) -> for file in files do diff --git a/FSharpPacker.Tests/Samples/Shebang.fsx b/FSharpPacker.Tests/Samples/Shebang.fsx new file mode 100644 index 0000000..a608cd2 --- /dev/null +++ b/FSharpPacker.Tests/Samples/Shebang.fsx @@ -0,0 +1,3 @@ +#!/usr/bin/env -S dotnet fsi + +printfn "Hello, world!" diff --git a/FSharpPacker.Tests/UnitTest1.cs b/FSharpPacker.Tests/UnitTest1.cs index ea0f134..d6a0290 100644 --- a/FSharpPacker.Tests/UnitTest1.cs +++ b/FSharpPacker.Tests/UnitTest1.cs @@ -245,4 +245,15 @@ public void MultipleLoadDirectivesFile() CollectionAssert.AreEqual(new string[] { "WithNamespace.fsx", "WithNamespaceAndComments.fsx", "Loader.fsx", "MultipleLoadDirectivesFile.fsx" }, preprocessor.GetSources().Select(_ => Path.GetFileName(_.FileName)).ToArray()); } + [TestMethod] + public void Shebang() + { + var sourceFile = "Samples/Shebang.fsx"; + var preprocessor = new FsxPreprocessor(verbose: false); + preprocessor.AddSource(sourceFile); + + preprocessor.Process(); + + Assert.AreEqual("module Shebang" + Environment.NewLine + Environment.NewLine + "printfn \"Hello, world!\"" + Environment.NewLine, preprocessor.GetSource(sourceFile)); + } } \ No newline at end of file