diff options
-rw-r--r-- | src/index.js | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/src/index.js b/src/index.js index a6ddc35..ff13302 100644 --- a/src/index.js +++ b/src/index.js | |||
@@ -39,7 +39,8 @@ var CACHE_VAR = { | |||
39 | compilationStarted: false, | 39 | compilationStarted: false, |
40 | compilationFinished: false, | 40 | compilationFinished: false, |
41 | installed: false, | 41 | installed: false, |
42 | srcOption: [] | 42 | srcOption: [], |
43 | spagoOutputPath: null | ||
43 | }; | 44 | }; |
44 | 45 | ||
45 | // include src files provided by psc-package or Spago | 46 | // include src files provided by psc-package or Spago |
@@ -73,6 +74,36 @@ function requestDependencySources(packagerCommand, srcPath, loaderOptions) { | |||
73 | } | 74 | } |
74 | } | 75 | } |
75 | 76 | ||
77 | // 'spago output path' will return the output folder in a monorepo | ||
78 | function getSpagoSources() { | ||
79 | const cachedVal = CACHE_VAR.spagoOutputPath; | ||
80 | if (cachedVal) { | ||
81 | return cachedVal | ||
82 | } | ||
83 | const command = "spago" | ||
84 | const args = ["path", "output"] | ||
85 | |||
86 | const cmd = spawn(command, args); | ||
87 | |||
88 | if (cmd.error) { | ||
89 | throw new Error(cmd.error); | ||
90 | } | ||
91 | else if (cmd.status !== 0) { | ||
92 | const error = cmd.stdout.toString(); | ||
93 | |||
94 | throw new Error(error); | ||
95 | } | ||
96 | else { | ||
97 | const result = cmd.stdout.toString().split(eol)[0] | ||
98 | |||
99 | debug('"spago path output" result: %o', result); | ||
100 | |||
101 | CACHE_VAR.spagoOutputPath = result; | ||
102 | |||
103 | return result; | ||
104 | } | ||
105 | } | ||
106 | |||
76 | module.exports = function purescriptLoader(source, map) { | 107 | module.exports = function purescriptLoader(source, map) { |
77 | this.cacheable && this.cacheable(); | 108 | this.cacheable && this.cacheable(); |
78 | 109 | ||
@@ -107,6 +138,8 @@ module.exports = function purescriptLoader(source, map) { | |||
107 | return result; | 138 | return result; |
108 | } | 139 | } |
109 | })(loaderOptions.pscPackage, loaderOptions.spago); | 140 | })(loaderOptions.pscPackage, loaderOptions.spago); |
141 | |||
142 | const outputPath = loaderOptions.spago ? getSpagoSources() : 'output' | ||
110 | 143 | ||
111 | const options = Object.assign({ | 144 | const options = Object.assign({ |
112 | context: webpackContext, | 145 | context: webpackContext, |
@@ -128,7 +161,7 @@ module.exports = function purescriptLoader(source, map) { | |||
128 | bundle: false, | 161 | bundle: false, |
129 | warnings: true, | 162 | warnings: true, |
130 | watch: false, | 163 | watch: false, |
131 | output: 'output', | 164 | output: outputPath, |
132 | src: [] | 165 | src: [] |
133 | }, loaderOptions, { | 166 | }, loaderOptions, { |
134 | src: srcOption | 167 | src: srcOption |