Skip to content

Commit 3cf806c

Browse files
committed
Added reportError for calls from ApiDocumentation
1 parent 04b8e24 commit 3cf806c

4 files changed

Lines changed: 22 additions & 15 deletions

File tree

‎api-extractor/src/DebugRun.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const externalPackageApiRef: IApiDefinitionReference = {
3737
exportName: '',
3838
memberName: ''
3939
};
40-
console.log(extractor.docItemLoader.getPackage(externalPackageApiRef));
40+
console.log(extractor.docItemLoader.getPackage(externalPackageApiRef, console.log));
4141

4242
const apiFileGenerator: ApiFileGenerator = new ApiFileGenerator();
4343
apiFileGenerator.writeApiFile('./lib/DebugRun.api.ts', extractor);

‎api-extractor/src/DocItemLoader.ts‎

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ export interface IParsedScopeName {
2929
* then use DocItemLoader.getItem to retrieve the IDocItem of a particular API item.
3030
*/
3131
export default class DocItemLoader {
32-
private cache: Map<string, IDocPackage>;
33-
private projectFolder: string; // Root directory to check for node modules
32+
private _cache: Map<string, IDocPackage>;
33+
private _projectFolder: string; // Root directory to check for node modules
34+
private _errorHandler: (message: string) => void;
3435

3536
/**
3637
* The projectFolder is the top-level folder containing package.json for a project
@@ -41,8 +42,8 @@ export default class DocItemLoader {
4142
throw new Error(`An NPM project was not found in the specified folder: ${projectFolder}`);
4243
}
4344

44-
this.projectFolder = projectFolder;
45-
this.cache = new Map<string, IDocPackage>();
45+
this._projectFolder = projectFolder;
46+
this._cache = new Map<string, IDocPackage>();
4647
}
4748

4849
/**
@@ -51,12 +52,13 @@ export default class DocItemLoader {
5152
* will attempt to the locate the associated json file to load the package and
5253
* check there. If the API item can not be found the method will return undefined.
5354
*/
54-
public getItem(apiDefinitionRef: IApiDefinitionReference): IDocItem {
55+
public getItem(apiDefinitionRef: IApiDefinitionReference, reportError: (message: string) => void): IDocItem {
5556
if (!apiDefinitionRef) {
56-
throw new Error('Expected param to DocItemLoader.getItem() to be defined');
57+
reportError('Expected reference within {@inheritdoc} tag');
58+
return undefined;
5759
}
5860
// Try to load the package given the provided packageName into the cache
59-
const docPackage: IDocPackage = this.getPackage(apiDefinitionRef);
61+
const docPackage: IDocPackage = this.getPackage(apiDefinitionRef, reportError);
6062

6163
// Check if package was not found
6264
if (!docPackage) {
@@ -90,7 +92,7 @@ export default class DocItemLoader {
9092
*
9193
* @param apiDefinitionRef - interface with propropties pertaining to the API definition reference
9294
*/
93-
public getPackage(apiDefinitionRef: IApiDefinitionReference): IDocPackage {
95+
public getPackage(apiDefinitionRef: IApiDefinitionReference, reportError: (message: string) => void): IDocPackage {
9496
let cachePackageName: string = '';
9597

9698
// We concatenate the scopeName and packageName in case there are packageName conflicts
@@ -100,13 +102,18 @@ export default class DocItemLoader {
100102
cachePackageName = apiDefinitionRef.packageName;
101103
}
102104
// Check if package exists in cache
103-
if (this.cache.has(cachePackageName)) {
104-
return this.cache.get(cachePackageName);
105+
if (this._cache.has(cachePackageName)) {
106+
return this._cache.get(cachePackageName);
107+
}
108+
109+
if (!apiDefinitionRef.packageName) {
110+
// Local export resolution is currently not supported yet
111+
return;
105112
}
106113

107114
// Doesn't exist in cache, attempt to load the json file
108115
const packageJsonFilePath: string = path.join(
109-
this.projectFolder,
116+
this._projectFolder,
110117
'node_modules',
111118
apiDefinitionRef.scopeName,
112119
apiDefinitionRef.packageName,
@@ -141,7 +148,7 @@ export default class DocItemLoader {
141148
);
142149

143150
const packageName: string = path.basename(packageJsonFilePath).split('.').shift();
144-
this.cache.set(packageName, apiPackage);
151+
this._cache.set(packageName, apiPackage);
145152
return apiPackage;
146153
}
147154
}

‎api-extractor/src/definitions/ApiDocumentation.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ export default class ApiDocumentation {
454454
}
455455

456456
// Atempt to locate the apiDefinitionRef
457-
const inheritedDoc: IDocItem = this.docItemLoader.getItem(apiDefinitionRef);
457+
const inheritedDoc: IDocItem = this.docItemLoader.getItem(apiDefinitionRef, this.reportError);
458458

459459
// If no IDocItem found then nothing to inherit
460460
// But for the time being set the summary to a text object

‎api-extractor/src/test/DocItemLoader.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('DocItemLoader tests', function (): void {
2020
};
2121
const docItemLoader: DocItemLoader = new DocItemLoader('./testInputs/example2');
2222
/* ts-lint:diasble:no-unused-variable */
23-
const apiDocItem: IDocItem = docItemLoader.getItem(apiDefRef);
23+
const apiDocItem: IDocItem = docItemLoader.getItem(apiDefRef, console.log);
2424

2525
JsonFile.saveJsonFile('./lib/inheritedDoc-output.json', JSON.stringify(apiDocItem));
2626
TestFileComparer.assertFileMatchesExpected(

0 commit comments

Comments
 (0)