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

Support plugins that execute as native ESM #1635

Closed
cspotcode opened this issue Jul 18, 2021 · 5 comments
Closed

Support plugins that execute as native ESM #1635

cspotcode opened this issue Jul 18, 2021 · 5 comments
Labels
enhancement Improved functionality
Milestone

Comments

@cspotcode
Copy link
Contributor

Search Terms

native ecmascript, esm, plugin

Problem

It would be nice to write TypeDoc plugins as ESM modules, using node's new native ESM support

Suggested Solution

typedoc can first try to require() the plugin, then if it gets an ERR_REQUIRE_ESM error, it can import() it instead. This will support both CJS and ESM and will also support CJS transpilers like ts-node. I'm not sure if the ts-node use-case is meant to be supported or not. If not, typedoc can merely import() the plugins.

import() is async; I don't know if typedoc's plugin loading can be async.

@cspotcode cspotcode added the enhancement Improved functionality label Jul 18, 2021
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Jul 18, 2021

This would be a breaking change, since plugins are loaded in Application.bootstrap which is currently not async, but it seems like a reasonable approach to me.

@Gerrit0 Gerrit0 added good first issue Easier issue for first time contributors help wanted Contributions are especially encouraged labels Jul 18, 2021
@cspotcode
Copy link
Contributor Author

cspotcode commented Jul 18, 2021 via email

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Jul 18, 2021

I like keeping it simple, this is a pretty minor breaking change.

@Gerrit0 Gerrit0 added this to To Do in Version 0.22 Aug 1, 2021
@Gerrit0 Gerrit0 moved this from To Do to In Progress in Version 0.22 Aug 20, 2021
@Gerrit0 Gerrit0 removed the good first issue Easier issue for first time contributors label Aug 20, 2021
@Gerrit0 Gerrit0 removed this from In Progress in Version 0.22 Aug 20, 2021
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Aug 20, 2021

So... I looked at doing this, and it's not something that I want to commit to in 0.22. I'm fine with the breaking change, but it seems that doing this properly either requires turning on allowJs so that TS doesn't transpile the import into Promise.resolve().then(() => require(...)) (ew), adding a dependency (double ew), or switching to emitting ESM (which is a rats nest that I don't want to get into right now)

If someone wants to use ESM plugins badly enough, and sends a PR, I'll definitely look at it, but this isn't as straightforward as I thought at first.

@cspotcode
Copy link
Contributor Author

cspotcode commented Aug 20, 2021 via email

@Gerrit0 Gerrit0 added this to To do in Guides (#247) - v0.24 via automation Jul 1, 2022
@Gerrit0 Gerrit0 moved this from To do to Done in Guides (#247) - v0.24 Jul 25, 2022
@Gerrit0 Gerrit0 removed the help wanted Contributions are especially encouraged label Jul 31, 2022
@Gerrit0 Gerrit0 added this to the v0.24 milestone Mar 11, 2023
@Gerrit0 Gerrit0 closed this as completed in 3d63da6 Apr 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improved functionality
Projects
No open projects
Development

No branches or pull requests

2 participants