Skip to content

Commit f26bb55

Browse files
authored
Merge branch 'master' into feature/api-documenter/permissive-ref-check
2 parents 1619351 + 46ce435 commit f26bb55

File tree

42 files changed

+288
-239
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+288
-239
lines changed

apps/api-documenter/src/start.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import * as os from 'os';
55
import * as colors from 'colors';
66
import * as path from 'path';
77

8+
import { FileConstants } from '@microsoft/node-core-library';
9+
810
import { ApiDocumenterCommandLine } from './cli/ApiDocumenterCommandLine';
911

1012
const myPackageJsonFilename: string = path.resolve(path.join(
11-
__dirname, '..', 'package.json')
13+
__dirname, '..', FileConstants.PackageJson)
1214
);
1315
const myPackageJson: { version: string } = require(myPackageJsonFilename);
1416

apps/api-extractor/src/DocItemLoader.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import * as os from 'os';
55
import * as path from 'path';
66
import {
77
JsonFile,
8-
FileSystem
8+
FileSystem,
9+
FileConstants
910
} from '@microsoft/node-core-library';
1011

1112
import {
@@ -40,7 +41,7 @@ export class DocItemLoader implements IReferenceResolver {
4041
* that we are compiling.
4142
*/
4243
constructor(projectFolder: string) {
43-
if (!FileSystem.exists(path.join(projectFolder, 'package.json'))) {
44+
if (!FileSystem.exists(path.join(projectFolder, FileConstants.PackageJson))) {
4445
throw new Error(`An NPM project was not found in the specified folder: ${projectFolder}`);
4546
}
4647

apps/api-extractor/src/start.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import * as os from 'os';
55
import * as colors from 'colors';
66
import * as path from 'path';
77

8+
import { FileConstants } from '@microsoft/node-core-library';
9+
810
import { ApiExtractorCommandLine } from './cli/ApiExtractorCommandLine';
911

1012
const myPackageJsonFilename: string = path.resolve(path.join(
11-
__dirname, '..', 'package.json')
13+
__dirname, '..', FileConstants.PackageJson)
1214
);
1315
const myPackageJson: { version: string } = require(myPackageJsonFilename);
1416

apps/rush-lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@microsoft/rush-lib",
3-
"version": "5.0.0",
3+
"version": "5.0.2",
44
"description": "A library for writing scripts that interact with the Rush tool",
55
"repository": {
66
"type": "git",

apps/rush-lib/src/api/ChangeFile.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,22 @@ export class ChangeFile {
6262
}
6363

6464
/**
65-
* Writes the change file to disk in sync mode
65+
* Writes the change file to disk in sync mode.
66+
* Returns the filepath.
67+
* @returns the path to the file that was written (based on generatePath())
6668
*/
67-
public writeSync(): void {
69+
public writeSync(): string {
6870
const filePath: string = this.generatePath();
6971
JsonFile.save(this._changeFileData, filePath, {
7072
ensureFolderExists: true
7173
});
74+
return filePath;
7275
}
7376

7477
/**
75-
* Generates a file path for storing the change file to disk
78+
* Generates a file path for storing the change file to disk.
79+
* Note that this value may change if called twice in a row,
80+
* as it is partially based on the current date/time.
7681
*/
7782
public generatePath(): string {
7883
let branch: string | undefined = undefined;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { RushConfiguration } from './RushConfiguration';
2+
import { RushConfigurationProject } from './RushConfigurationProject';
3+
import { ChangeFile } from './ChangeFile';
4+
import { IChangeFile } from './ChangeManagement';
5+
6+
/**
7+
* A class that helps with programatically interacting with Rush's change files.
8+
* @public
9+
*/
10+
export class ChangeManager {
11+
/**
12+
* Creates a change file that has a 'none' type.
13+
* @param rushConfiguration - The rush configuration we are working with
14+
* @param projectName - The name of the project for which to create a change file
15+
* @param emailAddress - The email address which should be associated with this change
16+
* @returns the path to the file that was created, or undefined if no file was written
17+
*/
18+
public static createEmptyChangeFiles(
19+
rushConfiguration: RushConfiguration,
20+
projectName: string,
21+
emailAddress: string): string | undefined {
22+
const projectInfo: RushConfigurationProject | undefined = rushConfiguration.getProjectByName(projectName);
23+
if (projectInfo && projectInfo.shouldPublish) {
24+
25+
const changefile: IChangeFile = { // tslint:disable-line:no-any
26+
'changes': [{
27+
comment: '',
28+
packageName: projectName,
29+
type: 'none'
30+
}],
31+
'packageName': projectName,
32+
'email': emailAddress
33+
};
34+
35+
return new ChangeFile(changefile, rushConfiguration).writeSync();
36+
}
37+
return undefined;
38+
}
39+
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
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';
7+
import {
8+
IPackageJson,
9+
FileConstants
10+
} from '@microsoft/node-core-library';
811

912
import { RushCommandLineParser } from '../cli/RushCommandLineParser';
1013
import { RushConstants } from '../logic/RushConstants';
@@ -65,7 +68,7 @@ export class Rush {
6568
*/
6669
public static get version(): string {
6770
if (!Rush._version) {
68-
const myPackageJsonFilename: string = path.resolve(path.join(__dirname, '..', '..', 'package.json'));
71+
const myPackageJsonFilename: string = path.resolve(path.join(__dirname, '..', '..', FileConstants.PackageJson));
6972
const myPackageJson: IPackageJson = require(myPackageJsonFilename);
7073
Rush._version = myPackageJson.version;
7174
}

apps/rush-lib/src/api/RushConfigurationProject.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
JsonFile,
77
IPackageJson,
88
PackageName,
9-
FileSystem
9+
FileSystem,
10+
FileConstants
1011
} from '@microsoft/node-core-library';
1112

1213
import { RushConfiguration } from '../api/RushConfiguration';
@@ -88,7 +89,7 @@ export class RushConfigurationProject {
8889
this._reviewCategory = projectJson.reviewCategory;
8990
}
9091

91-
const packageJsonFilename: string = path.join(this._projectFolder, 'package.json');
92+
const packageJsonFilename: string = path.join(this._projectFolder, FileConstants.PackageJson);
9293
this._packageJson = JsonFile.load(packageJsonFilename);
9394

9495
if (this._packageJson.name !== this._packageName) {

apps/rush-lib/src/cli/actions/PublishAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export class PublishAction extends BaseRushAction {
173173
* Executes the publish action, which will read change request files, apply changes to package.jsons,
174174
*/
175175
protected run(): Promise<void> {
176-
if (!GitPolicy.check(this.rushConfiguration)) {
176+
if (!GitPolicy.getUserEmail(this.rushConfiguration, true)) {
177177
process.exit(1);
178178
return Promise.resolve();
179179
}

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

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
// See LICENSE in the project root for license information.
33

44
import * as semver from 'semver';
5-
import { IPackageJson } from '@microsoft/node-core-library';
5+
import {
6+
IPackageJson,
7+
FileConstants
8+
} from '@microsoft/node-core-library';
69
import {
710
CommandLineFlagParameter,
811
CommandLineStringParameter
@@ -90,42 +93,34 @@ export class VersionAction extends BaseRushAction {
9093
}
9194

9295
protected run(): Promise<void> {
93-
// try to get the user email
94-
const userEmail: string | undefined = GitPolicy.getUserEmail(this.rushConfiguration);
95-
96-
if (!userEmail) {
97-
return Promise.reject(undefined);
98-
}
96+
return Promise.resolve().then(() => {
97+
const userEmail: string = GitPolicy.getUserEmail(this.rushConfiguration, this._bypassPolicy.value);
9998

100-
if (!this._bypassPolicy.value) {
101-
if (!GitPolicy.check(this.rushConfiguration, userEmail)) {
102-
return Promise.reject(undefined);
103-
}
104-
}
105-
this._validateInput();
99+
this._validateInput();
106100

107-
this._versionManager = new VersionManager(this.rushConfiguration, userEmail);
101+
this._versionManager = new VersionManager(this.rushConfiguration, userEmail);
108102

109-
if (this._ensureVersionPolicy.value) {
110-
this._overwritePolicyVersionIfNeeded();
111-
const tempBranch: string = 'version/ensure-' + new Date().getTime();
112-
this._versionManager.ensure(this._versionPolicy.value, true,
113-
!!this._overrideVersion.value || !!this._prereleaseIdentifier.value);
103+
if (this._ensureVersionPolicy.value) {
104+
this._overwritePolicyVersionIfNeeded();
105+
const tempBranch: string = 'version/ensure-' + new Date().getTime();
106+
this._versionManager.ensure(this._versionPolicy.value, true,
107+
!!this._overrideVersion.value || !!this._prereleaseIdentifier.value);
114108

115-
const updatedPackages: Map<string, IPackageJson> = this._versionManager.updatedProjects;
116-
if (updatedPackages.size > 0) {
117-
console.log(`${updatedPackages.size} packages are getting updated.`);
109+
const updatedPackages: Map<string, IPackageJson> = this._versionManager.updatedProjects;
110+
if (updatedPackages.size > 0) {
111+
console.log(`${updatedPackages.size} packages are getting updated.`);
112+
this._gitProcess(tempBranch);
113+
}
114+
} else if (this._bumpVersion.value) {
115+
const tempBranch: string = 'version/bump-' + new Date().getTime();
116+
this._versionManager.bump(this._versionPolicy.value,
117+
this._overwriteBump.value ? BumpType[this._overwriteBump.value] : undefined,
118+
this._prereleaseIdentifier.value,
119+
true);
118120
this._gitProcess(tempBranch);
119121
}
120-
} else if (this._bumpVersion.value) {
121-
const tempBranch: string = 'version/bump-' + new Date().getTime();
122-
this._versionManager.bump(this._versionPolicy.value,
123-
this._overwriteBump.value ? BumpType[this._overwriteBump.value] : undefined,
124-
this._prereleaseIdentifier.value,
125-
true);
126-
this._gitProcess(tempBranch);
127-
}
128-
return Promise.resolve();
122+
return Promise.resolve();
123+
});
129124
}
130125

131126
private _overwritePolicyVersionIfNeeded(): void {
@@ -220,7 +215,7 @@ export class VersionAction extends BaseRushAction {
220215

221216
// Commit the package.json and change files updates.
222217
const packageJsonUpdated: boolean = uncommittedChanges.some((changePath) => {
223-
return changePath.indexOf('package.json') > 0;
218+
return changePath.indexOf(FileConstants.PackageJson) > 0;
224219
});
225220

226221
if (packageJsonUpdated) {

0 commit comments

Comments
 (0)