Skip to content

Support custom babel config #1205

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 1 commit into from
Mar 12, 2019
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
6 changes: 6 additions & 0 deletions src/commands/shared_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
* Adds shared options to any command that runs documentation
*/
module.exports.sharedInputOptions = {
babel: {
describe:
'path to babelrc or babel.options.js to override default babel config',
type: 'string',
default: null
},
shallow: {
describe:
'shallow mode turns off dependency resolution, ' +
Expand Down
70 changes: 33 additions & 37 deletions src/input/dependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,35 @@ const concat = require('concat-stream');
const moduleFilters = require('../module_filters');
const smartGlob = require('../smart_glob.js');

const STANDARD_BABEL_CONFIG = {
sourceMaps: false,
compact: false,
cwd: path.resolve(__dirname, '../../'),
presets: ['@babel/preset-react', '@babel/preset-env', '@babel/preset-flow'],
plugins: [
// Stage 0
'@babel/plugin-proposal-function-bind',
// Stage 1
'@babel/plugin-proposal-export-default-from',
'@babel/plugin-proposal-logical-assignment-operators',
'@babel/plugin-proposal-optional-chaining',
['@babel/plugin-proposal-pipeline-operator', { proposal: 'minimal' }],
['@babel/plugin-proposal-nullish-coalescing-operator', { loose: false }],
'@babel/plugin-proposal-do-expressions',
// Stage 2
['@babel/plugin-proposal-decorators', { legacy: true }],
'@babel/plugin-proposal-function-sent',
'@babel/plugin-proposal-export-namespace-from',
'@babel/plugin-proposal-numeric-separator',
'@babel/plugin-proposal-throw-expressions',
// Stage 3
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-syntax-import-meta',
['@babel/plugin-proposal-class-properties', { loose: false }],
'@babel/plugin-proposal-json-strings'
]
};

/**
* Returns a readable stream of dependencies, given an array of entry
* points and an object of options to provide to module-deps.
Expand All @@ -17,6 +46,9 @@ const smartGlob = require('../smart_glob.js');
* @returns results
*/
function dependencyStream(indexes, config) {
const babelConfig = config.babel
? { configFile: path.resolve(__dirname, '../../../../', config.babel) }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea here is to load the config relative to wherever documentation was installed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be easier to manage as an absolute path

: STANDARD_BABEL_CONFIG;
const md = mdeps({
/**
* Determine whether a module should be included in documentation
Expand All @@ -28,43 +60,7 @@ function dependencyStream(indexes, config) {
.concat(config.requireExtension || [])
.map(ext => '.' + ext.replace(/^\./, ''))
.concat(['.mjs', '.js', '.json', '.es6', '.jsx']),
transform: [
babelify.configure({
sourceMaps: false,
compact: false,
cwd: path.resolve(__dirname, '../../'),
presets: [
'@babel/preset-react',
'@babel/preset-env',
'@babel/preset-flow'
],
plugins: [
// Stage 0
'@babel/plugin-proposal-function-bind',
// Stage 1
'@babel/plugin-proposal-export-default-from',
'@babel/plugin-proposal-logical-assignment-operators',
'@babel/plugin-proposal-optional-chaining',
['@babel/plugin-proposal-pipeline-operator', { proposal: 'minimal' }],
[
'@babel/plugin-proposal-nullish-coalescing-operator',
{ loose: false }
],
'@babel/plugin-proposal-do-expressions',
// Stage 2
['@babel/plugin-proposal-decorators', { legacy: true }],
'@babel/plugin-proposal-function-sent',
'@babel/plugin-proposal-export-namespace-from',
'@babel/plugin-proposal-numeric-separator',
'@babel/plugin-proposal-throw-expressions',
// Stage 3
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-syntax-import-meta',
['@babel/plugin-proposal-class-properties', { loose: false }],
'@babel/plugin-proposal-json-strings'
]
})
],
transform: [babelify.configure(babelConfig)],
postFilter: moduleFilters.externals(indexes, config),
resolve:
config.resolve === 'node' &&
Expand Down