From 2b2207bda69a8a948b7fb3aef583b183f7fca87f Mon Sep 17 00:00:00 2001 From: eric thul Date: Mon, 30 May 2016 21:43:29 -0400 Subject: Bumping version number to 2.0.0-rc.0 Adds support for PureScript 0.9.1 and newer (purescript/purescript#2151) The `next` tag on NPM points to this pre-release. Also note that `peerDependencies` has been removed (npm/npm#8854). Resolves #54 --- README.md | 11 ++++------- package.json | 6 +----- src/index.js | 33 +++++++++++++++++++-------------- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 9e887dc..ab4d9cd 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,8 @@ Install with [npm](https://npmjs.org/package/purs-loader). ``` npm install purs-loader --save-dev + +npm install purs-loader@next --save-dev ``` ## Example @@ -27,8 +29,7 @@ const webpackConfig = { exclude: /node_modules/, query: { psc: 'psa', - src: ['bower_components/purescript-*/src/**/*.purs', 'src/**/*.purs'], - ffi: ['bower_components/purescript-*/src/**/*.js', 'src/**/*.js'], + src: ['bower_components/purescript-*/src/**/*.purs', 'src/**/*.purs'] } } // ... @@ -59,11 +60,7 @@ Default options: src: [ path.join('src', '**', '*.purs'), path.join('bower_components', 'purescript-*', 'src', '**', '*.purs') - ], - ffi: [ - path.join('src', '**', '*.js'), - path.join('bower_components', 'purescript-*', 'src', '**', '*.js') - ], + ] } ``` diff --git a/package.json b/package.json index d06cf53..5fc5a7f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "purs-loader", - "version": "1.0.0", + "version": "2.0.0-rc.0", "description": "A webpack loader for PureScript.", "main": "index.js", "files": [ @@ -34,10 +34,6 @@ "url": "https://github.com/ethul/purs-loader/issues" }, "homepage": "https://github.com/ethul/purs-loader#readme", - "peerDependencies": { - "webpack": ">=1.0.0 <3.0.0", - "purescript": ">=0.8.0" - }, "dependencies": { "bluebird": "^3.3.5", "chalk": "^1.1.3", diff --git a/src/index.js b/src/index.js index cd85c89..cfba1e2 100644 --- a/src/index.js +++ b/src/index.js @@ -11,7 +11,6 @@ const path = require('path') const retryPromise = require('promise-retry') const jsStringEscape = require('js-string-escape') -const ffiModuleRegex = /\/\/\s+module\s+([\w\.]+)/i const srcModuleRegex = /(?:^|\n)module\s+([\w\.]+)/i const requireRegex = /require\(['"]\.\.\/([\w\.]+)['"]\)/g @@ -38,11 +37,7 @@ module.exports = function purescriptLoader(source, map) { src: [ path.join('src', '**', '*.purs'), path.join('bower_components', 'purescript-*', 'src', '**', '*.purs') - ], - ffi: [ - path.join('src', '**', '*.js'), - path.join('bower_components', 'purescript-*', 'src', '**', '*.js') - ], + ] }, webpackOptions, query) this.cacheable && this.cacheable() @@ -173,7 +168,6 @@ function compile(psModule) { const args = dargs(Object.assign({ _: options.src, - ffi: options.ffi, output: options.output, }, options.pscArgs)) @@ -374,26 +368,37 @@ function bundle(options, cache) { function psModuleMap(options, cache) { if (cache.psModuleMap) return Promise.resolve(cache.psModuleMap) - const globs = [].concat(options.src).concat(options.ffi) + const globs = [].concat(options.src); + + function pursToJs(file){ + const dirname = path.dirname(file) + const basename = path.basename(file, '.purs') + const fileJS = path.join(dirname, `${basename}.js`) + return fileJS + } return globby(globs).then(paths => { return Promise .props(paths.reduce((map, file) => { + const fileJS = pursToJs(file) map[file] = fs.readFileAsync(file, 'utf8') + map[fileJS] = fs.readFileAsync(fileJS, 'utf8').catch(() => undefined) return map }, {})) .then(fileMap => { cache.psModuleMap = Object.keys(fileMap).reduce((map, file) => { - const source = fileMap[file] const ext = path.extname(file) const isPurs = ext.match(/purs$/i) - const moduleRegex = isPurs ? srcModuleRegex : ffiModuleRegex - const moduleName = match(moduleRegex, source) - map[moduleName] = map[moduleName] || {} if (isPurs) { + const fileJs = pursToJs(file) + const source = fileMap[file] + const ffi = fileMap[fileJs] + const moduleName = match(srcModuleRegex, source) + map[moduleName] = map[moduleName] || {} map[moduleName].src = path.resolve(file) - } else { - map[moduleName].ffi = path.resolve(file) + if (ffi) { + map[moduleName].ffi = path.resolve(fileJs) + } } return map }, {}) -- cgit v1.2.3