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 /index.js | |
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.
Diffstat (limited to 'index.js')
-rw-r--r-- | index.js | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -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); |