Skip to content

Commit 746d0a9

Browse files
dougalgtmcw
authored andcommittedMar 12, 2019
feat: Support custom babel config (#1205)
BREAKING CHANGE: this may change babel configuration loading, and is a major change to the documentation.js approach to Babel.
1 parent f3511f9 commit 746d0a9

File tree

2 files changed

+39
-37
lines changed

2 files changed

+39
-37
lines changed
 

‎src/commands/shared_options.js

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
* Adds shared options to any command that runs documentation
33
*/
44
module.exports.sharedInputOptions = {
5+
babel: {
6+
describe:
7+
'path to babelrc or babel.options.js to override default babel config',
8+
type: 'string',
9+
default: null
10+
},
511
shallow: {
612
describe:
713
'shallow mode turns off dependency resolution, ' +

‎src/input/dependency.js

+33-37
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,35 @@ const concat = require('concat-stream');
55
const moduleFilters = require('../module_filters');
66
const smartGlob = require('../smart_glob.js');
77

8+
const STANDARD_BABEL_CONFIG = {
9+
sourceMaps: false,
10+
compact: false,
11+
cwd: path.resolve(__dirname, '../../'),
12+
presets: ['@babel/preset-react', '@babel/preset-env', '@babel/preset-flow'],
13+
plugins: [
14+
// Stage 0
15+
'@babel/plugin-proposal-function-bind',
16+
// Stage 1
17+
'@babel/plugin-proposal-export-default-from',
18+
'@babel/plugin-proposal-logical-assignment-operators',
19+
'@babel/plugin-proposal-optional-chaining',
20+
['@babel/plugin-proposal-pipeline-operator', { proposal: 'minimal' }],
21+
['@babel/plugin-proposal-nullish-coalescing-operator', { loose: false }],
22+
'@babel/plugin-proposal-do-expressions',
23+
// Stage 2
24+
['@babel/plugin-proposal-decorators', { legacy: true }],
25+
'@babel/plugin-proposal-function-sent',
26+
'@babel/plugin-proposal-export-namespace-from',
27+
'@babel/plugin-proposal-numeric-separator',
28+
'@babel/plugin-proposal-throw-expressions',
29+
// Stage 3
30+
'@babel/plugin-syntax-dynamic-import',
31+
'@babel/plugin-syntax-import-meta',
32+
['@babel/plugin-proposal-class-properties', { loose: false }],
33+
'@babel/plugin-proposal-json-strings'
34+
]
35+
};
36+
837
/**
938
* Returns a readable stream of dependencies, given an array of entry
1039
* points and an object of options to provide to module-deps.
@@ -17,6 +46,9 @@ const smartGlob = require('../smart_glob.js');
1746
* @returns results
1847
*/
1948
function dependencyStream(indexes, config) {
49+
const babelConfig = config.babel
50+
? { configFile: path.resolve(__dirname, '../../../../', config.babel) }
51+
: STANDARD_BABEL_CONFIG;
2052
const md = mdeps({
2153
/**
2254
* Determine whether a module should be included in documentation
@@ -28,43 +60,7 @@ function dependencyStream(indexes, config) {
2860
.concat(config.requireExtension || [])
2961
.map(ext => '.' + ext.replace(/^\./, ''))
3062
.concat(['.mjs', '.js', '.json', '.es6', '.jsx']),
31-
transform: [
32-
babelify.configure({
33-
sourceMaps: false,
34-
compact: false,
35-
cwd: path.resolve(__dirname, '../../'),
36-
presets: [
37-
'@babel/preset-react',
38-
'@babel/preset-env',
39-
'@babel/preset-flow'
40-
],
41-
plugins: [
42-
// Stage 0
43-
'@babel/plugin-proposal-function-bind',
44-
// Stage 1
45-
'@babel/plugin-proposal-export-default-from',
46-
'@babel/plugin-proposal-logical-assignment-operators',
47-
'@babel/plugin-proposal-optional-chaining',
48-
['@babel/plugin-proposal-pipeline-operator', { proposal: 'minimal' }],
49-
[
50-
'@babel/plugin-proposal-nullish-coalescing-operator',
51-
{ loose: false }
52-
],
53-
'@babel/plugin-proposal-do-expressions',
54-
// Stage 2
55-
['@babel/plugin-proposal-decorators', { legacy: true }],
56-
'@babel/plugin-proposal-function-sent',
57-
'@babel/plugin-proposal-export-namespace-from',
58-
'@babel/plugin-proposal-numeric-separator',
59-
'@babel/plugin-proposal-throw-expressions',
60-
// Stage 3
61-
'@babel/plugin-syntax-dynamic-import',
62-
'@babel/plugin-syntax-import-meta',
63-
['@babel/plugin-proposal-class-properties', { loose: false }],
64-
'@babel/plugin-proposal-json-strings'
65-
]
66-
})
67-
],
63+
transform: [babelify.configure(babelConfig)],
6864
postFilter: moduleFilters.externals(indexes, config),
6965
resolve:
7066
config.resolve === 'node' &&

0 commit comments

Comments
 (0)
Please sign in to comment.