Skip to content

Commit a6f6dcc

Browse files
Add option to exclude globs from given input (purescript#4480)
1 parent 1e4e0f2 commit a6f6dcc

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
* Exclude files from compiler input
2+
3+
The compiler now supports excluding files from the globs given to it as input.
4+
This means there's now a new option for `purs compile`, namely
5+
`--exclude-files` (or the short version `-x`):
6+
7+
```sh
8+
> purs compile --help
9+
Usage: purs compile [FILE] [-x|--exclude-files ARG] [-o|--output ARG] ...
10+
11+
Compile PureScript source files
12+
13+
Available options:
14+
-h,--help Show this help text
15+
FILE The input .purs file(s).
16+
-x,--exclude-files ARG Glob of .purs files to exclude from the supplied
17+
files.
18+
...
19+
```
20+
21+
This allows you to keep related files closer together (that is, [colocate](https://kentcdodds.com/blog/colocation) them).
22+
23+
Consider a setup like the following:
24+
25+
```sh
26+
src/
27+
Main.purs
28+
View/
29+
LoginPage.purs
30+
LoginPageTest.purs
31+
LoginPageStories.purs
32+
```
33+
34+
In order to exclude the files in the example above you can now invoke `purs`
35+
like this and it will only compile `LoginPage.purs`:
36+
37+
```sh
38+
purs compile "src/**/*.purs" --exclude-files "src/**/*Stories.purs" -x "src/**/*Test.purs"
39+
```
40+
41+
With `spago`, the equivalent command is:
42+
43+
```sh
44+
spago build --purs-args '-x "src/**/*Test.purs" -x "src/**/*Stories.purs"'
45+
```

app/Command/Compile.hs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Control.Monad (when)
77
import Data.Aeson qualified as A
88
import Data.Bool (bool)
99
import Data.ByteString.Lazy.UTF8 qualified as LBU8
10-
import Data.List (intercalate)
10+
import Data.List (intercalate, (\\))
1111
import Data.Map qualified as M
1212
import Data.Set qualified as S
1313
import Data.Text qualified as T
@@ -26,6 +26,7 @@ import System.IO.UTF8 (readUTF8FilesT)
2626

2727
data PSCMakeOptions = PSCMakeOptions
2828
{ pscmInput :: [FilePath]
29+
, pscmExclude :: [FilePath]
2930
, pscmOutputDir :: FilePath
3031
, pscmOpts :: P.Options
3132
, pscmUsePrefix :: Bool
@@ -53,7 +54,9 @@ printWarningsAndErrors verbose True files warnings errors = do
5354

5455
compile :: PSCMakeOptions -> IO ()
5556
compile PSCMakeOptions{..} = do
56-
input <- globWarningOnMisses warnFileTypeNotFound pscmInput
57+
included <- globWarningOnMisses warnFileTypeNotFound pscmInput
58+
excluded <- globWarningOnMisses warnFileTypeNotFound pscmExclude
59+
let input = included \\ excluded
5760
when (null input) $ do
5861
hPutStr stderr $ unlines [ "purs compile: No input files."
5962
, "Usage: For basic information, try the `--help' option."
@@ -86,6 +89,12 @@ inputFile = Opts.strArgument $
8689
Opts.metavar "FILE"
8790
<> Opts.help "The input .purs file(s)."
8891

92+
excludedFiles :: Opts.Parser FilePath
93+
excludedFiles = Opts.strOption $
94+
Opts.short 'x'
95+
<> Opts.long "exclude-files"
96+
<> Opts.help "Glob of .purs files to exclude from the supplied files."
97+
8998
outputDirectory :: Opts.Parser FilePath
9099
outputDirectory = Opts.strOption $
91100
Opts.short 'o'
@@ -153,6 +162,7 @@ options =
153162

154163
pscMakeOptions :: Opts.Parser PSCMakeOptions
155164
pscMakeOptions = PSCMakeOptions <$> many inputFile
165+
<*> many excludedFiles
156166
<*> outputDirectory
157167
<*> options
158168
<*> (not <$> noPrefix)

0 commit comments

Comments
 (0)