Skip to content

Commit b70f103

Browse files
committed
Fix and test behavior around requiring JSON files. Fixes #68
1 parent 390f648 commit b70f103

File tree

8 files changed

+30
-0
lines changed

8 files changed

+30
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.2.0
2+
3+
* Transforms in package.json `browserify.transform` fields are now applied to
4+
source code so that babel, etc can be supported.
5+
16
## 1.1.0
27

38
* Add `external` option that allows the user to whitelist specific external

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var mdeps = require('module-deps'),
77
sort = require('./streams/sort'),
88
normalize = require('./streams/normalize.js'),
99
filterAccess = require('./streams/filter_access.js'),
10+
filterJS = require('./streams/filter_js'),
1011
parse = require('./streams/parse'),
1112
inferName = require('./streams/infer_name'),
1213
inferKind = require('./streams/infer_kind'),
@@ -57,6 +58,7 @@ module.exports = function (indexes, options) {
5758
}
5859

5960
return md
61+
.pipe(deferErrors(filterJS()))
6062
.pipe(deferErrors(parse()))
6163
.pipe(deferErrors(inferName()))
6264
.pipe(sort())

streams/filter_js.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
var through = require('through');
4+
5+
/**
6+
* Node & browserify support requiring JSON files. JSON files can't be documented
7+
* with JSDoc or parsed with espree, so we filter them out before
8+
* they reach documentation's machinery.
9+
*
10+
* @name access
11+
* @public
12+
* @return {stream.Transform}
13+
*/
14+
module.exports = function () {
15+
return through(function (data) {
16+
if (!data.file.match(/\.json$/)) {
17+
this.push(data);
18+
}
19+
});
20+
};

test/fixture/require-json.input.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var data = require('./require-json.json');

test/fixture/require-json.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

test/fixture/require-json.output.custom.md

Whitespace-only changes.

test/fixture/require-json.output.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

test/fixture/require-json.output.md

Whitespace-only changes.

0 commit comments

Comments
 (0)