diff options
author | eric thul <thul.eric@gmail.com> | 2015-01-17 16:24:33 -0500 |
---|---|---|
committer | eric thul <thul.eric@gmail.com> | 2015-01-17 16:24:33 -0500 |
commit | a92aa714f0a5436d9f06f82b3cad4df8129e4064 (patch) | |
tree | ad7bb533a80a2a012d18317596bc5825ad1c2db8 | |
parent | 051c54bc5fd21db7758abfc8cbd53921bf50495e (diff) | |
download | purs-loader-a92aa714f0a5436d9f06f82b3cad4df8129e4064.tar.gz purs-loader-a92aa714f0a5436d9f06f82b3cad4df8129e4064.tar.zst purs-loader-a92aa714f0a5436d9f06f82b3cad4df8129e4064.zip |
Parsing module name from source
Resolves issue #3 since the the module name defined in the PureScript
file is used to resolve the location of the CommonJS-generated output.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | example/index.html | 18 | ||||
-rw-r--r-- | example/package.json | 3 | ||||
-rw-r--r-- | example/src/Foo.purs | 1 | ||||
-rw-r--r-- | example/src/Foo/Bar.purs | 3 | ||||
-rw-r--r-- | example/src/Foo/Baz.purs | 3 | ||||
-rw-r--r-- | example/src/entry.js | 4 | ||||
-rw-r--r-- | index.js | 4 |
8 files changed, 16 insertions, 21 deletions
@@ -1,3 +1,4 @@ | |||
1 | npm-debug.log | ||
1 | node_modules/ | 2 | node_modules/ |
2 | example/node_modules/ | 3 | example/node_modules/ |
3 | example/bower_components/ | 4 | example/bower_components/ |
diff --git a/example/index.html b/example/index.html deleted file mode 100644 index 8db646e..0000000 --- a/example/index.html +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | <!doctype html> | ||
2 | <html class="no-js" lang=""> | ||
3 | <head> | ||
4 | <meta charset="utf-8"> | ||
5 | <meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
6 | <title></title> | ||
7 | <meta name="description" content=""> | ||
8 | <meta name="viewport" content="width=device-width, initial-scale=1"> | ||
9 | </head> | ||
10 | <body> | ||
11 | <!--[if lt IE 8]> | ||
12 | <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p> | ||
13 | <![endif]--> | ||
14 | <!-- Add your site or application content here --> | ||
15 | <p>Hello world! This is HTML5 Boilerplate.</p> | ||
16 | <script src="dist/app.js"></script> | ||
17 | </body> | ||
18 | </html> | ||
diff --git a/example/package.json b/example/package.json index 482563f..6b0c04c 100644 --- a/example/package.json +++ b/example/package.json | |||
@@ -4,7 +4,8 @@ | |||
4 | "private": true, | 4 | "private": true, |
5 | "scripts": { | 5 | "scripts": { |
6 | "webpack": "./node_modules/.bin/webpack", | 6 | "webpack": "./node_modules/.bin/webpack", |
7 | "run": "node dist/app.js" | 7 | "run": "node dist/app.js", |
8 | "clean": "rm -rf bower_components && rm -rf dist && rm -rf node_modules && rm -rf output" | ||
8 | }, | 9 | }, |
9 | "license": "MIT", | 10 | "license": "MIT", |
10 | "devDependencies": { | 11 | "devDependencies": { |
diff --git a/example/src/Foo.purs b/example/src/Foo.purs index 2d35d3f..3e3a04c 100644 --- a/example/src/Foo.purs +++ b/example/src/Foo.purs | |||
@@ -1,5 +1,6 @@ | |||
1 | module Foo (foo) where | 1 | module Foo (foo) where |
2 | 2 | ||
3 | import Data.Maybe | 3 | import Data.Maybe |
4 | import qualified Foo.Bar as B | ||
4 | 5 | ||
5 | foo = "b" | 6 | foo = "b" |
diff --git a/example/src/Foo/Bar.purs b/example/src/Foo/Bar.purs new file mode 100644 index 0000000..4ae100d --- /dev/null +++ b/example/src/Foo/Bar.purs | |||
@@ -0,0 +1,3 @@ | |||
1 | module Foo.Bar (bar) where | ||
2 | |||
3 | bar = "c" | ||
diff --git a/example/src/Foo/Baz.purs b/example/src/Foo/Baz.purs new file mode 100644 index 0000000..7b0451e --- /dev/null +++ b/example/src/Foo/Baz.purs | |||
@@ -0,0 +1,3 @@ | |||
1 | module Foo.Baz (baz) where | ||
2 | |||
3 | baz = "d" | ||
diff --git a/example/src/entry.js b/example/src/entry.js index 4c15475..160bee4 100644 --- a/example/src/entry.js +++ b/example/src/entry.js | |||
@@ -2,4 +2,6 @@ var test = require('purs?output=output!./Test.purs'); | |||
2 | 2 | ||
3 | var foo = require('purs?output=output!./Foo.purs'); | 3 | var foo = require('purs?output=output!./Foo.purs'); |
4 | 4 | ||
5 | console.log(test, foo); | 5 | var baz = require('purs?output=output!./Foo/Baz.purs'); |
6 | |||
7 | console.log(test, foo, baz); | ||
@@ -6,6 +6,7 @@ var cp = require('child_process') | |||
6 | , chalk = require('chalk') | 6 | , chalk = require('chalk') |
7 | , lu = require('loader-utils') | 7 | , lu = require('loader-utils') |
8 | , cwd = process.cwd() | 8 | , cwd = process.cwd() |
9 | , MODULE_RE = /^module\s+([\w\.]+)\s+/i | ||
9 | , BOWER_PATTERN = path.join('bower_components', 'purescript-*', 'src') | 10 | , BOWER_PATTERN = path.join('bower_components', 'purescript-*', 'src') |
10 | , PSC_MAKE = 'psc-make' | 11 | , PSC_MAKE = 'psc-make' |
11 | , OUTPUT = 'output' | 12 | , OUTPUT = 'output' |
@@ -42,7 +43,8 @@ module.exports = function(source){ | |||
42 | cmd.on('close', function(e){ | 43 | cmd.on('close', function(e){ |
43 | if (e) callback(e); | 44 | if (e) callback(e); |
44 | else { | 45 | else { |
45 | var module = path.basename(request, '.purs'); | 46 | var result = MODULE_RE.exec(source); |
47 | var module = result.length > 1 ? result[1] : ''; | ||
46 | fs.readFile(path.join(query[OUTPUT] || OUTPUT, module, 'index.js'), 'utf-8', function(e, output){ | 48 | fs.readFile(path.join(query[OUTPUT] || OUTPUT, module, 'index.js'), 'utf-8', function(e, output){ |
47 | if (e) callback(e); | 49 | if (e) callback(e); |
48 | else callback(e, output); | 50 | else callback(e, output); |