typedoc 0.23.25 → 0.24.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/bin/typedoc +1 -130
  2. package/dist/index.d.ts +3 -4
  3. package/dist/index.js +15 -5
  4. package/dist/lib/application-events.d.ts +1 -0
  5. package/dist/lib/application-events.js +1 -0
  6. package/dist/lib/application.d.ts +26 -10
  7. package/dist/lib/application.js +138 -65
  8. package/dist/lib/cli.d.ts +1 -0
  9. package/dist/lib/cli.js +129 -0
  10. package/dist/lib/converter/comments/declarationReference.d.ts +1 -1
  11. package/dist/lib/converter/comments/declarationReferenceResolver.js +11 -5
  12. package/dist/lib/converter/comments/discovery.d.ts +1 -1
  13. package/dist/lib/converter/comments/discovery.js +96 -76
  14. package/dist/lib/converter/comments/index.d.ts +1 -1
  15. package/dist/lib/converter/comments/index.js +37 -17
  16. package/dist/lib/converter/comments/linkResolver.d.ts +2 -3
  17. package/dist/lib/converter/comments/linkResolver.js +37 -132
  18. package/dist/lib/converter/context.d.ts +1 -1
  19. package/dist/lib/converter/context.js +27 -14
  20. package/dist/lib/converter/convert-expression.d.ts +1 -1
  21. package/dist/lib/converter/convert-expression.js +35 -15
  22. package/dist/lib/converter/converter.d.ts +1 -1
  23. package/dist/lib/converter/converter.js +35 -23
  24. package/dist/lib/converter/factories/index-signature.d.ts +1 -1
  25. package/dist/lib/converter/factories/index-signature.js +26 -3
  26. package/dist/lib/converter/factories/signature.d.ts +2 -2
  27. package/dist/lib/converter/factories/signature.js +76 -52
  28. package/dist/lib/converter/jsdoc.d.ts +1 -1
  29. package/dist/lib/converter/jsdoc.js +39 -17
  30. package/dist/lib/converter/plugins/CommentPlugin.d.ts +0 -2
  31. package/dist/lib/converter/plugins/CommentPlugin.js +7 -28
  32. package/dist/lib/converter/plugins/GroupPlugin.d.ts +1 -39
  33. package/dist/lib/converter/plugins/GroupPlugin.js +3 -61
  34. package/dist/lib/converter/plugins/ImplementsPlugin.d.ts +1 -4
  35. package/dist/lib/converter/plugins/ImplementsPlugin.js +49 -28
  36. package/dist/lib/converter/plugins/InheritDocPlugin.d.ts +0 -3
  37. package/dist/lib/converter/plugins/InheritDocPlugin.js +6 -7
  38. package/dist/lib/converter/plugins/LinkResolverPlugin.d.ts +2 -3
  39. package/dist/lib/converter/plugins/LinkResolverPlugin.js +12 -10
  40. package/dist/lib/converter/plugins/PackagePlugin.d.ts +5 -14
  41. package/dist/lib/converter/plugins/PackagePlugin.js +44 -56
  42. package/dist/lib/converter/plugins/SourcePlugin.js +31 -6
  43. package/dist/lib/converter/plugins/TypePlugin.d.ts +4 -10
  44. package/dist/lib/converter/plugins/TypePlugin.js +23 -13
  45. package/dist/lib/converter/symbols.d.ts +1 -1
  46. package/dist/lib/converter/symbols.js +153 -132
  47. package/dist/lib/converter/types.d.ts +1 -1
  48. package/dist/lib/converter/types.js +121 -95
  49. package/dist/lib/converter/utils/nodes.d.ts +1 -1
  50. package/dist/lib/converter/utils/nodes.js +24 -4
  51. package/dist/lib/converter/utils/symbols.d.ts +1 -1
  52. package/dist/lib/converter/utils/symbols.js +24 -4
  53. package/dist/lib/models/ReflectionCategory.d.ts +2 -1
  54. package/dist/lib/models/ReflectionCategory.js +12 -0
  55. package/dist/lib/models/ReflectionGroup.d.ts +3 -2
  56. package/dist/lib/models/ReflectionGroup.js +20 -0
  57. package/dist/lib/models/comments/comment.d.ts +12 -1
  58. package/dist/lib/models/comments/comment.js +80 -17
  59. package/dist/lib/models/reflections/ReflectionSymbolId.d.ts +29 -0
  60. package/dist/lib/models/reflections/ReflectionSymbolId.js +94 -0
  61. package/dist/lib/models/reflections/abstract.d.ts +12 -37
  62. package/dist/lib/models/reflections/abstract.js +27 -35
  63. package/dist/lib/models/reflections/container.d.ts +6 -10
  64. package/dist/lib/models/reflections/container.js +8 -1
  65. package/dist/lib/models/reflections/declaration.d.ts +19 -4
  66. package/dist/lib/models/reflections/declaration.js +54 -1
  67. package/dist/lib/models/reflections/index.d.ts +2 -0
  68. package/dist/lib/models/reflections/index.js +3 -1
  69. package/dist/lib/models/reflections/kind.d.ts +15 -1
  70. package/dist/lib/models/reflections/kind.js +43 -1
  71. package/dist/lib/models/reflections/parameter.d.ts +3 -1
  72. package/dist/lib/models/reflections/parameter.js +10 -0
  73. package/dist/lib/models/reflections/project.d.ts +32 -5
  74. package/dist/lib/models/reflections/project.js +84 -20
  75. package/dist/lib/models/reflections/reference.d.ts +5 -9
  76. package/dist/lib/models/reflections/reference.js +13 -29
  77. package/dist/lib/models/reflections/signature.d.ts +8 -1
  78. package/dist/lib/models/reflections/signature.js +14 -0
  79. package/dist/lib/models/reflections/type-parameter.d.ts +7 -4
  80. package/dist/lib/models/reflections/type-parameter.js +9 -3
  81. package/dist/lib/models/reflections/variant.d.ts +18 -0
  82. package/dist/lib/models/reflections/variant.js +2 -0
  83. package/dist/lib/models/sources/file.d.ts +2 -0
  84. package/dist/lib/models/sources/file.js +3 -0
  85. package/dist/lib/models/types.d.ts +24 -20
  86. package/dist/lib/models/types.js +132 -33
  87. package/dist/lib/output/plugins/JavascriptIndexPlugin.js +3 -7
  88. package/dist/lib/output/renderer.d.ts +21 -14
  89. package/dist/lib/output/renderer.js +25 -25
  90. package/dist/lib/output/themes/MarkedPlugin.js +2 -3
  91. package/dist/lib/output/themes/default/DefaultTheme.d.ts +2 -20
  92. package/dist/lib/output/themes/default/DefaultTheme.js +4 -75
  93. package/dist/lib/output/themes/default/DefaultThemeRenderContext.d.ts +9 -8
  94. package/dist/lib/output/themes/default/DefaultThemeRenderContext.js +54 -0
  95. package/dist/lib/output/themes/default/partials/header.js +2 -5
  96. package/dist/lib/output/themes/default/partials/index.js +2 -2
  97. package/dist/lib/output/themes/default/partials/member.getterSetter.d.ts +2 -2
  98. package/dist/lib/output/themes/default/partials/member.getterSetter.js +4 -1
  99. package/dist/lib/output/themes/default/partials/member.js +1 -1
  100. package/dist/lib/output/themes/default/partials/member.signatures.js +2 -1
  101. package/dist/lib/output/themes/default/partials/members.d.ts +1 -1
  102. package/dist/lib/output/themes/default/partials/members.js +3 -1
  103. package/dist/lib/output/themes/default/partials/navigation.js +6 -4
  104. package/dist/lib/output/themes/default/partials/parameter.js +1 -1
  105. package/dist/lib/output/themes/default/partials/type.js +4 -4
  106. package/dist/lib/output/themes/default/templates/reflection.js +1 -1
  107. package/dist/lib/output/themes/lib.d.ts +1 -0
  108. package/dist/lib/output/themes/lib.js +13 -3
  109. package/dist/lib/serialization/deserializer.d.ts +54 -0
  110. package/dist/lib/serialization/deserializer.js +212 -0
  111. package/dist/lib/serialization/events.d.ts +0 -15
  112. package/dist/lib/serialization/index.d.ts +2 -3
  113. package/dist/lib/serialization/index.js +4 -3
  114. package/dist/lib/serialization/schema.d.ts +23 -17
  115. package/dist/lib/serialization/serializer.d.ts +5 -5
  116. package/dist/lib/serialization/serializer.js +4 -15
  117. package/dist/lib/utils/array.d.ts +0 -1
  118. package/dist/lib/utils/array.js +1 -2
  119. package/dist/lib/utils/entry-point.d.ts +15 -4
  120. package/dist/lib/utils/entry-point.js +45 -28
  121. package/dist/lib/utils/enum.d.ts +4 -1
  122. package/dist/lib/utils/enum.js +2 -3
  123. package/dist/lib/utils/fs.d.ts +3 -1
  124. package/dist/lib/utils/fs.js +36 -73
  125. package/dist/lib/utils/index.d.ts +4 -3
  126. package/dist/lib/utils/index.js +3 -3
  127. package/dist/lib/utils/loggers.d.ts +5 -26
  128. package/dist/lib/utils/loggers.js +38 -42
  129. package/dist/lib/utils/map.d.ts +17 -0
  130. package/dist/lib/utils/map.js +49 -1
  131. package/dist/lib/utils/options/declaration.d.ts +20 -6
  132. package/dist/lib/utils/options/help.js +1 -1
  133. package/dist/lib/utils/options/options.d.ts +27 -18
  134. package/dist/lib/utils/options/options.js +68 -14
  135. package/dist/lib/utils/options/readers/arguments.d.ts +2 -1
  136. package/dist/lib/utils/options/readers/arguments.js +9 -2
  137. package/dist/lib/utils/options/readers/tsconfig.d.ts +3 -7
  138. package/dist/lib/utils/options/readers/tsconfig.js +35 -36
  139. package/dist/lib/utils/options/readers/typedoc.d.ts +4 -5
  140. package/dist/lib/utils/options/readers/typedoc.js +9 -21
  141. package/dist/lib/utils/options/sources/typedoc.js +18 -64
  142. package/dist/lib/utils/package-manifest.d.ts +1 -1
  143. package/dist/lib/utils/package-manifest.js +1 -2
  144. package/dist/lib/utils/paths.d.ts +2 -2
  145. package/dist/lib/utils/paths.js +2 -0
  146. package/dist/lib/utils/plugins.d.ts +1 -2
  147. package/dist/lib/utils/plugins.js +22 -106
  148. package/dist/lib/utils/sort.d.ts +1 -1
  149. package/dist/lib/utils/sort.js +8 -11
  150. package/dist/lib/utils/tsconfig.d.ts +4 -0
  151. package/dist/lib/utils/tsconfig.js +36 -0
  152. package/dist/lib/utils/tsutils.d.ts +3 -2
  153. package/dist/lib/utils/tsutils.js +46 -12
  154. package/dist/lib/validation/documentation.d.ts +1 -1
  155. package/dist/lib/validation/documentation.js +5 -16
  156. package/dist/lib/validation/exports.js +18 -21
  157. package/dist/lib/validation/links.js +1 -1
  158. package/package.json +18 -19
  159. package/static/main.js +0 -54
@@ -3,3 +3,20 @@ export declare class DefaultMap<K, V> extends Map<K, V> {
3
3
  constructor(creator: () => V);
4
4
  get(key: K): V;
5
5
  }
6
+ export declare class StableKeyMap<K extends {
7
+ getStableKey(): string;
8
+ }, V> implements Map<K, V> {
9
+ [Symbol.toStringTag]: string;
10
+ private impl;
11
+ get size(): number;
12
+ set(key: K, value: V): this;
13
+ get(key: K): V | undefined;
14
+ has(key: K): boolean;
15
+ clear(): void;
16
+ delete(key: K): boolean;
17
+ forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void;
18
+ entries(): IterableIterator<[K, V]>;
19
+ keys(): IterableIterator<K>;
20
+ values(): IterableIterator<V>;
21
+ [Symbol.iterator](): IterableIterator<[K, V]>;
22
+ }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
+ var _a;
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DefaultMap = void 0;
4
+ exports.StableKeyMap = exports.DefaultMap = void 0;
4
5
  class DefaultMap extends Map {
5
6
  constructor(creator) {
6
7
  super();
@@ -17,3 +18,50 @@ class DefaultMap extends Map {
17
18
  }
18
19
  }
19
20
  exports.DefaultMap = DefaultMap;
21
+ class StableKeyMap {
22
+ constructor() {
23
+ this[_a] = "StableKeyMap";
24
+ this.impl = new Map();
25
+ }
26
+ get size() {
27
+ return this.impl.size;
28
+ }
29
+ set(key, value) {
30
+ this.impl.set(key.getStableKey(), [key, value]);
31
+ return this;
32
+ }
33
+ get(key) {
34
+ return this.impl.get(key.getStableKey())?.[1];
35
+ }
36
+ has(key) {
37
+ return this.get(key) != null;
38
+ }
39
+ clear() {
40
+ this.impl.clear();
41
+ }
42
+ delete(key) {
43
+ return this.impl.delete(key.getStableKey());
44
+ }
45
+ forEach(callbackfn, thisArg) {
46
+ for (const [k, v] of this.entries()) {
47
+ callbackfn.apply(thisArg, [v, k, this]);
48
+ }
49
+ }
50
+ entries() {
51
+ return this.impl.values();
52
+ }
53
+ *keys() {
54
+ for (const [k] of this.entries()) {
55
+ yield k;
56
+ }
57
+ }
58
+ *values() {
59
+ for (const [, v] of this.entries()) {
60
+ yield v;
61
+ }
62
+ }
63
+ [(_a = Symbol.toStringTag, Symbol.iterator)]() {
64
+ return this.entries();
65
+ }
66
+ }
67
+ exports.StableKeyMap = StableKeyMap;
@@ -10,7 +10,7 @@ export declare const EmitStrategy: {
10
10
  readonly none: "none";
11
11
  };
12
12
  /** @hidden */
13
- export type EmitStrategy = (typeof EmitStrategy)[keyof typeof EmitStrategy];
13
+ export type EmitStrategy = typeof EmitStrategy[keyof typeof EmitStrategy];
14
14
  /**
15
15
  * Determines how TypeDoc searches for comments.
16
16
  * @enum
@@ -21,7 +21,7 @@ export declare const CommentStyle: {
21
21
  readonly Line: "line";
22
22
  readonly All: "all";
23
23
  };
24
- export type CommentStyle = (typeof CommentStyle)[keyof typeof CommentStyle];
24
+ export type CommentStyle = typeof CommentStyle[keyof typeof CommentStyle];
25
25
  /**
26
26
  * An interface describing all TypeDoc specific options. Generated from a
27
27
  * map which contains more information about each option for better types when
@@ -41,6 +41,17 @@ export type TypeDocOptionValues = {
41
41
  /**
42
42
  * Describes all TypeDoc options. Used internally to provide better types when fetching options.
43
43
  * External consumers should likely use {@link TypeDocOptions} instead.
44
+ *
45
+ * If writing a plugin, you may find it useful to use declaration merging to add your options to this interface
46
+ * so that you have autocomplete when using `app.options.getValue`.
47
+ *
48
+ * ```ts
49
+ * declare module "typedoc" {
50
+ * export interface TypeDocOptionMap {
51
+ * pluginOption: string[];
52
+ * }
53
+ * }
54
+ * ```
44
55
  */
45
56
  export interface TypeDocOptionMap {
46
57
  options: string;
@@ -52,7 +63,6 @@ export interface TypeDocOptionMap {
52
63
  externalPattern: string[];
53
64
  excludeExternals: boolean;
54
65
  excludeNotDocumented: boolean;
55
- excludeNotDocumentedKinds: Array<keyof typeof ReflectionKind>;
56
66
  excludeInternal: boolean;
57
67
  excludePrivate: boolean;
58
68
  excludeProtected: boolean;
@@ -95,7 +105,7 @@ export interface TypeDocOptionMap {
95
105
  defaultCategory: string;
96
106
  categoryOrder: string[];
97
107
  sort: SortStrategy[];
98
- kindSortOrder: Array<keyof typeof ReflectionKind>;
108
+ kindSortOrder: ReflectionKind.KindString[];
99
109
  visibilityFilters: ManuallyValidatedOption<{
100
110
  protected?: boolean;
101
111
  private?: boolean;
@@ -112,12 +122,11 @@ export interface TypeDocOptionMap {
112
122
  version: boolean;
113
123
  showConfig: boolean;
114
124
  plugin: string[];
115
- logger: unknown;
116
125
  logLevel: typeof LogLevel;
117
126
  treatWarningsAsErrors: boolean;
118
127
  intentionallyNotExported: string[];
119
128
  validation: ValidationOptions;
120
- requiredToBeDocumented: (keyof typeof ReflectionKind)[];
129
+ requiredToBeDocumented: ReflectionKind.KindString[];
121
130
  }
122
131
  /**
123
132
  * Wrapper type for values in TypeDocOptionMap which are represented with an unknown option type, but
@@ -199,6 +208,11 @@ export interface DeclarationOptionBase {
199
208
  * If not set, the type will be a string.
200
209
  */
201
210
  type?: ParameterType;
211
+ /**
212
+ * If set, this option will be omitted from `--help`, and attempting to specify it on the command
213
+ * line will produce an error.
214
+ */
215
+ configFileOnly?: boolean;
202
216
  }
203
217
  export interface StringDeclarationOption extends DeclarationOptionBase {
204
218
  /**
@@ -21,7 +21,7 @@ function getParameterHelp(options) {
21
21
  const helps = [];
22
22
  let margin = 0;
23
23
  for (const parameter of parameters) {
24
- if (!parameter.help) {
24
+ if (!parameter.help || parameter.configFileOnly) {
25
25
  continue;
26
26
  }
27
27
  let name = " --" + parameter.name;
@@ -9,35 +9,36 @@ import { DeclarationOption, KeyToDeclaration, TypeDocOptionMap, TypeDocOptions,
9
9
  */
10
10
  export interface OptionsReader {
11
11
  /**
12
- * Readers will be processed according to their priority.
13
- * A higher priority indicates that the reader should be called *later* so that
14
- * it can override options set by lower priority readers.
12
+ * Readers will be processed according to their orders.
13
+ * A higher order indicates that the reader should be called *later*.
15
14
  *
16
15
  * Note that to preserve expected behavior, the argv reader must have both the lowest
17
- * priority so that it may set the location of config files used by other readers and
18
- * the highest priority so that it can override settings from lower priority readers.
19
- *
20
- * Note: In 0.23. `priority` will be renamed to `order`, with the same meaning
16
+ * order so that it may set the location of config files used by other readers and
17
+ * the highest order so that it can override settings from lower order readers.
21
18
  */
22
- priority: number;
19
+ readonly order: number;
23
20
  /**
24
21
  * The name of this reader so that it may be removed by plugins without the plugin
25
22
  * accessing the instance performing the read. Multiple readers may have the same
26
23
  * name.
27
24
  */
28
- name: string;
25
+ readonly name: string;
26
+ /**
27
+ * Flag to indicate that this reader should be included in sub-options objects created
28
+ * to read options for packages mode.
29
+ */
30
+ readonly supportsPackages: boolean;
29
31
  /**
30
32
  * Read options from the reader's source and place them in the options parameter.
31
33
  * Options without a declared name may be treated as if they were declared with type
32
34
  * {@link ParameterType.Mixed}. Options which have been declared must be converted to the
33
35
  * correct type. As an alternative to doing this conversion in the reader,
34
36
  * the reader may use {@link Options.setValue}, which will correctly convert values.
35
- * @param options
36
- * @param compilerOptions
37
37
  * @param container the options container that provides declarations
38
- * @param logger
38
+ * @param logger logger to be used to report errors
39
+ * @param cwd the directory which should be treated as the current working directory for option file discovery
39
40
  */
40
- read(container: Options, logger: Logger): void;
41
+ read(container: Options, logger: Logger, cwd: string): void;
41
42
  }
42
43
  /**
43
44
  * Maintains a collection of option declarations split into TypeDoc options
@@ -69,6 +70,10 @@ export declare class Options {
69
70
  private _projectReferences;
70
71
  private _logger;
71
72
  constructor(logger: Logger);
73
+ /**
74
+ * Clones the options, intended for use in packages mode.
75
+ */
76
+ copyForPackage(): Options;
72
77
  /**
73
78
  * Marks the options as readonly, enables caching when fetching options, which improves performance.
74
79
  */
@@ -96,10 +101,6 @@ export declare class Options {
96
101
  * @param logger
97
102
  */
98
103
  setLogger(logger: Logger): void;
99
- /**
100
- * Adds the option declarations declared by the TypeDoc and all supported TypeScript declarations.
101
- */
102
- addDefaultDeclarations(): void;
103
104
  /**
104
105
  * Resets the option bag to all default values.
105
106
  * If a name is provided, will only reset that name.
@@ -112,7 +113,7 @@ export declare class Options {
112
113
  * @param reader
113
114
  */
114
115
  addReader(reader: OptionsReader): void;
115
- read(logger: Logger): void;
116
+ read(logger: Logger, cwd?: string): void;
116
117
  /**
117
118
  * Adds an option declaration to the container with extra type checking to ensure that
118
119
  * the runtime type is consistent with the declared type.
@@ -177,6 +178,14 @@ export declare class Options {
177
178
  * Sets the compiler options that will be used to get a TS program.
178
179
  */
179
180
  setCompilerOptions(fileNames: readonly string[], options: ts.CompilerOptions, projectReferences: readonly ts.ProjectReference[] | undefined): void;
181
+ /**
182
+ * Discover similar option names to the given name, for use in error reporting.
183
+ */
184
+ getSimilarOptions(missingName: string): string[];
185
+ /**
186
+ * Get the help message to be displayed to the user if `--help` is passed.
187
+ */
188
+ getHelp(): string;
180
189
  }
181
190
  /**
182
191
  * Binds an option to the given property. Does not register the option.
@@ -5,6 +5,7 @@ const declaration_1 = require("./declaration");
5
5
  const array_1 = require("../array");
6
6
  const declaration_2 = require("./declaration");
7
7
  const sources_1 = require("./sources");
8
+ const help_1 = require("./help");
8
9
  const optionSnapshots = new WeakMap();
9
10
  /**
10
11
  * Maintains a collection of option declarations split into TypeDoc options
@@ -36,6 +37,16 @@ class Options {
36
37
  this._fileNames = [];
37
38
  this._projectReferences = [];
38
39
  this._logger = logger;
40
+ (0, sources_1.addTypeDocOptions)(this);
41
+ }
42
+ /**
43
+ * Clones the options, intended for use in packages mode.
44
+ */
45
+ copyForPackage() {
46
+ const options = new Options(this._logger);
47
+ options._readers = this._readers.filter((reader) => reader.supportsPackages);
48
+ options._declarations = new Map(this._declarations);
49
+ return options;
39
50
  }
40
51
  /**
41
52
  * Marks the options as readonly, enables caching when fetching options, which improves performance.
@@ -77,12 +88,6 @@ class Options {
77
88
  setLogger(logger) {
78
89
  this._logger = logger;
79
90
  }
80
- /**
81
- * Adds the option declarations declared by the TypeDoc and all supported TypeScript declarations.
82
- */
83
- addDefaultDeclarations() {
84
- (0, sources_1.addTypeDocOptions)(this);
85
- }
86
91
  reset(name) {
87
92
  if (name != null) {
88
93
  const declaration = this.getDeclaration(name);
@@ -107,11 +112,11 @@ class Options {
107
112
  * @param reader
108
113
  */
109
114
  addReader(reader) {
110
- (0, array_1.insertPrioritySorted)(this._readers, reader);
115
+ (0, array_1.insertOrderSorted)(this._readers, reader);
111
116
  }
112
- read(logger) {
117
+ read(logger, cwd = process.cwd()) {
113
118
  for (const reader of this._readers) {
114
- reader.read(this, logger);
119
+ reader.read(this, logger, cwd);
115
120
  }
116
121
  }
117
122
  addDeclaration(declaration) {
@@ -152,7 +157,8 @@ class Options {
152
157
  getValue(name) {
153
158
  const declaration = this.getDeclaration(name);
154
159
  if (!declaration) {
155
- throw new Error(`Unknown option '${name}'`);
160
+ const nearNames = this.getSimilarOptions(name);
161
+ throw new Error(`Unknown option '${name}', you may have meant:\n\t${nearNames.join("\n\t")}`);
156
162
  }
157
163
  return this._values[declaration.name];
158
164
  }
@@ -162,7 +168,8 @@ class Options {
162
168
  }
163
169
  const declaration = this.getDeclaration(name);
164
170
  if (!declaration) {
165
- throw new Error(`Tried to set an option (${name}) that was not declared.`);
171
+ const nearNames = this.getSimilarOptions(name);
172
+ throw new Error(`Tried to set an option (${name}) that was not declared. You may have meant:\n\t${nearNames.join("\n\t")}`);
166
173
  }
167
174
  let oldValue = this._values[declaration.name];
168
175
  if (typeof oldValue === "undefined")
@@ -226,6 +233,28 @@ class Options {
226
233
  this._compilerOptions = { ...options };
227
234
  this._projectReferences = projectReferences ?? [];
228
235
  }
236
+ /**
237
+ * Discover similar option names to the given name, for use in error reporting.
238
+ */
239
+ getSimilarOptions(missingName) {
240
+ const results = {};
241
+ let lowest = Infinity;
242
+ for (const name of this._declarations.keys()) {
243
+ const distance = editDistance(missingName, name);
244
+ lowest = Math.min(lowest, distance);
245
+ results[distance] || (results[distance] = []);
246
+ results[distance].push(name);
247
+ }
248
+ // Experimenting a bit, it seems an edit distance of 3 is roughly the
249
+ // right metric for relevant "similar" results without showing obviously wrong suggestions
250
+ return results[lowest].concat(results[lowest + 1] || [], results[lowest + 2] || []);
251
+ }
252
+ /**
253
+ * Get the help message to be displayed to the user if `--help` is passed.
254
+ */
255
+ getHelp() {
256
+ return (0, help_1.getOptionsHelp)(this);
257
+ }
229
258
  }
230
259
  exports.Options = Options;
231
260
  function BindOption(name) {
@@ -234,9 +263,6 @@ function BindOption(name) {
234
263
  get() {
235
264
  const options = "options" in this ? this.options : this.application.options;
236
265
  const value = options.getValue(name);
237
- if (options.isFrozen()) {
238
- Object.defineProperty(this, key, { value });
239
- }
240
266
  return value;
241
267
  },
242
268
  enumerable: true,
@@ -245,3 +271,31 @@ function BindOption(name) {
245
271
  };
246
272
  }
247
273
  exports.BindOption = BindOption;
274
+ // Based on https://en.wikipedia.org/wiki/Levenshtein_distance#Iterative_with_two_matrix_rows
275
+ // Slightly modified for improved match results for options
276
+ function editDistance(s, t) {
277
+ if (s.length < t.length)
278
+ return editDistance(t, s);
279
+ let v0 = Array.from({ length: t.length + 1 }, (_, i) => i);
280
+ let v1 = Array.from({ length: t.length + 1 }, () => 0);
281
+ for (let i = 0; i < s.length; i++) {
282
+ v1[0] = i + 1;
283
+ for (let j = 0; j < s.length; j++) {
284
+ const deletionCost = v0[j + 1] + 1;
285
+ const insertionCost = v1[j] + 1;
286
+ let substitutionCost;
287
+ if (s[i] === t[j]) {
288
+ substitutionCost = v0[j];
289
+ }
290
+ else if (s[i]?.toUpperCase() === t[j]?.toUpperCase()) {
291
+ substitutionCost = v0[j] + 1;
292
+ }
293
+ else {
294
+ substitutionCost = v0[j] + 3;
295
+ }
296
+ v1[j + 1] = Math.min(deletionCost, insertionCost, substitutionCost);
297
+ }
298
+ [v0, v1] = [v1, v0];
299
+ }
300
+ return v0[t.length];
301
+ }
@@ -5,7 +5,8 @@ import type { Logger } from "../../loggers";
5
5
  */
6
6
  export declare class ArgumentsReader implements OptionsReader {
7
7
  readonly name = "arguments";
8
- readonly priority: number;
8
+ readonly order: number;
9
+ readonly supportsPackages = false;
9
10
  private args;
10
11
  constructor(priority: number, args?: string[]);
11
12
  read(container: Options, logger: Logger): void;
@@ -15,7 +15,8 @@ const ARRAY_OPTION_TYPES = new Set([
15
15
  class ArgumentsReader {
16
16
  constructor(priority, args = process.argv.slice(2)) {
17
17
  this.name = "arguments";
18
- this.priority = priority;
18
+ this.supportsPackages = false;
19
+ this.order = priority;
19
20
  this.args = args;
20
21
  }
21
22
  read(container, logger) {
@@ -38,6 +39,10 @@ class ArgumentsReader {
38
39
  ? (index++, options.getDeclaration(name.replace(/^--?/, "")))
39
40
  : options.getDeclaration("entryPoints");
40
41
  if (decl) {
42
+ if (decl.configFileOnly) {
43
+ logger.error(`The '${decl.name}' option can only be specified via a config file.`);
44
+ continue;
45
+ }
41
46
  if (seen.has(decl.name) && ARRAY_OPTION_TYPES.has(decl.type)) {
42
47
  trySet(decl.name, options.getValue(decl.name).concat(this.args[index]));
43
48
  }
@@ -82,7 +87,9 @@ class ArgumentsReader {
82
87
  continue;
83
88
  }
84
89
  }
85
- logger.error(`Unknown option: ${name}`);
90
+ logger.error(`Unknown option: ${name}, you may have meant:\n\t${options
91
+ .getSimilarOptions(name)
92
+ .join("\n\t")}`);
86
93
  index++;
87
94
  }
88
95
  }
@@ -4,15 +4,11 @@ export declare class TSConfigReader implements OptionsReader {
4
4
  /**
5
5
  * Note: Runs after the {@link TypeDocReader}.
6
6
  */
7
- priority: number;
7
+ order: number;
8
8
  name: string;
9
+ supportsPackages: boolean;
9
10
  private seenTsdocPaths;
10
- /**
11
- * Not considered part of the public API. You can use it, but it might break.
12
- * @internal
13
- */
14
- static findConfigFile(file: string): string | undefined;
15
- read(container: Options, logger: Logger): void;
11
+ read(container: Options, logger: Logger, cwd: string): void;
16
12
  private addTagsFromTsdocJson;
17
13
  private readTsDoc;
18
14
  }
@@ -1,13 +1,32 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
4
24
  };
5
25
  Object.defineProperty(exports, "__esModule", { value: true });
6
26
  exports.TSConfigReader = void 0;
7
27
  const path_1 = require("path");
8
- const fs_1 = require("fs");
9
- const typescript_1 = __importDefault(require("typescript"));
10
- const fs_2 = require("../../fs");
28
+ const ts = __importStar(require("typescript"));
29
+ const fs_1 = require("../../fs");
11
30
  const assert_1 = require("assert");
12
31
  const validation_1 = require("../../validation");
13
32
  const paths_1 = require("../../paths");
@@ -15,12 +34,7 @@ const module_1 = require("module");
15
34
  const tsdoc_defaults_1 = require("../tsdoc-defaults");
16
35
  const array_1 = require("../../array");
17
36
  const entry_point_1 = require("../../entry-point");
18
- function isFile(file) {
19
- return (0, fs_1.existsSync)(file) && (0, fs_1.statSync)(file).isFile();
20
- }
21
- function isDir(path) {
22
- return (0, fs_1.existsSync)(path) && (0, fs_1.statSync)(path).isDirectory();
23
- }
37
+ const tsconfig_1 = require("../../tsconfig");
24
38
  function isSupportForTags(obj) {
25
39
  return ((0, validation_1.validate)({}, obj) &&
26
40
  Object.entries(obj).every(([key, val]) => {
@@ -52,27 +66,14 @@ class TSConfigReader {
52
66
  /**
53
67
  * Note: Runs after the {@link TypeDocReader}.
54
68
  */
55
- this.priority = 200;
69
+ this.order = 200;
56
70
  this.name = "tsconfig-json";
71
+ this.supportsPackages = true;
57
72
  this.seenTsdocPaths = new Set();
58
73
  }
59
- /**
60
- * Not considered part of the public API. You can use it, but it might break.
61
- * @internal
62
- */
63
- static findConfigFile(file) {
64
- let fileToRead = file;
65
- if (isDir(fileToRead)) {
66
- fileToRead = typescript_1.default.findConfigFile(file, isFile);
67
- }
68
- if (!fileToRead || !isFile(fileToRead)) {
69
- return;
70
- }
71
- return fileToRead;
72
- }
73
- read(container, logger) {
74
- const file = container.getValue("tsconfig");
75
- let fileToRead = TSConfigReader.findConfigFile(file);
74
+ read(container, logger, cwd) {
75
+ const file = container.getValue("tsconfig") || cwd;
76
+ let fileToRead = (0, tsconfig_1.findTsConfigFile)(file);
76
77
  if (!fileToRead) {
77
78
  // If the user didn't give us this option, we shouldn't complain about not being able to find it.
78
79
  if (container.isSet("tsconfig")) {
@@ -84,12 +85,10 @@ class TSConfigReader {
84
85
  }
85
86
  return;
86
87
  }
87
- fileToRead = (0, fs_2.normalizePath)((0, path_1.resolve)(fileToRead));
88
+ fileToRead = (0, fs_1.normalizePath)((0, path_1.resolve)(fileToRead));
89
+ logger.verbose(`Reading tsconfig at ${(0, paths_1.nicePath)(fileToRead)}`);
88
90
  this.addTagsFromTsdocJson(container, logger, (0, path_1.resolve)(fileToRead));
89
- const parsed = typescript_1.default.getParsedCommandLineOfConfigFile(fileToRead, {}, {
90
- ...typescript_1.default.sys,
91
- onUnRecoverableConfigFileDiagnostic: logger.diagnostic.bind(logger),
92
- });
91
+ const parsed = (0, tsconfig_1.readTsConfig)(fileToRead, logger);
93
92
  if (!parsed) {
94
93
  return;
95
94
  }
@@ -121,7 +120,7 @@ class TSConfigReader {
121
120
  addTagsFromTsdocJson(container, logger, tsconfig) {
122
121
  this.seenTsdocPaths.clear();
123
122
  const tsdoc = (0, path_1.join)((0, path_1.dirname)(tsconfig), "tsdoc.json");
124
- if (!isFile(tsdoc)) {
123
+ if (!(0, fs_1.isFile)(tsdoc)) {
125
124
  return;
126
125
  }
127
126
  const overwritten = ["blockTags", "inlineTags", "modifierTags"].filter((opt) => container.isSet(opt));
@@ -163,7 +162,7 @@ class TSConfigReader {
163
162
  return;
164
163
  }
165
164
  this.seenTsdocPaths.add(path);
166
- const { config, error } = typescript_1.default.readConfigFile((0, fs_2.normalizePath)(path), typescript_1.default.sys.readFile);
165
+ const { config, error } = ts.readConfigFile((0, fs_1.normalizePath)(path), ts.sys.readFile);
167
166
  if (error) {
168
167
  logger.error(`Failed to read tsdoc.json file at ${(0, paths_1.nicePath)(path)}.`);
169
168
  return;
@@ -9,14 +9,13 @@ export declare class TypeDocReader implements OptionsReader {
9
9
  /**
10
10
  * Should run before the tsconfig reader so that it can specify a tsconfig file to read.
11
11
  */
12
- priority: number;
12
+ order: number;
13
13
  name: string;
14
+ supportsPackages: boolean;
14
15
  /**
15
16
  * Read user configuration from a typedoc.json or typedoc.js configuration file.
16
- * @param container
17
- * @param logger
18
17
  */
19
- read(container: Options, logger: Logger): void;
18
+ read(container: Options, logger: Logger, cwd: string): void;
20
19
  /**
21
20
  * Read the given options file + any extended files.
22
21
  * @param file
@@ -25,7 +24,7 @@ export declare class TypeDocReader implements OptionsReader {
25
24
  */
26
25
  private readFile;
27
26
  /**
28
- * Search for the configuration file given path
27
+ * Search for the typedoc.js or typedoc.json file from the given path
29
28
  *
30
29
  * @param path Path to the typedoc.(js|json) file. If path is a directory
31
30
  * typedoc file will be attempted to be found at the root of this path