Skip to content

support babel-plugin-module-resolver #1187

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

Closed
zhenyulin opened this issue Nov 29, 2018 · 8 comments
Closed

support babel-plugin-module-resolver #1187

zhenyulin opened this issue Nov 29, 2018 · 8 comments

Comments

@zhenyulin
Copy link

related to #140

If use babel-plugin-module-resolver or Webpack to simplify path resolution, documentation.js would fail to resolve the imported modules from the entry point.

babel.config.js:

module.exports = {
  presets: [
    [
      '@babel/preset-env',
      {
        targets: {
          node: '8.10',
        },
      },
    ],
  ],
  plugins: [
    '@babel/plugin-proposal-object-rest-spread',
    ['module-resolver', { root: ['./src'] }],
  ],
};

src/index.js:

import { validate, join } from './utils';
import { FOO, BAR } from './constants';

/**
 * An example function just to show the build and ci pipeline works.
 * @returns {string} Hello world.
 */
export default () => {
  if (validate({ foo: FOO, bar: BAR })) {
    return join(FOO, BAR);
  }
  throw Error('Something interesting has happened ;-)');
};

Currently, I configured modulePaths in jest and eslint-import-resolver-node so that the path resolver config works across development, test, lint.

It would be nice to be able to add a plugin for path resolution or offer settings in .documentationrc.yml to have the same feature in docgen.

@tmcw
Copy link
Member

tmcw commented Nov 29, 2018

I'd welcome a PR in this direction, though my direction with the project is essentially going in the opposite direction. I think it's ideal to cater to mainstream code first and to avoid any plugins or transformations that wouldn't run natively in some runtime, like Node.js or a browser - Babel transforms that aren't ever going to be part of the standard language seem like a step too far in the direction of perl.

@zhenyulin
Copy link
Author

think I got a temporary workaround at the moment by doing documentation src/**, which bypasses the path resolution.

@green3g
Copy link

green3g commented Dec 12, 2018

Does documentationjs support any babel plugins? Like dynamic imports? I'm running into issues with code that happens to have

registry.add('relationshipQuery/relate', () => import('./util/getRelationshipQuery'));
registry.add('relationshipQuery/spatial', () => import('./util/getSpatialQuery'));

Documentation throws the error Unexpected token.

@tmcw
Copy link
Member

tmcw commented Dec 12, 2018

See #1149 - dynamic import support is temporarily dropped until there's a Babel 7 solution to it.

@zeorin
Copy link

zeorin commented Jan 22, 2019

I think it's ideal to cater to mainstream code first […]

Here's a list of projects that use babel-plugin-module-resolver, which is by no means exhaustive. This plugin in particular is becoming more popular, but more and more I am expecting JS tools to respect my project babel configuration, or at least allow me to opt-in to that. Projects like Jest, AVA, ESLint, etc. do this, and it's becoming mainstream.

Partly thanks to Babel, there really is no such thing as "mainstream JS". To some degree, we're all rolling our own versions of JS (or letting projects like Create React App do it for us). Do we support JSX? The latest version of ECMAScript? What about stage 3 proposals? TypeScript? The list goes on. (Even in untranspiled code in browsers there isn't 100% parity between them).

By supporting the local Babel config, we can support the mainstream.

@tmcw
Copy link
Member

tmcw commented Jan 22, 2019

I appreciate the line of thinking, but per the statement, the best way to argue for a feature is to submit a PR.

@tmcw
Copy link
Member

tmcw commented Apr 18, 2019

Custom babel configurations are now supported in 10.x like:

documentation build --babel=./babel.config.js

@tmcw tmcw closed this as completed Apr 18, 2019
@goodmind
Copy link

goodmind commented May 4, 2019

@tmcw this doesn't work with --document-exported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants