Skip to content
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

refactor: separate export default from function declaration #858

Closed
wants to merge 1 commit into from

Conversation

joeskeen
Copy link

@joeskeen joeskeen commented Feb 8, 2024

The issue

Currently all classes (I know they are not technically ES6 classes, but I'm sure you know what I mean) are the default export of the package, which is fine, but since the declaration reads export default function ClassName(){}, when the typings are generated and documentation from those typings, all the class names become named default. See this from https://joe.skeen.rocks/diagram-js/classes/core_ElementFactory.default.html:

image

This leads to a potentially confusing experience for those consuming typings or docs from the library.

Proposed solution

This PR exports each class as its own export, but also sets the default export to that class. The only change should be an additional export with the name of the class attached. This enables documentation to work better, as the names will exist in the docs, as well as links between referenced types.

image

How the code changes were made

In VSCode, I did a RegEx global search in lib/**/*.js for:

(\/\*\*\n(.*?\n)+? \*\/)\nexport default function ([^\(]+)\(

and replaced it with:

export default $3;\n\n$1\nexport function $3(

Related to #78
Related to #857

@joeskeen
Copy link
Author

joeskeen commented Feb 8, 2024

After looking more at the docs, it seems we may also want to do this for interfaces and modules. Thoughts @nikku?

Edit: I've completed similar changes for modules and interfaces on my local repo, if you would like I can push those changes to this PR as well. Here's how I changed the interfaces:

Replace: (\/\*\*\n(?:.*\n)*)export default interface ([^ ]+) \{
With: export default $2;\n\n$1export interface $2 {
in *.ts (but not *.d.ts)

For the modules, you can see this Gist on how I transformed them (I needed the folder name so it wasn't a find/replace kind of solution)

@nikku
Copy link
Member

nikku commented Feb 15, 2024

@joeskeen thanks for your contribution.

We'll not be able to merge it at this stage, but we're internally in discussion how to proceed both regarding this PR and the proposed documentation generation.

@nikku
Copy link
Member

nikku commented Mar 7, 2024

@joeskeen Thanks again for your work. I'm closing this PR as I don't see us progressing on it any time soon. There is a bunch of things that we need to clarify, and likely we'll simply build a custom, opinionated documentation generator for our (huge) code base.

@nikku nikku closed this Mar 7, 2024
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

Successfully merging this pull request may close these issues.

2 participants