Skip to content

Commit

Permalink
Bumping version number to 2.0.0-rc.0
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ethul committed Jun 4, 2016
1 parent a9a26a8 commit 2b2207b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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']
}
}
// ...
Expand Down Expand Up @@ -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')
],
]
}
```

Expand Down
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down Expand Up @@ -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",
Expand Down
33 changes: 19 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand Down Expand Up @@ -173,7 +168,6 @@ function compile(psModule) {

const args = dargs(Object.assign({
_: options.src,
ffi: options.ffi,
output: options.output,
}, options.pscArgs))

Expand Down Expand Up @@ -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
}, {})
Expand Down

0 comments on commit 2b2207b

Please sign in to comment.