diff options
author | eric thul <thul.eric@gmail.com> | 2016-05-30 21:43:29 -0400 |
---|---|---|
committer | eric thul <thul.eric@gmail.com> | 2016-06-04 00:14:03 -0400 |
commit | 2b2207bda69a8a948b7fb3aef583b183f7fca87f (patch) | |
tree | d8096c69a513124b4c173adee29a96d42c047a19 | |
parent | a9a26a84a97102474501f5463d529ae35399cb5a (diff) | |
download | purs-loader-2b2207bda69a8a948b7fb3aef583b183f7fca87f.tar.gz purs-loader-2b2207bda69a8a948b7fb3aef583b183f7fca87f.tar.zst purs-loader-2b2207bda69a8a948b7fb3aef583b183f7fca87f.zip |
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
-rw-r--r-- | README.md | 11 | ||||
-rw-r--r-- | package.json | 6 | ||||
-rw-r--r-- | src/index.js | 33 |
3 files changed, 24 insertions, 26 deletions
@@ -12,6 +12,8 @@ Install with [npm](https://npmjs.org/package/purs-loader). | |||
12 | 12 | ||
13 | ``` | 13 | ``` |
14 | npm install purs-loader --save-dev | 14 | npm install purs-loader --save-dev |
15 | |||
16 | npm install purs-loader@next --save-dev | ||
15 | ``` | 17 | ``` |
16 | 18 | ||
17 | ## Example | 19 | ## Example |
@@ -27,8 +29,7 @@ const webpackConfig = { | |||
27 | exclude: /node_modules/, | 29 | exclude: /node_modules/, |
28 | query: { | 30 | query: { |
29 | psc: 'psa', | 31 | psc: 'psa', |
30 | src: ['bower_components/purescript-*/src/**/*.purs', 'src/**/*.purs'], | 32 | src: ['bower_components/purescript-*/src/**/*.purs', 'src/**/*.purs'] |
31 | ffi: ['bower_components/purescript-*/src/**/*.js', 'src/**/*.js'], | ||
32 | } | 33 | } |
33 | } | 34 | } |
34 | // ... | 35 | // ... |
@@ -59,11 +60,7 @@ Default options: | |||
59 | src: [ | 60 | src: [ |
60 | path.join('src', '**', '*.purs'), | 61 | path.join('src', '**', '*.purs'), |
61 | path.join('bower_components', 'purescript-*', 'src', '**', '*.purs') | 62 | path.join('bower_components', 'purescript-*', 'src', '**', '*.purs') |
62 | ], | 63 | ] |
63 | ffi: [ | ||
64 | path.join('src', '**', '*.js'), | ||
65 | path.join('bower_components', 'purescript-*', 'src', '**', '*.js') | ||
66 | ], | ||
67 | } | 64 | } |
68 | ``` | 65 | ``` |
69 | 66 | ||
diff --git a/package.json b/package.json index d06cf53..5fc5a7f 100644 --- a/package.json +++ b/package.json | |||
@@ -1,6 +1,6 @@ | |||
1 | { | 1 | { |
2 | "name": "purs-loader", | 2 | "name": "purs-loader", |
3 | "version": "1.0.0", | 3 | "version": "2.0.0-rc.0", |
4 | "description": "A webpack loader for PureScript.", | 4 | "description": "A webpack loader for PureScript.", |
5 | "main": "index.js", | 5 | "main": "index.js", |
6 | "files": [ | 6 | "files": [ |
@@ -34,10 +34,6 @@ | |||
34 | "url": "https://github.com/ethul/purs-loader/issues" | 34 | "url": "https://github.com/ethul/purs-loader/issues" |
35 | }, | 35 | }, |
36 | "homepage": "https://github.com/ethul/purs-loader#readme", | 36 | "homepage": "https://github.com/ethul/purs-loader#readme", |
37 | "peerDependencies": { | ||
38 | "webpack": ">=1.0.0 <3.0.0", | ||
39 | "purescript": ">=0.8.0" | ||
40 | }, | ||
41 | "dependencies": { | 37 | "dependencies": { |
42 | "bluebird": "^3.3.5", | 38 | "bluebird": "^3.3.5", |
43 | "chalk": "^1.1.3", | 39 | "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') | |||
11 | const retryPromise = require('promise-retry') | 11 | const retryPromise = require('promise-retry') |
12 | const jsStringEscape = require('js-string-escape') | 12 | const jsStringEscape = require('js-string-escape') |
13 | 13 | ||
14 | const ffiModuleRegex = /\/\/\s+module\s+([\w\.]+)/i | ||
15 | const srcModuleRegex = /(?:^|\n)module\s+([\w\.]+)/i | 14 | const srcModuleRegex = /(?:^|\n)module\s+([\w\.]+)/i |
16 | const requireRegex = /require\(['"]\.\.\/([\w\.]+)['"]\)/g | 15 | const requireRegex = /require\(['"]\.\.\/([\w\.]+)['"]\)/g |
17 | 16 | ||
@@ -38,11 +37,7 @@ module.exports = function purescriptLoader(source, map) { | |||
38 | src: [ | 37 | src: [ |
39 | path.join('src', '**', '*.purs'), | 38 | path.join('src', '**', '*.purs'), |
40 | path.join('bower_components', 'purescript-*', 'src', '**', '*.purs') | 39 | path.join('bower_components', 'purescript-*', 'src', '**', '*.purs') |
41 | ], | 40 | ] |
42 | ffi: [ | ||
43 | path.join('src', '**', '*.js'), | ||
44 | path.join('bower_components', 'purescript-*', 'src', '**', '*.js') | ||
45 | ], | ||
46 | }, webpackOptions, query) | 41 | }, webpackOptions, query) |
47 | 42 | ||
48 | this.cacheable && this.cacheable() | 43 | this.cacheable && this.cacheable() |
@@ -173,7 +168,6 @@ function compile(psModule) { | |||
173 | 168 | ||
174 | const args = dargs(Object.assign({ | 169 | const args = dargs(Object.assign({ |
175 | _: options.src, | 170 | _: options.src, |
176 | ffi: options.ffi, | ||
177 | output: options.output, | 171 | output: options.output, |
178 | }, options.pscArgs)) | 172 | }, options.pscArgs)) |
179 | 173 | ||
@@ -374,26 +368,37 @@ function bundle(options, cache) { | |||
374 | function psModuleMap(options, cache) { | 368 | function psModuleMap(options, cache) { |
375 | if (cache.psModuleMap) return Promise.resolve(cache.psModuleMap) | 369 | if (cache.psModuleMap) return Promise.resolve(cache.psModuleMap) |
376 | 370 | ||
377 | const globs = [].concat(options.src).concat(options.ffi) | 371 | const globs = [].concat(options.src); |
372 | |||
373 | function pursToJs(file){ | ||
374 | const dirname = path.dirname(file) | ||
375 | const basename = path.basename(file, '.purs') | ||
376 | const fileJS = path.join(dirname, `${basename}.js`) | ||
377 | return fileJS | ||
378 | } | ||
378 | 379 | ||
379 | return globby(globs).then(paths => { | 380 | return globby(globs).then(paths => { |
380 | return Promise | 381 | return Promise |
381 | .props(paths.reduce((map, file) => { | 382 | .props(paths.reduce((map, file) => { |
383 | const fileJS = pursToJs(file) | ||
382 | map[file] = fs.readFileAsync(file, 'utf8') | 384 | map[file] = fs.readFileAsync(file, 'utf8') |
385 | map[fileJS] = fs.readFileAsync(fileJS, 'utf8').catch(() => undefined) | ||
383 | return map | 386 | return map |
384 | }, {})) | 387 | }, {})) |
385 | .then(fileMap => { | 388 | .then(fileMap => { |
386 | cache.psModuleMap = Object.keys(fileMap).reduce((map, file) => { | 389 | cache.psModuleMap = Object.keys(fileMap).reduce((map, file) => { |
387 | const source = fileMap[file] | ||
388 | const ext = path.extname(file) | 390 | const ext = path.extname(file) |
389 | const isPurs = ext.match(/purs$/i) | 391 | const isPurs = ext.match(/purs$/i) |
390 | const moduleRegex = isPurs ? srcModuleRegex : ffiModuleRegex | ||
391 | const moduleName = match(moduleRegex, source) | ||
392 | map[moduleName] = map[moduleName] || {} | ||
393 | if (isPurs) { | 392 | if (isPurs) { |
393 | const fileJs = pursToJs(file) | ||
394 | const source = fileMap[file] | ||
395 | const ffi = fileMap[fileJs] | ||
396 | const moduleName = match(srcModuleRegex, source) | ||
397 | map[moduleName] = map[moduleName] || {} | ||
394 | map[moduleName].src = path.resolve(file) | 398 | map[moduleName].src = path.resolve(file) |
395 | } else { | 399 | if (ffi) { |
396 | map[moduleName].ffi = path.resolve(file) | 400 | map[moduleName].ffi = path.resolve(fileJs) |
401 | } | ||
397 | } | 402 | } |
398 | return map | 403 | return map |
399 | }, {}) | 404 | }, {}) |