From a92aa714f0a5436d9f06f82b3cad4df8129e4064 Mon Sep 17 00:00:00 2001 From: eric thul Date: Sat, 17 Jan 2015 16:24:33 -0500 Subject: [PATCH] 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. --- .gitignore | 1 + example/index.html | 18 ------------------ example/package.json | 3 ++- example/src/Foo.purs | 1 + example/src/Foo/Bar.purs | 3 +++ example/src/Foo/Baz.purs | 3 +++ example/src/entry.js | 4 +++- index.js | 4 +++- 8 files changed, 16 insertions(+), 21 deletions(-) delete mode 100644 example/index.html create mode 100644 example/src/Foo/Bar.purs create mode 100644 example/src/Foo/Baz.purs diff --git a/.gitignore b/.gitignore index 8476a21..8cde684 100644 --- a/.gitignore +++ b/.gitignore @@ -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 index 8db646e..0000000 --- a/example/index.html +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - -

Hello world! This is HTML5 Boilerplate.

- - - 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 @@ "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": { 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 @@ 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 index 0000000..4ae100d --- /dev/null +++ b/example/src/Foo/Bar.purs @@ -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 index 0000000..7b0451e --- /dev/null +++ b/example/src/Foo/Baz.purs @@ -0,0 +1,3 @@ +module Foo.Baz (baz) where + +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'); 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); diff --git a/index.js b/index.js index ff2936f..4a74d15 100644 --- 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); -- 2.41.0