diff options
author | Andrei Dziahel <develop7@develop7.info> | 2017-02-13 00:12:35 +0300 |
---|---|---|
committer | eric <thul.eric@gmail.com> | 2017-02-12 16:12:35 -0500 |
commit | 86e2b3d4854157bbb65987f2939f50275edaea71 (patch) | |
tree | 08e6be9cedb3182064f2e13390d579f603cd69d4 | |
parent | 6d936842888ca5a5ff1efe2acfb502ac26b51004 (diff) | |
download | purs-loader-86e2b3d4854157bbb65987f2939f50275edaea71.tar.gz purs-loader-86e2b3d4854157bbb65987f2939f50275edaea71.tar.zst purs-loader-86e2b3d4854157bbb65987f2939f50275edaea71.zip |
initial psc-package support (#82)
* Extract deps path
* Initial psc-package support
* index.js: `pscPackage` and `src` incompatibility warning
* index.js: make use of user-provided options
* index.js: make use of user-provided options: now for pscIdeColors
* index.js: remember depsPaths call result
* index.js: implemented appending user src paths with psc-packages'
* README.md: sync changes of pscPackage behavior
Also reflect pscPackage support in "Default options" section
-rw-r--r-- | README.md | 12 | ||||
-rw-r--r-- | src/index.js | 31 |
2 files changed, 36 insertions, 7 deletions
@@ -47,7 +47,7 @@ Refer to the [purescript-webpack-example](https://github.com/ethul/purescript-we | |||
47 | Default options: | 47 | Default options: |
48 | 48 | ||
49 | ```javascript | 49 | ```javascript |
50 | { | 50 | const loaderConfig = { |
51 | psc: 'psc', | 51 | psc: 'psc', |
52 | pscArgs: {}, | 52 | pscArgs: {}, |
53 | pscBundle: 'psc-bundle', | 53 | pscBundle: 'psc-bundle', |
@@ -56,6 +56,7 @@ Default options: | |||
56 | pscIdeArgs: {}, // for example, to use different psc-ide-server port: {port: 4088} | 56 | pscIdeArgs: {}, // for example, to use different psc-ide-server port: {port: 4088} |
57 | pscIdeServerArgs: {}, // for example, to change the port { port: 4088 } | 57 | pscIdeServerArgs: {}, // for example, to change the port { port: 4088 } |
58 | pscIdeColors: false, // defaults to true if psc === 'psa' | 58 | pscIdeColors: false, // defaults to true if psc === 'psa' |
59 | pscPackage: false, | ||
59 | bundleOutput: 'output/bundle.js', | 60 | bundleOutput: 'output/bundle.js', |
60 | bundleNamespace: 'PS', | 61 | bundleNamespace: 'PS', |
61 | bundle: false, | 62 | bundle: false, |
@@ -63,7 +64,11 @@ Default options: | |||
63 | output: 'output', | 64 | output: 'output', |
64 | src: [ | 65 | src: [ |
65 | path.join('src', '**', '*.purs'), | 66 | path.join('src', '**', '*.purs'), |
67 | // if pscPackage = false | ||
66 | path.join('bower_components', 'purescript-*', 'src', '**', '*.purs') | 68 | path.join('bower_components', 'purescript-*', 'src', '**', '*.purs') |
69 | /* | ||
70 | * OR source paths reported by `psc-package sources`, if pscPackage = true | ||
71 | */ | ||
67 | ] | 72 | ] |
68 | } | 73 | } |
69 | ``` | 74 | ``` |
@@ -84,6 +89,7 @@ it might result in a slower initial webpack startup time (rebuilds are not | |||
84 | affected). To override the default behaviour, add: | 89 | affected). To override the default behaviour, add: |
85 | `pscIdeServerArgs: { "_": ['your/*globs/here'] }` to the loader config | 90 | `pscIdeServerArgs: { "_": ['your/*globs/here'] }` to the loader config |
86 | 91 | ||
92 | ### `psc-package` support (experimental) | ||
87 | 93 | ||
88 | 94 | Set `pscPackage` query parameter to `true` to enable `psc-package` support. The `psc-package`-supplied source paths | |
89 | 95 | will be appended to `src` parameter. | |
diff --git a/src/index.js b/src/index.js index f3390dc..249f472 100644 --- a/src/index.js +++ b/src/index.js | |||
@@ -10,6 +10,8 @@ const PsModuleMap = require('./PsModuleMap'); | |||
10 | const Psc = require('./Psc'); | 10 | const Psc = require('./Psc'); |
11 | const PscIde = require('./PscIde'); | 11 | const PscIde = require('./PscIde'); |
12 | const dargs = require('./dargs'); | 12 | const dargs = require('./dargs'); |
13 | const spawn = require('cross-spawn').sync | ||
14 | const eol = require('os').EOL | ||
13 | 15 | ||
14 | const requireRegex = /require\(['"]\.\.\/([\w\.]+)['"]\)/g | 16 | const requireRegex = /require\(['"]\.\.\/([\w\.]+)['"]\)/g |
15 | 17 | ||
@@ -19,15 +21,30 @@ module.exports = function purescriptLoader(source, map) { | |||
19 | const query = loaderUtils.parseQuery(this.query) | 21 | const query = loaderUtils.parseQuery(this.query) |
20 | const webpackOptions = this.options.purescriptLoader || {} | 22 | const webpackOptions = this.options.purescriptLoader || {} |
21 | 23 | ||
22 | const options = Object.assign({ | 24 | const depsPaths = (pscPackage => { |
25 | if (pscPackage) { | ||
26 | debug('calling psc-package...') | ||
27 | |||
28 | return spawn('psc-package', ['sources']).stdout.toString().split(eol).filter(v => v != '') | ||
29 | } | ||
30 | else { | ||
31 | return [ path.join('bower_components', 'purescript-*', 'src', '**', '*.purs') ] | ||
32 | } | ||
33 | }) | ||
34 | |||
35 | let options = Object.assign(webpackOptions, query) | ||
36 | |||
37 | const defaultDeps = depsPaths(options.pscPackage) | ||
38 | const defaultOptions = { | ||
23 | context: config.context, | 39 | context: config.context, |
24 | psc: 'psc', | 40 | psc: 'psc', |
25 | pscArgs: {}, | 41 | pscArgs: {}, |
26 | pscBundle: 'psc-bundle', | 42 | pscBundle: 'psc-bundle', |
27 | pscBundleArgs: {}, | 43 | pscBundleArgs: {}, |
28 | pscIde: false, | 44 | pscIde: false, |
29 | pscIdeColors: webpackOptions.psc === 'psa' || query.psc === 'psa', | 45 | pscIdeColors: options.psc === 'psa', |
30 | pscIdeArgs: {}, | 46 | pscIdeArgs: {}, |
47 | pscPackage: false, | ||
31 | bundleOutput: 'output/bundle.js', | 48 | bundleOutput: 'output/bundle.js', |
32 | bundleNamespace: 'PS', | 49 | bundleNamespace: 'PS', |
33 | bundle: false, | 50 | bundle: false, |
@@ -35,9 +52,9 @@ module.exports = function purescriptLoader(source, map) { | |||
35 | output: 'output', | 52 | output: 'output', |
36 | src: [ | 53 | src: [ |
37 | path.join('src', '**', '*.purs'), | 54 | path.join('src', '**', '*.purs'), |
38 | path.join('bower_components', 'purescript-*', 'src', '**', '*.purs') | 55 | ...defaultDeps |
39 | ] | 56 | ] |
40 | }, webpackOptions, query) | 57 | } |
41 | 58 | ||
42 | this.cacheable && this.cacheable() | 59 | this.cacheable && this.cacheable() |
43 | 60 | ||
@@ -49,6 +66,12 @@ module.exports = function purescriptLoader(source, map) { | |||
49 | errors: [] | 66 | errors: [] |
50 | } | 67 | } |
51 | 68 | ||
69 | if (options.pscPackage && options.src) { | ||
70 | options.src = options.src.concat(defaultDeps) // append psc-package-provided source paths with users' | ||
71 | } | ||
72 | |||
73 | options = Object.assign(defaultOptions, options) | ||
74 | |||
52 | if (!config.purescriptLoaderInstalled) { | 75 | if (!config.purescriptLoaderInstalled) { |
53 | config.purescriptLoaderInstalled = true | 76 | config.purescriptLoaderInstalled = true |
54 | 77 | ||