diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/index.js | 69 |
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 | ||
46 | function 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 | |||
45 | module.exports = function purescriptLoader(source, map) { | 76 | module.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, |