Skip to content

Update for PureScript 0.15 #96

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

Merged
merged 8 commits into from
May 16, 2022
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
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v2
- uses: purescript-contrib/setup-purescript@main
with:
purescript: "0.14.7"
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
Expand All @@ -26,6 +26,9 @@ jobs:
.spago
output

- name: Install esbuild
run: npm install --global esbuild@0.14.x

- name: Build source
run: npm run bundle

Expand Down
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,24 @@ The PureScript IDE plugin for VS Code supports `purs-tidy` as a built-in formatt

### Requirements

* `purs`: 0.14
* `purs`: 0.15
* `spago`: 0.20
* `node`: 14
* `esbuild`: 0.14

### Running `bin`

For local development pointing to the `output` directory:

```console
$ npm run build
$ ./bin/index.dev.js --help
```

For a local production build pointing to the `bundle` directory:

```console
$ spago -x ./bin/spago.dhall build
$ npm run bundle
$ ./bin/index.js --help
```

Expand All @@ -139,11 +149,11 @@ If you would like to use your local build of `purs-tidy` in your editor, use pat
To accept snapshot tests:

```console
$ spago -x ./test/spago.dhall test -a "--accept"
$ npm run test -- -a "--accept"
```

### Generating the built-in operator table

```console
$ spago -x ./script/spago.dhall run -m GenerateDefaultOperatorsModule
$ npm run generate-default-operators
```
10 changes: 5 additions & 5 deletions bin/Bin/Timing.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const process = require("process");
import process from "process";

exports.hrtime = function() {
export function hrtime() {
var t = process.hrtime()
return { seconds: t[0], nanos: t[1] };
};
}

exports.hrtimeDiff = function(old) {
export function hrtimeDiff(old) {
return function() {
var t = process.hrtime([old.seconds, old.nanos]);
return { seconds: t[0], nanos: t[1] };
};
};
}
2 changes: 1 addition & 1 deletion bin/Bin/Version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
exports.version = require("../../package.json").version;
export const version = "v0.8.0";
25 changes: 11 additions & 14 deletions bin/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Control.Plus ((<|>))
import Data.Argonaut.Core as Json
import Data.Argonaut.Decode (parseJson, printJsonDecodeError)
import Data.Array as Array
import Data.Either (Either(..))
import Data.Either (Either(..), isLeft)
import Data.Foldable (fold, foldMap, foldl, for_, oneOf)
import Data.Lazy (Lazy)
import Data.Lazy as Lazy
Expand All @@ -35,6 +35,7 @@ import Data.Tuple (Tuple(..))
import Data.Tuple.Nested ((/\))
import Effect (Effect)
import Effect.Aff (Aff, error, launchAff_, makeAff, throwError, try)
import Effect.Aff as Aff
import Effect.Class (liftEffect)
import Effect.Class.Console as Console
import Effect.Ref as Ref
Expand Down Expand Up @@ -174,13 +175,13 @@ main = launchAff_ do
generateOperatorsCommand globs

GenerateRc cliOptions -> do
rcExists <- FS.exists rcFileName
if rcExists then do
Console.error $ rcFileName <> " already exists."
liftEffect $ Process.exit 1
else do
rcStats <- Aff.try $ FS.stat rcFileName
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exists was removed as part of the 0.15 updates, as its been recommended against by Node for years. This instead tries to stat the file, and if that throws an exception (the file is missing) then we write the file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you use liftEffect $ FSSync.exists?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is also possible, but we can use proper async here via stat (which is also used elsewhere in this file)

if isLeft rcStats then do
let contents = Json.stringifyWithIndent 2 $ FormatOptions.toJson cliOptions
FS.writeTextFile UTF8 rcFileName $ contents <> "\n"
else do
Console.error $ rcFileName <> " already exists."
liftEffect $ Process.exit 1

FormatInPlace mode cliOptions configOption numThreads printTiming globs -> do
currentDir <- liftEffect Process.cwd
Expand Down Expand Up @@ -212,17 +213,14 @@ main = launchAff_ do

results <-
if Array.length filesWithOptions > numThreads * 2 then do
-- Worker location for production bin.
-- Worker location for production bin
let bundleLocation = Path.concat [ srcLocation, "bundle", "Bin.Worker", "index.js" ]
-- Worker location for dev.
-- Worker location for local dev
let outputLocation = Path.concat [ srcLocation, "output", "Bin.Worker", "index.js" ]
worker <-
oneOf
[ FS.stat bundleLocation $> Worker.unsafeWorkerFromPath bundleLocation
, FS.stat outputLocation $> Worker.unsafeWorkerFromPathAndExport
{ filePath: outputLocation
, export: "main"
}
, FS.stat outputLocation $> Worker.unsafeWorkerFromPath outputLocation
]
<|> throwError (error "Worker not found")
poolTraverse worker workerData numThreads filesWithOptions
Expand Down Expand Up @@ -278,7 +276,7 @@ main = launchAff_ do
liftEffect $ Process.exit 1
Right str ->
makeAff \k -> do
_ <- Stream.writeString Process.stdout UTF8 str (k (Right unit))
_ <- Stream.writeString Process.stdout UTF8 str (const (k (Right unit)))
pure mempty

expandGlobs :: Array String -> Aff (Array String)
Expand Down Expand Up @@ -407,4 +405,3 @@ generateOperatorsCommand globs = do
OperatorValue -> ".(" <> unwrap op <> ")"
, " " <> show prec
]

8 changes: 8 additions & 0 deletions bin/index.dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env -S node --experimental-json-modules
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import path from "path";
import { main } from "../output/Main/index.js";

const __dirname = path.dirname(new URL(import.meta.url).pathname);
process.env["TIDY_INSTALL_LOC"] = path.resolve(__dirname, "..");

main();
12 changes: 6 additions & 6 deletions bin/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env node
var path = require("path");
import path from "path";
import { main } from "../bundle/Main/index.js";

const __dirname = path.dirname(new URL(import.meta.url).pathname);
process.env["TIDY_INSTALL_LOC"] = path.resolve(__dirname, "..");
try {
require("../bundle/Main/index.js");
} catch (e) {
require("../output/Main/index.js").main();
}

main();
4 changes: 2 additions & 2 deletions bin/spago.dhall
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ name = "purescript-tidy-cli"
{ name = "tidy-cli"
, dependencies =
[ "aff"
, "argonaut-codecs"
Expand Down Expand Up @@ -30,7 +30,7 @@
, "parallel"
, "partial"
, "prelude"
, "purescript-language-cst-parser"
, "language-cst-parser"
, "refs"
, "strings"
, "transformers"
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "purs-tidy",
"version": "0.8.0",
"type": "module",
"description": "A syntax tidy-upper (formatter) for PureScript.",
"bin": {
"purs-tidy": "bin/index.js"
Expand All @@ -13,10 +14,12 @@
"bundle/**/*.js"
],
"scripts": {
"version": "echo 'export const version = \"v'$npm_package_version'\";' > ./bin/Bin/Version.js && git add ./bin/Bin/Version.js",
"postversion": "git push && git push --tags",
"build": "spago -x bin/spago.dhall build",
"bundle": "npm run build && npm run bundle:main && npm run bundle:worker",
"bundle:main": "spago -x bin/spago.dhall bundle-app --to './bundle/Main/index.js' --no-build",
"bundle:worker": "spago -x bin/spago.dhall bundle-app --to './bundle/Bin.Worker/index.js' --main Bin.Worker --no-build",
"bundle:main": "spago -x bin/spago.dhall bundle-module --platform node --to './bundle/Main/index.js' --no-build --quiet",
"bundle:worker": "spago -x bin/spago.dhall bundle-app --platform node --to './bundle/Bin.Worker/index.js' --main Bin.Worker --no-build --quiet",
"test": "spago -x test/spago.dhall test",
"generate-default-operators": "spago -x script/spago.dhall run -m GenerateDefaultOperatorsModule",
"format-self": "npm run build && node ./bin/index.js format-in-place src 'test/*.purs' bin script",
Expand Down
114 changes: 36 additions & 78 deletions packages.dhall
Original file line number Diff line number Diff line change
@@ -1,81 +1,39 @@
let upstream =
https://github.com/purescript/package-sets/releases/download/psc-0.14.3-20210811/packages.dhall sha256:a2de7ef2f2e753733eddfa90573a82da0c7c61d46fa87d015b7f15ef8a6e97d5
https://github.com/purescript/package-sets/releases/download/psc-0.15.0-20220513/packages.dhall
sha256:1ed784f37ae6131d99acd542d058d5ce39954ccaacc3adba5cc7cf1549d2bffa

let overrides = {=}
in upstream
with node-glob-basic =
{ dependencies =
[ "aff"
, "console"
, "effect"
, "lists"
, "maybe"
, "node-fs-aff"
, "node-path"
, "node-process"
, "ordered-collections"
, "strings"
]
, repo = "https://github.com/natefaubion/purescript-node-glob-basic.git"
, version = "v1.2.2"
}

let additions =
{ purescript-language-cst-parser =
{ dependencies =
[ "arrays"
, "const"
, "effect"
, "either"
, "foldable-traversable"
, "free"
, "functors"
, "maybe"
, "numbers"
, "ordered-collections"
, "strings"
, "transformers"
, "tuples"
, "typelevel-prelude"
]
, repo =
"https://github.com/natefaubion/purescript-language-cst-parser.git"
, version = "v0.11.0"
}
, dodo-printer =
{ dependencies =
[ "ansi", "foldable-traversable", "lists", "maybe", "strings" ]
, repo = "https://github.com/natefaubion/purescript-dodo-printer.git"
, version = "v2.1.0"
}
, node-glob-basic =
{ dependencies =
[ "aff"
, "console"
, "effect"
, "lists"
, "maybe"
, "node-fs-aff"
, "node-path"
, "node-process"
, "ordered-collections"
, "strings"
]
, repo = "https://github.com/natefaubion/purescript-node-glob-basic.git"
, version = "v1.2.2"
}
, node-workerbees =
{ dependencies =
[ "aff"
, "argonaut-core"
, "arraybuffer-types"
, "avar"
, "effect"
, "either"
, "exceptions"
, "maybe"
, "newtype"
, "parallel"
, "variant"
]
, repo = "https://github.com/natefaubion/purescript-node-workerbees.git"
, version = "v0.2.1"
}
, argparse-basic =
{ dependencies =
[ "either"
, "foldable-traversable"
, "lists"
, "maybe"
, "record"
, "strings"
]
, repo = "https://github.com/natefaubion/purescript-argparse-basic.git"
, version = "v1.0.0"
}
}

in upstream // overrides // additions
with node-workerbees =
{ dependencies =
[ "aff"
, "argonaut-core"
, "arraybuffer-types"
, "avar"
, "effect"
, "either"
, "exceptions"
, "maybe"
, "newtype"
, "parallel"
, "variant"
]
, repo = "https://github.com/natefaubion/purescript-node-workerbees.git"
, version = "node-esm"
}
12 changes: 7 additions & 5 deletions script/GenerateDefaultOperatorsModule.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const fs = require("fs");
const os = require("os");
const path = require("path");
import fs from "fs";
import os from "os";
import path from "path";

exports.tmpdir = (prefix) => () =>
fs.mkdtempSync(path.join(os.tmpdir(), prefix), "utf-8");
export function tmpdir(prefix) {
return () =>
fs.mkdtempSync(path.join(os.tmpdir(), prefix), "utf-8");
}
3 changes: 2 additions & 1 deletion script/GenerateDefaultOperatorsModule.purs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ defaultPackageJson =
"""
{
"private": true,
"type": "module",
"dependencies": {
"purescript": "^0.15.0",
"spago": "^0.20.8"
Expand Down Expand Up @@ -192,7 +193,7 @@ defaultSpagoDhall =
, "uri"
, "validation"
]
, packages = https://github.com/purescript/package-sets/releases/download/psc-0.15.0-20220429/packages.dhall
, packages = https://github.com/purescript/package-sets/releases/download/psc-0.15.0-20220513/packages.dhall
, sources = [] : List Text
}
"""
4 changes: 2 additions & 2 deletions spago.dhall
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ name = "purescript-tidy"
{ name = "tidy"
, dependencies =
[ "arrays"
, "control"
Expand All @@ -11,7 +11,7 @@
, "ordered-collections"
, "partial"
, "prelude"
, "purescript-language-cst-parser"
, "language-cst-parser"
, "strings"
, "tuples"
]
Expand Down
4 changes: 2 additions & 2 deletions src/Tidy.purs
Original file line number Diff line number Diff line change
Expand Up @@ -682,8 +682,8 @@ formatHangingMonotype conf = case _ of
hangBreak $ formatName conf n
TypeString t _ ->
hangBreak $ formatToken conf t
TypeInt t _ ->
hangBreak $ formatToken conf t
TypeInt neg t _ ->
hangBreak $ foldMap (formatToken conf) neg <> formatToken conf t
TypeArrowName t ->
hangBreak $ formatToken conf t
TypeOpName n ->
Expand Down
2 changes: 1 addition & 1 deletion test/Snapshot.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Test.Snapshot where

import Prelude

import Control.MonadZero (guard)
import Control.Alternative (guard)
import Data.Array (dropEnd, mapMaybe)
import Data.Array as Array
import Data.Array.NonEmpty as NEA
Expand Down
Loading