Merge pull request #445 from documentationjs/json-require

Requiring JSON files is broken
This commit is contained in:
Tom MacWright 2016-06-03 14:01:39 -04:00
commit ff37f2b736
14 changed files with 175 additions and 13 deletions

View File

@ -10,13 +10,13 @@ var path = require('path');
* expect as argument a file as an objectg with the 'file' property
*
* @private
* @param {String|Array} extensions to be filtered
* @param {String|Array} extension to be filtered
* @param {boolean} allowAll ignore the entire extension check and always
* pass through files. This is used by the polglot mode.
* @return {Function} a filter function, this function returns true if the input filename extension
* is in the extension whitelist
*/
function filterJS(extensions, allowAll) {
function filterJS(extension, allowAll) {
if (allowAll) {
return function () {
@ -24,11 +24,7 @@ function filterJS(extensions, allowAll) {
};
}
extensions = extensions || [];
if (typeof extensions === 'string') {
extensions = [extensions];
}
extensions = extensions.concat(['js', 'es6', 'jsx']);
var extensions = [].concat(extension || []).concat(['js', 'es6', 'jsx']);
return function (data) {
return extensions.indexOf(path.extname(data.file).substring(1)) !== -1;

View File

@ -23,6 +23,7 @@ var mdeps = require('module-deps-sortable'),
*/
function dependencyStream(indexes, options, callback) {
var filterer = filterJS(options.extension, options.polyglot);
var md = mdeps({
/**
* Determine whether a module should be included in documentation
@ -32,6 +33,11 @@ function dependencyStream(indexes, options, callback) {
filter: function (id) {
return !!options.external || moduleFilters.internalOnly(id);
},
extensions: [].concat(options.extension || [])
.concat(['js', 'es6', 'jsx', 'json'])
.map(function (ext) {
return '.' + ext;
}),
transform: [babelify.configure({
sourceMap: false,
presets: [

View File

@ -128,6 +128,13 @@ test('extension option', function (t) {
});
});
test('extension option', function (t) {
documentation(['build fixture/extension.jsx'], function (err, data) {
t.ifError(err);
t.end();
});
});
test('invalid arguments', function (group) {
group.test('bad -f option', function (t) {
documentation(['build -f DOES-NOT-EXIST fixture/internal.input.js'], function (err) {

4
test/fixture/es6-ext.es6 Normal file
View File

@ -0,0 +1,4 @@
/**
* This is the default export frogs!
*/
export default 10;

View File

@ -1,3 +1,4 @@
import hasEx6 from './es6-ext';
import multiply from "./es6.input.js";
import * as foo from "some-other-module";

View File

@ -65,26 +65,26 @@
],
"loc": {
"start": {
"line": 4,
"line": 5,
"column": 0
},
"end": {
"line": 7,
"line": 8,
"column": 3
}
},
"context": {
"loc": {
"start": {
"line": 8,
"line": 9,
"column": 0
},
"end": {
"line": 8,
"line": 9,
"column": 43
}
},
"code": "import multiply from \"./es6.input.js\";\nimport * as foo from \"some-other-module\";\n\n/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiplyTwice = (a) => a * multiply(a);\n\nexport default multiplyTwice;\n"
"code": "import hasEx6 from './es6-ext';\nimport multiply from \"./es6.input.js\";\nimport * as foo from \"some-other-module\";\n\n/**\n * This function returns the number one.\n * @returns {Number} numberone\n */\nvar multiplyTwice = (a) => a * multiply(a);\n\nexport default multiplyTwice;\n"
},
"errors": [],
"returns": [
@ -153,7 +153,7 @@
{
"title": "param",
"name": "a",
"lineNumber": 8
"lineNumber": 9
}
],
"members": {
@ -168,6 +168,96 @@
],
"namespace": "multiplyTwice"
},
{
"description": {
"type": "root",
"children": [
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "This is the default export frogs!",
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 1,
"column": 34,
"offset": 33
},
"indent": []
}
}
],
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 1,
"column": 34,
"offset": 33
},
"indent": []
}
}
],
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 1,
"column": 34,
"offset": 33
}
}
},
"tags": [],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 3
}
},
"context": {
"loc": {
"start": {
"line": 4,
"column": 0
},
"end": {
"line": 4,
"column": 18
}
},
"code": "/**\n * This is the default export frogs!\n */\nexport default 10;\n"
},
"errors": [],
"name": "es6-ext",
"members": {
"instance": [],
"static": []
},
"path": [
{
"name": "es6-ext"
}
],
"namespace": "es6-ext"
},
{
"description": {
"type": "root",

View File

@ -8,6 +8,10 @@ This function returns the number one.
Returns **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** numberone
# es6-ext
This is the default export frogs!
# destructure
This function destructures with defaults.

View File

@ -147,6 +147,51 @@
}
]
},
{
"depth": 1,
"type": "heading",
"children": [
{
"type": "text",
"value": "es6-ext"
}
]
},
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "This is the default export frogs!",
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 1,
"column": 34,
"offset": 33
},
"indent": []
}
}
],
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 1,
"column": 34,
"offset": 33
},
"indent": []
}
},
{
"depth": 1,
"type": "heading",

View File

@ -0,0 +1 @@
var required = require('./extension/extension-required');

View File

@ -0,0 +1 @@
module.exports = {};

View File

@ -0,0 +1 @@
var data = require('./require-json');

View File

@ -0,0 +1 @@
[]

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,4 @@
{
"type": "root",
"children": []
}