Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bumping version number to 2.0.0-rc.0 #55

Merged
merged 1 commit into from
Jun 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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