From 86e2b3d4854157bbb65987f2939f50275edaea71 Mon Sep 17 00:00:00 2001 From: Andrei Dziahel Date: Mon, 13 Feb 2017 00:12:35 +0300 Subject: [PATCH] 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 --- README.md | 12 +++++++++--- src/index.js | 31 +++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 292ab85..add7756 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Refer to the [purescript-webpack-example](https://github.com/ethul/purescript-we Default options: ```javascript -{ +const loaderConfig = { psc: 'psc', pscArgs: {}, pscBundle: 'psc-bundle', @@ -56,6 +56,7 @@ Default options: pscIdeArgs: {}, // for example, to use different psc-ide-server port: {port: 4088} pscIdeServerArgs: {}, // for example, to change the port { port: 4088 } pscIdeColors: false, // defaults to true if psc === 'psa' + pscPackage: false, bundleOutput: 'output/bundle.js', bundleNamespace: 'PS', bundle: false, @@ -63,7 +64,11 @@ Default options: output: 'output', src: [ path.join('src', '**', '*.purs'), + // if pscPackage = false path.join('bower_components', 'purescript-*', 'src', '**', '*.purs') + /* + * OR source paths reported by `psc-package sources`, if pscPackage = true + */ ] } ``` @@ -84,6 +89,7 @@ it might result in a slower initial webpack startup time (rebuilds are not affected). To override the default behaviour, add: `pscIdeServerArgs: { "_": ['your/*globs/here'] }` to the loader config +### `psc-package` support (experimental) - - +Set `pscPackage` query parameter to `true` to enable `psc-package` support. The `psc-package`-supplied source paths +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'); const Psc = require('./Psc'); const PscIde = require('./PscIde'); const dargs = require('./dargs'); +const spawn = require('cross-spawn').sync +const eol = require('os').EOL const requireRegex = /require\(['"]\.\.\/([\w\.]+)['"]\)/g @@ -19,15 +21,30 @@ module.exports = function purescriptLoader(source, map) { const query = loaderUtils.parseQuery(this.query) const webpackOptions = this.options.purescriptLoader || {} - const options = Object.assign({ + const depsPaths = (pscPackage => { + if (pscPackage) { + debug('calling psc-package...') + + return spawn('psc-package', ['sources']).stdout.toString().split(eol).filter(v => v != '') + } + else { + return [ path.join('bower_components', 'purescript-*', 'src', '**', '*.purs') ] + } + }) + + let options = Object.assign(webpackOptions, query) + + const defaultDeps = depsPaths(options.pscPackage) + const defaultOptions = { context: config.context, psc: 'psc', pscArgs: {}, pscBundle: 'psc-bundle', pscBundleArgs: {}, pscIde: false, - pscIdeColors: webpackOptions.psc === 'psa' || query.psc === 'psa', + pscIdeColors: options.psc === 'psa', pscIdeArgs: {}, + pscPackage: false, bundleOutput: 'output/bundle.js', bundleNamespace: 'PS', bundle: false, @@ -35,9 +52,9 @@ module.exports = function purescriptLoader(source, map) { output: 'output', src: [ path.join('src', '**', '*.purs'), - path.join('bower_components', 'purescript-*', 'src', '**', '*.purs') + ...defaultDeps ] - }, webpackOptions, query) + } this.cacheable && this.cacheable() @@ -49,6 +66,12 @@ module.exports = function purescriptLoader(source, map) { errors: [] } + if (options.pscPackage && options.src) { + options.src = options.src.concat(defaultDeps) // append psc-package-provided source paths with users' + } + + options = Object.assign(defaultOptions, options) + if (!config.purescriptLoaderInstalled) { config.purescriptLoaderInstalled = true -- 2.41.0