Skip to content

Commit 9b665ff

Browse files
committed
Expose control methods for deferred conversion
Ref: Gerrit0/typedoc-plugin-missing-exports#31
1 parent 00fb078 commit 9b665ff

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ title: Changelog
88

99
- The `TypeDocOptions` interface now marks options as optional so it no longer has to be wrapped in `Partial`
1010
for use in config files, #2901.
11+
- API: Expose control methods for deferred conversion for plugin use (typedoc-plugin-missing-exports)
1112

1213
### Bug Fixes
1314

src/lib/converter/converter.ts

+29-12
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,35 @@ export class Converter extends AbstractComponent<Application, ConverterEvents> {
451451
}
452452
}
453453

454+
/**
455+
* Permit deferred conversion steps to take place. Until this is called, {@link deferConversion}
456+
* will throw if used.
457+
* @since 0.28.1
458+
*/
459+
permitDeferredConversion(): void {
460+
ok(!this._deferPermitted, "Attempted to allow deferred conversion when already permitted");
461+
this._deferPermitted = true;
462+
}
463+
464+
/**
465+
* Finalize deferred conversion, must be called by the caller of {@link permitDeferredConversion}
466+
* @since 0.28.1
467+
*/
468+
finalizeDeferredConversion(): void {
469+
this.application.logger.verbose(`Have ${this._defer.length} initial deferred tasks`);
470+
let count = 0;
471+
while (this._defer.length) {
472+
++count;
473+
const first = this._defer.shift()!;
474+
first();
475+
}
476+
this.application.logger.verbose(`Ran ${count} total deferred tasks`);
477+
this._deferPermitted = false;
478+
}
479+
454480
/**
455481
* Defer a conversion step until later. This may only be called during conversion.
482+
* @since 0.28.0
456483
*/
457484
deferConversion(cb: () => void): void {
458485
ok(this._deferPermitted, "Attempted to defer conversion when not permitted");
@@ -469,9 +496,7 @@ export class Converter extends AbstractComponent<Application, ConverterEvents> {
469496
entryPoints: readonly DocumentationEntryPoint[],
470497
context: Context,
471498
) {
472-
ok(!this._deferPermitted);
473-
this._deferPermitted = true;
474-
499+
this.permitDeferredConversion();
475500
let createModuleReflections = entryPoints.length > 1;
476501
if (!createModuleReflections) {
477502
const opts = this.application.options;
@@ -495,15 +520,7 @@ export class Converter extends AbstractComponent<Application, ConverterEvents> {
495520
this.convertExports(entryContext, entry, createModuleReflections);
496521
}
497522

498-
this.application.logger.verbose(`Have ${this._defer.length} initial deferred tasks`);
499-
let count = 0;
500-
while (this._defer.length) {
501-
++count;
502-
const first = this._defer.shift()!;
503-
first();
504-
}
505-
this.application.logger.verbose(`Ran ${count} total deferred tasks`);
506-
this._deferPermitted = false;
523+
this.finalizeDeferredConversion();
507524
}
508525

509526
private convertExports(

0 commit comments

Comments
 (0)