Skip to content

Commit 0ef42b2

Browse files
authored
Update to v0.15.0 (#26)
1 parent d62f362 commit 0ef42b2

File tree

8 files changed

+122
-19
lines changed

8 files changed

+122
-19
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
/output/
55
/.psci*
66
/src/.webpack.js
7+
/.spago/
8+
/.psc-ide-port

Diff for: CHANGELOG.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
Features:
11+
- Update to v0.15.0 and support es modules
12+
13+
Breaking changes:
14+
- `discover` now needs `MonadAff` constraint instead of `MonadEffect` due to dynamic imports returning promises

Diff for: package.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "purescript-spec-discovery",
3+
"version": "1.0.0",
4+
"description": "purescript-spec-discovery is an extension to [purescript-spec](https://github.com/purescript-spec/purescript-spec) that finds specs automatically, given a regular expression pattern.",
5+
"main": "index.js",
6+
"directories": {
7+
"test": "test"
8+
},
9+
"scripts": {
10+
"test": "echo \"Error: no test specified\" && exit 1"
11+
},
12+
"repository": {
13+
"type": "git",
14+
"url": "git+https://github.com/working-group-purescript-es/purescript-spec-discovery.git"
15+
},
16+
"keywords": [],
17+
"author": "",
18+
"license": "ISC",
19+
"bugs": {
20+
"url": "https://github.com/working-group-purescript-es/purescript-spec-discovery/issues"
21+
},
22+
"homepage": "https://github.com/working-group-purescript-es/purescript-spec-discovery#readme",
23+
"type": "module"
24+
}

Diff for: packages.dhall

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
let upstream =
2+
https://raw.githubusercontent.com/purescript/package-sets/prepare-0.15/src/packages.dhall
3+
sha256:5f32c078b014909642302b328bd9bebcdcedc301956a709b302f19521680a0aa
4+
5+
in upstream
6+
with metadata.version = "v0.15.0-alpha-02"
7+
with spec =
8+
{ repo = "https://github.com/purescript-spec/purescript-spec.git"
9+
, version = "master"
10+
, dependencies =
11+
[ "aff"
12+
, "ansi"
13+
, "avar"
14+
, "console"
15+
, "exceptions"
16+
, "foldable-traversable"
17+
, "fork"
18+
, "now"
19+
, "pipes"
20+
, "prelude"
21+
, "strings"
22+
, "transformers"
23+
]
24+
}

Diff for: spago.dhall

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{-
2+
Welcome to a Spago project!
3+
You can edit this file as you like.
4+
5+
Need help? See the following resources:
6+
- Spago documentation: https://github.com/purescript/spago
7+
- Dhall language tour: https://docs.dhall-lang.org/tutorials/Language-Tour.html
8+
9+
When creating a new Spago project, you can use
10+
`spago init --no-comments` or `spago init -C`
11+
to generate this file without the comments in this block.
12+
-}
13+
{ name = "spec-discovery"
14+
, dependencies =
15+
[ "aff"
16+
, "aff-promise"
17+
, "arrays"
18+
, "console"
19+
, "effect"
20+
, "foldable-traversable"
21+
, "node-fs"
22+
, "prelude"
23+
, "spec"
24+
]
25+
, packages = ./packages.dhall
26+
, sources = [ "src/**/*.purs", "test/**/*.purs" ]
27+
}

Diff for: src/Test/Spec/Discovery.js

+18-12
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
1-
'use strict';
1+
import path from "path"
2+
import fs from 'fs';
3+
import { fileURLToPath } from "url"
24

3-
if (typeof require !== 'function') {
4-
throw new Error('Sorry, purescript-spec-discovery only supports NodeJS environments!');
5-
}
5+
const __filename = fileURLToPath(import.meta.url)
6+
const __dirname = path.dirname(__filename)
67

7-
var fs = require('fs');
8-
var path = require('path');
8+
if (import.meta.url === `file://${process.argv[1]}`) {
9+
throw new Error('Sorry, purescript-spec-discovery only supports NodeJS environments!');
10+
}
911

1012
function getMatchingModules(pattern) {
1113
var directories = fs.readdirSync(path.join(__dirname, '..'));
12-
return directories.filter(function (directory) {
14+
const modulePromises = directories.filter(function (directory) {
1315
return (new RegExp(pattern).test(directory));
1416
}).map(function (name) {
15-
var module = require(path.join(__dirname, '..', name));
16-
return (module && typeof module.spec !== 'undefined') ? module.spec : null;
17-
}).filter(function (x) { return x; });
17+
var modulePromise = import(path.join(__dirname, '..', name, 'index.js'));
18+
return modulePromise.then( module => {
19+
return (module && typeof module.spec !== 'undefined') ? module.spec : null;
20+
})
21+
})
22+
const modules = Promise.all(modulePromises)
23+
return modules.then(ms => ms.filter(function (x) { return x; }));
1824
}
1925

20-
exports.getSpecs = function (pattern) {
26+
export function getSpecs(pattern) {
2127
return function () {
2228
return getMatchingModules(pattern);
2329
};
24-
};
30+
}

Diff for: src/Test/Spec/Discovery.purs

+12-6
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@ module Test.Spec.Discovery (discover) where
22

33
import Prelude
44

5+
import Control.Promise (Promise)
6+
import Control.Promise as Promise
57
import Data.Traversable (sequence_)
68
import Effect (Effect)
7-
import Effect.Class (class MonadEffect, liftEffect)
9+
import Effect.Aff.Class (class MonadAff, liftAff)
810
import Test.Spec (Spec)
911

10-
foreign import getSpecs :: String
11-
-> Effect (Array (Spec Unit))
12+
foreign import getSpecs
13+
:: String
14+
-> Effect (Promise (Array (Spec Unit)))
1215

13-
discover :: forall m. MonadEffect m => String
14-
-> m (Spec Unit)
15-
discover pattern = getSpecs pattern >>= (pure <<< sequence_) # liftEffect
16+
discover
17+
:: forall m
18+
. MonadAff m
19+
=> String
20+
-> m (Spec Unit)
21+
discover pattern = getSpecs pattern # Promise.toAffE >>= (pure <<< sequence_) # liftAff

Diff for: test/Main.purs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ import Test.Spec.Reporter.Console (consoleReporter)
99
import Test.Spec.Runner (runSpec)
1010

1111
main :: Effect Unit
12-
main = discover "Test\\.Spec\\.Discovery.*Spec" >>= runSpec [consoleReporter] >>> launchAff_
12+
main = launchAff_ $ discover "Test\\.Spec\\.Discovery.*Spec" >>= runSpec [consoleReporter]

0 commit comments

Comments
 (0)