aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorDaniel Harvey <daniel.harvey@habito.com>2019-12-17 01:11:06 +0000
committereric <thul.eric@gmail.com>2019-12-16 20:11:06 -0500
commit1029c0322c943313bcdd28145d518fbc83f661c7 (patch)
tree2187a581429899a3671c428283c00c92bc44f8ee /src
parent410f1bd1cd69edb70b286e864c83347b444ff380 (diff)
downloadpurs-loader-1029c0322c943313bcdd28145d518fbc83f661c7.tar.gz
purs-loader-1029c0322c943313bcdd28145d518fbc83f661c7.tar.zst
purs-loader-1029c0322c943313bcdd28145d518fbc83f661c7.zip
Use 'spago path output' to choose default output path (#132)
* Use 'spago path output' * Remove eol from path
Diffstat (limited to 'src')
-rw-r--r--src/index.js37
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
78function 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
76module.exports = function purescriptLoader(source, map) { 107module.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