Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 12 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,28 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: purescript-contrib/setup-purescript@main
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
purescript: "0.15.0"
- uses: actions/cache@v2
# This cache uses the .dhall files to know when it should reinstall
# and rebuild packages. It caches both the installed packages from
# the `.spago` directory and compilation artifacts from the `output`
# directory. When restored the compiler will rebuild any files that
# have changed.
node-version: 20
cache: 'npm'

- name: Cache PureScript dependencies
uses: actions/cache@v4
with:
key: ${{ runner.os }}-spago-${{ hashFiles('**/*.dhall') }}
key: ${{ runner.os }}-spago-${{ hashFiles('**/spago.lock') }}
path: |
.spago
output

- name: Install esbuild and dev dependencies
run: npm install --global [email protected] && npm install
- name: Install npm dependencies
run: npm install

- name: Build source
run: npm run bundle

- name: Build script
run: spago --config script/spago.dhall build

- name: Build bin
run: spago --config bin/spago.dhall build

- name: Build tests
run: spago --config test/spago.dhall build
run: npm run bundle -- --pedantic-packages

- name: Run tests
run: spago --quiet --config test/spago.dhall test
run: npm run test -- --offline --quiet

- name: Verify formatting
run: npm run check-self
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
/.psa*
/.spago
/*.purs*
/.vscode
41 changes: 0 additions & 41 deletions bin/spago.dhall

This file was deleted.

41 changes: 41 additions & 0 deletions bin/spago.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package:
name: tidy-bin
build:
strict: true
dependencies:
- aff: ">=8.0.0 <9.0.0"
- argonaut-codecs: ">=9.1.0 <10.0.0"
- argonaut-core: ">=7.0.0 <8.0.0"
- argparse-basic: ">=2.0.0 <3.0.0"
- arrays: ">=7.3.0 <8.0.0"
- console: ">=6.1.0 <7.0.0"
- control: ">=6.0.0 <7.0.0"
- datetime: ">=6.1.0 <7.0.0"
- dodo-printer: ">=2.2.3 <3.0.0"
- effect: ">=4.0.0 <5.0.0"
- either: ">=6.1.0 <7.0.0"
- foldable-traversable: ">=6.0.0 <7.0.0"
- foreign-object: ">=4.1.0 <5.0.0"
- language-cst-parser: ">=0.14.1 <0.15.0"
- lazy: ">=6.0.0 <7.0.0"
- lists: ">=7.0.0 <8.0.0"
- maybe: ">=6.0.0 <7.0.0"
- newtype: ">=5.0.0 <6.0.0"
- node-buffer: ">=9.0.0 <10.0.0"
- node-event-emitter: ">=3.0.0 <4.0.0"
- node-fs: ">=9.2.0 <10.0.0"
- node-glob-basic: ">=2.0.0 <3.0.0"
- node-path: ">=5.0.1 <6.0.0"
- node-process: ">=11.2.0 <12.0.0"
- node-streams: ">=9.0.1 <10.0.0"
- node-workerbees: ">=0.3.1 <0.4.0"
- numbers: ">=9.0.1 <10.0.0"
- ordered-collections: ">=3.2.0 <4.0.0"
- parallel: ">=7.0.0 <8.0.0"
- partial: ">=4.0.0 <5.0.0"
- prelude: ">=6.0.1 <7.0.0"
- refs: ">=6.0.0 <7.0.0"
- strings: ">=6.0.1 <7.0.0"
- tidy: "*"
- transformers: ">=6.1.0 <7.0.0"
- tuples: ">=7.0.0 <8.0.0"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
40 changes: 22 additions & 18 deletions bin/Main.purs → bin/src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import Data.Traversable (for, traverse)
import Data.Tuple (Tuple(..))
import Data.Tuple.Nested ((/\))
import Effect (Effect)
import Effect.Aff (Aff, error, launchAff_, makeAff, throwError, try)
import Effect.Aff (Aff, effectCanceler, error, launchAff_, makeAff, throwError, try)
import Effect.Aff as Aff
import Effect.Class (liftEffect)
import Effect.Class.Console as Console
Expand All @@ -43,6 +43,7 @@ import Foreign.Object (Object)
import Foreign.Object as Object
import Node.Buffer as Buffer
import Node.Encoding (Encoding(..))
import Node.EventEmitter (on)
import Node.FS.Aff as FS
import Node.FS.Stats as Stats
import Node.Glob.Basic (expandGlobsCwd, expandGlobsWithStatsCwd)
Expand Down Expand Up @@ -160,14 +161,14 @@ main = launchAff_ do

case parsedCmd of
Left err -> do
Console.log $ Arg.printArgError err
Console.error $ Arg.printArgError err
case err of
Arg.ArgError _ Arg.ShowHelp ->
liftEffect $ Process.exit 0
pure unit
Arg.ArgError _ (Arg.ShowInfo _) ->
liftEffect $ Process.exit 0
pure unit
_ ->
liftEffect $ Process.exit 1
liftEffect $ Process.setExitCode 1
Right cmd ->
case cmd of
GenerateOperators globs ->
Expand All @@ -180,7 +181,7 @@ main = launchAff_ do
FS.writeTextFile UTF8 rcFileName $ contents <> "\n"
else do
Console.error $ rcFileName <> " already exists."
liftEffect $ Process.exit 1
liftEffect $ Process.setExitCode 1

FormatInPlace mode cliOptions configOption numThreads printTiming globs -> do
currentDir <- liftEffect Process.cwd
Expand Down Expand Up @@ -236,7 +237,7 @@ main = launchAff_ do
when printTiming do
for_ (Array.sortBy (comparing _.timing) results) \{ filePath, timing } ->
when (timing > 0.0) do
Console.log $ fold
Console.error $ fold
[ Path.relative currentDir filePath
, " "
, NF.toStringWith (NF.fixed 2) timing
Expand All @@ -251,16 +252,16 @@ main = launchAff_ do
Check -> liftEffect do
if Array.null errors && Array.null notFormatted then do
Console.log "All files are formatted."
Process.exit 0
Process.setExitCode 0
else do
unless (Array.null errors) do
Console.log "Some files have errors:\n"
Console.error "Some files have errors:\n"
for_ errors \(Tuple filePath error) ->
Console.error $ filePath <> ":\n " <> error <> "\n"
unless (Array.null notFormatted) do
Console.log "Some files are not formatted:\n"
Console.error "Some files are not formatted:\n"
for_ notFormatted Console.error
Process.exit 1
Process.setExitCode 1

Format cliOptions configOption -> do
currentDir <- liftEffect Process.cwd
Expand All @@ -272,11 +273,9 @@ main = launchAff_ do
case formatCommand options operators contents of
Left err -> do
Console.error err
liftEffect $ Process.exit 1
liftEffect $ Process.setExitCode 1
Right str ->
makeAff \k -> do
_ <- Stream.writeString Process.stdout UTF8 str (const (k (Right unit)))
pure mempty
writeStdout str

expandGlobs :: Array String -> Aff (Array String)
expandGlobs = map dirToGlob >>> expandGlobsWithStatsCwd >>> map onlyFiles
Expand All @@ -303,7 +302,7 @@ getOptions cliOptions rcOptions filePath = case _ of
case rcOptions of
Nothing -> do
Console.error $ rcFileName <> " not found for " <> filePath
liftEffect $ Process.exit 1
liftEffect $ Process.exit' 1
Just options ->
pure options

Expand Down Expand Up @@ -362,10 +361,15 @@ resolveRcForDir root = go List.Nil
readStdin :: Aff String
readStdin = makeAff \k -> do
contents <- Ref.new []
Stream.onData Process.stdin \buff -> do
c1 <- Process.stdin # on Stream.dataH \buff ->
void $ Ref.modify (_ `Array.snoc` buff) contents
Stream.onEnd Process.stdin do
c2 <- Process.stdin # on Stream.endH do
k <<< Right =<< Buffer.toString UTF8 =<< Buffer.concat =<< Ref.read contents
pure $ effectCanceler (c1 *> c2)

writeStdout :: String -> Aff Unit
writeStdout str = makeAff \k -> do
_ <- Stream.writeString' Process.stdout UTF8 str (const (k (Right unit)))
pure mempty

generateOperatorsCommand :: Array String -> Aff Unit
Expand Down
Loading