diff options
author | eric <thul.eric@gmail.com> | 2016-03-13 10:07:58 -0400 |
---|---|---|
committer | eric <thul.eric@gmail.com> | 2016-03-13 10:07:58 -0400 |
commit | 7a70d4eb331b60186e3800d15efd9115462c6a80 (patch) | |
tree | 9af0a5120593adeb47229d6a564fee86ab9f0856 | |
parent | cfd5d2afba83a0082a3be638a05d1768ee73335e (diff) | |
parent | 1a7a07b7a4fa93a55a600ca9d466020f3e11ab5a (diff) | |
download | purs-loader-7a70d4eb331b60186e3800d15efd9115462c6a80.tar.gz purs-loader-7a70d4eb331b60186e3800d15efd9115462c6a80.tar.zst purs-loader-7a70d4eb331b60186e3800d15efd9115462c6a80.zip |
Merge pull request #44 from ethul/topic/output-only-once
Topic/output only once
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | README.md | 34 | ||||
-rw-r--r-- | bower.json | 3 | ||||
-rw-r--r-- | docs/PursLoader/Plugin.md | 2 | ||||
-rw-r--r-- | example/README.md | 6 | ||||
-rw-r--r-- | example/bower.json | 7 | ||||
-rw-r--r-- | example/package.json | 18 | ||||
-rw-r--r-- | example/src/Bar.purs | 3 | ||||
-rw-r--r-- | example/src/Foo.purs | 15 | ||||
-rw-r--r-- | example/src/Foo/Bar.purs | 13 | ||||
-rw-r--r-- | example/src/Foo/Baz.purs | 3 | ||||
-rw-r--r-- | example/src/Foo/Boz.purs | 5 | ||||
-rw-r--r-- | example/src/FooFFI.js | 5 | ||||
-rw-r--r-- | example/src/Test.purs | 7 | ||||
-rw-r--r-- | example/src/TestFFI.js | 7 | ||||
-rw-r--r-- | example/src/entry.js | 11 | ||||
-rw-r--r-- | example/src/jam.js | 5 | ||||
-rw-r--r-- | example/webpack.config.js | 28 | ||||
-rw-r--r-- | src/PursLoader/Loader.purs | 14 | ||||
-rw-r--r-- | src/PursLoader/Plugin.purs | 2 |
20 files changed, 7 insertions, 185 deletions
@@ -6,8 +6,4 @@ index.js | |||
6 | node_modules/ | 6 | node_modules/ |
7 | bower_components/ | 7 | bower_components/ |
8 | build/ | 8 | build/ |
9 | example/bundle.js | ||
10 | example/node_modules/ | ||
11 | example/bower_components/ | ||
12 | example/output/ | ||
13 | tmp/ | 9 | tmp/ |
@@ -14,36 +14,4 @@ npm install purs-loader --save-dev | |||
14 | 14 | ||
15 | ## Example | 15 | ## Example |
16 | 16 | ||
17 | ```js | 17 | Refer to the [purescript-webpack-example](https://github.com/ethul/purescript-webpack-example) for an example. |
18 | // webpack.config.js | ||
19 | 'use strict'; | ||
20 | |||
21 | var PurescriptWebpackPlugin = require('purescript-webpack-plugin'); | ||
22 | |||
23 | var src = ['bower_components/purescript-*/src/**/*.purs', 'src/**/*.purs']; | ||
24 | |||
25 | var ffi = ['bower_components/purescript-*/src/**/*.js', 'src/**/*FFI.js']; | ||
26 | |||
27 | var modulesDirectories = [ | ||
28 | 'node_modules', | ||
29 | 'bower_components' | ||
30 | ]; | ||
31 | |||
32 | var config | ||
33 | = { entry: './src/entry' | ||
34 | , output: { path: __dirname | ||
35 | , pathinfo: true | ||
36 | , filename: 'bundle.js' | ||
37 | } | ||
38 | , module: { loaders: [ { test: /\.purs$/ | ||
39 | , loader: 'purs-loader' | ||
40 | } ] } | ||
41 | , resolve: { modulesDirectories: modulesDirectories } | ||
42 | , plugins: [ new PurescriptWebpackPlugin({src: src, ffi: ffi}) ] | ||
43 | } | ||
44 | ; | ||
45 | |||
46 | module.exports = config; | ||
47 | ``` | ||
48 | |||
49 | See the [example](https://github.com/ethul/purs-loader/tree/master/example) directory for a complete example. | ||
@@ -5,7 +5,6 @@ | |||
5 | "purescript-aff": "^0.13.0", | 5 | "purescript-aff": "^0.13.0", |
6 | "purescript-foreign": "^0.7.0", | 6 | "purescript-foreign": "^0.7.0", |
7 | "purescript-unsafe-coerce": "~0.1.0", | 7 | "purescript-unsafe-coerce": "~0.1.0", |
8 | "purescript-nullable": "~0.2.1", | 8 | "purescript-nullable": "~0.2.1" |
9 | "purescript-node-process": "~0.4.1" | ||
10 | } | 9 | } |
11 | } | 10 | } |
diff --git a/docs/PursLoader/Plugin.md b/docs/PursLoader/Plugin.md index 9f9f852..7a524da 100644 --- a/docs/PursLoader/Plugin.md +++ b/docs/PursLoader/Plugin.md | |||
@@ -3,7 +3,7 @@ | |||
3 | #### `Compile` | 3 | #### `Compile` |
4 | 4 | ||
5 | ``` purescript | 5 | ``` purescript |
6 | type Compile eff = Nullable Error -> DependencyGraph -> String -> Eff eff Unit | 6 | type Compile eff = Nullable Error -> DependencyGraph -> Eff eff Unit |
7 | ``` | 7 | ``` |
8 | 8 | ||
9 | #### `Context` | 9 | #### `Context` |
diff --git a/example/README.md b/example/README.md deleted file mode 100644 index bac4f6c..0000000 --- a/example/README.md +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | ```bash | ||
2 | bower install | ||
3 | npm install | ||
4 | npm run-script build | ||
5 | npm run-script run | ||
6 | ``` | ||
diff --git a/example/bower.json b/example/bower.json deleted file mode 100644 index c83e735..0000000 --- a/example/bower.json +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | { | ||
2 | "name": "example", | ||
3 | "private": true, | ||
4 | "devDependencies": { | ||
5 | "purescript-prelude": "~0.1.0" | ||
6 | } | ||
7 | } | ||
diff --git a/example/package.json b/example/package.json deleted file mode 100644 index e256de8..0000000 --- a/example/package.json +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | { | ||
2 | "name": "example", | ||
3 | "version": "0.0.0", | ||
4 | "private": true, | ||
5 | "scripts": { | ||
6 | "build": "webpack --progress --colors --bail", | ||
7 | "build:watch": "webpack --progress --colors --watch", | ||
8 | "run": "node bundle.js", | ||
9 | "clean": "rm -rf bower_components && rm -rf bundle.js && rm -rf node_modules && rm -rf output" | ||
10 | }, | ||
11 | "license": "MIT", | ||
12 | "devDependencies": { | ||
13 | "node-libs-browser": "^0.5.2", | ||
14 | "purescript-webpack-plugin": "^0.1.1", | ||
15 | "purs-loader": "file:../", | ||
16 | "webpack": "^1.12.9" | ||
17 | } | ||
18 | } | ||
diff --git a/example/src/Bar.purs b/example/src/Bar.purs deleted file mode 100644 index a37171f..0000000 --- a/example/src/Bar.purs +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | module Bar where | ||
2 | |||
3 | test = "b" | ||
diff --git a/example/src/Foo.purs b/example/src/Foo.purs deleted file mode 100644 index a715be0..0000000 --- a/example/src/Foo.purs +++ /dev/null | |||
@@ -1,15 +0,0 @@ | |||
1 | module Foo where | ||
2 | |||
3 | import Prelude | ||
4 | |||
5 | import qualified Foo.Bar as B | ||
6 | |||
7 | foo = "A" | ||
8 | |||
9 | bar = "B" | ||
10 | |||
11 | jaz = "D" ++ B.jar ++ B.jee | ||
12 | |||
13 | foreign import foot :: String | ||
14 | |||
15 | foreign import meter :: String | ||
diff --git a/example/src/Foo/Bar.purs b/example/src/Foo/Bar.purs deleted file mode 100644 index 1b0919c..0000000 --- a/example/src/Foo/Bar.purs +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | module Foo.Bar (bar, jar, jee) where | ||
2 | |||
3 | import Foo.Boz | ||
4 | |||
5 | bar = "u" | ||
6 | |||
7 | bar' = "d" | ||
8 | |||
9 | jam = "c" | ||
10 | |||
11 | jar = "xyzw" | ||
12 | |||
13 | jee = "abcde" | ||
diff --git a/example/src/Foo/Baz.purs b/example/src/Foo/Baz.purs deleted file mode 100644 index 7b0451e..0000000 --- a/example/src/Foo/Baz.purs +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | module Foo.Baz (baz) where | ||
2 | |||
3 | baz = "d" | ||
diff --git a/example/src/Foo/Boz.purs b/example/src/Foo/Boz.purs deleted file mode 100644 index c802e47..0000000 --- a/example/src/Foo/Boz.purs +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | module Foo.Boz where | ||
2 | |||
3 | a = "a" | ||
4 | |||
5 | b = "b" | ||
diff --git a/example/src/FooFFI.js b/example/src/FooFFI.js deleted file mode 100644 index a2681c8..0000000 --- a/example/src/FooFFI.js +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | // module Foo | ||
2 | |||
3 | exports.foot = "a"; | ||
4 | |||
5 | exports.meter = "b"; | ||
diff --git a/example/src/Test.purs b/example/src/Test.purs deleted file mode 100644 index 3a92681..0000000 --- a/example/src/Test.purs +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | module Test (testing) where | ||
2 | |||
3 | bar = "c" | ||
4 | |||
5 | goo = "a" | ||
6 | |||
7 | foreign import testing :: String | ||
diff --git a/example/src/TestFFI.js b/example/src/TestFFI.js deleted file mode 100644 index dc2f04f..0000000 --- a/example/src/TestFFI.js +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | 'use strict'; | ||
2 | |||
3 | // module Test | ||
4 | |||
5 | var testing = 'abcde'; | ||
6 | |||
7 | exports.testing = testing; | ||
diff --git a/example/src/entry.js b/example/src/entry.js deleted file mode 100644 index a1e2a99..0000000 --- a/example/src/entry.js +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | var Prelude = require('purescript-prelude/src/Prelude'); | ||
2 | |||
3 | var test = require('./Test'); | ||
4 | |||
5 | var foo = require('./Foo.purs'); | ||
6 | |||
7 | var baz = require('./Foo/Baz'); | ||
8 | |||
9 | var jam = require('./jam'); | ||
10 | |||
11 | console.log(Prelude, test, foo, baz, jam); | ||
diff --git a/example/src/jam.js b/example/src/jam.js deleted file mode 100644 index 8889a69..0000000 --- a/example/src/jam.js +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | var x = 'a'; | ||
2 | |||
3 | var abcde = require('./Bar'); | ||
4 | |||
5 | module.exports = abcde; | ||
diff --git a/example/webpack.config.js b/example/webpack.config.js deleted file mode 100644 index 602de84..0000000 --- a/example/webpack.config.js +++ /dev/null | |||
@@ -1,28 +0,0 @@ | |||
1 | 'use strict'; | ||
2 | |||
3 | var PurescriptWebpackPlugin = require('purescript-webpack-plugin'); | ||
4 | |||
5 | var src = ['bower_components/purescript-*/src/**/*.purs', 'src/**/*.purs']; | ||
6 | |||
7 | var ffi = ['bower_components/purescript-*/src/**/*.js', 'src/**/*FFI.js']; | ||
8 | |||
9 | var modulesDirectories = [ | ||
10 | 'node_modules', | ||
11 | 'bower_components' | ||
12 | ]; | ||
13 | |||
14 | var config | ||
15 | = { entry: './src/entry' | ||
16 | , output: { path: __dirname | ||
17 | , pathinfo: true | ||
18 | , filename: 'bundle.js' | ||
19 | } | ||
20 | , module: { loaders: [ { test: /\.purs$/ | ||
21 | , loader: 'purs-loader' | ||
22 | } ] } | ||
23 | , resolve: { modulesDirectories: modulesDirectories, extensions: [ '', '.js', '.purs'] } | ||
24 | , plugins: [ new PurescriptWebpackPlugin({src: src, ffi: ffi}) ] | ||
25 | } | ||
26 | ; | ||
27 | |||
28 | module.exports = config; | ||
diff --git a/src/PursLoader/Loader.purs b/src/PursLoader/Loader.purs index c50c63c..97954f6 100644 --- a/src/PursLoader/Loader.purs +++ b/src/PursLoader/Loader.purs | |||
@@ -5,12 +5,12 @@ module PursLoader.Loader | |||
5 | , loaderFn | 5 | , loaderFn |
6 | ) where | 6 | ) where |
7 | 7 | ||
8 | import Prelude (Unit(), ($), (>>=), (<$>), (<*>), (++), (<<<), bind, const, id, pure, unit, void) | 8 | import Prelude (Unit(), ($), (>>=), (<$>), (<*>), (++), (<<<), bind, const, id, pure, unit) |
9 | 9 | ||
10 | import Control.Bind (join) | 10 | import Control.Bind (join) |
11 | import Control.Monad.Eff (Eff(), foreachE) | 11 | import Control.Monad.Eff (Eff(), foreachE) |
12 | import Control.Monad.Eff.Console (CONSOLE()) | 12 | import Control.Monad.Eff.Console (CONSOLE()) |
13 | import Control.Monad.Eff.Exception (EXCEPTION(), Error(), error, message) | 13 | import Control.Monad.Eff.Exception (EXCEPTION(), Error(), error) |
14 | 14 | ||
15 | import Data.Array ((!!)) | 15 | import Data.Array ((!!)) |
16 | import Data.Either (Either(..), either) | 16 | import Data.Either (Either(..), either) |
@@ -19,10 +19,6 @@ import Data.Maybe (maybe) | |||
19 | import Data.Nullable (toMaybe) | 19 | import Data.Nullable (toMaybe) |
20 | import Data.String.Regex (Regex(), match, noFlags, regex) | 20 | import Data.String.Regex (Regex(), match, noFlags, regex) |
21 | 21 | ||
22 | import Node.Encoding (Encoding(UTF8)) | ||
23 | import Node.Process (stderr) | ||
24 | import Node.Stream (writeString) | ||
25 | |||
26 | import Unsafe.Coerce (unsafeCoerce) | 22 | import Unsafe.Coerce (unsafeCoerce) |
27 | 23 | ||
28 | import PursLoader.LoaderRef | 24 | import PursLoader.LoaderRef |
@@ -57,15 +53,11 @@ loader ref source = do | |||
57 | pluginContext = (unsafeCoerce ref).purescriptWebpackPluginContext | 53 | pluginContext = (unsafeCoerce ref).purescriptWebpackPluginContext |
58 | 54 | ||
59 | compile :: AsyncCallback (Effects eff) -> Plugin.Compile (Effects_ eff) | 55 | compile :: AsyncCallback (Effects eff) -> Plugin.Compile (Effects_ eff) |
60 | compile callback error' graph output = do | 56 | compile callback error' graph = do |
61 | either (const $ pure unit) (\a -> debug ("Adding PureScript dependency " ++ a)) name | 57 | either (const $ pure unit) (\a -> debug ("Adding PureScript dependency " ++ a)) name |
62 | 58 | ||
63 | addDependency ref (resourcePath ref) | 59 | addDependency ref (resourcePath ref) |
64 | 60 | ||
65 | void $ writeString stderr UTF8 output (pure unit) | ||
66 | |||
67 | maybe (pure unit) (\a -> void $ writeString stderr UTF8 (message a) (pure unit)) (toMaybe error') | ||
68 | |||
69 | either (const $ callback (pure fixedError) "") id | 61 | either (const $ callback (pure fixedError) "") id |
70 | (handle <$> name <*> dependencies <*> exports) | 62 | (handle <$> name <*> dependencies <*> exports) |
71 | where | 63 | where |
diff --git a/src/PursLoader/Plugin.purs b/src/PursLoader/Plugin.purs index 8bb53be..c798c83 100644 --- a/src/PursLoader/Plugin.purs +++ b/src/PursLoader/Plugin.purs | |||
@@ -15,7 +15,7 @@ import Data.Either (Either(..)) | |||
15 | import Data.Function (Fn4(), runFn4) | 15 | import Data.Function (Fn4(), runFn4) |
16 | import Data.Nullable (Nullable()) | 16 | import Data.Nullable (Nullable()) |
17 | 17 | ||
18 | type Compile eff = Nullable Error -> DependencyGraph -> String -> Eff eff Unit | 18 | type Compile eff = Nullable Error -> DependencyGraph -> Eff eff Unit |
19 | 19 | ||
20 | type Context eff = { compile :: Compile eff -> Eff eff Unit, options :: Options } | 20 | type Context eff = { compile :: Compile eff -> Eff eff Unit, options :: Options } |
21 | 21 | ||