diff options
author | eric thul <thul.eric@gmail.com> | 2017-04-22 10:52:54 -0400 |
---|---|---|
committer | eric <thul.eric@gmail.com> | 2017-04-23 18:20:22 -0400 |
commit | 1c12889c0adf91cf3116a9d5ff44b7466b1dfcc9 (patch) | |
tree | 1f3ac400c629bc040a8c54478363956e37a585b4 /src/index.js | |
parent | e1bf1f98de548fb2cbaca1a2b6c1d4cb3e173848 (diff) | |
download | purs-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.js | 48 |
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 | ||
3 | const debug = require('debug')('purs-loader') | 3 | const debug = require('debug')('purs-loader') |
4 | |||
4 | const loaderUtils = require('loader-utils') | 5 | const loaderUtils = require('loader-utils') |
6 | |||
5 | const Promise = require('bluebird') | 7 | const Promise = require('bluebird') |
8 | |||
6 | const path = require('path') | 9 | const path = require('path') |
7 | const PsModuleMap = require('./PsModuleMap'); | 10 | |
8 | const Psc = require('./Psc'); | 11 | const PsModuleMap = require('./purs-module-map'); |
9 | const PscIde = require('./PscIde'); | 12 | |
13 | const compile = require('./compile'); | ||
14 | |||
15 | const bundle = require('./bundle'); | ||
16 | |||
17 | const ide = require('./ide'); | ||
18 | |||
10 | const toJavaScript = require('./to-javascript'); | 19 | const toJavaScript = require('./to-javascript'); |
20 | |||
11 | const dargs = require('./dargs'); | 21 | const dargs = require('./dargs'); |
22 | |||
12 | const spawn = require('cross-spawn').sync | 23 | const spawn = require('cross-spawn').sync |
24 | |||
13 | const eol = require('os').EOL | 25 | const eol = require('os').EOL |
14 | 26 | ||
15 | module.exports = function purescriptLoader(source, map) { | 27 | module.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) |