aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/index.js
diff options
context:
space:
mode:
authoreric thul <thul.eric@gmail.com>2017-04-22 10:52:54 -0400
committereric <thul.eric@gmail.com>2017-04-23 18:20:22 -0400
commit1c12889c0adf91cf3116a9d5ff44b7466b1dfcc9 (patch)
tree1f3ac400c629bc040a8c54478363956e37a585b4 /src/index.js
parente1bf1f98de548fb2cbaca1a2b6c1d4cb3e173848 (diff)
downloadpurs-loader-1c12889c0adf91cf3116a9d5ff44b7466b1dfcc9.tar.gz
purs-loader-1c12889c0adf91cf3116a9d5ff44b7466b1dfcc9.tar.zst
purs-loader-1c12889c0adf91cf3116a9d5ff44b7466b1dfcc9.zip
Support for PureScript 0.11
Resolves #89
Diffstat (limited to 'src/index.js')
-rw-r--r--src/index.js48
1 files changed, 35 insertions, 13 deletions
diff --git a/src/index.js b/src/index.js
index 047927c..799f8f9 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,15 +1,27 @@
1'use strict' 1'use strict'
2 2
3const debug = require('debug')('purs-loader') 3const debug = require('debug')('purs-loader')
4
4const loaderUtils = require('loader-utils') 5const loaderUtils = require('loader-utils')
6
5const Promise = require('bluebird') 7const Promise = require('bluebird')
8
6const path = require('path') 9const path = require('path')
7const PsModuleMap = require('./PsModuleMap'); 10
8const Psc = require('./Psc'); 11const PsModuleMap = require('./purs-module-map');
9const PscIde = require('./PscIde'); 12
13const compile = require('./compile');
14
15const bundle = require('./bundle');
16
17const ide = require('./ide');
18
10const toJavaScript = require('./to-javascript'); 19const toJavaScript = require('./to-javascript');
20
11const dargs = require('./dargs'); 21const dargs = require('./dargs');
22
12const spawn = require('cross-spawn').sync 23const spawn = require('cross-spawn').sync
24
13const eol = require('os').EOL 25const eol = require('os').EOL
14 26
15module.exports = function purescriptLoader(source, map) { 27module.exports = function purescriptLoader(source, map) {
@@ -34,9 +46,9 @@ module.exports = function purescriptLoader(source, map) {
34 const defaultDeps = depsPaths(options.pscPackage) 46 const defaultDeps = depsPaths(options.pscPackage)
35 const defaultOptions = { 47 const defaultOptions = {
36 context: config.context, 48 context: config.context,
37 psc: 'psc', 49 psc: null,
38 pscArgs: {}, 50 pscArgs: {},
39 pscBundle: 'psc-bundle', 51 pscBundle: null,
40 pscBundleArgs: {}, 52 pscBundleArgs: {},
41 pscIde: false, 53 pscIde: false,
42 pscIdeColors: options.psc === 'psa', 54 pscIdeColors: options.psc === 'psa',
@@ -102,7 +114,7 @@ module.exports = function purescriptLoader(source, map) {
102 }); 114 });
103 } 115 }
104 116
105 const psModuleName = PsModuleMap.match(source) 117 const psModuleName = PsModuleMap.matchModule(source)
106 const psModule = { 118 const psModule = {
107 name: psModuleName, 119 name: psModuleName,
108 load: js => callback(null, js), 120 load: js => callback(null, js),
@@ -131,8 +143,8 @@ module.exports = function purescriptLoader(source, map) {
131 } 143 }
132 144
133 if (cache.rebuild) { 145 if (cache.rebuild) {
134 return PscIde.connect(psModule) 146 return ide.connect(psModule)
135 .then(PscIde.rebuild) 147 .then(ide.rebuild)
136 .then(toJavaScript) 148 .then(toJavaScript)
137 .then(psModule.load) 149 .then(psModule.load)
138 .catch(psModule.reject) 150 .catch(psModule.reject)
@@ -147,11 +159,21 @@ module.exports = function purescriptLoader(source, map) {
147 cache.deferred.push(psModule) 159 cache.deferred.push(psModule)
148 160
149 if (!cache.compilationStarted) { 161 if (!cache.compilationStarted) {
150 return Psc.compile(psModule) 162 cache.compilationStarted = true;
151 .then(() => PsModuleMap.makeMap(options.src).then(map => { 163
152 debug('rebuilt module map after compile'); 164 return compile(psModule)
153 cache.psModuleMap = map; 165 .then(() => {
154 })) 166 cache.compilationFinished = true;
167
168 const bundlePromise = options.bundle ? bundle(options, cache) : Promise.resolve();
169
170 return bundlePromise.then(() =>
171 PsModuleMap.makeMap(options.src).then(map => {
172 debug('rebuilt module map after compile');
173 cache.psModuleMap = map;
174 })
175 );
176 })
155 .then(() => Promise.map(cache.deferred, psModule => { 177 .then(() => Promise.map(cache.deferred, psModule => {
156 if (typeof cache.ideServer === 'object') cache.ideServer.kill() 178 if (typeof cache.ideServer === 'object') cache.ideServer.kill()
157 return toJavaScript(psModule).then(psModule.load) 179 return toJavaScript(psModule).then(psModule.load)