aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--README.md14
-rw-r--r--src/index.js69
2 files changed, 49 insertions, 34 deletions
diff --git a/README.md b/README.md
index cc4373e..28c2783 100644
--- a/README.md
+++ b/README.md
@@ -62,7 +62,8 @@ const loaderConfig = {
62 pscIdeServerArgs: {}, // for example, to change the port {port: 4088} 62 pscIdeServerArgs: {}, // for example, to change the port {port: 4088}
63 pscIdeRebuildArgs: {} // for example, for sourcemaps {codegen: ['js', 'sourcemaps']} 63 pscIdeRebuildArgs: {} // for example, for sourcemaps {codegen: ['js', 'sourcemaps']}
64 pscIdeColors: false, // defaults to true if psc === 'psa' 64 pscIdeColors: false, // defaults to true if psc === 'psa'
65 pscPackage: false, 65 pscPackage: false, // include dependencies from psc-package
66 spago: false, // include dependencies from spago
66 bundleOutput: 'output/bundle.js', 67 bundleOutput: 'output/bundle.js',
67 bundleNamespace: 'PS', 68 bundleNamespace: 'PS',
68 bundle: false, 69 bundle: false,
@@ -71,10 +72,12 @@ const loaderConfig = {
71 output: 'output', 72 output: 'output',
72 src: [ 73 src: [
73 path.join('src', '**', '*.purs'), 74 path.join('src', '**', '*.purs'),
74 // if pscPackage = false
75 path.join('bower_components', 'purescript-*', 'src', '**', '*.purs')
76 // if pscPackage = true 75 // if pscPackage = true
77 // source paths reported by `psc-package sources` 76 // source paths reported by `psc-package sources`
77 // if spago = true
78 // source paths reported by `spago sources`
79 // if pscPackage = false and spago = false
80 path.join('bower_components', 'purescript-*', 'src', '**', '*.purs')
78 ] 81 ]
79} 82}
80``` 83```
@@ -91,6 +94,11 @@ if there is no server running this loader will start one for you.
91Set `pscPackage` query parameter to `true` to enable `psc-package` support. The `psc-package`-supplied source paths 94Set `pscPackage` query parameter to `true` to enable `psc-package` support. The `psc-package`-supplied source paths
92will be appended to `src` parameter. 95will be appended to `src` parameter.
93 96
97### `spago` support (experimental)
98
99Set `spago` query parameter to `true` to enable `spago` support. The `spago`-supplied source paths
100will be appended to `src` parameter.
101
94### Troubleshooting 102### Troubleshooting
95 103
96#### Slower webpack startup after enabling psc-ide support? 104#### Slower webpack startup after enabling psc-ide support?
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,