mirror of
https://github.com/documentationjs/documentation.git
synced 2026-01-25 14:26:29 +00:00
Merge pull request #445 from documentationjs/json-require
Requiring JSON files is broken
This commit is contained in:
commit
ff37f2b736
@ -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;
|
||||
|
||||
@ -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: [
|
||||
|
||||
@ -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
4
test/fixture/es6-ext.es6
Normal file
@ -0,0 +1,4 @@
|
||||
/**
|
||||
* This is the default export frogs!
|
||||
*/
|
||||
export default 10;
|
||||
@ -1,3 +1,4 @@
|
||||
import hasEx6 from './es6-ext';
|
||||
import multiply from "./es6.input.js";
|
||||
import * as foo from "some-other-module";
|
||||
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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",
|
||||
|
||||
1
test/fixture/extension.jsx
Normal file
1
test/fixture/extension.jsx
Normal file
@ -0,0 +1 @@
|
||||
var required = require('./extension/extension-required');
|
||||
1
test/fixture/extension/extension-required.jsx
Normal file
1
test/fixture/extension/extension-required.jsx
Normal file
@ -0,0 +1 @@
|
||||
module.exports = {};
|
||||
1
test/fixture/require-json-no-extension.input.js
Normal file
1
test/fixture/require-json-no-extension.input.js
Normal file
@ -0,0 +1 @@
|
||||
var data = require('./require-json');
|
||||
1
test/fixture/require-json-no-extension.output.json
Normal file
1
test/fixture/require-json-no-extension.output.json
Normal file
@ -0,0 +1 @@
|
||||
[]
|
||||
1
test/fixture/require-json-no-extension.output.md
Normal file
1
test/fixture/require-json-no-extension.output.md
Normal file
@ -0,0 +1 @@
|
||||
|
||||
4
test/fixture/require-json-no-extension.output.md.json
Normal file
4
test/fixture/require-json-no-extension.output.md.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"type": "root",
|
||||
"children": []
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user