@@ -13,6 +13,20 @@ import {parse as parseYaml} from 'yaml';
1313import { ngDevNpmPackageName , workspaceRelativePackageJsonPath } from './constants.js' ;
1414import { Log } from './logging.js' ;
1515import { tryGetPackageId } from '@pnpm/dependency-path' ;
16+ import { determineRepoBaseDirFromCwd } from './repo-directory.js' ;
17+
18+ /** Whether ngDevVersionMiddleware verification has already occured. */
19+ let verified = false ;
20+ export async function ngDevVersionMiddleware ( ) {
21+ // TODO(josephperrott): remove this guard against running multiple times after
22+ // https://github.com/yargs/yargs/issues/2223 is fixed
23+ if ( verified ) {
24+ return ;
25+ }
26+ // TODO(josephperrott): Create an enforcement configuration option.
27+ await verifyNgDevToolIsUpToDate ( determineRepoBaseDirFromCwd ( ) ) ;
28+ verified = true ;
29+ }
1630
1731/**
1832 * Verifies that the `ng-dev` tool is up-to-date in the workspace. The check will compare
@@ -26,6 +40,10 @@ import {tryGetPackageId} from '@pnpm/dependency-path';
2640export async function verifyNgDevToolIsUpToDate ( workspacePath : string ) : Promise < boolean > {
2741 // The placeholder will be replaced by the `pkg_npm` substitutions.
2842 const localVersion = `0.0.0-{SCM_HEAD_SHA}` ;
43+ if ( localVersion === ( '0.0.0-{{BUILD_SCM_COMMIT_SHA}}' as string ) ) {
44+ Log . debug ( 'Skipping ng-dev version check as this is a locally generated version.' ) ;
45+ return true ;
46+ }
2947 const workspacePackageJsonFile = path . join ( workspacePath , workspaceRelativePackageJsonPath ) ;
3048 const pnpmLockFile = path . join ( workspacePath , 'pnpm-lock.yaml' ) ;
3149 const yarnLockFile = path . join ( workspacePath , 'yarn.lock' ) ;
@@ -36,12 +54,14 @@ export async function verifyNgDevToolIsUpToDate(workspacePath: string): Promise<
3654 ? getExpectedVersionFromPnpmLock ( workspacePackageJsonFile , pnpmLockFile )
3755 : getExpectedVersionFromYarnLock ( workspacePackageJsonFile , yarnLockFile ) ;
3856
39- Log . debug ( `Expecting the following ng-dev version: ${ expectedVersion } ` ) ;
57+ Log . debug ( 'Checking ng-dev version in lockfile and in the running script:' ) ;
58+ Log . debug ( ` Local: ${ localVersion } ` ) ;
59+ Log . debug ( ` Expected: ${ expectedVersion } ` ) ;
4060
4161 if ( localVersion !== expectedVersion ) {
42- Log . error ( ' ✘ Your locally installed version of the `ng-dev` tool is outdated and not' ) ;
43- Log . error ( ' matching with the version in the `package.json` file.' ) ;
44- Log . error ( ' Re-install the dependencies to ensure you are using the correct version.' ) ;
62+ Log . warn ( ' ⚠ Your locally installed version of the `ng-dev` tool is outdated and not' ) ;
63+ Log . warn ( ' matching with the version in the `package.json` file.' ) ;
64+ Log . warn ( ' Re-install the dependencies to ensure you are using the correct version.' ) ;
4565 return false ;
4666 }
4767
0 commit comments