Skip to content

Commit bf6fcb0

Browse files
committed
enabled error for DocItemLoader package json files not found
1 parent 8861bdd commit bf6fcb0

9 files changed

Lines changed: 13 additions & 26 deletions

File tree

‎api-extractor/src/DebugRun.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import * as ts from 'typescript';
55
import * as os from 'os';
6-
import * as path from 'path';
76
import Extractor from './Extractor';
87
import ApiFileGenerator from './generators/ApiFileGenerator';
98
import ApiJsonGenerator from './generators/ApiJsonGenerator';
@@ -27,7 +26,7 @@ const extractor: Extractor = new Extractor( {
2726
}
2827
});
2928

30-
extractor.loadExternalPackages(path.join(__dirname, '/external-api-json'));
29+
extractor.loadExternalPackages('./testInputs/external-api-json');
3130

3231
extractor.analyze({entryPointFile: './testInputs/example2/index.ts',
3332
otherFiles: []});

‎api-extractor/src/DocItemLoader.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export default class DocItemLoader {
122122
*/
123123
public loadPackageIntoCache(packageJsonFilePath: string): IDocPackage {
124124
if (!fsx.existsSync(path.join(packageJsonFilePath))) {
125-
return undefined;
125+
throw new Error(`External json package file does not exist: ${packageJsonFilePath}`);
126126
}
127127

128128
const apiPackage: IDocPackage = JsonFile.loadJsonFile(packageJsonFilePath) as IDocPackage;

‎api-extractor/src/Extractor.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ export interface IExtractorOptions {
2626
/**
2727
* Options for Extractor.analyze()
2828
*/
29-
export interface IApiAnalyzerOptions {
29+
export interface IExtractorAnalyzeOptions {
3030
/**
3131
* The entry point for the project. This should correspond to the "main" field
3232
* from NPM's package.json file. If it is a relative path, it will be relative to
33-
* the project folder described by IApiAnalyzerOptions.compilerOptions.
33+
* the project folder described by IExtractorAnalyzeOptions.compilerOptions.
3434
*/
3535
entryPointFile: string;
3636

@@ -76,7 +76,7 @@ export default class Extractor {
7676
/**
7777
* Analyzes the specified project.
7878
*/
79-
public analyze(options: IApiAnalyzerOptions): void {
79+
public analyze(options: IExtractorAnalyzeOptions): void {
8080
const rootFiles: string[] = [options.entryPointFile].concat(options.otherFiles || []);
8181

8282
const program: ts.Program = ts.createProgram(rootFiles, this._compilerOptions);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class TestApiDocumentation extends ApiDocumentation {
4242
}
4343
}
4444

45+
extractor.loadExternalPackages('./testInputs/external-api-json');
4546
// Run the analyzer once to be used by unit tests
4647
extractor.analyze({
4748
entryPointFile: path.join(inputFolder, 'index.ts')

‎api-extractor/src/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
declare const packageDescription: void;
77

8-
export { default as Extractor, IExtractorOptions, IApiAnalyzerOptions, ApiErrorHandler } from './Extractor';
8+
export { default as Extractor, IExtractorOptions, IExtractorAnalyzeOptions, ApiErrorHandler } from './Extractor';
99
export { default as ApiFileGenerator } from './generators/ApiFileGenerator';
1010
export { default as ApiJsonGenerator } from './generators/ApiJsonGenerator';
1111
export { default as ExternalApiHelper } from './ExternalApiHelper';

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class TestApiDocumentation extends ApiDocumentation {
5050
}
5151
}
5252

53+
extractor.loadExternalPackages('./testInputs/external-api-json');
5354
// Run the analyze method once to be used by unit tests
5455
extractor.analyze({
5556
entryPointFile: path.join(inputFolder, 'index.ts')

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/// <reference types="mocha" />
22

3-
import { assert } from 'chai';
43
import { IDocItem } from '../IDocItem';
54
import DocItemLoader from '../DocItemLoader';
65
import TestFileComparer from '../TestFileComparer';
@@ -29,18 +28,5 @@ describe('DocItemLoader tests', function (): void {
2928
'./testInputs/inheritedDoc-output.json'
3029
);
3130
});
32-
33-
it('Should not raise error without scope and not found', (): void => {
34-
const apiDefRef: IApiDefinitionReference = {
35-
scopeName: '',
36-
packageName: 'sp-core-libarary',
37-
exportName: 'DisplayMode',
38-
memberName: ''
39-
};
40-
const docItemLoader: DocItemLoader = new DocItemLoader('./testInputs/example2');
41-
42-
const apiDocItem: IDocItem = docItemLoader.getItem(apiDefRef);
43-
assert.equal(apiDocItem, undefined);
44-
});
4531
});
4632
});

‎common/reviews/api/api-extractor.api.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class ExternalApiHelper {
5555
class Extractor {
5656
// (undocumented)
5757
constructor(options: IExtractorOptions);
58-
public analyze(options: IApiAnalyzerOptions): void;
58+
public analyze(options: IExtractorAnalyzeOptions): void;
5959
public static defaultErrorHandler(message: string, fileName: string, lineNumber: number): void;
6060
public docItemLoader: DocItemLoader;
6161
// (undocumented)
@@ -68,7 +68,7 @@ class Extractor {
6868
public typeChecker: ts.TypeChecker;
6969
}
7070

71-
interface IApiAnalyzerOptions {
71+
interface IExtractorAnalyzeOptions {
7272
entryPointFile: string;
7373
otherFiles?: string[];
7474
}

‎gulp-core-build-typescript/src/ApiExtractorTask.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as gulpUtil from 'gulp-util';
88
import { GulpTask } from '@microsoft/gulp-core-build';
99
import { Extractor,
1010
IExtractorOptions,
11-
IApiAnalyzerOptions,
11+
IExtractorAnalyzeOptions,
1212
ApiFileGenerator,
1313
ApiJsonGenerator } from '@microsoft/api-extractor';
1414
import { TypeScriptConfiguration } from './TypeScriptConfiguration';
@@ -103,14 +103,14 @@ export class ApiExtractorTask extends GulpTask<IApiExtractorTaskConfig> {
103103
}
104104
};
105105

106-
const analyzerOptions: IApiAnalyzerOptions = {
106+
const analyzeOptions: IExtractorAnalyzeOptions = {
107107
entryPointFile,
108108
otherFiles
109109
} as any; /* tslint:disable-line:no-any */
110110

111111
const extractor: Extractor = new Extractor(extractorOptions);
112112
extractor.loadExternalPackages(path.join(__dirname, 'external-api-json'));
113-
extractor.analyze(analyzerOptions);
113+
extractor.analyze(analyzeOptions);
114114

115115
const jsonGenerator: ApiJsonGenerator = new ApiJsonGenerator();
116116
// const jsonContent: string = generator.generateJsonFileContent(analyzer);

0 commit comments

Comments
 (0)