]> git.immae.eu Git - github/fretlink/purs-loader.git/commitdiff
Parsing module name from source
authoreric thul <thul.eric@gmail.com>
Sat, 17 Jan 2015 21:24:33 +0000 (16:24 -0500)
committereric thul <thul.eric@gmail.com>
Sat, 17 Jan 2015 21:24:33 +0000 (16:24 -0500)
Resolves issue #3 since the the module name defined in the PureScript
file is used to resolve the location of the CommonJS-generated output.

.gitignore
example/index.html [deleted file]
example/package.json
example/src/Foo.purs
example/src/Foo/Bar.purs [new file with mode: 0644]
example/src/Foo/Baz.purs [new file with mode: 0644]
example/src/entry.js
index.js

index 8476a21cef4c7d52fe7b6b88acf29249207617a1..8cde68436c403ff7b4250b4be5b7f04bd488628d 100644 (file)
@@ -1,3 +1,4 @@
+npm-debug.log
 node_modules/
 example/node_modules/
 example/bower_components/
diff --git a/example/index.html b/example/index.html
deleted file mode 100644 (file)
index 8db646e..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<!doctype html>
-<html class="no-js" lang="">
-  <head>
-    <meta charset="utf-8">
-    <meta http-equiv="X-UA-Compatible" content="IE=edge">
-    <title></title>
-    <meta name="description" content="">
-    <meta name="viewport" content="width=device-width, initial-scale=1">
-  </head>
-  <body>
-    <!--[if lt IE 8]>
-        <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>
-    <![endif]-->
-    <!-- Add your site or application content here -->
-    <p>Hello world! This is HTML5 Boilerplate.</p>
-    <script src="dist/app.js"></script>
-  </body>
-</html>
index 482563f893e14bd27a3bb34f6f86b92d7174d30c..6b0c04ce1f2d1c2a7b00b263999d775f7b7d1895 100644 (file)
@@ -4,7 +4,8 @@
   "private": true,
   "scripts": {
     "webpack": "./node_modules/.bin/webpack",
-    "run": "node dist/app.js"
+    "run": "node dist/app.js",
+    "clean": "rm -rf bower_components && rm -rf dist && rm -rf node_modules && rm -rf output"
   },
   "license": "MIT",
   "devDependencies": {
index 2d35d3f97bb2c704ca82472eedc4b0852aa0375a..3e3a04c13b910cb9fc7953e43058d1269fcc4b1d 100644 (file)
@@ -1,5 +1,6 @@
 module Foo (foo) where
 
 import Data.Maybe
+import qualified Foo.Bar as B
 
 foo = "b"
diff --git a/example/src/Foo/Bar.purs b/example/src/Foo/Bar.purs
new file mode 100644 (file)
index 0000000..4ae100d
--- /dev/null
@@ -0,0 +1,3 @@
+module Foo.Bar (bar) where
+
+bar = "c"
diff --git a/example/src/Foo/Baz.purs b/example/src/Foo/Baz.purs
new file mode 100644 (file)
index 0000000..7b0451e
--- /dev/null
@@ -0,0 +1,3 @@
+module Foo.Baz (baz) where
+
+baz = "d"
index 4c15475664cfca51b2c25675c4121a779b9e2903..160bee48b47067d9d31e8b0364eeb305d4c043ae 100644 (file)
@@ -2,4 +2,6 @@ var test = require('purs?output=output!./Test.purs');
 
 var foo = require('purs?output=output!./Foo.purs');
 
-console.log(test, foo);
+var baz = require('purs?output=output!./Foo/Baz.purs');
+
+console.log(test, foo, baz);
index ff2936f61f853959b2866de1496803e9023300d1..4a74d154ad45a16ac73237279bb06284d3f8817c 100644 (file)
--- a/index.js
+++ b/index.js
@@ -6,6 +6,7 @@ var cp = require('child_process')
   , chalk = require('chalk')
   , lu = require('loader-utils')
   , cwd = process.cwd()
+  , MODULE_RE = /^module\s+([\w\.]+)\s+/i
   , BOWER_PATTERN = path.join('bower_components', 'purescript-*', 'src')
   , PSC_MAKE = 'psc-make'
   , OUTPUT = 'output'
@@ -42,7 +43,8 @@ module.exports = function(source){
       cmd.on('close', function(e){
         if (e) callback(e);
         else {
-          var module = path.basename(request, '.purs');
+          var result = MODULE_RE.exec(source);
+          var module = result.length > 1 ? result[1] : '';
           fs.readFile(path.join(query[OUTPUT] || OUTPUT, module, 'index.js'), 'utf-8', function(e, output){
             if (e) callback(e);
             else callback(e, output);