Skip to content

Commit

Permalink
fix: Do not crash when typedoc "disableSources" option is true (this …
Browse files Browse the repository at this point in the history
…turns off automatic module name feature)

Fixes #507
  • Loading branch information
christopherthielen committed Dec 20, 2020
1 parent a52a58a commit 8cfb30c
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions typedoc-plugin-external-module-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ export class ExternalModuleNamePlugin extends ConverterComponent {

/** Process options */
const option = this.application.options.getValue('disableAutoModuleName');
this.disableAutoModuleName = option === 'true' || option === true;
let disableSources: boolean;
try {
disableSources = this.application.options.getValue('disableSources');
} catch (ignored) {}
this.disableAutoModuleName = option === 'true' || option === true || disableSources === true;
}

/**
Expand All @@ -126,12 +130,17 @@ export class ExternalModuleNamePlugin extends ConverterComponent {
const preferred = /@preferred/.exec(comment) != null;
// Look for @module
const [, match] = /@module\s+([\w\u4e00-\u9fa5\.\-_/@"]+)/.exec(comment) || [];
// Make a guess based on enclosing directory structure
const filename = reflection.sources[0].file.fullFileName;

let guess = this.disableAutoModuleName ? undefined : path.dirname(path.relative(this.baseDir, filename));
if (guess === '.') {
guess = 'root';
let guess: string;
let filename: string;
if (!this.disableAutoModuleName) {
// Make a guess based on enclosing directory structure
filename = reflection.sources[0].file.fullFileName;
guess = this.disableAutoModuleName ? undefined : path.dirname(path.relative(this.baseDir, filename));

if (guess === '.') {
guess = 'root';
}
}

// Try the custom function
Expand Down

0 comments on commit 8cfb30c

Please sign in to comment.