8000 Requiring JSON files is broken by tmcw · Pull Request #445 · documentationjs/documentation · GitHub
[go: up one dir, main page]

Skip to content

Requiring JSON files is broken #445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions lib/filter_js.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,21 @@ 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 () {
return true;
};
}

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;
Expand Down
6 changes: 6 additions & 0 deletions lib/input/dependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: [
Expand Down
7 changes: 7 additions & 0 deletions test/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions test/fixture/es6-ext.es6
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* This is the default export frogs!
*/
export default 10;
1 change: 1 addition & 0 deletions test/fixture/es6-import.input.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import hasEx6 from './es6-ext';
import multiply from "./es6.input.js";
import * as foo from "some-other-module";

Expand Down
102 changes: 96 additions & 6 deletions test/fixture/es6-import.output.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -153,7 +153,7 @@
{
"title": "param",
"name": "a",
"lineNumber": 8
"lineNumber": 9
}
],
"members": {
Expand All @@ -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",
Expand Down
4 chang F438 es: 4 additions & 0 deletions test/fixture/es6-import.output.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
45 changes: 45 additions & 0 deletions test/fixture/es6-import.output.md.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions test/fixture/extension.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var required = require('./extension/extension-required');
1 change: 1 addition & 0 deletions test/fixture/extension/extension-required.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
1 change: 1 addition & 0 deletions test/fixture/require-json-no-extension.input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var data = require('./require-json');
1 change: 1 addition & 0 deletions test/fixture/require-json-no-extension.output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
1 change: 1 addition & 0 deletions test/fixture/require-json-no-extension.output.md