Skip to content

Commit e89aefb

Browse files
authored
Merge pull request microsoft#564 from Microsoft/pgonzal/package-json-lookup
Redesign the PackageJsonLookup API
2 parents 5e3862d + f9c4b04 commit e89aefb

34 files changed

Lines changed: 469 additions & 165 deletions

‎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);

‎apps/rush-lib/src/Rush.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import { EOL } from 'os';
55
import * as path from 'path';
66
import * as colors from 'colors';
7+
import { IPackageJson } from '@microsoft/node-core-library';
78

89
import RushCommandLineParser from './cli/actions/RushCommandLineParser';
9-
import IPackageJson from './utilities/IPackageJson';
1010

1111
/**
1212
* Operations involving the rush tool and its operation.

‎apps/rush-lib/src/cli/actions/VersionAction.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4+
import { IPackageJson } from '@microsoft/node-core-library';
45
import {
56
CommandLineFlagParameter,
67
CommandLineStringParameter
78
} from '@microsoft/ts-command-line';
89

910
import { BumpType } from '../../data/VersionPolicy';
10-
import IPackageJson from '../../utilities/IPackageJson';
1111
import RushConfiguration from '../../data/RushConfiguration';
1212
import Utilities from '../../utilities/Utilities';
1313
import VersionControl from '../../utilities/VersionControl';

‎apps/rush-lib/src/cli/logic/ApprovedPackagesChecker.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
import IPackageJson from '../../utilities/IPackageJson';
4+
import { IPackageJson } from '@microsoft/node-core-library';
5+
56
import { ApprovedPackagesPolicy } from '../../data/ApprovedPackagesPolicy';
67
import RushConfiguration from '../../data/RushConfiguration';
78
import RushConfigurationProject from '../../data/RushConfigurationProject';

‎apps/rush-lib/src/cli/logic/ChangeManager.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4+
import { IPackageJson } from '@microsoft/node-core-library';
5+
46
import { IChangeInfo } from '../../data/ChangeManagement';
57
import { IChangelog } from '../../data/Changelog';
6-
import IPackageJson from '../../utilities/IPackageJson';
78
import RushConfiguration from '../../data/RushConfiguration';
89
import RushConfigurationProject from '../../data/RushConfigurationProject';
910
import { VersionPolicyConfiguration } from '../../data/VersionPolicyConfiguration';

‎apps/rush-lib/src/cli/logic/InstallManager.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ import * as semver from 'semver';
1010
import * as tar from 'tar';
1111
import * as wordwrap from 'wordwrap';
1212
import globEscape = require('glob-escape');
13-
import { JsonFile, LockFile, Text } from '@microsoft/node-core-library';
13+
import {
14+
JsonFile,
15+
LockFile,
16+
Text,
17+
IPackageJson
18+
} from '@microsoft/node-core-library';
1419

1520
import AsyncRecycler from '../../utilities/AsyncRecycler';
1621
import RushConfiguration, {
@@ -20,7 +25,6 @@ import RushConfigurationProject from '../../data/RushConfigurationProject';
2025
import { RushConstants } from '../../RushConstants';
2126
import Utilities from '../../utilities/Utilities';
2227
import { Stopwatch } from '../../utilities/Stopwatch';
23-
import IPackageJson from '../../utilities/IPackageJson';
2428
import { IRushTempPackageJson } from '../logic/base/BasePackage';
2529
import { BaseShrinkwrapFile } from '../logic/base/BaseShrinkwrapFile';
2630
import { LastInstallFlag } from '../../utilities/LastInstallFlag';

‎apps/rush-lib/src/cli/logic/PublishUtilities.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import * as fsx from 'fs-extra';
1111
import * as path from 'path';
1212
import * as semver from 'semver';
1313

14-
import IPackageJson from '../../utilities/IPackageJson';
14+
import { IPackageJson } from '@microsoft/node-core-library';
15+
1516
import {
1617
IChangeInfo,
1718
ChangeType

‎apps/rush-lib/src/cli/logic/VersionManager.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as path from 'path';
55
import * as semver from 'semver';
66
import * as fsx from 'fs-extra';
77
import { cloneDeep } from 'lodash';
8+
import { IPackageJson } from '@microsoft/node-core-library';
89

910
import {
1011
VersionPolicy,
@@ -16,7 +17,6 @@ import { ChangeType, IChangeInfo } from '../../data/ChangeManagement';
1617
import RushConfiguration from '../../data/RushConfiguration';
1718
import RushConfigurationProject from '../../data/RushConfigurationProject';
1819
import { VersionPolicyConfiguration } from '../../data/VersionPolicyConfiguration';
19-
import IPackageJson from '../../utilities/IPackageJson';
2020
import PublishUtilities from './PublishUtilities';
2121
import ChangeManager from './ChangeManager';
2222

0 commit comments

Comments
 (0)