diff --git a/ng-dev/release/publish/external-commands.ts b/ng-dev/release/publish/external-commands.ts index 402f9df3e..0299f27a5 100644 --- a/ng-dev/release/publish/external-commands.ts +++ b/ng-dev/release/publish/external-commands.ts @@ -97,3 +97,31 @@ export async function invokeYarnInstallCommand(projectDir: string): Promise { + try { + await spawn('yarn', ['check', '--integrity'], {cwd: projectDir, mode: 'silent'}); + info(green(' ✓ Confirmed dependencies from package.json match those in yarn.lock.')); + } catch (e) { + error(red(' ✘ Failed yarn integrity check, your installed dependencies are likely out of')); + error(red(' date. Please run `yarn install` to update your installed dependencies.')); + throw new FatalReleaseActionError(); + } +} + +/** + * Invokes the `yarn check --verify-tree` command in order to verify up to date dependencies. + */ +export async function invokeYarnVerifyTreeCheck(projectDir: string): Promise { + try { + await spawn('yarn', ['check', '--verify-tree'], {cwd: projectDir, mode: 'silent'}); + info(green(' ✓ Confirmed installed dependencies match those defined in package.json.')); + } catch (e) { + error(red(' ✘ Failed yarn verify tree check, your installed dependencies are likely out')); + error(red(' of date. Please run `yarn install` to update your installed dependencies.')); + throw new FatalReleaseActionError(); + } +} diff --git a/ng-dev/release/publish/index.ts b/ng-dev/release/publish/index.ts index 4d536c4e0..a11261de1 100644 --- a/ng-dev/release/publish/index.ts +++ b/ng-dev/release/publish/index.ts @@ -19,6 +19,7 @@ import {getNextBranchName, ReleaseRepoWithApi} from '../versioning/version-branc import {ReleaseAction} from './actions'; import {FatalReleaseActionError, UserAbortedReleaseActionError} from './actions-error'; import {actions} from './actions/index'; +import {invokeYarnIntegryCheck, invokeYarnVerifyTreeCheck} from './external-commands'; export enum CompletionState { SUCCESS, @@ -51,7 +52,8 @@ export class ReleaseTool { if ( !(await this._verifyNoUncommittedChanges()) || !(await this._verifyRunningFromNextBranch(nextBranchName)) || - !(await this._verifyNoShallowRepository()) + !(await this._verifyNoShallowRepository()) || + !(await this._verifyInstalledDependenciesAreUpToDate()) ) { return CompletionState.FATAL_ERROR; } @@ -144,6 +146,21 @@ export class ReleaseTool { return true; } + /** + * Verifiy that the install dependencies match the the versions defined in the package.json and + * yarn.lock files. + * @returns a boolean indicating success or failure. + */ + private async _verifyInstalledDependenciesAreUpToDate(): Promise { + try { + await invokeYarnVerifyTreeCheck(this._projectRoot); + await invokeYarnIntegryCheck(this._projectRoot); + return true; + } catch { + return false; + } + } + /** * Verifies that the local repository is not configured as shallow. * @returns a boolean indicating success or failure.