Skip to content

Commit

Permalink
fix: Support resolveJsonModule
Browse files Browse the repository at this point in the history
Closes #1323.
  • Loading branch information
Gerrit0 committed Jun 28, 2020
1 parent e553af2 commit d704709
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion scripts/rebuild_specs.js
Expand Up @@ -21,7 +21,8 @@ app.bootstrap({
],
name: 'typedoc',
excludeExternals: true,
disableSources: true
disableSources: true,
resolveJsonModule: true
});

// Note that this uses the test files in dist, not in src, this is important since
Expand Down
3 changes: 3 additions & 0 deletions src/lib/application.ts
Expand Up @@ -281,6 +281,7 @@ export class Application extends ChildableComponent<
return exclude.some(mm => mm.match(fileName));
}

const includeJson = this.options.getCompilerOptions().resolveJsonModule;
const supportedFileRegex = this.options.getCompilerOptions().allowJs ? /\.[tj]sx?$/ : /\.tsx?$/;
function add(file: string, entryPoint: boolean) {
let stats: FS.Stats;
Expand All @@ -305,6 +306,8 @@ export class Application extends ChildableComponent<
});
} else if (supportedFileRegex.test(file)) {
files.push(file);
} else if (includeJson && file.endsWith('.json')) {
files.push(file);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/lib/converter/converter.ts
Expand Up @@ -250,7 +250,9 @@ export class Converter extends ChildableComponent<Application, ConverterComponen
* @param fileNames Array of the file names that should be compiled.
*/
convert(fileNames: string[]): ConverterResult {
const normalizedFiles = fileNames.map(normalizePath);
// JSON files should never result in extra members in the documentation, but need to be included so that TS
// can find them.
const normalizedFiles = fileNames.map(normalizePath).filter(path => !path.endsWith('.json'));

const program = ts.createProgram(normalizedFiles, this.application.options.getCompilerOptions());
const checker = program.getTypeChecker();
Expand Down
3 changes: 2 additions & 1 deletion src/test/converter.test.ts
Expand Up @@ -20,7 +20,8 @@ describe('Converter', function() {
name: 'typedoc',
ignoreCompilerErrors: true,
excludeExternals: true,
disableSources: true
disableSources: true,
resolveJsonModule: true
});

const checks: [string, () => void, () => void][] = [
Expand Down
5 changes: 5 additions & 0 deletions src/test/converter/exports/export.ts
Expand Up @@ -11,3 +11,8 @@ function add(x: number, y: number) {
// Note that this will show up in the docs, not the default function from mod2.
// export * from './mod2' does *not* re-export the default function.
export default function (a: number) {}

import * as x from './test.json';

/** @hidden */
const x2: string = x.issue;
3 changes: 3 additions & 0 deletions src/test/converter/exports/test.json
@@ -0,0 +1,3 @@
{
"issue": "https://github.com/TypeStrong/typedoc/issues/1323"
}

0 comments on commit d704709

Please sign in to comment.