From 1029c0322c943313bcdd28145d518fbc83f661c7 Mon Sep 17 00:00:00 2001 From: Daniel Harvey Date: Tue, 17 Dec 2019 01:11:06 +0000 Subject: Use 'spago path output' to choose default output path (#132) * Use 'spago path output' * Remove eol from path --- src/index.js | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'src') 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 = { compilationStarted: false, compilationFinished: false, installed: false, - srcOption: [] + srcOption: [], + spagoOutputPath: null }; // include src files provided by psc-package or Spago @@ -73,6 +74,36 @@ function requestDependencySources(packagerCommand, srcPath, loaderOptions) { } } +// 'spago output path' will return the output folder in a monorepo +function getSpagoSources() { + const cachedVal = CACHE_VAR.spagoOutputPath; + if (cachedVal) { + return cachedVal + } + const command = "spago" + const args = ["path", "output"] + + const cmd = spawn(command, args); + + if (cmd.error) { + throw new Error(cmd.error); + } + else if (cmd.status !== 0) { + const error = cmd.stdout.toString(); + + throw new Error(error); + } + else { + const result = cmd.stdout.toString().split(eol)[0] + + debug('"spago path output" result: %o', result); + + CACHE_VAR.spagoOutputPath = result; + + return result; + } +} + module.exports = function purescriptLoader(source, map) { this.cacheable && this.cacheable(); @@ -107,6 +138,8 @@ module.exports = function purescriptLoader(source, map) { return result; } })(loaderOptions.pscPackage, loaderOptions.spago); + + const outputPath = loaderOptions.spago ? getSpagoSources() : 'output' const options = Object.assign({ context: webpackContext, @@ -128,7 +161,7 @@ module.exports = function purescriptLoader(source, map) { bundle: false, warnings: true, watch: false, - output: 'output', + output: outputPath, src: [] }, loaderOptions, { src: srcOption -- cgit v1.2.3