Skip to content

Commit e801d5f

Browse files
committed
Merge branch 'release/0.2.0'
2 parents 6b85561 + ea9ee07 commit e801d5f

11 files changed

+191
-27
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/node_modules/*

.eslintrc

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"rules": {
3+
"indent": [2, 2],
4+
"quotes": [2, "single"],
5+
"linebreak-style": [2, "unix"],
6+
"new-cap": 0,
7+
"semi": [2, "always"]
8+
},
9+
"env": {
10+
"es6": true,
11+
"browser": false
12+
},
13+
"extends": "airbnb",
14+
"ecmaFeatures": {
15+
"experimentalObjectRestSpread": true
16+
}
17+
}

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
*~
2-
node_modules
2+
node_modules
3+
.DS_Store
4+
*.log
5+
lib

.npmignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.log
2+
/.*/
3+
/.eslint*
4+
/.gitignore
5+
/.npmignore
6+
/.travis.yml

.travis.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- "4"
5+
- "5"
6+
script:
7+
- npm run lint
8+
- npm run build

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Change Log
2+
3+
This project adheres to [Semantic Versioning](http://semver.org/).
4+
Every release, along with the migration instructions, if any, is documented on the Github [Releases](https://github.com/eploko/pegjs-loader/releases) page.

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014–2015 Andrey Subbotin
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+73-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,76 @@
1-
# PEG.js loader for webpack
1+
# [PEG.js](https://github.com/pegjs/pegjs) loader for [webpack](http://webpack.github.io/)
22

3-
## Usage:
3+
[![build status](https://img.shields.io/travis/eploko/pegjs-loader/master.svg?style=flat-square)](https://travis-ci.org/eploko/pegjs-loader)
4+
[![npm version](https://img.shields.io/npm/v/pegjs-loader.svg?style=flat-square)](https://www.npmjs.com/package/pegjs-loader)
5+
[![npm downloads](https://img.shields.io/npm/dm/pegjs-loader.svg?style=flat-square)](https://www.npmjs.com/package/pegjs-loader)
46

5-
```js
6-
{..., loader: 'pegjs-loader'}
7+
## Install
8+
9+
`npm install --save-dev pegjs-loader pegjs webpack`
10+
11+
The pegjs-loader requires [PEG.js](https://github.com/pegjs/pegjs) and [webpack](https://github.com/webpack/webpack)
12+
as [`peerDependency`](https://docs.npmjs.com/files/package.json#peerdependencies). Thus you are able to specify the required versions accurately.
13+
14+
## Usage
15+
16+
[Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html)
17+
18+
``` js
19+
var parser = require("!pegjs!./parser.pegjs");
20+
// => returns compiled PEG.js parser
21+
```
22+
23+
### Apply via webpack config
24+
25+
It's recommended to adjust your `webpack.config` so `pegjs!` is applied automatically on all files ending on `.pegjs`:
26+
27+
``` js
28+
module.exports = {
29+
...
30+
module: {
31+
loaders: [
32+
{
33+
test: /\.pegjs$/,
34+
loader: 'pegjs-loader'
35+
}
36+
]
37+
}
38+
};
39+
```
40+
41+
Then you only need to write: `require("./parser.pegjs")`.
42+
43+
### PEG.js options
44+
45+
You can pass options to PEG.js as [query parameters](http://webpack.github.io/docs/using-loaders.html#query-parameters). The following options are supported:
46+
47+
* `cache` — if `true`, makes the parser cache results, avoiding exponential
48+
parsing time in pathological cases but making the parser slower (default:
49+
`false`)
50+
51+
``` js
52+
module.exports = {
53+
...
54+
module: {
55+
loaders: [
56+
{
57+
test: /\.pegjs$/,
58+
loader: 'pegjs-loader?cache=true'
59+
}
60+
]
61+
}
62+
};
763
```
64+
65+
## Change Log
66+
67+
This project adheres to [Semantic Versioning](http://semver.org/).
68+
Every release, along with the migration instructions, if any, is documented on the Github [Releases](https://github.com/eploko/pegjs-loader/releases) page.
69+
70+
## Thanks
71+
72+
[Victor Homyakov](https://github.com/victor-homyakov) for the propagation of the cache option.
73+
74+
## License
75+
76+
MIT (http://www.opensource.org/licenses/mit-license.php)

index.js

-11
This file was deleted.

package.json

+41-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
{
22
"name": "pegjs-loader",
3-
"version": "0.1.1",
3+
"version": "0.2.0",
44
"description": "PEG.js loader for webpack",
5-
"main": "index.js",
6-
"dependencies": {
7-
"loader-utils": "^0.2.2",
8-
"pegjs": "^0.8.0"
9-
},
10-
"scripts": {
11-
"test": "echo \"Error: no test specified\" && exit 1"
12-
},
5+
"authors": [
6+
"Andrey Subbotin <[email protected]> (https://github.com/eploko)",
7+
"Victor Homyakov (https://github.com/victor-homyakov)"
8+
],
9+
"license": "MIT",
10+
"main": "lib/index.js",
11+
"jsnext:main": "src/index.js",
1312
"repository": {
1413
"type": "git",
1514
"url": "https://github.com/eploko/pegjs-loader"
@@ -21,6 +20,37 @@
2120
"peg",
2221
"loader"
2322
],
24-
"author": "Andrey Subbotin",
25-
"license": "MIT"
23+
"bugs": {
24+
"url": "https://github.com/eploko/pegjs-loader/issues"
25+
},
26+
"homepage": "http://eploko.github.io/pegjs-loader",
27+
"peerDependencies": {
28+
"pegjs": "^0.8.0",
29+
"webpack": "^1.12.2"
30+
},
31+
"dependencies": {
32+
"loader-utils": "^0.2.5"
33+
},
34+
"devDependencies": {
35+
"babel": "^5.5.8",
36+
"babel-core": "^5.6.18",
37+
"babel-eslint": "^4.1.0",
38+
"babel-loader": "^5.1.4",
39+
"eslint": "^1.7.1",
40+
"eslint-config-airbnb": "^0.1.0",
41+
"eslint-plugin-react": "^3.6.3",
42+
"rimraf": "^2.3.4",
43+
"webpack": "1.12.2"
44+
},
45+
"scripts": {
46+
"clean": "rimraf lib",
47+
"lint": "eslint src",
48+
"check": "npm run lint",
49+
"build:lib": "babel src --out-dir lib",
50+
"build": "npm run build:lib",
51+
"preversion": "npm run clean && npm run check",
52+
"version": "npm run build",
53+
"postversion": "git push && git push --tags && npm run clean",
54+
"prepublish": "npm run clean && npm run build"
55+
}
2656
}

src/index.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import pegjs from 'pegjs';
2+
import loaderUtils from 'loader-utils';
3+
4+
export default (source) => {
5+
if (this.cacheable) {
6+
this.cacheable();
7+
}
8+
9+
const query = loaderUtils.parseQuery(this.query);
10+
const cacheParserResults = !!query.cache;
11+
12+
// Description of PEG.js options: https://github.com/pegjs/pegjs#javascript-api
13+
const pegOptions = { output: 'source', cache: cacheParserResults };
14+
15+
return `module.exports = ${pegjs.buildParser(source, pegOptions)};`;
16+
};

0 commit comments

Comments
 (0)