From 64a93236ea6fb720e98e10e703716fa299d9d86d Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Tue, 14 Jan 2020 19:30:51 -0700 Subject: [PATCH] fix: Circular dependencies Closes #1172 --- src/index.ts | 5 +---- src/lib/converter/index.ts | 2 -- src/lib/converter/nodes/block.ts | 6 +----- src/lib/converter/nodes/export.ts | 2 +- src/lib/converter/nodes/index.ts | 2 +- src/lib/utils/index.ts | 17 +++++++++++++++-- src/lib/utils/options/declaration.ts | 5 ++++- src/lib/utils/options/index.ts | 1 + src/lib/utils/options/sources/decorator.ts | 18 +++++++++++++++--- src/lib/utils/options/sources/typedoc.ts | 3 +-- src/test/converter.test.ts | 3 +-- 11 files changed, 41 insertions(+), 23 deletions(-) diff --git a/src/index.ts b/src/index.ts index 7e00ee89c..1b2218567 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,10 +12,6 @@ export { DefaultTheme } from './lib/output/themes/DefaultTheme'; export { NavigationItem } from './lib/output/models/NavigationItem'; export { UrlMapping } from './lib/output/models/UrlMapping'; -export { - SourceFileMode -} from './lib/converter'; - export { Option, // deprecated BindOption, @@ -29,6 +25,7 @@ export { TypeDocAndTSOptions, TypeDocOptionMap, KeyToDeclaration, + SourceFileMode, TSConfigReader, TypeDocReader, diff --git a/src/lib/converter/index.ts b/src/lib/converter/index.ts index 7f9e43756..a6421efb3 100644 --- a/src/lib/converter/index.ts +++ b/src/lib/converter/index.ts @@ -3,8 +3,6 @@ export { Converter } from './converter'; export { convertDefaultValue, convertExpression } from './convert-expression'; -export { SourceFileMode } from './nodes'; - import './nodes/index'; import './types/index'; import './plugins/index'; diff --git a/src/lib/converter/nodes/block.ts b/src/lib/converter/nodes/block.ts index 2b1e386df..bd3581b75 100644 --- a/src/lib/converter/nodes/block.ts +++ b/src/lib/converter/nodes/block.ts @@ -4,7 +4,7 @@ import { Reflection, ReflectionKind, ReflectionFlag } from '../../models/index'; import { createDeclaration } from '../factories/index'; import { Context } from '../context'; import { Component, ConverterNodeComponent } from '../components'; -import { BindOption } from '../../utils'; +import { BindOption, SourceFileMode } from '../../utils'; const preferred: ts.SyntaxKind[] = [ ts.SyntaxKind.ClassDeclaration, @@ -12,10 +12,6 @@ const preferred: ts.SyntaxKind[] = [ ts.SyntaxKind.EnumDeclaration ]; -export enum SourceFileMode { - File, Modules -} - @Component({name: 'node:block'}) export class BlockConverter extends ConverterNodeComponent { @BindOption('mode') diff --git a/src/lib/converter/nodes/export.ts b/src/lib/converter/nodes/export.ts index 19dc0f90e..f48cfc3c4 100644 --- a/src/lib/converter/nodes/export.ts +++ b/src/lib/converter/nodes/export.ts @@ -4,7 +4,7 @@ import { Reflection, ReflectionFlag, DeclarationReflection, ContainerReflection import { Context } from '../context'; import { Component, ConverterNodeComponent } from '../components'; import { createReferenceReflection } from '../factories/reference'; -import { SourceFileMode } from './block'; +import { SourceFileMode } from '../../utils'; @Component({name: 'node:export'}) export class ExportConverter extends ConverterNodeComponent { diff --git a/src/lib/converter/nodes/index.ts b/src/lib/converter/nodes/index.ts index e67fdab23..bdf4e681f 100644 --- a/src/lib/converter/nodes/index.ts +++ b/src/lib/converter/nodes/index.ts @@ -1,6 +1,6 @@ export { AccessorConverter } from './accessor'; export { AliasConverter } from './alias'; -export { BlockConverter, SourceFileMode } from './block'; +export { BlockConverter } from './block'; export { ClassConverter } from './class'; export { ConstructorConverter } from './constructor'; export { EnumConverter } from './enum'; diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index 8ee093b44..ff990e093 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -1,8 +1,21 @@ -export { Option, Options, ParameterType, ParameterHint, ParameterScope, BindOption } from './options'; +export { + Option, + Options, + ParameterType, + ParameterHint, + ParameterScope, + BindOption, + SourceFileMode +} from './options'; export { insertPrioritySorted, removeIfPresent } from './array'; export { Component, AbstractComponent, ChildableComponent } from './component'; export { Event, EventDispatcher } from './events'; -export { normalizePath, directoryExists, ensureDirectoriesExist, writeFile } from './fs'; +export { + normalizePath, + directoryExists, + ensureDirectoriesExist, + writeFile +} from './fs'; export { Logger, LogLevel, ConsoleLogger, CallbackLogger } from './loggers'; export { PluginHost } from './plugins'; export { Result } from './result'; diff --git a/src/lib/utils/options/declaration.ts b/src/lib/utils/options/declaration.ts index 984075525..15effbda4 100644 --- a/src/lib/utils/options/declaration.ts +++ b/src/lib/utils/options/declaration.ts @@ -1,7 +1,6 @@ import * as _ from 'lodash'; import { CompilerOptions } from 'typescript'; import { Result } from '../result'; -import { SourceFileMode } from '../../converter/nodes/block'; import { IgnoredTsOptionKeys } from './sources/typescript'; /** @@ -31,6 +30,10 @@ type KnownKeys = { export type TypeDocAndTSOptions = TypeDocOptions & Pick, IgnoredTsOptionKeys>>; +export enum SourceFileMode { + File, Modules +} + /** * Describes all TypeDoc options. Used internally to provide better types when fetching options. * External consumers should likely use either [[TypeDocAndTSOptions]] or [[TypeDocOptions]]. diff --git a/src/lib/utils/options/index.ts b/src/lib/utils/options/index.ts index 3a7ffdccd..92275d7b3 100644 --- a/src/lib/utils/options/index.ts +++ b/src/lib/utils/options/index.ts @@ -4,6 +4,7 @@ export { ArgumentsReader, TypeDocReader, TSConfigReader } from './readers'; export { TypeDocOptions, TypeDocAndTSOptions, + SourceFileMode, TypeDocOptionMap, KeyToDeclaration, diff --git a/src/lib/utils/options/sources/decorator.ts b/src/lib/utils/options/sources/decorator.ts index 0a255eb2a..b8b4b990a 100644 --- a/src/lib/utils/options/sources/decorator.ts +++ b/src/lib/utils/options/sources/decorator.ts @@ -1,6 +1,6 @@ import { DeclarationOption } from '../declaration'; import { Options } from '..'; -import { BindOption } from '../options'; +import { Application } from '../../../application'; const declared: DeclarationOption[] = []; @@ -14,10 +14,22 @@ export function addDecoratedOptions(options: Options) { * @deprecated Options should be declared on the options object. Will be removed in 0.17. * @param option */ -export function Option(option: DeclarationOption): PropertyDecorator { +export function Option(option: DeclarationOption) { console.warn('The @Option decorator is deprecated and will be removed in v0.17.'); console.warn(` (Used to register ${option.name})`); declared.push(option); - return BindOption(option.name) as any; + return function(target: { application: Application } | { options: Options }, key: PropertyKey) { + Object.defineProperty(target, key, { + get(this: { application: Application } | { options: Options }) { + if ('options' in this) { + return this.options.getValue(name); + } else { + return this.application.options.getValue(name); + } + }, + enumerable: true, + configurable: true + }); + }; } diff --git a/src/lib/utils/options/sources/typedoc.ts b/src/lib/utils/options/sources/typedoc.ts index d9afbb34a..b85a2e5b9 100644 --- a/src/lib/utils/options/sources/typedoc.ts +++ b/src/lib/utils/options/sources/typedoc.ts @@ -1,6 +1,5 @@ import { Options } from '..'; -import { ParameterType, ParameterHint } from '../declaration'; -import { SourceFileMode } from '../../../..'; +import { ParameterType, ParameterHint, SourceFileMode } from '../declaration'; export function addTypeDocOptions(options: Options) { options.addDeclaration({ diff --git a/src/test/converter.test.ts b/src/test/converter.test.ts index 9bc8dd909..dac3ecd62 100644 --- a/src/test/converter.test.ts +++ b/src/test/converter.test.ts @@ -2,7 +2,6 @@ import { Application, resetReflectionID, normalizePath, ProjectReflection } from import * as FS from 'fs'; import * as Path from 'path'; import { deepStrictEqual as equal, ok } from 'assert'; -import { SourceFileMode } from '../lib/converter/nodes/block'; import { ScriptTarget, ModuleKind, JsxEmit } from 'typescript'; import json = require('./converter/class/specs.json'); @@ -12,7 +11,7 @@ describe('Converter', function() { const base = Path.join(__dirname, 'converter'); const app = new Application(); app.bootstrap({ - mode: SourceFileMode.Modules, + mode: 'modules', logger: 'none', target: ScriptTarget.ES5, module: ModuleKind.CommonJS,