Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update to spago@next #122

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 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
54 changes: 31 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,47 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: purescript-contrib/setup-purescript@main
- uses: actions/checkout@v4

- name: Set up a PureScript toolchain
uses: purescript-contrib/setup-purescript@main
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.
purescript: "latest"
purs-tidy: "latest"
spago: "unstable"

- 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: Build source
run: npm run bundle
- name: Cache NPM dependencies
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}-
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-

- name: Build script
run: spago --config script/spago.dhall build
- name: Install npm dependencies
run: npm install

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

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

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

- name: Verify formatting
run: npm run check-self
1 change: 0 additions & 1 deletion bin/Bin/Version.js

This file was deleted.

3 changes: 0 additions & 3 deletions bin/Bin/Version.purs

This file was deleted.

41 changes: 0 additions & 41 deletions bin/spago.dhall

This file was deleted.

1 change: 1 addition & 0 deletions cli/.psc-ide-port
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
15368
File renamed without changes.
File renamed without changes.
43 changes: 43 additions & 0 deletions cli/spago.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package:
name: tidy-cli
publish:
license: MIT
version: 0.11.0
location:
githubOwner: natefaubion
githubRepo: purescript-tidy
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: "*"
- 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: "*"
- 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-fs: ">=9.2.0 <10.0.0"
- node-glob-basic: "*"
- node-path: ">=5.0.0 <6.0.0"
- node-process: ">=11.2.0 <12.0.0"
- node-streams: ">=9.0.0 <10.0.0"
- node-workerbees: "*"
- 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"
- 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.
2 changes: 1 addition & 1 deletion bin/Bin/Timing.purs → cli/src/Cli/Timing.purs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Bin.Timing where
module Cli.Timing where

import Prelude

Expand Down
7 changes: 7 additions & 0 deletions cli/src/Cli/Version.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Cli.Version where

import Prelude
import Spago.Generated.BuildInfo (packages)

version :: String
version = "v" <> packages."tidy-cli"
8 changes: 4 additions & 4 deletions bin/Bin/Worker.purs → cli/src/Cli/Worker.purs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
module Bin.Worker where
module Cli.Worker where

import Prelude

import Bin.FormatOptions (FormatOptions)
import Bin.FormatOptions as FormatOptions
import Bin.Timing (hrtime, hrtimeDiff, toMilliseconds)
import Cli.Timing (hrtime, hrtimeDiff, toMilliseconds)
import Data.Array.NonEmpty as NonEmptyArray
import Data.Either (Either(..), either, fromRight')
import Data.Lazy (Lazy)
Expand All @@ -28,6 +26,8 @@ import PureScript.CST (RecoveredParserResult(..), parseModule)
import PureScript.CST.Errors (printParseError)
import PureScript.CST.Parser.Monad (PositionedError)
import Tidy (defaultFormatOptions, formatModule, toDoc)
import Tidy.FormatOptions (FormatOptions)
import Tidy.FormatOptions as FormatOptions
import Tidy.Operators (parseOperatorTable)
import Tidy.Precedence (PrecedenceMap, remapOperators)

Expand Down
46 changes: 18 additions & 28 deletions bin/Main.purs → cli/src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import Prelude

import ArgParse.Basic (ArgParser)
import ArgParse.Basic as Arg
import Bin.FormatOptions (FormatOptions, formatOptions)
import Bin.FormatOptions as FormatOptions
import Bin.Version (version)
import Bin.Worker (WorkerData, WorkerInput, WorkerOutput, formatCommand, formatInPlaceCommand, toWorkerConfig)
import Cli.Version (version)
import Cli.Worker (WorkerData, WorkerInput, WorkerOutput, formatCommand, formatInPlaceCommand, toWorkerConfig)
import Control.Monad.State (evalStateT, lift)
import Control.Monad.State as State
import Control.Parallel (parTraverse)
Expand All @@ -34,11 +32,10 @@ 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, error, launchAff_, throwError, try)
import Effect.Aff as Aff
import Effect.Class (liftEffect)
import Effect.Class.Console as Console
import Effect.Ref as Ref
import Foreign.Object (Object)
import Foreign.Object as Object
import Node.Buffer as Buffer
Expand All @@ -49,12 +46,14 @@ import Node.Glob.Basic (expandGlobsCwd, expandGlobsWithStatsCwd)
import Node.Path (FilePath)
import Node.Path as Path
import Node.Process as Process
import Node.Stream as Stream
import Node.Stream.Aff as Stream.Aff
import Node.WorkerBees as Worker
import Node.WorkerBees.Aff.Pool (poolTraverse)
import PureScript.CST (RecoveredParserResult(..), parseModule, toRecovered)
import PureScript.CST.ModuleGraph (ModuleSort(..), sortModules)
import PureScript.CST.Types (Module(..), ModuleHeader(..), Name(..))
import Tidy.FormatOptions (FormatOptions, formatOptions)
import Tidy.FormatOptions as FormatOptions
import Tidy.Operators (parseOperatorTable, resolveOperatorExports)
import Tidy.Operators.Defaults (defaultOperators)
import Tidy.Precedence (OperatorNamespace(..), PrecedenceMap)
Expand Down Expand Up @@ -163,11 +162,11 @@ main = launchAff_ do
Console.log $ Arg.printArgError err
case err of
Arg.ArgError _ Arg.ShowHelp ->
liftEffect $ Process.exit 0
liftEffect $ Process.exit
Arg.ArgError _ (Arg.ShowInfo _) ->
liftEffect $ Process.exit 0
liftEffect $ Process.exit' 0
_ ->
liftEffect $ Process.exit 1
liftEffect $ Process.exit' 1
Right cmd ->
case cmd of
GenerateOperators globs ->
Expand All @@ -180,7 +179,7 @@ main = launchAff_ do
FS.writeTextFile UTF8 rcFileName $ contents <> "\n"
else do
Console.error $ rcFileName <> " already exists."
liftEffect $ Process.exit 1
liftEffect $ Process.exit' 1

FormatInPlace mode cliOptions configOption numThreads printTiming globs -> do
currentDir <- liftEffect Process.cwd
Expand Down Expand Up @@ -213,9 +212,9 @@ main = launchAff_ do
results <-
if Array.length filesWithOptions > numThreads * 2 then do
-- Worker location for production bin
let bundleLocation = Path.concat [ srcLocation, "bundle", "Bin.Worker", "index.js" ]
let bundleLocation = Path.concat [ srcLocation, "bundle", "Cli.Worker", "index.js" ]
-- Worker location for local dev
let outputLocation = Path.concat [ srcLocation, "output", "Bin.Worker", "index.js" ]
let outputLocation = Path.concat [ srcLocation, "output", "Cli.Worker", "index.js" ]
worker <-
oneOf
[ FS.stat bundleLocation $> Worker.unsafeWorkerFromPath bundleLocation
Expand Down Expand Up @@ -251,7 +250,7 @@ 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.exit
else do
unless (Array.null errors) do
Console.log "Some files have errors:\n"
Expand All @@ -260,7 +259,7 @@ main = launchAff_ do
unless (Array.null notFormatted) do
Console.log "Some files are not formatted:\n"
for_ notFormatted Console.error
Process.exit 1
Process.exit' 1

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

expandGlobs :: Array String -> Aff (Array String)
expandGlobs = map dirToGlob >>> expandGlobsWithStatsCwd >>> map onlyFiles
Expand All @@ -303,7 +299,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 @@ -360,13 +356,7 @@ resolveRcForDir root = go List.Nil
Tuple res cache

readStdin :: Aff String
readStdin = makeAff \k -> do
contents <- Ref.new []
Stream.onData Process.stdin \buff -> do
void $ Ref.modify (_ `Array.snoc` buff) contents
Stream.onEnd Process.stdin do
k <<< Right =<< Buffer.toString UTF8 =<< Buffer.concat =<< Ref.read contents
pure mempty
readStdin = Stream.Aff.readableToStringUtf8 Process.stdin

generateOperatorsCommand :: Array String -> Aff Unit
generateOperatorsCommand globs = do
Expand Down
22 changes: 22 additions & 0 deletions generate-default-operators/spago.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package:
name: tidy-generate-default-operators
dependencies:
- aff: ">=8.0.0 <9.0.0"
- argonaut-codecs: ">=9.1.0 <10.0.0"
- argonaut-core: ">=7.0.0 <8.0.0"
- arrays: ">=7.3.0 <8.0.0"
- console: ">=6.1.0 <7.0.0"
- effect: ">=4.0.0 <5.0.0"
- either: ">=6.1.0 <7.0.0"
- exceptions: ">=6.1.0 <7.0.0"
- foreign-object: ">=4.1.0 <5.0.0"
- maybe: ">=6.0.0 <7.0.0"
- node-buffer: ">=9.0.0 <10.0.0"
- node-child-process: ">=11.1.0 <12.0.0"
- node-execa: ">=5.0.0 <6.0.0"
- node-fs: ">=9.2.0 <10.0.0"
- node-path: ">=5.0.0 <6.0.0"
- node-process: ">=11.2.0 <12.0.0"
- numbers: ">=9.0.1 <10.0.0"
- prelude: ">=6.0.1 <7.0.0"
- strings: ">=6.0.1 <7.0.0"
Loading