Skip to content

Commit 36ac2cd

Browse files
committed
Changing the promise convention to always wrap in Promise.resolve().then(() => { ... });
1 parent 2edfe36 commit 36ac2cd

4 files changed

Lines changed: 54 additions & 55 deletions

File tree

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,9 @@ export abstract class BaseRushAction extends CommandLineAction {
7676
}
7777

7878
console.log(`Starting "rush ${this.actionName}"${os.EOL}`);
79-
return Promise.resolve().then(() => {
80-
return this.run().then(() => {
81-
// If we make it here, everything went fine, so reset the exit code back to 0
82-
process.exitCode = 0;
83-
});
79+
return this.run().then(() => {
80+
// If we make it here, everything went fine, so reset the exit code back to 0
81+
process.exitCode = 0;
8482
});
8583
}
8684

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -173,27 +173,28 @@ 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-
PolicyValidator.validatePolicy(this.rushConfiguration, false);
176+
return Promise.resolve().then(() => {
177+
PolicyValidator.validatePolicy(this.rushConfiguration, false);
177178

178-
const allPackages: Map<string, RushConfigurationProject> = this.rushConfiguration.projectsByName;
179+
const allPackages: Map<string, RushConfigurationProject> = this.rushConfiguration.projectsByName;
179180

180-
if (this._regenerateChangelogs.value) {
181-
console.log('Regenerating changelogs');
182-
ChangelogGenerator.regenerateChangelogs(allPackages, this.rushConfiguration);
183-
return Promise.resolve();
184-
}
181+
if (this._regenerateChangelogs.value) {
182+
console.log('Regenerating changelogs');
183+
ChangelogGenerator.regenerateChangelogs(allPackages, this.rushConfiguration);
184+
return Promise.resolve();
185+
}
185186

186-
this._validate();
187+
this._validate();
187188

188-
if (this._includeAll.value) {
189-
this._publishAll(allPackages);
190-
} else {
191-
this._prereleaseToken = new PrereleaseToken(this._prereleaseName.value, this._suffix.value);
192-
this._publishChanges(allPackages);
193-
}
189+
if (this._includeAll.value) {
190+
this._publishAll(allPackages);
191+
} else {
192+
this._prereleaseToken = new PrereleaseToken(this._prereleaseName.value, this._suffix.value);
193+
this._publishChanges(allPackages);
194+
}
194195

195-
console.log(EOL + colors.green('Rush publish finished successfully.'));
196-
return Promise.resolve();
196+
console.log(EOL + colors.green('Rush publish finished successfully.'));
197+
});
197198
}
198199

199200
/**

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ export class PurgeAction extends BaseRushAction {
3434
}
3535

3636
protected run(): Promise<void> {
37-
const stopwatch: Stopwatch = Stopwatch.start();
37+
return Promise.resolve().then(() => {
38+
const stopwatch: Stopwatch = Stopwatch.start();
3839

39-
const purgeManager: PurgeManager = new PurgeManager(this.rushConfiguration);
40+
const purgeManager: PurgeManager = new PurgeManager(this.rushConfiguration);
4041

41-
if (this._unsafeParameter.value!) {
42-
purgeManager.purgeUnsafe();
43-
} else {
44-
purgeManager.purgeNormal();
45-
}
42+
if (this._unsafeParameter.value!) {
43+
purgeManager.purgeUnsafe();
44+
} else {
45+
purgeManager.purgeNormal();
46+
}
4647

47-
purgeManager.deleteAll();
48+
purgeManager.deleteAll();
4849

49-
console.log(os.EOL + colors.green(`Rush purge started successfully and will complete asynchronously.`
50-
+ ` (${stopwatch.toString()})`));
51-
52-
return Promise.resolve();
50+
console.log(os.EOL + colors.green(`Rush purge started successfully and will complete asynchronously.`
51+
+ ` (${stopwatch.toString()})`));
52+
});
5353
}
5454
}

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -94,34 +94,34 @@ export class VersionAction extends BaseRushAction {
9494
}
9595

9696
protected run(): Promise<void> {
97-
PolicyValidator.validatePolicy(this.rushConfiguration, this._bypassPolicy.value);
98-
const userEmail: string = Git.getGitEmail(this.rushConfiguration);
97+
return Promise.resolve().then(() => {
98+
PolicyValidator.validatePolicy(this.rushConfiguration, this._bypassPolicy.value);
99+
const userEmail: string = Git.getGitEmail(this.rushConfiguration);
99100

100-
this._validateInput();
101+
this._validateInput();
101102

102-
this._versionManager = new VersionManager(this.rushConfiguration, userEmail);
103+
this._versionManager = new VersionManager(this.rushConfiguration, userEmail);
103104

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

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

127127
private _overwritePolicyVersionIfNeeded(): void {

0 commit comments

Comments
 (0)