Skip to content

Commit 016bb8b

Browse files
authored
Migrate to spago next (#126)
* Minimal migration (leaves the generate operators script as is)> * Leaves tidy lib as the root project so it can still be published.
1 parent 33910b8 commit 016bb8b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+5714
-240
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,28 @@ jobs:
1010
runs-on: ubuntu-latest
1111

1212
steps:
13-
- uses: actions/checkout@v2
14-
- uses: purescript-contrib/setup-purescript@main
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-node@v4
1515
with:
16-
purescript: "0.15.0"
17-
- uses: actions/cache@v2
18-
# This cache uses the .dhall files to know when it should reinstall
19-
# and rebuild packages. It caches both the installed packages from
20-
# the `.spago` directory and compilation artifacts from the `output`
21-
# directory. When restored the compiler will rebuild any files that
22-
# have changed.
16+
node-version: 20
17+
cache: 'npm'
18+
19+
- name: Cache PureScript dependencies
20+
uses: actions/cache@v4
2321
with:
24-
key: ${{ runner.os }}-spago-${{ hashFiles('**/*.dhall') }}
22+
key: ${{ runner.os }}-spago-${{ hashFiles('**/spago.lock') }}
2523
path: |
2624
.spago
2725
output
2826
29-
- name: Install esbuild and dev dependencies
30-
run: npm install --global esbuild@0.14.x && npm install
27+
- name: Install npm dependencies
28+
run: npm install
3129

3230
- name: Build source
33-
run: npm run bundle
34-
35-
- name: Build script
36-
run: spago --config script/spago.dhall build
37-
38-
- name: Build bin
39-
run: spago --config bin/spago.dhall build
40-
41-
- name: Build tests
42-
run: spago --config test/spago.dhall build
31+
run: npm run bundle -- --pedantic-packages
4332

4433
- name: Run tests
45-
run: spago --quiet --config test/spago.dhall test
34+
run: npm run test -- --offline --quiet
4635

4736
- name: Verify formatting
4837
run: npm run check-self

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
/.psa*
1212
/.spago
1313
/*.purs*
14+
/.vscode

bin/spago.dhall

Lines changed: 0 additions & 41 deletions
This file was deleted.

bin/spago.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package:
2+
name: tidy-bin
3+
build:
4+
strict: true
5+
dependencies:
6+
- aff: ">=8.0.0 <9.0.0"
7+
- argonaut-codecs: ">=9.1.0 <10.0.0"
8+
- argonaut-core: ">=7.0.0 <8.0.0"
9+
- argparse-basic: ">=2.0.0 <3.0.0"
10+
- arrays: ">=7.3.0 <8.0.0"
11+
- console: ">=6.1.0 <7.0.0"
12+
- control: ">=6.0.0 <7.0.0"
13+
- datetime: ">=6.1.0 <7.0.0"
14+
- dodo-printer: ">=2.2.3 <3.0.0"
15+
- effect: ">=4.0.0 <5.0.0"
16+
- either: ">=6.1.0 <7.0.0"
17+
- foldable-traversable: ">=6.0.0 <7.0.0"
18+
- foreign-object: ">=4.1.0 <5.0.0"
19+
- language-cst-parser: ">=0.14.1 <0.15.0"
20+
- lazy: ">=6.0.0 <7.0.0"
21+
- lists: ">=7.0.0 <8.0.0"
22+
- maybe: ">=6.0.0 <7.0.0"
23+
- newtype: ">=5.0.0 <6.0.0"
24+
- node-buffer: ">=9.0.0 <10.0.0"
25+
- node-event-emitter: ">=3.0.0 <4.0.0"
26+
- node-fs: ">=9.2.0 <10.0.0"
27+
- node-glob-basic: ">=2.0.0 <3.0.0"
28+
- node-path: ">=5.0.1 <6.0.0"
29+
- node-process: ">=11.2.0 <12.0.0"
30+
- node-streams: ">=9.0.1 <10.0.0"
31+
- node-workerbees: ">=0.3.1 <0.4.0"
32+
- numbers: ">=9.0.1 <10.0.0"
33+
- ordered-collections: ">=3.2.0 <4.0.0"
34+
- parallel: ">=7.0.0 <8.0.0"
35+
- partial: ">=4.0.0 <5.0.0"
36+
- prelude: ">=6.0.1 <7.0.0"
37+
- refs: ">=6.0.0 <7.0.0"
38+
- strings: ">=6.0.1 <7.0.0"
39+
- tidy: "*"
40+
- transformers: ">=6.1.0 <7.0.0"
41+
- 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.

bin/Main.purs renamed to bin/src/Main.purs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import Data.Traversable (for, traverse)
3434
import Data.Tuple (Tuple(..))
3535
import Data.Tuple.Nested ((/\))
3636
import Effect (Effect)
37-
import Effect.Aff (Aff, error, launchAff_, makeAff, throwError, try)
37+
import Effect.Aff (Aff, effectCanceler, error, launchAff_, makeAff, throwError, try)
3838
import Effect.Aff as Aff
3939
import Effect.Class (liftEffect)
4040
import Effect.Class.Console as Console
@@ -43,6 +43,7 @@ import Foreign.Object (Object)
4343
import Foreign.Object as Object
4444
import Node.Buffer as Buffer
4545
import Node.Encoding (Encoding(..))
46+
import Node.EventEmitter (on)
4647
import Node.FS.Aff as FS
4748
import Node.FS.Stats as Stats
4849
import Node.Glob.Basic (expandGlobsCwd, expandGlobsWithStatsCwd)
@@ -160,14 +161,14 @@ main = launchAff_ do
160161

161162
case parsedCmd of
162163
Left err -> do
163-
Console.log $ Arg.printArgError err
164+
Console.error $ Arg.printArgError err
164165
case err of
165166
Arg.ArgError _ Arg.ShowHelp ->
166-
liftEffect $ Process.exit 0
167+
pure unit
167168
Arg.ArgError _ (Arg.ShowInfo _) ->
168-
liftEffect $ Process.exit 0
169+
pure unit
169170
_ ->
170-
liftEffect $ Process.exit 1
171+
liftEffect $ Process.setExitCode 1
171172
Right cmd ->
172173
case cmd of
173174
GenerateOperators globs ->
@@ -180,7 +181,7 @@ main = launchAff_ do
180181
FS.writeTextFile UTF8 rcFileName $ contents <> "\n"
181182
else do
182183
Console.error $ rcFileName <> " already exists."
183-
liftEffect $ Process.exit 1
184+
liftEffect $ Process.setExitCode 1
184185

185186
FormatInPlace mode cliOptions configOption numThreads printTiming globs -> do
186187
currentDir <- liftEffect Process.cwd
@@ -236,7 +237,7 @@ main = launchAff_ do
236237
when printTiming do
237238
for_ (Array.sortBy (comparing _.timing) results) \{ filePath, timing } ->
238239
when (timing > 0.0) do
239-
Console.log $ fold
240+
Console.error $ fold
240241
[ Path.relative currentDir filePath
241242
, " "
242243
, NF.toStringWith (NF.fixed 2) timing
@@ -251,16 +252,16 @@ main = launchAff_ do
251252
Check -> liftEffect do
252253
if Array.null errors && Array.null notFormatted then do
253254
Console.log "All files are formatted."
254-
Process.exit 0
255+
Process.setExitCode 0
255256
else do
256257
unless (Array.null errors) do
257-
Console.log "Some files have errors:\n"
258+
Console.error "Some files have errors:\n"
258259
for_ errors \(Tuple filePath error) ->
259260
Console.error $ filePath <> ":\n " <> error <> "\n"
260261
unless (Array.null notFormatted) do
261-
Console.log "Some files are not formatted:\n"
262+
Console.error "Some files are not formatted:\n"
262263
for_ notFormatted Console.error
263-
Process.exit 1
264+
Process.setExitCode 1
264265

265266
Format cliOptions configOption -> do
266267
currentDir <- liftEffect Process.cwd
@@ -272,11 +273,9 @@ main = launchAff_ do
272273
case formatCommand options operators contents of
273274
Left err -> do
274275
Console.error err
275-
liftEffect $ Process.exit 1
276+
liftEffect $ Process.setExitCode 1
276277
Right str ->
277-
makeAff \k -> do
278-
_ <- Stream.writeString Process.stdout UTF8 str (const (k (Right unit)))
279-
pure mempty
278+
writeStdout str
280279

281280
expandGlobs :: Array String -> Aff (Array String)
282281
expandGlobs = map dirToGlob >>> expandGlobsWithStatsCwd >>> map onlyFiles
@@ -303,7 +302,7 @@ getOptions cliOptions rcOptions filePath = case _ of
303302
case rcOptions of
304303
Nothing -> do
305304
Console.error $ rcFileName <> " not found for " <> filePath
306-
liftEffect $ Process.exit 1
305+
liftEffect $ Process.exit' 1
307306
Just options ->
308307
pure options
309308

@@ -362,10 +361,15 @@ resolveRcForDir root = go List.Nil
362361
readStdin :: Aff String
363362
readStdin = makeAff \k -> do
364363
contents <- Ref.new []
365-
Stream.onData Process.stdin \buff -> do
364+
c1 <- Process.stdin # on Stream.dataH \buff ->
366365
void $ Ref.modify (_ `Array.snoc` buff) contents
367-
Stream.onEnd Process.stdin do
366+
c2 <- Process.stdin # on Stream.endH do
368367
k <<< Right =<< Buffer.toString UTF8 =<< Buffer.concat =<< Ref.read contents
368+
pure $ effectCanceler (c1 *> c2)
369+
370+
writeStdout :: String -> Aff Unit
371+
writeStdout str = makeAff \k -> do
372+
_ <- Stream.writeString' Process.stdout UTF8 str (const (k (Right unit)))
369373
pure mempty
370374

371375
generateOperatorsCommand :: Array String -> Aff Unit

0 commit comments

Comments
 (0)