Skip to content

Commit 92ce563

Browse files
committed
Update api-extractor to use new PackageJsonLookup API
1 parent ed3404f commit 92ce563

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

apps/api-extractor/src/ExtractorContext.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ export class ExtractorContext {
7373
this.policies = options.policies;
7474
this.validationRules = options.validationRules;
7575

76-
const folder: string | undefined = this.packageJsonLookup.tryGetPackageFolder(options.entryPointFile);
76+
const folder: string | undefined = this.packageJsonLookup.tryGetPackageFolderFor(options.entryPointFile);
7777
if (!folder) {
7878
throw new Error('Unable to find a package.json for entry point: ' + options.entryPointFile);
7979
}
8080
this._packageFolder = folder;
8181

82-
this._packageName = this.packageJsonLookup.getPackageName(this._packageFolder);
82+
this._packageName = this.packageJsonLookup.tryLoadPackageJsonFor(this._packageFolder)!.name;
8383

8484
this.docItemLoader = new DocItemLoader(this._packageFolder);
8585

apps/api-extractor/src/ast/AstItem.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
IApiDefinitionReferenceParts
1919
} from '../ApiDefinitionReference';
2020
import { AstItemContainer } from './AstItemContainer';
21+
import { IPackageJson } from '@microsoft/node-core-library';
2122

2223
/**
2324
* Indicates the type of definition represented by a AstItem object.
@@ -602,18 +603,17 @@ export abstract class AstItem {
602603
// Walk upwards from that directory until you find a directory containing package.json,
603604
// this is where the referenced type is located.
604605
// Example: "c:\users\<username>\sp-client\spfx-core\sp-core-library"
605-
const typeReferencePackagePath: string | undefined = this.context.packageJsonLookup
606-
.tryGetPackageFolder(sourceFile.fileName);
606+
const typeReferencePackageJson: IPackageJson | undefined = this.context.packageJsonLookup
607+
.tryLoadPackageJsonFor(sourceFile.fileName);
607608
// Example: "@microsoft/sp-core-library"
608609
let typeReferencePackageName: string = '';
609610

610611
// If we can not find a package path, we consider the type to be part of the current project's package.
611612
// One case where this happens is when looking for a type that is a symlink
612-
if (!typeReferencePackagePath) {
613+
if (!typeReferencePackageJson) {
613614
typeReferencePackageName = this.context.package.name;
614615
} else {
615-
typeReferencePackageName = this.context.packageJsonLookup
616-
.getPackageName(typeReferencePackagePath);
616+
typeReferencePackageName = typeReferencePackageJson.name;
617617

618618
typingsScopeNames.every(typingScopeName => {
619619
if (typeReferencePackageName.indexOf(typingScopeName) > -1) {
@@ -630,7 +630,7 @@ export abstract class AstItem {
630630
const currentPackageName: string = this.context.package.name;
631631

632632
const typeName: string = typeReferenceNode.typeName.getText();
633-
if (!typeReferencePackagePath || typeReferencePackageName === currentPackageName) {
633+
if (!typeReferencePackageJson || typeReferencePackageName === currentPackageName) {
634634
// The type is defined in this project. Did the person remember to export it?
635635
const exportedLocalName: string | undefined = this.context.package.tryGetExportedSymbolName(currentSymbol);
636636
if (exportedLocalName) {

apps/api-extractor/src/cli/RunAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class RunAction extends CommandLineAction {
6363
// Otherwise, figure out which project we're in and look for the config file
6464
// at the project root
6565
const lookup: PackageJsonLookup = new PackageJsonLookup();
66-
const packageFolder: string|undefined = lookup.tryGetPackageFolder('.');
66+
const packageFolder: string|undefined = lookup.tryGetPackageFolderFor('.');
6767

6868
if (packageFolder) {
6969
configFilename = path.join(packageFolder, AE_CONFIG_FILENAME);

0 commit comments

Comments
 (0)