Skip to content

Commit e3c59d7

Browse files
fix: external was removed as prefer of input usages
BREAKING CHANGE: external parameter was removed Migration plan propose to move all external resources to input usages Motivation: packages has many inputs which describe in package.json so that mean need each time to parse all package.json of exsternal resources to understand which etry point need to pick. But it is base on guesses because entry point may could not contains a documentation and the best way to handle it manualy.
1 parent 4cc70a5 commit e3c59d7

File tree

9 files changed

+393
-486
lines changed

9 files changed

+393
-486
lines changed

__tests__/__snapshots__/test.js.snap

+378-378
Large diffs are not rendered by default.

__tests__/bin.js

-8
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,6 @@ test('--shallow option', async function () {
9898
expect(data.length).toBe(0);
9999
});
100100

101-
test('external modules option', async function () {
102-
const data = await documentation([
103-
'build fixture/external.input.js ' +
104-
'--external=external --external=external/node_modules'
105-
]);
106-
expect(data.length).toBe(2);
107-
});
108-
109101
test('when a file is specified both in a glob and explicitly, it is only documented once', async function () {
110102
const data = await documentation([
111103
'build fixture/simple.input.js fixture/simple.input.*'

__tests__/lib/module_filters.js

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
import moduleFilters from '../../src/module_filters.js';
1+
import internalOnly from '../../src/module_filters.js';
22

33
test('moduleFilters.internalOnly', function () {
4-
expect(moduleFilters.internalOnly('./foo')).toEqual(true);
5-
expect(moduleFilters.internalOnly('foo')).toEqual(false);
6-
});
7-
8-
test('moduleFilters.externals', function () {
9-
expect(moduleFilters.externals([], {})('./foo')).toEqual(true);
10-
expect(
11-
moduleFilters.externals([], { external: 'node_modules' })('./foo')
12-
).toEqual(true);
4+
expect(internalOnly('./foo')).toEqual(true);
5+
expect(internalOnly('foo')).toEqual(false);
136
});

__tests__/test.js

+8-12
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,15 @@ test('document-exported error', async function () {
5959
}
6060
});
6161

62-
test('external modules option', async function () {
63-
const result = await documentation.build(
64-
[path.join(__dirname, 'fixture', 'external.input.js')],
65-
{
66-
external: '(external|external/node_modules/*)'
67-
}
68-
);
62+
test('Check that external modules could parse as input', async function () {
63+
const dir = path.join(__dirname, 'fixture');
64+
const result = await documentation.build([
65+
path.join(dir, 'node_modules', 'external', 'lib', 'main.js'),
66+
path.join(dir, 'node_modules', 'external2', 'index.js'),
67+
path.join(dir, 'external.input.js')
68+
]);
6969
normalize(result);
70-
const outputfile = path.join(
71-
__dirname,
72-
'fixture',
73-
'_external-deps-included.json'
74-
);
70+
const outputfile = path.join(dir, '_external-deps-included.json');
7571
expect(result).toMatchSnapshot();
7672
});
7773

docs/USAGE.md

-5
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,10 @@ Options:
4040
--no-package, --np dont find and use package.json for project-
4141
configuration option defaults
4242
[boolean] [default: false]
43-
--external a string / glob match pattern that defines which
44-
external modules will be whitelisted and included
45-
in the generated documentation. [default: null]
4643
--require-extension, --re additional extensions to include in require() and
4744
import's search algorithm.For instance, adding .es5
4845
would allow require("adder") to find "adder.es5"
4946
--parse-extension, --pe additional extensions to parse as source code.
50-
--private, -p generate documentation tagged as private
51-
[boolean] [default: false]
5247
--access, -a Include only comments with a given access level,
5348
out of private, protected, public, undefined. By
5449
default, public, protected, and undefined access

package-lock.json

+1-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"@babel/parser": "^7.15.4",
1515
"@babel/traverse": "^7.15.4",
1616
"@babel/types": "^7.14.1",
17-
"babelify": "^10.0.0",
1817
"chalk": "^4.1.2",
1918
"chokidar": "^3.4.0",
2019
"concat-stream": "^2.0.0",
@@ -31,7 +30,6 @@
3130
"mdast-util-find-and-replace": "^2.1.0",
3231
"mdast-util-inject": "^1.1.0",
3332
"micromark-util-character": "^1.1.0",
34-
"micromatch": "^4.0.4",
3533
"module-deps-sortable": "^5.0.3",
3634
"parse-filepath": "^1.0.2",
3735
"pify": "^5.0.0",

src/input/dependency.js

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
import mdeps from 'module-deps-sortable';
22
import path from 'path';
3-
import babelify from 'babelify';
43
import concat from 'concat-stream';
5-
import moduleFilters from '../module_filters.js';
6-
import { standardBabelParserPlugins } from '../parsers/parse_to_ast.js';
4+
import internalOnly from '../module_filters.js';
75
import smartGlob from '../smart_glob.js';
86

9-
const STANDARD_BABEL_CONFIG = {
10-
compact: false,
11-
parserOpts: { plugins: [...standardBabelParserPlugins, 'flow', 'jsx'] }
12-
};
13-
147
/**
158
* Returns a readable stream of dependencies, given an array of entry
169
* points and an object of options to provide to module-deps.
@@ -23,22 +16,17 @@ const STANDARD_BABEL_CONFIG = {
2316
* @returns results
2417
*/
2518
export default function dependencyStream(indexes, config) {
26-
const babelConfig = config.babel
27-
? { configFile: path.resolve(__dirname, '../../../../', config.babel) }
28-
: STANDARD_BABEL_CONFIG;
2919
const md = mdeps({
3020
/**
3121
* Determine whether a module should be included in documentation
3222
* @param {string} id path to a module
3323
* @returns {boolean} true if the module should be included.
3424
*/
35-
filter: id => !!config.external || moduleFilters.internalOnly(id),
25+
filter: id => internalOnly(id),
3626
extensions: []
3727
.concat(config.requireExtension || [])
3828
.map(ext => '.' + ext.replace(/^\./, ''))
3929
.concat(['.mjs', '.js', '.json', '.es6', '.jsx']),
40-
transform: [babelify.configure(babelConfig)],
41-
postFilter: moduleFilters.externals(indexes, config),
4230
resolve:
4331
config.resolve === 'node' &&
4432
((id, opts, cb) => {

src/module_filters.js

+1-52
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import path from 'path';
2-
import micromatch from 'micromatch';
3-
41
// Skip external modules. Based on http://git.io/pzPO.
52
const internalModuleRegexp =
63
process.platform === 'win32'
@@ -11,52 +8,4 @@ const internalModuleRegexp =
118
/**
129
* Module filters
1310
*/
14-
export default {
15-
internalOnly: internalModuleRegexp.test.bind(internalModuleRegexp),
16-
17-
/**
18-
* Create a filter function for use with module-deps, allowing the specified
19-
* external modules through.
20-
*
21-
* @param {Array<string>} indexes - the list of entry points that will be
22-
* used by module-deps
23-
* @param {Object} options - An options object with `external` being a
24-
* micromatch-compatible glob. *NOTE:* the glob will be matched relative to
25-
* the top-level node_modules directory for each entry point.
26-
* @returns {function} - A function for use as the module-deps `postFilter`
27-
* options.
28-
*/
29-
externals: function externalModuleFilter(indexes, options) {
30-
let externalFilters = false;
31-
if (options.external) {
32-
externalFilters = indexes.map(index => {
33-
// grab the path of the top-level node_modules directory.
34-
const topNodeModules = path.join(path.dirname(index), 'node_modules');
35-
return function matchGlob(file, pkg) {
36-
// if a module is not found, don't include it.
37-
if (!file || !pkg) {
38-
return false;
39-
}
40-
// if package.json specifies a 'main' script, strip that path off
41-
// the file to get the module's directory.
42-
// otherwise, just use the dirname of the file.
43-
if (pkg.main) {
44-
file = file.slice(0, -path.normalize(pkg.main).length);
45-
} else {
46-
file = path.dirname(file);
47-
}
48-
// test the path relative to the top node_modules dir.
49-
const p = path.relative(topNodeModules, file);
50-
return micromatch.any(p, options.external);
51-
};
52-
});
53-
}
54-
55-
return function (id, file, pkg) {
56-
const internal = internalModuleRegexp.test(id);
57-
return (
58-
internal || (externalFilters && externalFilters.some(f => f(file, pkg)))
59-
);
60-
};
61-
}
62-
};
11+
export default id => internalModuleRegexp.test(id);

0 commit comments

Comments
 (0)