From d87eb76a2c2b10cd0af82d419f7503b264e1655c Mon Sep 17 00:00:00 2001 From: eric thul Date: Sat, 4 Jun 2016 18:28:15 -0400 Subject: [PATCH 1/3] Adding support for PureScript 0.9.1 and newer Resolves #60 and resolves #59 --- .gitignore | 2 - README.md | 29 ++--- bower.json | 6 +- entry.js => index.js | 2 +- package.json | 44 +++---- src/GulpPurescript/Buffer.js | 2 - src/GulpPurescript/Buffer.purs | 2 +- src/GulpPurescript/ChildProcess.js | 2 - src/GulpPurescript/ChildProcess.purs | 10 +- src/GulpPurescript/Glob.js | 2 - src/GulpPurescript/Glob.purs | 12 +- src/GulpPurescript/GulpUtil.js | 2 - src/GulpPurescript/GulpUtil.purs | 8 +- src/GulpPurescript/Logalot.js | 2 - src/GulpPurescript/Logalot.purs | 6 +- src/GulpPurescript/OS.js | 2 - src/GulpPurescript/OS.purs | 14 ++- src/GulpPurescript/Options.js | 2 - src/GulpPurescript/Options.purs | 169 ++++++++++++++++----------- src/GulpPurescript/Package.js | 11 -- src/GulpPurescript/Package.purs | 27 ----- src/GulpPurescript/Path.js | 2 - src/GulpPurescript/Path.purs | 2 +- src/GulpPurescript/Plugin.js | 2 - src/GulpPurescript/Plugin.purs | 71 ++++++----- src/GulpPurescript/ResolveBin.js | 2 - src/GulpPurescript/ResolveBin.purs | 12 +- src/GulpPurescript/Stream.js | 2 - src/GulpPurescript/Stream.purs | 14 +-- src/GulpPurescript/Which.js | 2 - src/GulpPurescript/Which.purs | 12 +- Fixture1.purs => test/Fixture1.purs | 1 + Fixture2.purs => test/Fixture2.purs | 1 + foreign.js => test/foreign.js | 0 test.js => test/test.js | 22 ++-- webpack.config.js | 33 ------ 36 files changed, 221 insertions(+), 313 deletions(-) rename entry.js => index.js (87%) delete mode 100644 src/GulpPurescript/Package.js delete mode 100644 src/GulpPurescript/Package.purs rename Fixture1.purs => test/Fixture1.purs (70%) rename Fixture2.purs => test/Fixture2.purs (68%) rename foreign.js => test/foreign.js (100%) rename test.js => test/test.js (77%) delete mode 100644 webpack.config.js diff --git a/.gitignore b/.gitignore index 48935d8..ae8bbb8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,5 @@ .psci npm-debug.log -index.js node_modules/ bower_components/ -build/ output/ diff --git a/README.md b/README.md index 9dc7085..ebfe967 100644 --- a/README.md +++ b/README.md @@ -44,10 +44,6 @@ Invokes the `psc` command. The following options are supported. Files to compile. Glob syntax is supported. -###### `ffi` (String or String Array) - -Files for code that is included with a `foreign import` in the PureScript source. Glob syntax is supported. - ###### `noTco` (Boolean) Toggles `--no-tco` that disables tail-call optimizations. @@ -76,9 +72,13 @@ Sets `--output=` the specifies the output directory, `output` by default Toggles `--no-prefix` that does not include the comment header. -###### `requirePath` (String) +###### `sourceMaps` (Boolean) + +Toggles `--source-maps` that generates source maps. -Sets `--require-path=` that specifies the path prefix to use for `require()` calls in the generated JavaScript. +###### `jsonErrors` (Boolean) + +Toggles `--json-errors` that prints errors to stderr as JSON. ### `purescript.pscBundle(options)` @@ -104,10 +104,6 @@ Toggles `--main` or sets `--main=` that generates code to run the `main` Sets `--namespace=` that specifies the namespace that PureScript modules will be exported to when running in the browser. -###### `requirePath` (String) - -Sets `--require-path=` that specifies the path prefix to use for `require()` calls in the generated JavaScript. This should be set to match any value used in the `psc` task. - ### `purescript.pscDocs(options)` Invokes the `psc-docs` command. The following options are supported. @@ -136,10 +132,6 @@ Generates a `.psci` file. Files added to the `.psci` file with the `:m` command. Glob syntax is supported. -###### `ffi` (String or String Array) - -Files added to the `.psci` file with the `:f` command. Glob syntax is supported. - ## Full example This example will make and bundle the code, run tests, and produce a `.psci` file and documentation for a project using the common `bower_components`/`src` file layout. @@ -154,13 +146,8 @@ var sources = [ "bower_components/purescript-*/src/**/*.purs", ]; -var foreigns = [ - "src/**/*.js", - "bower_components/purescript-*/src/**/*.js" -]; - gulp.task("make", function () { - return purescript.psc({ src: sources, ffi: foreigns }); + return purescript.psc({ src: sources }); }); gulp.task("bundle", ["make"], function () { @@ -178,7 +165,7 @@ gulp.task("docs", function () { }); gulp.task("dotpsci", function () { - return purescript.psci({ src: sources, ffi: foreigns }) + return purescript.psci({ src: sources }) .pipe(gulp.dest(".")); }); diff --git a/bower.json b/bower.json index d6e617e..cd31692 100644 --- a/bower.json +++ b/bower.json @@ -1,8 +1,8 @@ { "name": "gulp-purescript", "private": true, - "devDependencies": { - "purescript-aff": "~0.13.0", - "purescript-foreign": "~0.7.0" + "dependencies": { + "purescript-aff": "slamdata/purescript-aff#088ef5f4f14c29fe239c89826029ac2f76dce666", + "purescript-foreign": "~1.0.0" } } diff --git a/entry.js b/index.js similarity index 87% rename from entry.js rename to index.js index 1efd5d6..e64d945 100644 --- a/entry.js +++ b/index.js @@ -1,6 +1,6 @@ 'use strict'; -var gulpPurescript = require('GulpPurescript.Plugin'); +var gulpPurescript = require('./output/GulpPurescript.Plugin'); function psc(options) { return gulpPurescript.psc(options)(); diff --git a/package.json b/package.json index 90c45ed..064253f 100644 --- a/package.json +++ b/package.json @@ -12,42 +12,34 @@ "node": ">=0.10.0" }, "files": [ - "index.js" + "LICENSE", + "index.js", + "output" ], "scripts": { - "test:run": "node test.js | tap-spec", - "test": "npm run-script build && npm run-script test:run", - "build": "npm run-script build:compile && npm run-script build:docs && npm run-script build:package", - "build:compile": "./node_modules/.bin/pulp build -o build", - "build:docs": "./node_modules/.bin/pulp docs", - "build:package": "./node_modules/.bin/webpack --progress --colors --profile --bail", - "build:json": "./node_modules/.bin/webpack --progress --colors --profile --bail --json > index.json", - "prepublish": "npm run-script build" + "psc": "psc 'src/**/*.purs' 'bower_components/purescript-*/src/**/*.purs'", + "test": "npm run psc && (node test/test.js | tap-spec)", + "prepublish": "rm -r output && npm run psc" }, "keywords": [ "gulpplugin", "purescript" ], "dependencies": { - "async": "^1.3.0", - "camelcase": "^1.1.0", - "cross-spawn": "^0.4.0", - "glob": "^5.0.5", - "gulp-util": "^3.0.4", + "async": "^2.0.0-rc.5", + "camelcase": "^3.0.0", + "cross-spawn": "^4.0.0", + "glob": "^7.0.3", + "gulp-util": "^3.0.7", "logalot": "^2.1.0", - "resolve-bin": "^0.3.0", - "which": "^1.0.9" + "resolve-bin": "^0.4.0", + "which": "^1.2.9" }, "devDependencies": { - "del": "^1.1.1", - "gulp": "^3.8.11", - "gulp-plumber": "^1.0.0", - "json-loader": "^0.5.1", - "pulp": "^4.3.0", - "run-sequence": "^1.0.2", - "tap-spec": "^2.2.2", - "tape": "^3.5.0", - "through2": "^0.6.3", - "webpack": "^1.8.9" + "gulp": "^3.9.1", + "purescript": "^0.9.1-rc.1", + "tap-spec": "^4.1.1", + "tape": "^4.5.1", + "through2": "^2.0.1" } } diff --git a/src/GulpPurescript/Buffer.js b/src/GulpPurescript/Buffer.js index 94b1bf8..da51363 100644 --- a/src/GulpPurescript/Buffer.js +++ b/src/GulpPurescript/Buffer.js @@ -1,7 +1,5 @@ 'use strict'; -// module GulpPurescript.Buffer - function mkBufferFromString(str) { return new Buffer(str); } diff --git a/src/GulpPurescript/Buffer.purs b/src/GulpPurescript/Buffer.purs index 4a5cb32..b03e7d8 100644 --- a/src/GulpPurescript/Buffer.purs +++ b/src/GulpPurescript/Buffer.purs @@ -1,5 +1,5 @@ module GulpPurescript.Buffer - ( Buffer() + ( Buffer , mkBufferFromString ) where diff --git a/src/GulpPurescript/ChildProcess.js b/src/GulpPurescript/ChildProcess.js index 99f8ff7..70b0e43 100644 --- a/src/GulpPurescript/ChildProcess.js +++ b/src/GulpPurescript/ChildProcess.js @@ -1,7 +1,5 @@ 'use strict'; -// module GulpPurescript.ChildProcess - var child_process = require('cross-spawn'); function spawnFn(command, args, errback, callback) { diff --git a/src/GulpPurescript/ChildProcess.purs b/src/GulpPurescript/ChildProcess.purs index e7769a8..df85a79 100644 --- a/src/GulpPurescript/ChildProcess.purs +++ b/src/GulpPurescript/ChildProcess.purs @@ -1,15 +1,15 @@ module GulpPurescript.ChildProcess - ( ChildProcess() + ( ChildProcess , spawn ) where import Prelude -import Control.Monad.Aff (Aff(), makeAff) -import Control.Monad.Eff (Eff()) -import Control.Monad.Eff.Exception (Error()) +import Control.Monad.Aff (Aff, makeAff) +import Control.Monad.Eff (Eff) +import Control.Monad.Eff.Exception (Error) -import Data.Function +import Data.Function.Uncurried (Fn4, runFn4) foreign import data ChildProcess :: ! diff --git a/src/GulpPurescript/Glob.js b/src/GulpPurescript/Glob.js index 70ce480..c6b83d9 100644 --- a/src/GulpPurescript/Glob.js +++ b/src/GulpPurescript/Glob.js @@ -1,7 +1,5 @@ 'use strict'; -// module GulpPurescript.Glob - var glob = require('glob'); var async = require('async'); diff --git a/src/GulpPurescript/Glob.purs b/src/GulpPurescript/Glob.purs index 32a54b8..06be943 100644 --- a/src/GulpPurescript/Glob.purs +++ b/src/GulpPurescript/Glob.purs @@ -1,16 +1,16 @@ module GulpPurescript.Glob - ( Glob() + ( Glob , glob , globAll ) where -import Prelude +import Prelude (Unit, ($)) -import Control.Monad.Aff (Aff(), makeAff) -import Control.Monad.Eff (Eff()) -import Control.Monad.Eff.Exception (Error()) +import Control.Monad.Aff (Aff, makeAff) +import Control.Monad.Eff (Eff) +import Control.Monad.Eff.Exception (Error) -import Data.Function +import Data.Function.Uncurried (Fn3, runFn3) foreign import data Glob :: ! diff --git a/src/GulpPurescript/GulpUtil.js b/src/GulpPurescript/GulpUtil.js index 7f504c0..c149ba1 100644 --- a/src/GulpPurescript/GulpUtil.js +++ b/src/GulpPurescript/GulpUtil.js @@ -1,7 +1,5 @@ 'use strict'; -// module GulpPurescript.GulpUtil - var gutil = require('gulp-util'); function mkPluginErrorFn(name, message) { diff --git a/src/GulpPurescript/GulpUtil.purs b/src/GulpPurescript/GulpUtil.purs index 9a7081f..516c170 100644 --- a/src/GulpPurescript/GulpUtil.purs +++ b/src/GulpPurescript/GulpUtil.purs @@ -1,14 +1,14 @@ module GulpPurescript.GulpUtil - ( File() + ( File , mkPluginError , mkFile ) where -import Control.Monad.Eff.Exception (Error()) +import Control.Monad.Eff.Exception (Error) -import Data.Function +import Data.Function.Uncurried (Fn2, runFn2) -import GulpPurescript.Buffer (Buffer()) +import GulpPurescript.Buffer (Buffer) data File diff --git a/src/GulpPurescript/Logalot.js b/src/GulpPurescript/Logalot.js index 4822e55..403a2ce 100644 --- a/src/GulpPurescript/Logalot.js +++ b/src/GulpPurescript/Logalot.js @@ -1,7 +1,5 @@ 'use strict'; -// module GulpPurescript.Logalot - var logalot = require('logalot'); function info(message) { diff --git a/src/GulpPurescript/Logalot.purs b/src/GulpPurescript/Logalot.purs index 143014c..c2144bc 100644 --- a/src/GulpPurescript/Logalot.purs +++ b/src/GulpPurescript/Logalot.purs @@ -1,11 +1,11 @@ module GulpPurescript.Logalot - ( Logalot() + ( Logalot , info ) where -import Prelude +import Prelude (Unit) -import Control.Monad.Eff (Eff()) +import Control.Monad.Eff (Eff) foreign import data Logalot :: ! diff --git a/src/GulpPurescript/OS.js b/src/GulpPurescript/OS.js index 496dcf3..70cb5a6 100644 --- a/src/GulpPurescript/OS.js +++ b/src/GulpPurescript/OS.js @@ -1,7 +1,5 @@ 'use strict'; -// module GulpPurescript.OS - var os = require('os'); function platformFn() { diff --git a/src/GulpPurescript/OS.purs b/src/GulpPurescript/OS.purs index 25d6100..c7e6deb 100644 --- a/src/GulpPurescript/OS.purs +++ b/src/GulpPurescript/OS.purs @@ -1,16 +1,17 @@ module GulpPurescript.OS - ( OS() + ( OS , Platform(..) , platform ) where -import Prelude +import Prelude (class Show, (<$>), (<>), const) -import Control.Monad.Eff (Eff()) +import Control.Monad.Eff (Eff) +import Control.Monad.Eff.Exception.Unsafe (unsafeThrow) import Data.Either (either) -import Data.Foreign (Foreign()) -import Data.Foreign.Class (IsForeign, read) +import Data.Foreign (Foreign) +import Data.Foreign.Class (class IsForeign, read) import Data.Maybe (Maybe(..)) foreign import data OS :: ! @@ -27,7 +28,8 @@ instance isForeignPlatform :: IsForeign Platform where read a = (\a -> case a of "darwin" -> Darwin "linux" -> Linux - "win32" -> Win32) <$> read a + "win32" -> Win32 + _ -> unsafeThrow ("Unhandled platform: " <> a)) <$> read a platform :: forall eff. Eff (os :: OS | eff) (Maybe Platform) platform = either (const Nothing) Just <$> read <$> platformFn diff --git a/src/GulpPurescript/Options.js b/src/GulpPurescript/Options.js index b95a0dc..530fdea 100644 --- a/src/GulpPurescript/Options.js +++ b/src/GulpPurescript/Options.js @@ -1,7 +1,5 @@ 'use strict'; -// module GulpPurescript.Options - var glob = require('glob'); var camelcase = require('camelcase'); diff --git a/src/GulpPurescript/Options.purs b/src/GulpPurescript/Options.purs index dd02139..8cb4123 100644 --- a/src/GulpPurescript/Options.purs +++ b/src/GulpPurescript/Options.purs @@ -5,84 +5,108 @@ module GulpPurescript.Options , pscDocsOptions ) where -import Prelude +import Prelude ((<>), (<$>), (<*>), (<<<), ($), (>>=), bind, const, id, pure) import Control.Alt ((<|>)) import Data.Array (concat, singleton) import Data.Either (Either(..), either) -import Data.Foreign (Foreign(), ForeignError(TypeMismatch), F()) -import Data.Foreign.Class (IsForeign, read, readProp) +import Data.Foreign (Foreign, ForeignError(TypeMismatch), F) +import Data.Foreign.Class (class IsForeign, read, readProp) import Data.Foreign.Keys (keys) -import Data.Foreign.NullOrUndefined (NullOrUndefined(..), runNullOrUndefined) +import Data.Foreign.NullOrUndefined (NullOrUndefined(..), unNullOrUndefined) import Data.Maybe (Maybe(..), fromMaybe, maybe) import Data.Traversable (for) -import Data.Tuple (Tuple()) -import Data.Tuple.Nested (tuple2) - -srcOpt = "src" +srcKey :: String srcKey = "src" +noOptsOpt :: String noOptsOpt = "no-opts" +noOptsKey :: String noOptsKey = camelcaseFn noOptsOpt +noMagicDoOpt :: String noMagicDoOpt = "no-magic-do" +noMagicDoKey :: String noMagicDoKey = camelcaseFn noMagicDoOpt +noTcoOpt :: String noTcoOpt = "no-tco" +noTcoKey :: String noTcoKey = camelcaseFn noTcoOpt +verboseErrorsOpt :: String verboseErrorsOpt = "verbose-errors" +verboseErrorsKey :: String verboseErrorsKey = camelcaseFn verboseErrorsOpt +outputOpt :: String outputOpt = "output" +outputKey :: String outputKey = outputOpt +namespaceOpt :: String namespaceOpt = "namespace" +namespaceKey :: String namespaceKey = namespaceOpt +commentsOpt :: String commentsOpt = "comments" +commentsKey :: String commentsKey = commentsOpt +noPrefixOpt :: String noPrefixOpt = "no-prefix" +noPrefixKey :: String noPrefixKey = camelcaseFn noPrefixOpt +sourceMapsOpt :: String +sourceMapsOpt = "source-maps" + +sourceMapsKey :: String +sourceMapsKey = camelcaseFn sourceMapsOpt + +jsonErrorsOpt :: String +jsonErrorsOpt = "json-errors" + +jsonErrorsKey :: String +jsonErrorsKey = camelcaseFn jsonErrorsOpt + +mainOpt :: String mainOpt = "main" +mainKey :: String mainKey = mainOpt +moduleOpt :: String moduleOpt = "module" +moduleKey :: String moduleKey = moduleOpt +formatOpt :: String formatOpt = "format" +formatKey :: String formatKey = formatOpt -ffiOpt = "ffi" - -ffiKey = ffiOpt - +docgenOpt :: String docgenOpt = "docgen" +docgenKey :: String docgenKey = docgenOpt -requirePathOpt = "require-path" - -requirePathKey = camelcaseFn requirePathOpt - newtype Psc = Psc { src :: Either String (Array String) - , ffi :: NullOrUndefined (Either String (Array String)) , output :: NullOrUndefined String , noTco :: NullOrUndefined Boolean , noMagicDo :: NullOrUndefined Boolean @@ -90,7 +114,8 @@ newtype Psc , verboseErrors :: NullOrUndefined Boolean , comments :: NullOrUndefined Boolean , noPrefix :: NullOrUndefined Boolean - , requirePath :: NullOrUndefined String + , sourceMaps :: NullOrUndefined Boolean + , jsonErrors :: NullOrUndefined Boolean } newtype PscBundle @@ -99,7 +124,6 @@ newtype PscBundle , "module" :: NullOrUndefined (Either String (Array String)) , main :: NullOrUndefined (Either Boolean String) , namespace :: NullOrUndefined String - , requirePath :: NullOrUndefined String } newtype PscDocs @@ -109,9 +133,7 @@ newtype PscDocs } newtype Psci - = Psci { src :: Either String (Array String) - , ffi :: NullOrUndefined (Either String (Array String)) - } + = Psci { src :: Either String (Array String) } newtype Docgen = Docgen Foreign @@ -122,7 +144,6 @@ data Format = Markdown | ETags | CTags instance isForeignPsc :: IsForeign Psc where read obj = Psc <$> ({ src: _ - , ffi: _ , output: _ , noTco: _ , noMagicDo: _ @@ -130,9 +151,9 @@ instance isForeignPsc :: IsForeign Psc where , verboseErrors: _ , comments: _ , noPrefix: _ - , requirePath: _ + , sourceMaps: _ + , jsonErrors: _ } <$> (readProp srcKey obj >>= readEither) - <*> (readProp ffiKey obj >>= readEitherNU) <*> readProp outputKey obj <*> readProp noTcoKey obj <*> readProp noMagicDoKey obj @@ -140,7 +161,8 @@ instance isForeignPsc :: IsForeign Psc where <*> readProp verboseErrorsKey obj <*> readProp commentsKey obj <*> readProp noPrefixKey obj - <*> readProp requirePathKey obj) + <*> readProp sourceMapsKey obj + <*> readProp jsonErrorsKey obj) instance isForeignPscBundle :: IsForeign PscBundle where read obj = @@ -149,13 +171,11 @@ instance isForeignPscBundle :: IsForeign PscBundle where , "module": _ , main: _ , namespace: _ - , requirePath: _ } <$> (readProp srcKey obj >>= readEither) <*> readProp outputKey obj <*> (readProp moduleKey obj >>= readEitherNU) <*> (readProp mainKey obj >>= readEitherNU) - <*> readProp namespaceKey obj - <*> readProp requirePathKey obj) + <*> readProp namespaceKey obj) instance isForeignPscDocs :: IsForeign PscDocs where read obj = @@ -167,11 +187,7 @@ instance isForeignPscDocs :: IsForeign PscDocs where <*> readProp docgenOpt obj) instance isForeignPsci :: IsForeign Psci where - read obj = - Psci <$> ({ src: _ - , ffi: _ - } <$> (readProp srcKey obj >>= readEither) - <*> (readProp ffiKey obj >>= readEitherNU)) + read obj = Psci <$> ({ src: _ } <$> (readProp srcKey obj >>= readEither)) instance isForeignPathArray :: IsForeign PathArray where read val = PathArray <$> read val @@ -190,25 +206,25 @@ class CommandLineOption a where opt :: String -> NullOrUndefined a -> Array String instance commandLineOptionBoolean :: CommandLineOption Boolean where - opt key val = maybe [] (\a -> if a then ["--" ++ key] else []) (runNullOrUndefined val) + opt key val = maybe [] (\a -> if a then ["--" <> key] else []) (unNullOrUndefined val) instance commandLineOptionString :: CommandLineOption String where - opt key val = maybe [] (\a -> ["--" ++ key ++ "=" ++ a]) (runNullOrUndefined val) + opt key val = maybe [] (\a -> ["--" <> key <> "=" <> a]) (unNullOrUndefined val) instance commandLineOptionEither :: (CommandLineOption a, CommandLineOption b) => CommandLineOption (Either a b) where opt key val = maybe [] (either (\a -> opt key (NullOrUndefined $ Just a)) (\a -> opt key (NullOrUndefined $ Just a))) - (runNullOrUndefined val) + (unNullOrUndefined val) instance commandLineOptionArray :: (CommandLineOption a) => CommandLineOption (Array a) where opt key val = concat $ opt key <$> (NullOrUndefined <<< Just) - <$> (fromMaybe [] $ runNullOrUndefined val) + <$> (fromMaybe [] $ unNullOrUndefined val) instance commandLineOptionPathArray :: CommandLineOption PathArray where - opt key val = opt key (NullOrUndefined ((\(PathArray a) -> a >>= expandGlob) <$> (runNullOrUndefined val))) + opt key val = opt key (NullOrUndefined ((\(PathArray a) -> a >>= expandGlob) <$> (unNullOrUndefined val))) instance commandLineOptionDocgen :: CommandLineOption Docgen where - opt key val = opt key (NullOrUndefined (parseDocgen <$> (runNullOrUndefined val))) + opt key val = opt key (NullOrUndefined (parseDocgen <$> (unNullOrUndefined val))) parseDocgen :: Docgen -> Array String parseDocgen (Docgen obj) = either (const []) id $ parseName obj @@ -216,16 +232,16 @@ parseDocgen (Docgen obj) = either (const []) id $ parseName obj <|> parseObj obj <|> pure [] where - parseName :: Foreign -> F (Array String) - parseName obj = singleton <$> read obj + parseName :: Foreign -> F (Array String) + parseName obj = singleton <$> read obj - parseList :: Foreign -> F (Array String) - parseList obj = read obj + parseList :: Foreign -> F (Array String) + parseList obj = read obj - parseObj :: Foreign -> F (Array String) - parseObj obj = do - modules <- keys obj - for modules \m -> (\f -> m ++ ":" ++ f) <$> readProp m obj + parseObj :: Foreign -> F (Array String) + parseObj obj = do + modules <- keys obj + for modules \m -> (\f -> m <> ":" <> f) <$> readProp m obj instance commandLineOptionFormat :: CommandLineOption Format where opt key val = opt key (maybe (NullOrUndefined Nothing) @@ -233,38 +249,49 @@ instance commandLineOptionFormat :: CommandLineOption Format where Markdown -> NullOrUndefined (Just "markdown") ETags -> NullOrUndefined (Just "etags") CTags -> NullOrUndefined (Just "ctags")) - (runNullOrUndefined val)) + (unNullOrUndefined val)) pscOptions :: Foreign -> Either ForeignError (Array String) pscOptions opts = fold <$> parsed - where parsed = read opts :: F Psc - fold (Psc a) = either pure id a.src <> - opt ffiOpt a.ffi <> - opt outputOpt a.output <> - opt noTcoOpt a.noTco <> - opt noMagicDoOpt a.noMagicDo <> - opt noOptsOpt a.noOpts <> - opt verboseErrorsOpt a.verboseErrors <> - opt commentsOpt a.comments <> - opt noPrefixOpt a.noPrefix <> - opt requirePathOpt a.requirePath + where + parsed :: F Psc + parsed = read opts + + fold :: Psc -> Array String + fold (Psc a) = either pure id a.src <> + opt outputOpt a.output <> + opt noTcoOpt a.noTco <> + opt noMagicDoOpt a.noMagicDo <> + opt noOptsOpt a.noOpts <> + opt verboseErrorsOpt a.verboseErrors <> + opt commentsOpt a.comments <> + opt noPrefixOpt a.noPrefix <> + opt sourceMapsOpt a.sourceMaps <> + opt jsonErrorsOpt a.jsonErrors pscBundleOptions :: Foreign -> Either ForeignError (Array String) pscBundleOptions opts = fold <$> parsed - where parsed = read opts :: F PscBundle - fold (PscBundle a) = either pure id a.src <> - opt outputOpt a.output <> - opt moduleOpt a."module" <> - opt mainOpt a.main <> - opt namespaceOpt a.namespace <> - opt requirePathOpt a.requirePath + where + parsed :: F PscBundle + parsed = read opts + + fold :: PscBundle -> Array String + fold (PscBundle a) = either pure id a.src <> + opt outputOpt a.output <> + opt moduleOpt a."module" <> + opt mainOpt a.main <> + opt namespaceOpt a.namespace pscDocsOptions :: Foreign -> Either ForeignError (Array String) pscDocsOptions opts = fold <$> parsed - where parsed = read opts :: F PscDocs - fold (PscDocs a) = either pure id a.src <> - opt formatOpt a.format <> - opt docgenOpt a.docgen + where + parsed :: F PscDocs + parsed = read opts + + fold :: PscDocs -> Array String + fold (PscDocs a) = either pure id a.src <> + opt formatOpt a.format <> + opt docgenOpt a.docgen readEither :: forall left right. (IsForeign left, IsForeign right) => Foreign -> F (Either left right) readEither a = (Left <$> read a) <|> (Right <$> read a) diff --git a/src/GulpPurescript/Package.js b/src/GulpPurescript/Package.js deleted file mode 100644 index abb9271..0000000 --- a/src/GulpPurescript/Package.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -// module GulpPurescript.Package - -var pkg = require('../../package.json'); - -function packageFn() { - return pkg; -} - -exports.packageFn = packageFn; diff --git a/src/GulpPurescript/Package.purs b/src/GulpPurescript/Package.purs deleted file mode 100644 index 600bafa..0000000 --- a/src/GulpPurescript/Package.purs +++ /dev/null @@ -1,27 +0,0 @@ -module GulpPurescript.Package - ( Pkg() - , Package(..) - , package - ) where - -import Prelude - -import Control.Monad.Eff (Eff()) - -import Data.Either (either) -import Data.Foreign (Foreign()) -import Data.Foreign.Class (IsForeign, read, readProp) -import Data.Function -import Data.Maybe (Maybe(..)) - -foreign import data Pkg :: ! - -newtype Package = Package { name :: String } - -instance isForeignPackage :: IsForeign Package where - read a = (\a -> Package { name: a }) <$> readProp "name" a - -package :: forall eff. Eff (package :: Pkg | eff) (Maybe Package) -package = either (const Nothing) Just <$> read <$> packageFn - -foreign import packageFn :: forall eff. Eff (package :: Pkg | eff) Foreign diff --git a/src/GulpPurescript/Path.js b/src/GulpPurescript/Path.js index 1fa879d..9660e73 100644 --- a/src/GulpPurescript/Path.js +++ b/src/GulpPurescript/Path.js @@ -1,7 +1,5 @@ 'use strict'; -// module GulpPurescript.Path - var path = require('path'); function relativeFn(from, to) { diff --git a/src/GulpPurescript/Path.purs b/src/GulpPurescript/Path.purs index 3c6bd97..94395ea 100644 --- a/src/GulpPurescript/Path.purs +++ b/src/GulpPurescript/Path.purs @@ -1,6 +1,6 @@ module GulpPurescript.Path (relative) where -import Data.Function +import Data.Function.Uncurried (Fn2, runFn2) relative :: String -> String -> String relative from to = runFn2 relativeFn from to diff --git a/src/GulpPurescript/Plugin.js b/src/GulpPurescript/Plugin.js index 9bf806a..16cc363 100644 --- a/src/GulpPurescript/Plugin.js +++ b/src/GulpPurescript/Plugin.js @@ -1,7 +1,5 @@ 'use strict'; -// module GulpPurescript.Plugin - var cwd = process.cwd(); exports.cwd = cwd; diff --git a/src/GulpPurescript/Plugin.purs b/src/GulpPurescript/Plugin.purs index 2c35f74..aaf6eea 100644 --- a/src/GulpPurescript/Plugin.purs +++ b/src/GulpPurescript/Plugin.purs @@ -1,51 +1,49 @@ module GulpPurescript.Plugin - ( Effects() - , Errorback() - , Callback() + ( Effects + , Errorback + , Callback , psc , pscBundle , pscDocs , psci ) where -import Prelude +import Prelude (Unit, ($), (<>), (<$>), (<*>), (<<<), (>>=), (+), bind, const, id, pure, show, unit) -import Control.Monad.Aff (Aff()) -import Control.Monad.Eff (Eff()) +import Control.Monad.Aff (Aff) +import Control.Monad.Eff (Eff) import Control.Monad.Eff.Class (liftEff) -import Control.Monad.Eff.Exception (Error()) +import Control.Monad.Eff.Exception (Error) import Control.Monad.Error.Class (catchError, throwError) -import Data.Array as A -import Data.Either (Either(..), either) -import Data.Foreign (Foreign()) +import Data.Array (elemIndex, drop, concat) as Array +import Data.Either (either) +import Data.Foreign (Foreign) import Data.Foreign.Class (read) -import Data.Foreign.NullOrUndefined (runNullOrUndefined) -import Data.Maybe (Maybe(..), maybe, fromMaybe) +import Data.Maybe (Maybe(Just)) import Data.String (joinWith, null) import Data.Tuple (Tuple(..)) import Data.Tuple.Nested (tuple2) import GulpPurescript.Buffer (mkBufferFromString) -import GulpPurescript.ChildProcess (ChildProcess(), spawn) -import GulpPurescript.Glob (Glob(), globAll) -import GulpPurescript.GulpUtil (File(), mkFile, mkPluginError) -import GulpPurescript.Logalot (Logalot(), info) -import GulpPurescript.OS (OS(), Platform(Win32), platform) +import GulpPurescript.ChildProcess (ChildProcess, spawn) +import GulpPurescript.Glob (Glob, globAll) +import GulpPurescript.GulpUtil (File, mkFile, mkPluginError) +import GulpPurescript.Logalot (Logalot, info) +import GulpPurescript.OS (OS, Platform(Win32), platform) import GulpPurescript.Options (Psci(..), pscOptions, pscBundleOptions, pscDocsOptions) -import GulpPurescript.Package (Pkg(), Package(..), package) import GulpPurescript.Path (relative) -import GulpPurescript.ResolveBin (ResolveBin(), resolveBin) -import GulpPurescript.Stream (Stream(), ReadableStream(), mkReadableStreamFromAff) -import GulpPurescript.Which (Which(), which) +import GulpPurescript.ResolveBin (ResolveBin, resolveBin) +import GulpPurescript.Stream (Stream, ReadableStream, mkReadableStreamFromAff) +import GulpPurescript.Which (Which, which) foreign import argv :: Array String rtsOpts :: Array String rtsOpts = - let startIndex = A.elemIndex "--psc-rts-flags" argv + let startIndex = Array.elemIndex "--psc-rts-flags" argv in case startIndex of - Just i -> ["+RTS"] <> A.drop (i + 1) argv <> ["-RTS"] + Just i -> ["+RTS"] <> Array.drop (i + 1) argv <> ["-RTS"] _ -> [] type Effects eff = @@ -53,7 +51,6 @@ type Effects eff = , glob :: Glob , logalot :: Logalot , os :: OS - , package :: Pkg , resolveBin :: ResolveBin , stream :: Stream , which :: Which @@ -91,8 +88,7 @@ pscDocsCommand = "psc-docs" foreign import cwd :: String throwPluginError :: forall eff result. String -> Aff (Effects eff) result -throwPluginError msg = liftEff (flip mkPluginError msg <$> (maybe "" (\(Package a) -> a.name)) - <$> package) >>= throwError +throwPluginError = throwError <<< mkPluginError "gulp-purescript" resolve :: forall eff. String -> Array String -> Aff (Effects eff) (Tuple String (Array String)) resolve cmd args = catchError primary fallback @@ -101,30 +97,30 @@ resolve cmd args = catchError primary fallback primary = do bin <- resolveBin pursPackage { executable: cmd } os <- liftEff platform - return $ case os of - Just Win32 -> tuple2 nodeCommand ([bin] <> args) - _ -> tuple2 bin args + pure $ case os of + Just Win32 -> tuple2 nodeCommand ([bin] <> args) + _ -> tuple2 bin args fallback :: Error -> Aff (Effects eff) (Tuple String (Array String)) fallback _ = (const $ tuple2 cmd args) <$> catchError (which cmd) mapError mapError :: Error -> Aff (Effects eff) String - mapError _ = throwPluginError ("Failed to find " ++ cmd ++ ". " ++ "Please ensure it is available on your system.") + mapError _ = throwPluginError ("Failed to find " <> cmd <> ". " <> "Please ensure it is available on your system.") execute :: forall eff. String -> Array String -> Aff (Effects eff) String execute cmd args = do Tuple cmd' args' <- resolve cmd args result <- spawn cmd' args' - return result + pure result psc :: forall eff. Foreign -> Eff (Effects eff) (ReadableStream Unit) psc opts = mkReadableStreamFromAff $ do output <- either (throwPluginError <<< show) - (execute pscCommand <<< (<> rtsOpts)) + (execute pscCommand <<< (_ <> rtsOpts)) (pscOptions opts) if null output then pure unit - else liftEff $ info $ pscCommand ++ "\n" ++ output + else liftEff $ info $ pscCommand <> "\n" <> output pscBundle :: forall eff. Foreign -> Eff (Effects eff) (ReadableStream File) pscBundle opts = mkReadableStreamFromAff (either (throwPluginError <<< show) run (pscBundleOptions opts)) @@ -146,15 +142,14 @@ psci opts = mkReadableStreamFromAff (either (throwPluginError <<< show) run (rea run :: Psci -> Aff (Effects eff) File run (Psci a) = do srcs <- globAll (either pure id a.src) - ffis <- globAll (either pure id (fromMaybe (Right []) (runNullOrUndefined a.ffi))) - let lines = (loadModule <$> A.concat srcs) <> (loadForeign <$> A.concat ffis) + let lines = loadModule <$> Array.concat srcs buffer = mkBufferFromString (joinWith "\n" lines) - return (mkFile psciFilename buffer) + pure (mkFile psciFilename buffer) loadModule :: String -> String - loadModule a = psciLoadModuleCommand ++ " " ++ relative cwd a + loadModule a = psciLoadModuleCommand <> " " <> relative cwd a loadForeign :: String -> String - loadForeign a = psciLoadForeignCommand ++ " " ++ relative cwd a + loadForeign a = psciLoadForeignCommand <> " " <> relative cwd a diff --git a/src/GulpPurescript/ResolveBin.js b/src/GulpPurescript/ResolveBin.js index 5b5fd8a..23116bc 100644 --- a/src/GulpPurescript/ResolveBin.js +++ b/src/GulpPurescript/ResolveBin.js @@ -1,7 +1,5 @@ 'use strict'; -// module GulpPurescript.ResolveBin - var resolveBin = require('resolve-bin'); function resolveBinFn(pkg, options, errback, callback) { diff --git a/src/GulpPurescript/ResolveBin.purs b/src/GulpPurescript/ResolveBin.purs index 95bf542..9e43d29 100644 --- a/src/GulpPurescript/ResolveBin.purs +++ b/src/GulpPurescript/ResolveBin.purs @@ -1,16 +1,16 @@ module GulpPurescript.ResolveBin - ( ResolveBin() + ( ResolveBin , Options(..) , resolveBin ) where -import Prelude +import Prelude (Unit, ($)) -import Control.Monad.Aff (Aff(), makeAff) -import Control.Monad.Eff (Eff()) -import Control.Monad.Eff.Exception (Error()) +import Control.Monad.Aff (Aff, makeAff) +import Control.Monad.Eff (Eff) +import Control.Monad.Eff.Exception (Error) -import Data.Function +import Data.Function.Uncurried (Fn4, runFn4) foreign import data ResolveBin :: ! diff --git a/src/GulpPurescript/Stream.js b/src/GulpPurescript/Stream.js index a25aac9..d8fa972 100644 --- a/src/GulpPurescript/Stream.js +++ b/src/GulpPurescript/Stream.js @@ -1,7 +1,5 @@ 'use strict'; -// module GulpPurescript.Stream - var stream = require('stream'); function mkReadableStreamFromAffFn(runAff, aff) { diff --git a/src/GulpPurescript/Stream.purs b/src/GulpPurescript/Stream.purs index a53ae3a..ba8997a 100644 --- a/src/GulpPurescript/Stream.purs +++ b/src/GulpPurescript/Stream.purs @@ -1,16 +1,16 @@ module GulpPurescript.Stream - ( Stream() - , ReadableStream() + ( Stream + , ReadableStream , mkReadableStreamFromAff ) where -import Prelude +import Prelude (Unit) -import Control.Monad.Aff (Aff(), runAff) -import Control.Monad.Eff (Eff()) -import Control.Monad.Eff.Exception (Error()) +import Control.Monad.Aff (Aff, runAff) +import Control.Monad.Eff (Eff) +import Control.Monad.Eff.Exception (Error) -import Data.Function +import Data.Function.Uncurried (Fn2, runFn2) foreign import data Stream :: ! diff --git a/src/GulpPurescript/Which.js b/src/GulpPurescript/Which.js index 273e50e..f7a977a 100644 --- a/src/GulpPurescript/Which.js +++ b/src/GulpPurescript/Which.js @@ -1,7 +1,5 @@ 'use strict'; -// module GulpPurescript.Which - var which = require('which'); function whichFn(command, errback, callback) { diff --git a/src/GulpPurescript/Which.purs b/src/GulpPurescript/Which.purs index 6418abe..b2ce1e1 100644 --- a/src/GulpPurescript/Which.purs +++ b/src/GulpPurescript/Which.purs @@ -1,15 +1,15 @@ module GulpPurescript.Which - ( Which() + ( Which , which ) where -import Prelude +import Prelude (Unit, ($)) -import Control.Monad.Aff (Aff(), makeAff) -import Control.Monad.Eff (Eff()) -import Control.Monad.Eff.Exception (Error()) +import Control.Monad.Aff (Aff, makeAff) +import Control.Monad.Eff (Eff) +import Control.Monad.Eff.Exception (Error) -import Data.Function +import Data.Function.Uncurried (Fn3, runFn3) foreign import data Which :: ! diff --git a/Fixture1.purs b/test/Fixture1.purs similarity index 70% rename from Fixture1.purs rename to test/Fixture1.purs index d745db1..88fdbfe 100644 --- a/Fixture1.purs +++ b/test/Fixture1.purs @@ -1,3 +1,4 @@ module Fixture1 where +fixture :: String fixture = "fixture" diff --git a/Fixture2.purs b/test/Fixture2.purs similarity index 68% rename from Fixture2.purs rename to test/Fixture2.purs index 59e5b97..8af434c 100644 --- a/Fixture2.purs +++ b/test/Fixture2.purs @@ -1,3 +1,4 @@ module Fixture2 w +fixture :: String fixture = "fixture" diff --git a/foreign.js b/test/foreign.js similarity index 100% rename from foreign.js rename to test/foreign.js diff --git a/test.js b/test/test.js similarity index 77% rename from test.js rename to test/test.js index 892fe9e..2c9cb15 100644 --- a/test.js +++ b/test/test.js @@ -10,12 +10,12 @@ var gulp = require('gulp'); var through2 = require('through2'); -var purescript = require('./'); +var purescript = require('../'); test('psc - basic', function(t){ t.plan(1); - var fixture = 'Fixture1.purs'; + var fixture = './test/Fixture1.purs'; var stream = purescript.psc({src: fixture}); @@ -28,13 +28,13 @@ test('psc - basic', function(t){ test('psc - error', function(t){ t.plan(2); - var fixture = 'Fixture2.purs'; + var fixture = './test/Fixture2.purs'; var stream = purescript.psc({src: fixture}); stream.on('error', function(e){ t.ok(/"where"/.test(e.message), 'should have a failure message'); - t.equal('Error', e.name); + t.equal(e.name, 'Error'); }); }); @@ -46,19 +46,19 @@ test('psc - invalid option type', function(t){ stream.on('error', function(e){ t.ok(/type mismatch/i.test(error.message), 'should have a failure message'); - t.equal('Error', error.name); + t.equal(error.name, 'Error'); }); } catch (error) { t.ok(/type mismatch/i.test(error.message), 'should have a failure message'); - t.equal('Error', error.name); + t.equal(error.name, 'Error'); } }); test('psc-bundle - basic', function(t){ t.plan(1); - var fixture = 'foreign.js'; + var fixture = './test/foreign.js'; var stream = purescript.pscBundle({src: fixture}); @@ -71,15 +71,15 @@ test('psc-bundle - basic', function(t){ test('psci - basic', function(t){ t.plan(2); - var fixture = 'Fixture1.purs'; + var fixture = './test/Fixture1.purs'; - var output = ':m ' + fixture; + var output = ':m test/Fixture1.purs'; var stream = purescript.psci({src: fixture}); stream.pipe(through2.obj(function(chunk, encoding, callback){ - t.equal('.psci', chunk.path); - t.equal(output, chunk.contents.toString()); + t.equal(chunk.path, '.psci'); + t.equal(chunk.contents.toString(), output); callback(); })); }); diff --git a/webpack.config.js b/webpack.config.js deleted file mode 100644 index 52944c9..0000000 --- a/webpack.config.js +++ /dev/null @@ -1,33 +0,0 @@ -'use strict'; - -var path = require('path'); - -var webpack = require('webpack'); - -var packageJson = require('./package.json'); - -var noErrorsPlugin = webpack.NoErrorsPlugin; - -var dedupePlugin = webpack.optimize.DedupePlugin; - -var config - = { cache: true - , target: 'node' - , entry: { index: './entry' } - , externals: Object.keys(packageJson.dependencies).reduce(function(b, a){ - b[a] = 'commonjs ' + a; - return b; - }, {}) - , module: { loaders: [ { test: /\.json$/, loader: 'json-loader' } ] } - , output: { path: __dirname - , filename: '[name].js' - , libraryTarget: 'commonjs2' - } - , plugins: [ new noErrorsPlugin() - , new dedupePlugin() - ] - , resolve: { modulesDirectories: [ 'build' ] } - } - ; - -module.exports = config; From 74fc4bc3b98bbc23c7e03fe1922251e269332422 Mon Sep 17 00:00:00 2001 From: eric thul Date: Sun, 5 Jun 2016 18:06:48 -0400 Subject: [PATCH 2/3] Remove members from Data.Aray import --- src/GulpPurescript/Plugin.purs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GulpPurescript/Plugin.purs b/src/GulpPurescript/Plugin.purs index aaf6eea..7cb9516 100644 --- a/src/GulpPurescript/Plugin.purs +++ b/src/GulpPurescript/Plugin.purs @@ -16,7 +16,7 @@ import Control.Monad.Eff.Class (liftEff) import Control.Monad.Eff.Exception (Error) import Control.Monad.Error.Class (catchError, throwError) -import Data.Array (elemIndex, drop, concat) as Array +import Data.Array as Array import Data.Either (either) import Data.Foreign (Foreign) import Data.Foreign.Class (read) From 34f6a79001ac4e5d34cb94398f49d94fac0fb440 Mon Sep 17 00:00:00 2001 From: eric thul Date: Sun, 5 Jun 2016 22:00:08 -0400 Subject: [PATCH 3/3] Update purescript-aff dependency --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index cd31692..95baee1 100644 --- a/bower.json +++ b/bower.json @@ -2,7 +2,7 @@ "name": "gulp-purescript", "private": true, "dependencies": { - "purescript-aff": "slamdata/purescript-aff#088ef5f4f14c29fe239c89826029ac2f76dce666", + "purescript-aff": "~0.17.0", "purescript-foreign": "~1.0.0" } }