Skip to content

Conversation

phated
Copy link
Contributor

@phated phated commented Sep 1, 2020

Alright, I think this is ready to get some serious feedback. Promoting from draft!

Building on the excellent work by @devongovett and @motiz88, I've been trying to implement the requested changes in #352 (specifically #352 (comment))

What I've done

  • Made the "importer" configurable. It is passed as an argument to the parse method, but if using the defaultParse from main.js, it is an additional option that can be specified. This is to make everything backwards compatible.
  • Made the default importer a no-op, which might result in some extra function calls during resolution, but keeps all behavior completely the same unless someone explicitly overrides it. This is to make everything backwards compatible.
  • Threaded the importer throughout the codebase.
  • Added tests for a "mockImporter" throughout the entire test suite.
  • Renamed the importer added in Support for importing types #352 to fsImporter and wrapped it in a factory function so the module lookup and cache could be configured. This also allows caching to be done for entire run of react-docgen (if you have a way to reuse your cache, it can even be done between runs).

Stuff I still need to do:

  • Add tests for makeFsImporter
  • Add docs for importers
@phated
Copy link
Contributor Author

phated commented Sep 3, 2020

I might have run into a problem when testing this against some local code today. Need to dig in further.

@shilman shilman mentioned this pull request Sep 14, 2020
2 tasks
motiz88 and others added 27 commits September 20, 2020 12:50
Squashed commit of the following: commit 3b3bbf6 Author: Daniel Tschinder <daniel@tschinder.de> Date: Thu Nov 21 21:52:40 2019 +0100 Add additional test commit 048646d Author: Daniel Tschinder <daniel@tschinder.de> Date: Thu Nov 21 21:41:41 2019 +0100 Fix order of deps commit e69ef4f Author: Daniel Tschinder <daniel@tschinder.de> Date: Thu Nov 21 21:39:59 2019 +0100 Add mjs commit 26874ee Merge: 02649b7 b3601b6 Author: Daniel Tschinder <daniel@tschinder.de> Date: Fri Oct 25 22:25:43 2019 +0200 Merge branch 'master' into importing # Conflicts: #	src/utils/isReactComponentClass.js commit 02649b7 Merge: 8c0a15f aa54200 Author: Daniel Tschinder <daniel@tschinder.de> Date: Fri Oct 25 22:21:51 2019 +0200 Merge branch 'master' into importing # Conflicts: #	src/__tests__/__snapshots__/main-test.js.snap #	src/__tests__/fixtures/component_28.tsx commit 8c0a15f Author: Devon Govett <devongovett@gmail.com> Date: Sat May 4 17:56:04 2019 -0700 Missing typedef commit 08b5e7f Author: Devon Govett <devongovett@gmail.com> Date: Sat May 4 17:45:34 2019 -0700 Fix lint commit c180af8 Author: Devon Govett <devongovett@gmail.com> Date: Sat May 4 15:08:19 2019 -0700 Support named re-exports commit 80200c8 Author: Devon Govett <devongovett@gmail.com> Date: Sat May 4 13:18:59 2019 -0700 Handle recursive imports commit 79a814f Author: Devon Govett <devongovett@gmail.com> Date: Sat May 4 13:09:16 2019 -0700 Support export all declaration commit 840ca88 Author: Devon Govett <devongovett@gmail.com> Date: Fri May 3 23:25:57 2019 -0700 Handle namespace imports commit 268b828 Author: Devon Govett <devongovett@gmail.com> Date: Fri May 3 22:51:00 2019 -0700 Add noop browser version of resolveImportedValue commit 00b3d35 Author: Devon Govett <devongovett@gmail.com> Date: Sun Apr 28 21:59:00 2019 -0700 Initial support for importing prop types
This is not airtight. 1. We may need to make this configurable with a pragma comment. 2. We should probably shallowly resolve the import and record the file and exported name of the alias, instead of just the local name.
@phated phated marked this pull request as ready for review September 21, 2020 23:00
@phated
Copy link
Contributor Author

phated commented Sep 21, 2020

Alright, I think this is ready for an initial review while I continue the follow up work of adding test for makeFsImporter and document importers.

What do you think @danez?

@phated phated changed the title WIP: Importing types Add custom importers for importing types/values Sep 21, 2020
@shilman
Copy link

shilman commented Sep 22, 2020

Heroic work @phated 🎖️ 🏅 🥇

@phated
Copy link
Contributor Author

phated commented Sep 23, 2020

It's probably worth mentioning; I bootstrapped this into a large project that I'm working on and it works splendidly!

@kivervinicius
Copy link

@phated wow!

@kivervinicius
Copy link

@phated can i use this with you repository? In npm

@danez
Copy link
Collaborator

danez commented Oct 21, 2020

I will merge now and release an alpha version with it. Feel free to create follow up PRs for the tests, bugfixes etc.

yarn add react-docgen@next 
@stu039
Copy link

stu039 commented Jun 2, 2021

@danez - Any documentation on usage of this please? Using imported proptypes has been an issue for us for a while. If there is no documentation showing how to enable this in the alpha version, we may have to move away from docgen.

@danez
Copy link
Collaborator

danez commented Jun 2, 2021

@stu039 see #507 the cli does not support it at the moment. There might still be bugs, so if you find anything not working please report.

@dozortsev
Copy link

@danez @phated I guess note that imported types aren't supported is redundant, right?

https://github.com/reactjs/react-docgen/blob/master/README.md#flow-and-typescript-support

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

7 participants