diff --git a/libraries/rush-lib/src/logic/Autoinstaller.ts b/libraries/rush-lib/src/logic/Autoinstaller.ts index 8c35ea07b8..84fb06f243 100644 --- a/libraries/rush-lib/src/logic/Autoinstaller.ts +++ b/libraries/rush-lib/src/logic/Autoinstaller.ts @@ -265,6 +265,44 @@ export class Autoinstaller { } else { this._logIfConsoleOutputIsNotRestricted(Colorize.green('Already up to date.')); } + + // Write the last-install.flag file so that a subsequent "rush install-autoinstaller" + // will not perform a redundant install. + await this._createFlagsAsync(); + } + + private async _createFlagsAsync(): Promise { + const autoinstallerFullPath: string = this.folderFullPath; + + // Example: .../common/autoinstallers/my-task/.rush/temp + const lastInstallFlagPath: string = path.join( + autoinstallerFullPath, + RushConstants.projectRushFolderName, + 'temp' + ); + + const packageJsonPath: string = path.join(autoinstallerFullPath, 'package.json'); + const packageJson: IPackageJson = JsonFile.load(packageJsonPath); + + const lastInstallFlag: LastInstallFlag = new LastInstallFlag(lastInstallFlagPath, { + node: process.versions.node, + packageManager: this._rushConfiguration.packageManager, + packageManagerVersion: this._rushConfiguration.packageManagerToolVersion, + packageJson: packageJson, + rushJsonFolder: this._rushConfiguration.rushJsonFolder + }); + + // Create file: ../common/autoinstallers/my-task/.rush/temp/last-install.flag + await lastInstallFlag.createAsync(); + + // Example: ../common/autoinstallers/my-task/node_modules + const nodeModulesFolder: string = `${autoinstallerFullPath}/${RushConstants.nodeModulesFolderName}`; + const flagPath: string = `${nodeModulesFolder}/rush-autoinstaller.flag`; + + FileSystem.writeFile( + flagPath, + 'If this file is deleted, Rush will assume that the node_modules folder has been cleaned and will reinstall it.' + ); } private _logIfConsoleOutputIsNotRestricted(message?: string): void {