aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorDaniel Harvey <danieljamesharvey@gmail.com>2019-06-02 13:31:30 +0100
committereric <thul.eric@gmail.com>2019-06-02 08:31:30 -0400
commitbef7f4e2a86551735cdf24d661b20b1ed83cc276 (patch)
tree5c7747c88c3b411e4f0aa21441317a5a2b4d1548 /src
parentbf7d67bb123db582285fe0c7930dda56737b5701 (diff)
downloadpurs-loader-bef7f4e2a86551735cdf24d661b20b1ed83cc276.tar.gz
purs-loader-bef7f4e2a86551735cdf24d661b20b1ed83cc276.tar.zst
purs-loader-bef7f4e2a86551735cdf24d661b20b1ed83cc276.zip
Add option to include Spago sources (#126)
Diffstat (limited to 'src')
-rw-r--r--src/index.js69
1 files changed, 38 insertions, 31 deletions
diff --git a/src/index.js b/src/index.js
index 0c620bf..a6ddc35 100644
--- a/src/index.js
+++ b/src/index.js
@@ -42,6 +42,37 @@ var CACHE_VAR = {
42 srcOption: [] 42 srcOption: []
43}; 43};
44 44
45// include src files provided by psc-package or Spago
46function requestDependencySources(packagerCommand, srcPath, loaderOptions) {
47 const packagerArgs = ['sources'];
48
49 const loaderSrc = loaderOptions.src || [
50 srcPath
51 ];
52
53 debug('%s %o', packagerCommand, packagerArgs);
54
55 const cmd = spawn(packagerCommand, packagerArgs);
56
57 if (cmd.error) {
58 throw new Error(cmd.error);
59 }
60 else if (cmd.status !== 0) {
61 const error = cmd.stdout.toString();
62
63 throw new Error(error);
64 }
65 else {
66 const result = cmd.stdout.toString().split(eol).filter(v => v != '').concat(loaderSrc);
67
68 debug('%s result: %o', packagerCommand, result);
69
70 CACHE_VAR.srcOption = result;
71
72 return result;
73 }
74}
75
45module.exports = function purescriptLoader(source, map) { 76module.exports = function purescriptLoader(source, map) {
46 this.cacheable && this.cacheable(); 77 this.cacheable && this.cacheable();
47 78
@@ -51,7 +82,7 @@ module.exports = function purescriptLoader(source, map) {
51 82
52 const loaderOptions = loaderUtils.getOptions(this) || {}; 83 const loaderOptions = loaderUtils.getOptions(this) || {};
53 84
54 const srcOption = (pscPackage => { 85 const srcOption = ((pscPackage, spago) => {
55 const srcPath = path.join('src', '**', '*.purs'); 86 const srcPath = path.join('src', '**', '*.purs');
56 87
57 const bowerPath = path.join('bower_components', 'purescript-*', 'src', '**', '*.purs'); 88 const bowerPath = path.join('bower_components', 'purescript-*', 'src', '**', '*.purs');
@@ -60,36 +91,11 @@ module.exports = function purescriptLoader(source, map) {
60 return CACHE_VAR.srcOption; 91 return CACHE_VAR.srcOption;
61 } 92 }
62 else if (pscPackage) { 93 else if (pscPackage) {
63 const pscPackageCommand = 'psc-package'; 94 return requestDependencySources('psc-package', srcPath, loaderOptions)
64
65 const pscPackageArgs = ['sources'];
66
67 const loaderSrc = loaderOptions.src || [
68 srcPath
69 ];
70
71 debug('psc-package %s %o', pscPackageCommand, pscPackageArgs);
72
73 const cmd = spawn(pscPackageCommand, pscPackageArgs);
74
75 if (cmd.error) {
76 throw new Error(cmd.error);
77 }
78 else if (cmd.status !== 0) {
79 const error = cmd.stdout.toString();
80
81 throw new Error(error);
82 }
83 else {
84 const result = cmd.stdout.toString().split(eol).filter(v => v != '').concat(loaderSrc);
85
86 debug('psc-package result: %o', result);
87
88 CACHE_VAR.srcOption = result;
89
90 return result;
91 }
92 } 95 }
96 else if (spago) {
97 return requestDependencySources('spago', srcPath, loaderOptions)
98 }
93 else { 99 else {
94 const result = loaderOptions.src || [ 100 const result = loaderOptions.src || [
95 bowerPath, 101 bowerPath,
@@ -100,7 +106,7 @@ module.exports = function purescriptLoader(source, map) {
100 106
101 return result; 107 return result;
102 } 108 }
103 })(loaderOptions.pscPackage); 109 })(loaderOptions.pscPackage, loaderOptions.spago);
104 110
105 const options = Object.assign({ 111 const options = Object.assign({
106 context: webpackContext, 112 context: webpackContext,
@@ -116,6 +122,7 @@ module.exports = function purescriptLoader(source, map) {
116 pscIde: false, 122 pscIde: false,
117 pscIdeColors: loaderOptions.psc === 'psa', 123 pscIdeColors: loaderOptions.psc === 'psa',
118 pscPackage: false, 124 pscPackage: false,
125 spago: false,
119 bundleOutput: 'output/bundle.js', 126 bundleOutput: 'output/bundle.js',
120 bundleNamespace: 'PS', 127 bundleNamespace: 'PS',
121 bundle: false, 128 bundle: false,