Gerrit0 / typedoc-plugin-missing-exports

MIT License
44 stars 4 forks source link

Plugin throws Error ("cannot be loaded multiple times") upon bootstrapping TypeDoc multiple times #21

Closed Maluscat closed 10 months ago

Maluscat commented 10 months ago

Hi!

I have written a script that calls the TypeDoc bootstrapper (basically the main() function described in the docs) multiple times in a row in order to take independent entry points and generate their respective output. However, when multiple bootstrapWithPlugins calls have specified typedoc-plugin-missing-exports as one of their plugins, any call after the first will raise this error.

Is this the desired behavior?

I would assume that every call to TypeDoc.Application.bootstrapWithPlugins initializes a (more or less) fresh state, in which case this plugin's hasMonkeyPatched global variable should be scoped to a single bootstrap? Removing the check altogether worked in my case, at least.

I know that TypeDoc is not made to generate multiple outputs in a single project, just wondering if this error is preventing that on purpose (because I don't care about the minor implications that come with generating multiple configs)!

Gerrit0 commented 10 months ago

In general, plugins should support being loaded multiple times. This plugin is an exception because of this patching. If this plugin is loaded multiple times, each load will increase the depth of reference tracking done.

I don't recall why I went with this approach rather than not replacing the method multiple times, and moving the tracking sets outside into the module scope.... but it was intentional at the time. There's likely room for improvement here, PR welcome if you'd like to give it a shot!

Maluscat commented 10 months ago

I see, thanks for the explainer, I might give it a try when I've got time! In theory, could it be resolved by restoring the patch to the original createSymbolReference upon the end of the conversion?

Still gonna close this issue tho, since it is the expected behavior – I just didn't know whether it was supposed to throw on multiple bootstrapped instances as well :)

Gerrit0 commented 9 months ago

Restoring the patch when conversion ends won't work unfortunately because conversion may happen multiple times if --watch is used or the packages entryPointStrategy is used