Skip to content

Commit db180f4

Browse files
committed
Convert doInstall function to async/await.
1 parent 0c285cd commit db180f4

1 file changed

Lines changed: 93 additions & 97 deletions

File tree

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

Lines changed: 93 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -264,119 +264,115 @@ export class InstallManager {
264264
});
265265
}
266266

267-
public doInstall(): Promise<void> {
268-
return Promise.resolve().then(() => {
269-
const options: IInstallManagerOptions = this._options;
267+
public async doInstall(): Promise<void> {
268+
const options: IInstallManagerOptions = this._options;
270269

271-
// Check the policies
272-
PolicyValidator.validatePolicy(this._rushConfiguration, options.bypassPolicy);
270+
// Check the policies
271+
PolicyValidator.validatePolicy(this._rushConfiguration, options.bypassPolicy);
273272

274-
ApprovedPackagesChecker.rewriteConfigFiles(this._rushConfiguration);
273+
ApprovedPackagesChecker.rewriteConfigFiles(this._rushConfiguration);
275274

276-
// Git hooks are only installed if the repo opts in by including files in /common/git-hooks
277-
const hookSource: string = path.join(this._rushConfiguration.commonFolder, 'git-hooks');
278-
const hookDestination: string | undefined = Git.getHooksFolder();
275+
// Git hooks are only installed if the repo opts in by including files in /common/git-hooks
276+
const hookSource: string = path.join(this._rushConfiguration.commonFolder, 'git-hooks');
277+
const hookDestination: string | undefined = Git.getHooksFolder();
279278

280-
if (FileSystem.exists(hookSource) && hookDestination) {
281-
const hookFilenames: Array<string> = FileSystem.readFolder(hookSource);
282-
if (hookFilenames.length > 0) {
283-
console.log(os.EOL + colors.bold('Found files in the "common/git-hooks" folder.'));
279+
if (FileSystem.exists(hookSource) && hookDestination) {
280+
const hookFilenames: Array<string> = FileSystem.readFolder(hookSource);
281+
if (hookFilenames.length > 0) {
282+
console.log(os.EOL + colors.bold('Found files in the "common/git-hooks" folder.'));
284283

285-
// Clear the currently installed git hooks and install fresh copies
286-
FileSystem.ensureEmptyFolder(hookDestination);
284+
// Clear the currently installed git hooks and install fresh copies
285+
FileSystem.ensureEmptyFolder(hookDestination);
287286

288-
// Only copy files that look like Git hook names
289-
const filteredHookFilenames: string[] = hookFilenames.filter(x => /^[a-z\-]+/.test(x));
290-
for (const filename of filteredHookFilenames) {
291-
FileSystem.copyFile({
292-
sourcePath: path.join(hookSource, filename),
293-
destinationPath: path.join(hookDestination, filename)
294-
});
295-
FileSystem.changePosixModeBits(path.join(hookDestination, filename),
296-
PosixModeBits.UserRead | PosixModeBits.UserExecute);
297-
}
298-
299-
console.log('Successfully installed these Git hook scripts: ' + filteredHookFilenames.join(', ') + os.EOL);
287+
// Only copy files that look like Git hook names
288+
const filteredHookFilenames: string[] = hookFilenames.filter(x => /^[a-z\-]+/.test(x));
289+
for (const filename of filteredHookFilenames) {
290+
FileSystem.copyFile({
291+
sourcePath: path.join(hookSource, filename),
292+
destinationPath: path.join(hookDestination, filename)
293+
});
294+
FileSystem.changePosixModeBits(path.join(hookDestination, filename),
295+
PosixModeBits.UserRead | PosixModeBits.UserExecute);
300296
}
297+
298+
console.log('Successfully installed these Git hook scripts: ' + filteredHookFilenames.join(', ') + os.EOL);
301299
}
300+
}
302301

303-
// Ensure that the package manager is installed
304-
return this.ensureLocalPackageManager()
305-
.then(() => {
306-
let shrinkwrapFile: BaseShrinkwrapFile | undefined = undefined;
302+
// Ensure that the package manager is installed
303+
await this.ensureLocalPackageManager();
307304

308-
// (If it's a full update, then we ignore the shrinkwrap from Git since it will be overwritten)
309-
if (!options.fullUpgrade) {
310-
try {
311-
shrinkwrapFile = ShrinkwrapFileFactory.getShrinkwrapFile(this._rushConfiguration.packageManager,
312-
this._rushConfiguration.getCommittedShrinkwrapFilename(options.variant));
313-
} catch (ex) {
314-
console.log();
315-
console.log(`Unable to load the ${this._shrinkwrapFilePhrase}: ${ex.message}`);
316-
317-
if (!options.allowShrinkwrapUpdates) {
318-
console.log();
319-
console.log(colors.red('You need to run "rush update" to fix this problem'));
320-
throw new AlreadyReportedError();
321-
}
305+
let shrinkwrapFile: BaseShrinkwrapFile | undefined = undefined;
322306

323-
shrinkwrapFile = undefined;
324-
}
325-
}
307+
// (If it's a full update, then we ignore the shrinkwrap from Git since it will be overwritten)
308+
if (!options.fullUpgrade) {
309+
try {
310+
shrinkwrapFile = ShrinkwrapFileFactory.getShrinkwrapFile(this._rushConfiguration.packageManager,
311+
this._rushConfiguration.getCommittedShrinkwrapFilename(options.variant));
312+
} catch (ex) {
313+
console.log();
314+
console.log(`Unable to load the ${this._shrinkwrapFilePhrase}: ${ex.message}`);
315+
316+
if (!options.allowShrinkwrapUpdates) {
317+
console.log();
318+
console.log(colors.red('You need to run "rush update" to fix this problem'));
319+
throw new AlreadyReportedError();
320+
}
326321

327-
// Write a file indicating which variant is being installed.
328-
// This will be used by bulk scripts to determine the correct Shrinkwrap file to track.
329-
const currentVariantJsonFilename: string = this._rushConfiguration.currentVariantJsonFilename;
330-
const currentVariantJson: ICurrentVariantJson = {
331-
variant: options.variant || null // tslint:disable-line:no-null-keyword
332-
};
333-
334-
// Determine if the variant is already current by updating current-variant.json.
335-
// If nothing is written, the variant has not changed.
336-
const variantIsUpToDate: boolean = !JsonFile.save(currentVariantJson, currentVariantJsonFilename, {
337-
onlyIfChanged: true
338-
});
322+
shrinkwrapFile = undefined;
323+
}
324+
}
339325

340-
if (options.variant) {
341-
console.log();
342-
console.log(colors.bold(`Using variant '${options.variant}' for installation.`));
343-
} else if (!variantIsUpToDate && !options.variant) {
344-
console.log();
345-
console.log(colors.bold('Using the default variant for installation.'));
346-
}
326+
// Write a file indicating which variant is being installed.
327+
// This will be used by bulk scripts to determine the correct Shrinkwrap file to track.
328+
const currentVariantJsonFilename: string = this._rushConfiguration.currentVariantJsonFilename;
329+
const currentVariantJson: ICurrentVariantJson = {
330+
variant: options.variant || null // tslint:disable-line:no-null-keyword
331+
};
347332

348-
const shrinkwrapIsUpToDate: boolean =
349-
this._createTempModulesAndCheckShrinkwrap({
350-
shrinkwrapFile,
351-
variant: options.variant
352-
})
353-
&& !options.recheckShrinkwrap;
354-
355-
if (!shrinkwrapIsUpToDate) {
356-
if (!options.allowShrinkwrapUpdates) {
357-
console.log();
358-
console.log(colors.red(`The ${this._shrinkwrapFilePhrase} is out of date.`
359-
+ ` You need to run "rush update".`));
360-
throw new AlreadyReportedError();
361-
}
362-
}
333+
// Determine if the variant is already current by updating current-variant.json.
334+
// If nothing is written, the variant has not changed.
335+
const variantIsUpToDate: boolean = !JsonFile.save(currentVariantJson, currentVariantJsonFilename, {
336+
onlyIfChanged: true
337+
});
363338

364-
return this._installCommonModules({
365-
shrinkwrapIsUpToDate,
366-
variantIsUpToDate,
367-
...options
368-
})
369-
.then(() => {
370-
if (!options.noLink) {
371-
const linkManager: BaseLinkManager = LinkManagerFactory.getLinkManager(this._rushConfiguration);
372-
return linkManager.createSymlinksForProjects(false);
373-
} else {
374-
console.log(os.EOL
375-
+ colors.yellow('Since "--no-link" was specified, you will need to run "rush link" manually.'));
376-
}
377-
});
378-
});
339+
if (options.variant) {
340+
console.log();
341+
console.log(colors.bold(`Using variant '${options.variant}' for installation.`));
342+
} else if (!variantIsUpToDate && !options.variant) {
343+
console.log();
344+
console.log(colors.bold('Using the default variant for installation.'));
345+
}
346+
347+
const shrinkwrapIsUpToDate: boolean = this._createTempModulesAndCheckShrinkwrap({
348+
shrinkwrapFile,
349+
variant: options.variant
350+
}) && !options.recheckShrinkwrap;
351+
352+
if (!shrinkwrapIsUpToDate) {
353+
if (!options.allowShrinkwrapUpdates) {
354+
console.log();
355+
console.log(colors.red(
356+
`The ${this._shrinkwrapFilePhrase} is out of date. You need to run "rush update".`
357+
));
358+
throw new AlreadyReportedError();
359+
}
360+
}
361+
362+
await this._installCommonModules({
363+
shrinkwrapIsUpToDate,
364+
variantIsUpToDate,
365+
...options
379366
});
367+
368+
if (!options.noLink) {
369+
const linkManager: BaseLinkManager = LinkManagerFactory.getLinkManager(this._rushConfiguration);
370+
await linkManager.createSymlinksForProjects(false);
371+
} else {
372+
console.log(
373+
os.EOL + colors.yellow('Since "--no-link" was specified, you will need to run "rush link" manually.')
374+
);
375+
}
380376
}
381377

382378
/**

0 commit comments

Comments
 (0)